PerformancePoint Services のスコアカード変換を作成する

最終更新日: 2011年8月30日

適用対象: SharePoint Server 2010

Microsoft SharePoint Server 2010 の PerformancePoint Services のスコアカード変換では、ダッシュボード内でスコアカード ビューがレンダリングされる前に、スコアカード ビューの外観、コンテンツ、または機能が変換されます。

適用先: PerformancePoint Services for SharePoint Server (Enterprise バージョン)

注意

スコアカード変換のサンプルをカスタム変換のテンプレートとして使用することをお勧めします。このサンプルは、PerformancePoint Services API のオブジェクトを呼び出す方法、および PerformancePoint Services 開発のベスト プラクティスを示しています。

スコアカードの変換の作成

以下の手順は、スコアカード ビューに列を追加する AddColumnTransform サンプルに基づいています。クラスの完全なコードは、このトピックの最初の例で提供されています。

スコアカード変換を作成するには

  1. PerformancePoint Services をインストールするか、PerformancePoint Services と共にインストールされた DLL を、使用するコンピューターにコピーします。詳細については、「開発シナリオで使用される PerformancePoint Services DLL」を参照してください。

  2. Visual Studio で、C# クラス ライブラリを作成します。拡張機能のためのクラス ライブラリを既に作成している場合、新しい C# クラスを追加します。

  3. Microsoft.PerformancePoint.Scorecards.Client.dll をアセンブリ リファレンスとしてプロジェクトに追加します。

  4. 次の名前空間に対して using ディレクティブを追加します。

    • Microsoft.PerformancePoint.Scorecards

    • Microsoft.PerformancePoint.Scorecards.Extensions

    • System.Collections.Generic

  5. IGridViewTransform インターフェイスを実装します。

  6. GetId メソッドを上書きして、変換の文字列識別子を返すようにします。GetId は、PerformancePoint Services web.config ファイルで変換用に登録されている key 属性と同じ文字列を返す必要があります。スコアカード変換の登録の詳細については、「[方法] PerformancePoint Services の拡張機能を手動で登録する」を参照してください。

  7. GetTransformType メソッドを上書きして、変換の実行タイミングを指定します。変換を実行するポイントは、GridViewTransformType 列挙に定義されているそのタイプ (PreQuery、PostQuery、または PreRender) によって決まります。詳細については、「PerformancePoint Services スコアカード変換の概要」を参照してください。

  8. Execute メソッドを上書きして、スコアカードを変換する方法を定義します。以下のコード例は、スコアカード ビューに列を追加する方法と、空のスコアカード セルの書式設定を変更する方法を示します。

DLL の署名と構築を行った後、「[方法] PerformancePoint Services の拡張機能を手動で登録する」の説明のとおりに拡張機能をインストールします。

例 1: スコアカード ビューに列を追加する

次のコード例は、スコアカード変換のサンプルからのものです。このコード例では、列のリーフ レベルで KPI を含むレンダリングされたスコアカード ビューに列を追加する PreQuery 変換が作成されます (スコアカード ビューの KPI の下にメンバーが含まれる場合、列は追加されません)。

注意

このコード例をコンパイルできるようにするには、「スコアカード変換を作成するには」の手順で説明されているように開発環境を設定する必要があります。

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: 空のスコアカード セルの書式設定を変更する

以下のコード例では、空のスコアカード セルにグレーの背景色を適用する PreQuery 変換を作成します。

注意

このコード例をコンパイルできるようにするには、「スコアカード変換を作成するには」の手順で説明されているように開発環境を設定する必要があります。さらに、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;
                }
            }
        }
    }
}

コードのコンパイル

このコード例をコンパイルできるようにするには、「スコアカード変換を作成するには」の手順で説明されているように開発環境を設定する必要があります。

セキュリティ

DLL には厳密な名前で署名する必要があります。さらに、DLL によって参照されたすべてのアセンブリが厳密な名前を持つことを確認してください。厳密な名前を使用してアセンブリに署名する方法の詳細、および公開/秘密キーのペアを作成する方法の詳細については、「How to: Create a Public/Private Key Pair」を参照してください。

関連項目

概念

PerformancePoint Services スコアカード変換の概要

その他の技術情報

PerformancePoint Services スコアカード

PerformancePoint Services に関するトピック集

SharePoint Server 2010 の PerformancePoint Services のコード例