SharePoint の PerformancePoint Services 用にフィルター データ プロバイダーを作成する

PerformancePoint サービス のユーザー設定フィルター拡張機能においてデータ プロバイダー コンポーネントを作成する方法を説明します。

PerformancePoint サービス のカスタム データ プロバイダーとは

PerformancePoint Servicesでは、カスタム データ プロバイダーはフィルターの基になるデータ ソースからデータを取得し、データの使用方法を定義します。 最も重要なのは、データ プロバイダーは、フィルター コントロールで公開するデータ値と、フィルターの開始点として使用できるデータを指定することです。 データ プロバイダーには、ユーザーがフィルター コントロールから選択した値も格納され、フィルター コンシューマーに送信されます。 データ プロバイダーは、2 つの DataTable オブジェクトを使用してデータを整理および格納します。 詳細については、「フィルターの 概要」を参照してください。

フィルター データ プロバイダーを作成、構成、定義する方法を示す、次の手順と例は、カスタム オブジェクト サンプルSampleFilterDataProvider クラスに基づいています。 エディターは、ユーザーがレポートの名前と詳細を変更できるシン Web アプリケーションです。 クラスの完全なコードについては、「コード例: SharePoint でカスタム PerformancePoint Services フィルター用のデータ プロバイダーを作成する」を参照してください。

サンプルのデータ プロバイダーをテンプレートとして使用することをお勧めします。 サンプルは、PerformancePoint サービス API のオブジェクトを呼び出す方法と、PerformancePoint サービス 開発のベスト プラクティスを示します。

ユーザー設定の PerformancePoint サービス フィルター用のデータ プロバイダーの作成

  1. PerformancePoint サービス をインストールするか、拡張機能で使用する DLL (手順 3 で表示) をコンピューターにコピーします。 詳細については、「 クラス ライブラリを含む DLL」を参照してください。

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

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

  3. 以下の PerformancePoint サービス DLL をアセンブリ参照としてプロジェクトに追加します。

    • Microsoft.PerformancePoint.Scorecards.Client.dll
    • Microsoft.PerformancePoint.Scorecards.Server.dll

    拡張機能によっては、その他のプロジェクト参照が必要になることがあります。

  4. プロバイダー クラスで、以下の PerformancePoint サービス 名前空間のために using ディレクティブを追加します。

    拡張機能によっては、その他の using ディレクティブが必要になることがあります。

  5. CustomParameterDataProvider 基底クラスから継承します。

  6. データ プロバイダー名の文字列識別子を設定します。 これは、拡張機能を登録するときに web.config ファイルの CustomParameterDataProviders セクションに追加するキーと一致する必要があります。 詳細については、「 [方法] PerformancePoint Services の拡張機能を手動で登録する」を参照してください。

  7. GetId() メソッドをオーバーライドして、データ プロバイダーの識別子を返します。

  8. GetDisplayDataInternal メソッドをオーバーライドして、基になるデータ ソースのデータ値を格納する DataTable オブジェクトを定義します。 フィルターはこのメソッドを使用して、フィルター選択コントロールのデータを設定します。 表示データ テーブルには、以下の列名を含める必要があります。

    • キー レコードの一意識別子。 パフォーマンスとセキュリティ上の目的で、コントロールではキーのみが作成されます。 他の列からの値は作成されません。

    • Display フィルター コントロールに表示する値。

    • ParentKey この値は、ツリー コントロール内の階層データの配置に使用されます。

    • IsDefault この値は、フィルター永続化のために使用されます。

      ヒント

      列をさらに追加して、フィルターの機能を拡張できます。

    GetDisplayDataInternalDataSourceRegistry.GetDataSource(DataSource) メソッドを呼び出して、次のように、名前によってデータ ソースの種類を確認します。

    • データ ソースの SubTypeId プロパティを使用して、カスタム データ ソース型を参照します。これは、データ ソース拡張機能のPerformancePoint Services web.config ファイルに登録されている subType 属性と同じ値です。
    • SourceName プロパティを使用してネイティブ データ ソースを参照します。このプロパティは、DataSourceNames クラスからフィールドを返します。
  9. GetMessageData メソッドをオーバーライドして、フィルター コントロールからのユーザーの選択を格納します。 フィルターは、ユーザーの選択をコンシューマーに送信するときに、このメソッドを使用します。

コード例: SharePoint でカスタム PerformancePoint Services フィルターのデータ プロバイダーを作成する

次のコード例は、データ プロバイダーが Web サービスまたは Excel ワークシートから値を取得し、フィルターの表示データとメッセージ データの DataTable オブジェクトを返す方法を示しています。

このコード例をコンパイルする前に、「プロバイダー クラスを作成して設定するには」で説明しているように、開発環境を設定する必要があります。

using System.Data;
using Microsoft.PerformancePoint.Scorecards;
using Microsoft.PerformancePoint.Scorecards.Server.Extensions;

namespace Microsoft.PerformancePoint.SDK.Samples.SampleFilter
{
    // Represents the sample filter's data provider.
    public class SampleFilterDataProvider : CustomParameterDataProvider
    {

        // This value must match the key that you register for this extension
        // in the CustomParameterDataProviders section in the web.config file.
        private const string dataProviderName = "SampleFilterDataProvider";

        // Returns a table of all possible values (rows) for the
        // filter's beginpoints. The filter's BeginPoint property returns
        // one ParameterDefinition object.
        protected override DataTable GetDisplayDataInternal(ParameterDefinition parameterDefinition, RepositoryLocation parameterSourceLocation, object custom)
        {
            DataTable retrievedData = null;

            // Get the data source.
            DataSource parameterDataSource = SafeGetDataSource(parameterSourceLocation);
            if (null != parameterDataSource)
            {

                // Verify that the data source is the sample data source
                // or an Excel workbook, which are the types that the
                // sample supports.
                // If you modify these types of data source, you must make
                // the corresponding change in the filter's editor.
                if (parameterDataSource.SourceName == "WSTabularDataSource" || parameterDataSource.SourceName == DataSourceNames.ExcelWorkbook)
                {
                    IDataSourceProvider parameterDataSourceProvider =
                        DataSourceRegistry.GetDataSource(parameterDataSource);
                    if (null != parameterDataSourceProvider)
                    {
                        var dataSourceMetadata = parameterDataSourceProvider as IDataSourceMetadata;
                        if (null != dataSourceMetadata)
                        {

                            // Get the data and store it in the retrievedDataSet
                            // variable. The -1 parameter returns all records
                            // from the data source.
                            DataSet retrievedDataSet = dataSourceMetadata.GetPreviewDataSet(-1);

                            // Verify that the dataset contains data.
                            if (retrievedDataSet != null &&
                                retrievedDataSet.Tables != null &&
                                retrievedDataSet.Tables.Count > 0 &&
                                retrievedDataSet.Tables[0] != null &&
                                retrievedDataSet.Tables[0].Columns != null &&
                                retrievedDataSet.Tables[0].Columns.Count > 0 &&
                                retrievedDataSet.Tables[0].Rows != null &&
                                retrievedDataSet.Tables[0].Rows.Count > 0 &&
                                retrievedDataSet.Tables[0].Columns.Contains(parameterDefinition.KeyColumn))
                            {
                                retrievedData = retrievedDataSet.Tables[0];
                            }
                        }
                    }
                }

                if (null != retrievedData)
                {
                    // Name the display data table.
                    retrievedData.TableName = "ParamData";

                    // Verify that the table has the correct structure.
                    EnsureDataColumns(retrievedData, parameterDefinition);

                    bool firstRowSeen = false;
                    foreach (DataRow row in retrievedData.Rows)
                    {
                        // Set the ParentKeyColumn to null because the data
                        // does not have a hierarchical structure.
                        row[parameterDefinition.ParentKeyColumn] = null;

                        // Set the IsDefaultColumn column in the first row to true.
                        row[parameterDefinition.IsDefaultColumn] = !firstRowSeen;
                        if (!firstRowSeen)
                        {
                            firstRowSeen = true;
                        }
                    }

                    // Set the column visibility.
                    SetColumnVisibility(retrievedData);
                }
            }

            return retrievedData;
        }

        // Adds the ShowColumn extended property to a column in the display data table
        // and sets it to true. This exposes the column in Dashboard Designer as
        // a source value for the beginpoint.
        private static void SetColumnVisibility(DataTable displayData)
        {
            for (int i = 0; i < displayData.Columns.Count; i++)
            {
                if (!displayData.Columns[i].ExtendedProperties.Contains("ShowColumn"))
                {
                    displayData.Columns[i].ExtendedProperties.Add("ShowColumn", true);
                }
            }
        }

        // Verify that all required columns are in the data table.
        // The data table returned by this method is expected to contain a
        // Key, ParentKey, IsDefault, Display, and an arbitrary number of
        // Value columns.
        // The specific column names (except for Value columns) are defined
        // in the filter's ParameterDefinition object, which is referenced by
        // the filter's BeginPoint property.
        private static void EnsureDataColumns(DataTable dataTable, ParameterDefinition parameterDefinition)
        {
            if (!string.IsNullOrEmpty(parameterDefinition.KeyColumn) &amp;&amp; !dataTable.Columns.Contains(parameterDefinition.KeyColumn))
            {
                dataTable.Columns.Add(parameterDefinition.KeyColumn);
            }
            if (!string.IsNullOrEmpty(parameterDefinition.DisplayColumn) &amp;&amp; !dataTable.Columns.Contains(parameterDefinition.DisplayColumn))
            {
                dataTable.Columns.Add(parameterDefinition.DisplayColumn);
            }
            if (!string.IsNullOrEmpty(parameterDefinition.ParentKeyColumn) &amp;&amp; !dataTable.Columns.Contains(parameterDefinition.ParentKeyColumn))
            {
                dataTable.Columns.Add(parameterDefinition.ParentKeyColumn);
            }
            if (!string.IsNullOrEmpty(parameterDefinition.IsDefaultColumn) &amp;&amp; !dataTable.Columns.Contains(parameterDefinition.IsDefaultColumn))
            {
                dataTable.Columns.Add(parameterDefinition.IsDefaultColumn, typeof(bool));
            }
        }

        // Returns the unique string identifier of the data provider.
        // This value must match the key that you register for this extension
        // in the CustomParameterDataProviders section in the web.config file.
        public override string GetId()
        {
            return dataProviderName;
        }

        // Returns a table of rows that match the keys in the passed
        // ParameterMessage object.
        // This method is used by controls that accept parameters, such as
        // scorecard and reports. It can also apply a Post Formula.
        public override DataTable GetMessageData(RepositoryLocation providerLocation, ParameterMessage parameterMessage, RepositoryLocation parameterSourceLocation, ParameterMapping parameterMapping, object custom)
        {
            DataTable msgTable = null;

            // The ParameterMapping object contains information about
            // linked dashboard items.
            // The CustomData object is optionally used to store information
            // that is not stored in other properties.
            DataTable displayTable = GetDisplayDataInternal(parameterMessage, parameterSourceLocation, custom);

            if (null != displayTable)
            {
                msgTable = displayTable.Clone();
                for (int i = 0;i < parameterMessage.Values.Rows.Count; i++)
                {
                    for (int j = 0;j < displayTable.Rows.Count; j++)
                    {
                        if (!parameterMessage.Values.Rows[i][parameterMessage.KeyColumn].Equals(displayTable.Rows[j][parameterMessage.KeyColumn].ToString()))
                            continue;

                        msgTable.ImportRow(displayTable.Rows[j]);
                        break;
                    }
                }
            }

            return msgTable;
        }
    }
}

次の手順

データ プロバイダーとフィルター エディター (必要に応じてユーザー インターフェイスを含む) を作成した後、「方法: PerformancePoint Services拡張機能を手動で登録する」の説明に従って拡張機能をデプロイします

関連項目