SharePoint で PerformancePoint Services のレポート エディターを作成する

PerformancePoint サービス 用のカスタム レポート拡張機能のコンポーネントを作成する方法について説明します。

PerformancePoint サービス 用カスタム レポート エディターとは何か。

PerformancePoint Servicesでは、カスタム レポート エディターを使用すると、ユーザーはカスタム レポートのプロパティを設定できます。 レポート エディターは、スコアカードとフィルター プロバイダーからパラメーター値を受け取るレポート エンドポイントも初期化します。 エディターの要件と機能の詳細については、「 カスタム PerformancePoint Services オブジェクトのエディター」を参照してください。

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

サンプル エディターをテンプレートとして使用することをお勧めします。 サンプルは PerformancePoint サービス API のオブジェクトを呼び出す方法を示し、リポジトリ操作 (オブジェクトの作成、更新など) の呼び出しを容易にするヘルパー オブジェクトを提供し、PerformancePoint サービス 開発のためのベスト プラクティスを示します。

カスタム PerformancePoint サービス レポート用エディターの作成

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

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

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

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

    • Microsoft.PerformancePoint.Scorecards.Client.dll
    • Microsoft.PerformancePoint.Scorecards.ServerCommon.dll
    • Microsoft.PerformancePoint.Scorecards.Store.dll (ヘルパー クラスが使用)
    • Microsoft.SharePoint.dll (ヘルパー クラスが使用)

    サンプル エディターには、System.Web.dll と System.Web.Services.dll へのアセンブリ参照も含まれます。 拡張機能の機能によっては、その他のプロジェクト参照が必要になることがあります。

  4. サンプルから以下のクラスをプロジェクトに追加します。 エディターは、PerformancePoint サービス リポジトリを操作するためにこれらのヘルパークラスを使用します。

    • DataSourceConsumerHelper.cs
    • ExtensionRepositoryHelper.cs
    • ReportViewRepositoryHelper.cs
    • IDataSourceConsumer.cs

    注:

    サンプル レポートでは、データをフィルターから取得します。このため、DataSourceConsumerHelper または IDataSourceConsumer オブジェクトは使用しません。 ただし、レポートがPerformancePoint Services データ ソースからデータを取得する場合は、「SharePoint でPerformancePoint Servicesのフィルター エディターを作成する」の説明に従って、DataSourceConsumerHelper クラスによって公開されるメソッドを使用してデータ ソースを取得できます。

  5. エディター クラスで、以下の PerformancePoint サービス名前空間のために using ディレクティブを追加します。

    • Microsoft.PerformancePoint.Scorecards
    • Microsoft.PerformancePoint.Scorecards.ServerCommon

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

  6. エディターの実装をサポートする基本クラスから継承します。 サンプル レポート エディターは Web アプリケーションであるため、 Page クラスから継承します。 他の実装では、 UserControl クラス、 WebPart クラスなどの基本クラスから派生できます。

  7. ユーザーが表示または変更できるプロパティを表示するコントロールの変数を宣言します。 サンプル レポート エディターでは、最初にユーザー インターフェイス コンポーネント (ASPX ページ) で定義されている Web サーバー コントロールの変数を宣言します。 また、サンプル エディターは、変更をユーザーが送信できるようにするボタン コントロールも定義します。 次に、エディターは CreateChildControls() メソッドを呼び出して、コントロールをページで使用できるようにします。

    注:

    エディターは、ユーザー インターフェイスとは別のプログラミング ロジックを定義します。 エディターのユーザー インターフェイス コンポーネントを作成するための説明は、この文書の範囲外となります。

    サンプル レポート エディターでは、 Page_Load メソッドで手順 8 から 12 を実行します。 Page_Load は、変数とコントロールの初期化と検証、コントロールの設定、カスタム レポートおよびヘルパー オブジェクトの状態情報の保存にも使用されます。

  8. AllowUnsafeUpdates プロパティを true に設定します。 これにより、レポート エディターはフォーム POST 操作を使用せずにデータをリポジトリに書き込むことができます。

  9. クエリ文字列からパラメーターを取得し、それらを以下のコード例で示すローカル変数のための値として設定します。

    // The URL of the site collection that contains the PerformancePoint Services repository.
    string server = Request.QueryString[ClickOnceLaunchKeys.SiteCollectionUrl];
    
    // The location of the report in the repository.
    string itemLocation = Request.QueryString[ClickOnceLaunchKeys.ItemLocation];
    
    // The operation to perform: OpenItem or CreateItem.
    string action = Request.QueryString[ClickOnceLaunchKeys.LaunchOperation];
    

    注:

    クエリ文字列パラメーターの詳細については、「カスタム PerformancePoint Services オブジェクトのエディター」を参照してください。

  10. 以下のコード例に示すように、リポジトリを呼び出すための ReportViewRepositoryHelper オブジェクトを取得します。

    reportviewRepositoryHelper = new ReportViewRepositoryHelper();
    
  11. 以下のコード例に示すように、クエリ文字列パラメーターに基づいてレポートの場所を設定します。

    RepositoryLocation repositoryReportViewLocation = RepositoryLocation.CreateFromUriString(itemLocation);
    
  12. クエリ文字列から実行する操作 ( OpenItem または CreateItem) を取得し、カスタム レポートを取得または作成します。

    • カスタム レポートを取得するには、 ReportViewRepositoryHelper.Get メソッドを使用します。
    • カスタム レポートを作成するには、 ReportView() コンストラクターを使用し、レポートの NameRendererClassName 、および SubTypeId プロパティを定義します。

    SubTypeId はレポートの一意の識別子であり、PerformancePoint サービス web.config ファイルのカスタム レポートに指定する subType 属性と一致している必要があります。 RendererClassName は、レンダラーの Web サーバー コントロールを定義するクラスの完全修飾名です。 これをエディターに定義しない場合、この値は、web.config ファイルに指定されたレンダラー クラスに既定設定されます。

    if (ClickOnceLaunchValues.OpenItem.Equals(action, StringComparison.OrdinalIgnoreCase))
    {
      // Use the repository-helper object to retrieve the report.
      reportview = reportviewRepositoryHelper.Get(repositoryReportViewLocation);
      if (reportview == null)
      {
        displayError("Could not retrieve the report view for editing.");
        return;
      }
    }
    else if (ClickOnceLaunchValues.CreateItem.Equals(action, StringComparison.OrdinalIgnoreCase))
    {
      reportview = new ReportView
      {
        RendererClassName = typeof(SampleReportRenderer).AssemblyQualifiedName,
        SubTypeId = "SampleReportView"
      };
    }
    else
    {
      displayError("Invalid Action.");
      return;
    }
    

    注:

    既定では、ユーザーは PerformancePoint ダッシュボード デザイナーからのみカスタム オブジェクトを作成できます。 ユーザーがダッシュボード デザイナーの外部でカスタム オブジェクトを作成できるようにするには、リポジトリ内のコンテンツ タイプから CreateItem 要求をエディターに送信するメニュー項目を追加する必要があります。 詳細については、「 カスタム PerformancePoint Services オブジェクトのエディター」を参照してください。

  13. レポートのエンドポイントを定義します。これにより、レポートはフィルターとスコアカードからデータを受信できます。 サンプル レポート エディターでは、次のコード例に示すように、エンドポイントに必要なプロパティを定義します。

    if (0 == reportview.EndPoints.Count)
    {
      EndPoint endpoint = new EndPoint
      {
        Category = EndPointCategory.None,
        UniqueName = "SampleReportView_EndPoint",
    
        // The display name is shown to users in Dashboard Designer.
        // It represents the endpoint that can be connected
        // to a filter or scorecard.
        DisplayName = "Sample Report View EndPoint"
      };
    
      reportview.EndPoints.Add(endpoint);
    }
    

    サンプル エディターは、 VerifyReportView メソッドでエンドポイントを定義します。 また、 VerifyReportView を使用して、必要なプロパティが設定されていることを確認し、オプションの CustomData プロパティを定義します。これは、レポートの情報を格納するために使用できます。

  14. レポートをユーザー定義の変更で更新します。 サンプル レポート エディターの buttonOK_Click メソッドは、 ReportViewRepositoryHelper.Update メソッドを呼び出して、リポジトリでレポートの NameDescription プロパティを更新します。 buttonOK_Click は、コントロールの内容を検証したり、カスタム レポートとヘルパー オブジェクトの状態情報を取得するときにも使用されます。

    注:

    ユーザーは、カスタム オブジェクトの名前説明所有者 (責任者) プロパティを編集し、ダッシュボード デザイナーとPerformancePoint Services リポジトリから直接カスタム オブジェクトを削除できます。

コード例: SharePoint のカスタム PerformancePoint サービス レポートの作成、取得、更新

次のコード例では、カスタム レポートを作成、取得、および更新します。 このコードはエディターの分離コードクラスからのもので、ASPX ページで定義されているコントロールのプログラミング ロジックとして使用できます。

このコード例をコンパイルする前に、「カスタム PerformancePoint Services レポートのエディターを作成する」の説明に従って開発環境を構成する必要があります。

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.PerformancePoint.Scorecards;
using Microsoft.PerformancePoint.Scorecards.ServerCommon;

namespace Microsoft.PerformancePoint.SDK.Samples.SampleReport
{

    // Represents the class that defines the sample report editor.
    public class SampleReportViewEditor : Page
    {

        // Declare private variables for the ASP.NET controls defined in the user interface.
        // The sample's user interface is an ASPX page that defines the controls in HTML.
        private TextBox textboxName;
        private TextBox textboxDescription;
        private Label labelErrorMessage;
        private Button buttonOK;

        // Make the controls available to this class.
        protected override void CreateChildControls()
        {
            base.CreateChildControls();

            if (null == textboxName)
                textboxName = FindControl("textboxName") as TextBox;
            if (null == textboxDescription)
                textboxDescription = FindControl("textboxDescription") as TextBox;
            if (null == labelErrorMessage)
                labelErrorMessage = FindControl("labelErrorMessage") as Label;
            if (null == buttonOK)
                buttonOK = FindControl("buttonOK") as Button;
        }

        // Handles the Load event of the Page control.
        // Methods that use a control variable should call the Control.EnsureChildControls
        // method before accessing the variable for the first time.
        protected void Page_Load(object sender, EventArgs e)
        {

            // Required to enable custom report and filter editors to
            // write data to the repository.
            ServerUtils.AllowUnsafeUpdates = true;

            // Initialize controls the first time the page loads only.
            if (!IsPostBack)
            {
                EnsureChildControls();
                ReportViewRepositoryHelper reportviewRepositoryHelper = null;
                try
                {

                    // Get information from the query string parameters.
                    string server = Request.QueryString[ClickOnceLaunchKeys.SiteCollectionUrl];
                    string itemLocation = Request.QueryString[ClickOnceLaunchKeys.ItemLocation];
                    string action = Request.QueryString[ClickOnceLaunchKeys.LaunchOperation];

                    // Validate the query string parameters.
                    if (string.IsNullOrEmpty(server) ||
                        string.IsNullOrEmpty(itemLocation) ||
                        string.IsNullOrEmpty(action))
                    {
                        displayError("Invalid URL.");
                        return;
                    }

                    // Retrieve the repository-helper object.
                    reportviewRepositoryHelper =
                        new ReportViewRepositoryHelper();

                    // Set the report location by using the location from the query string.
                    RepositoryLocation repositoryReportViewLocation = RepositoryLocation.CreateFromUriString(itemLocation);

                    ReportView reportview;

                    // Retrieve or create the report object, depending on the operation
                    // passed in the query string (OpenItem or CreateItem).
                    if (ClickOnceLaunchValues.OpenItem.Equals(action, StringComparison.OrdinalIgnoreCase))
                    {

                        // Retrieve the report object by using the repository-helper object.
                        reportview = reportviewRepositoryHelper.Get(repositoryReportViewLocation);
                        if (reportview == null)
                        {
                            displayError("Could not retrieve the report view for editing.");
                            return;
                        }
                    }
                    else if (ClickOnceLaunchValues.CreateItem.Equals(action, StringComparison.OrdinalIgnoreCase))
                    {

                        // Create a report view.
                        // CreateItem requests can be sent from a SharePoint list, but
                        // you must create a custom menu item to send the request.
                        // Dashboard Designer can send edit requests only.
                        reportview = new ReportView
                        {
                            RendererClassName = typeof(SampleReportRenderer).AssemblyQualifiedName,
                            SubTypeId = "SampleReportView"
                        };
                    }
                    else
                    {
                        displayError("Invalid Action.");
                        return;
                    }

                    VerifyReportView(reportview);

                    // Save the original report and helper objects across page postbacks.
                    ViewState["action"] = action;
                    ViewState["reportview"] = reportview;
                    ViewState["reportviewrepositoryhelper"] = reportviewRepositoryHelper;
                    ViewState["itemlocation"] = itemLocation;

                    // Populate the child controls.
                    textboxName.Text = reportview.Name.ToString();
                    textboxDescription.Text = reportview.Description.ToString();
                }
                catch (Exception ex)
                {
                    displayError("An error has occurred. Please contact your administrator for more information.");
                    if (reportviewRepositoryHelper != null)
                    {

                        // Add the exception detail to the server event log.
                        reportviewRepositoryHelper.HandleException(ex);
                    }
                }
            }
        }

        // Handles the Click event of the buttonOK control.
        protected void buttonOK_Click(object sender, EventArgs e)
        {
            EnsureChildControls();

            // Verify that the textboxName control contains a value.
            if (string.IsNullOrEmpty(textboxName.Text))
            {
                labelErrorMessage.Text = "A report view name is required.";
                return;
            }

            // Clear any pre-existing error message.
            labelErrorMessage.Text = string.Empty;

            // Retrieve the report and helper objects from view state.
            string action = (string)ViewState["action"];
            string itemLocation = (string) ViewState["itemlocation"];
            ReportView reportview = (ReportView)ViewState["reportview"];
            ReportViewRepositoryHelper reportviewRepositoryHelper = (ReportViewRepositoryHelper)ViewState["reportviewrepositoryhelper"];

            // Update the report object with form changes.
            reportview.Name.Text = textboxName.Text;
            reportview.Description.Text = textboxDescription.Text;

            // Save the report object to the PerformancePoint Services repository.
            try
            {
                reportview.Validate();
                if (ClickOnceLaunchValues.CreateItem.Equals(action, StringComparison.OrdinalIgnoreCase))
                {
                    reportview.CreatedDate = DateTime.Now;
                    ReportView newReportView = reportviewRepositoryHelper.Create(
                        string.IsNullOrEmpty(reportview.Location.ItemUrl) ? itemLocation : reportview.Location.ItemUrl,
                        reportview);
                    ViewState["reportview"] = newReportView;
                    ViewState["action"] = ClickOnceLaunchValues.OpenItem;
                }
                else
                {
                    reportviewRepositoryHelper.Update(reportview);
                }
            }
            catch (Exception ex)
            {
                displayError("An error has occurred. Please contact your administrator for more information.");
                if (reportviewRepositoryHelper != null)
                {
                    // Add the exception detail to the server event log.
                    reportviewRepositoryHelper.HandleException(ex);
                }
            }
        }

        // Displays the error string in the labelErrorMessage label.
        void displayError(string msg)
        {
            EnsureChildControls();

            labelErrorMessage.Text = msg;

            // Disable the OK button because the page is in an error state.
            buttonOK.Enabled = false;
            return;
        }

        // Verifies that the properties for the report object are set.
        static void VerifyReportView(ReportView reportview)
        {

            // Verify that all required properties are set.
            if (string.IsNullOrEmpty(reportview.SubTypeId))
            {

                // This value must match the subType attribute specified
                // in the web.config file.
                reportview.SubTypeId = "SampleReportView";
            }

            if (string.IsNullOrEmpty(reportview.RendererClassName))
            {
                reportview.RendererClassName = typeof (SampleReportRenderer).AssemblyQualifiedName;
            }

            // Reports are consumers and do not use provider endpoints.
           reportview.BeginPoints.Clear();

            // If there are no consumer endpoints, create one so we can connect a filter or a scorecard to the report.
            if (0 == reportview.EndPoints.Count)
            {
                EndPoint endpoint = new EndPoint
                {
                    Category = EndPointCategory.None,
                    UniqueName = "SampleReportView_EndPoint",

                    // The display name is shown to users in Dashboard
                    // Designer to represent the endpoint that can be
                    // connected to a filter or scorecard.
                    DisplayName = "Sample Report View EndPoint"
                };

                reportview.EndPoints.Add(endpoint);
            }

            // Set optional properties for reports.
            reportview.CustomData = "You can use this property to store custom information for this filter as a string or a serialized object.";
        }
    }
}

次の手順

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

関連項目