SharePoint で PerformancePoint Services のスコアカード変換を作成する
SharePoint で PerformancePoint Services 用のカスタムのスコアカード変換を作成する方法について説明します。
PerformancePoint Services のスコアカード変換とは
PerformancePoint サービス のスコアカード変換では、スコアカード ビューをダッシュボードに表示する前に、その外観、コンテンツ、または機能を変更できます。 詳細については、「 変換の種類」を参照してください。
PerformancePoint サービス スコアカードの変換を作成する
PerformancePoint Servicesをインストールするか、PerformancePoint Servicesでインストールされている DLL をコンピューターにコピーします。 詳細については、「 クラス ライブラリを含む DLL」を参照してください。
Visual Studio で、C# クラス ライブラリを作成します。 拡張機能用に既にクラス ライブラリを作成済みの場合は、新しい C# クラスを追加します。
厳密な名前で DLL に署名し、DLL によって参照されるすべてのアセンブリに厳密な名前が付けられていることを確認する必要があります。 厳密な名前でアセンブリに署名する方法と、公開キーと秘密キーのペアを作成する方法については、「 方法: 公開/秘密キー ペアを作成する」を参照してください。
Microsoft.PerformancePoint.Scorecards.Client.dll をアセンブリ参照としてプロジェクトに追加します。
次の名前空間について using ディレクティブを追加します。
Microsoft.PerformancePoint.Scorecards
Microsoft.PerformancePoint.Scorecards.Extensions
System.Collections.Generic
IGridViewTransform インターフェイスを実装します。
GetId メソッドをオーバーライドして、変換の文字列識別子を返します。 GetId は、PerformancePoint サービス web.config ファイルで変換用に登録されている key 属性と同じ文字列を返す必要があります。 スコアカード変換の登録の詳細については、 [方法] PerformancePoint Services の拡張機能を手動で登録する を参照してください。
GetTransformType メソッドをオーバーライドして、変換を実行するタイミングを指定します。 変換を実行するポイントは、 GridViewTransformType 列挙に定義されているそのタイプ ( PreQuery、 PostQuery、または PreRender) によって決まります。 詳細については、「 変換の種類」を参照してください。
Execute メソッドをオーバーライドして、スコアカードを変換する方法を定義します。 以下のコード例は、スコアカード ビューに列を追加する方法と、空のスコアカード セルの書式設定を変更する方法を示します。
DLL に署名してビルドした後、「方法: PerformancePoint Services拡張機能を手動で登録する」の説明に従って拡張機能をインストールします。
コード例 1: PerformancePoint サービス スコアカードに列を追加する
次のコード例では、列リーフ レベルで KPI を含むレンダリングされたスコアカード ビューに列を追加する PreQuery 変換を作成します。 (スコアカード ビューに KPI の下にメンバーが含まれている場合、列は追加されません)。
このコード例をコンパイルする前に、「PerformancePoint Services スコアカードの変換を作成する」の説明に従って開発環境を構成する必要があります。
using System;
using System.Collections.Generic;
using Microsoft.PerformancePoint.Scorecards;
using Microsoft.PerformancePoint.Scorecards.Extensions;
namespace Microsoft.PerformancePoint.SDK.Samples.ScorecardTransforms.PreQuery
{
// Represents the class that adds columns of data to a scorecard view.
public class AddColumnTransform : IGridViewTransform
{
// Set transform type to PreQuery.
public GridViewTransformType GetTransformType()
{
return GridViewTransformType.PreQuery;
}
// Return the string identifier of your transform. This value must
// match the key attribute registered in the web.config file.
public string GetId()
{
return "AddColumn";
}
// Run the transform to add a column.
public void Execute(GridViewData viewData, PropertyBag parameters, IGlobalCache cache)
{
// Verify the scorecard definition.
if (viewData == null)
{
throw new ArgumentException("Parameter cannot be null", "viewData");
}
List<GridHeaderItem> leafRowHeaders = viewData.RootRowHeader.GetAllLeafHeadersInTree();
foreach (GridHeaderItem rowHeader in leafRowHeaders)
{
if (rowHeader.HeaderType == ScorecardNodeTypes.Kpi)
{
Kpi kpi = cache.GetKpi(rowHeader.LinkedKpiLocation);
if (kpi != null && viewData.RootColumnHeader != null)
{
// Create the column header and add it to the root.
GridHeaderItem theNewColumn = GridHeaderItem.CreateDetailsHeader(kpi.Owner.DisplayName);
// Set the GUIDs for the data headers.
// Setting the DefinitionGuid property to the
// same value as the root column header enables
// Dashboard Designer to display the scorecard.
// Note: Do not try to modify or delete the new
// column from within Dashboard Designer.
theNewColumn.DefinitionGuid = viewData.RootColumnHeader.DefinitionGuid;
theNewColumn.Parent = viewData.RootColumnHeader;
theNewColumn.Guid = new Guid();
// Insert the column at the end of the collection
// of child elements.
if (viewData.RootColumnHeader.Children.Count != 0)
{
viewData.RootColumnHeader.Children.Insert(viewData.RootColumnHeader.Children.Count, theNewColumn);
}
break;
}
}
}
viewData.RootColumnHeader.LinkAndIndexTreeFromRoot();
}
}
}
コード例 2: PerformancePoint サービス スコアカードの空のセルの書式設定を変更する
次のコード例では PreQuery 変換を作成します。この変換は、空のスコアカード セルに灰色の背景色を適用します。
注:
このコード例をコンパイルする前に、「PerformancePoint Services スコアカードの変換を作成する」の説明に従って開発環境を構成する必要があります。 さらに、System.Drawing アセンブリへの参照をプロジェクトに追加する必要があります。
using System;
using System.Collections.Generic;
using Microsoft.PerformancePoint.Scorecards;
using Microsoft.PerformancePoint.Scorecards.Extensions;
namespace Microsoft.PerformancePoint.SDK.Samples
{
// Represents a transform that applies a grey background color to empty scorecard cells.
public class GreyEmptiesTransform : IGridViewTransform
{
// Set the transform type to "PreRender".
public GridViewTransformType GetTransformType()
{
return GridViewTransformType.PreRender;
}
// Return the string identifier of the transform.
public string GetId()
{
return "GreyEmptyCells";
}
// Run the transform.
public void Execute(GridViewData viewData, PropertyBag parameters, IGlobalCache cache)
{
// Validate parameters.
if (viewData == null)
{
throw new ArgumentException("Parameter cannot be null", "viewData");
}
// Get the headers under the root row header.
List<GridHeaderItem> nonLeafRowHeaders = viewData.RootRowHeader.GetAllHeadersInTree();
// Get the leaf headers under the root column header.
List<GridHeaderItem> leafColumnHeaders = viewData.RootColumnHeader.GetAllLeafHeadersInTree();
foreach (GridHeaderItem rowHeader in nonLeafRowHeaders)
{
foreach (GridHeaderItem columnHeader in leafColumnHeaders)
{
// Get scorecard cells.
GridCell cell = viewData.Cells[rowHeader, columnHeader];
if (cell.IsCellEmpty || string.IsNullOrEmpty(cell.ActualValue.ToString()))
{
GridFormatInfo emptyFormat = new GridFormatInfo(viewData.DefaultCellFormatInfo);
emptyFormat.BackColor = new GridColor(System.Drawing.Color.Gray);
cell.FormatInfo = emptyFormat;
}
viewData.Cells[rowHeader, columnHeader] = cell;
}
}
}
}
}