SharePoint で PerformancePoint Services のレポート レンダラーを作成する
PerformancePoint サービス のカスタム レポート拡張でレンダラー コンポーネントを作成する方法を説明します。
PerformancePoint サービス のカスタム レポート レンダラーとは
PerformancePoint Servicesでは、カスタム レポート レンダラーは Web パーツにカスタム レポートを表示する Web サーバー コントロールです。 レンダラーは、レポート可視化 (テーブルやグラフなど) の HTML を記述し、レポートのパラメーターを処理するロジックを提供し、リポジトリーからレポート オブジェクトを取得します。
次に示す手順とコード サンプルは、カスタム オブジェクト サンプルからの SampleReportRenderer クラスに基づいています。 レンダラーはテーブルをレンダリングし、リンクされたフィルターから受信した値をテーブルに取り込みます。 クラスの完全なコードについては、「コード例: SharePoint でカスタム PerformancePoint Services レポート用のレンダラーを作成する」を参照してください。
テンプレートとして、サンプル レポート レンダラーを使用するようお勧めします。 サンプルは、PerformancePoint サービス API のオブジェクトを呼び出す方法と、PerformancePoint サービス 開発のベスト プラクティスを示しています。
カスタム PerformancePoint サービス レポートのレンダラーの作成
PerformancePoint サービス をインストールするか、拡張機能で使用する DLL (手順 3 で表示) をコンピューターにコピーします。 詳細については、「 クラス ライブラリを含む DLL」を参照してください。
Visual Studio で、C# クラス ライブラリを作成します。 拡張機能のためのクラス ライブラリを既に作成している場合、新しい C# クラスを追加します。
DLL には厳密な名前で署名する必要があります。 さらに、DLL によって参照されたすべてのアセンブリが厳密な名前を持つことを確認してください。 厳密な名前でアセンブリに署名する方法と、公開キーと秘密キーのペアを作成する方法については、「 方法: 公開/秘密キー ペアを作成する」を参照してください。
以下の PerformancePoint サービス DLL をアセンブリ参照としてプロジェクトに追加します。
- Microsoft.PerformancePoint.Scorecards.Client.dll
- Microsoft.PerformancePoint.Scorecards.Server.dll
- Microsoft.PerformancePoint.Scorecards.Store.dll
拡張機能の機能によっては、その他のプロジェクト参照が必要になることがあります。
レンダラー クラスで、次の PerformancePoint サービス 名前空間の using ディレクティブを追加します。
- Microsoft.PerformancePoint.Scorecards
- Microsoft.PerformancePoint.Scorecards.Server.Extensions
- Microsoft.PerformancePoint.Scorecards.Store
拡張機能に応じ、その他の using ディレクディブが必要になることがあります。
ParameterizableControl 基底クラスから継承します。
GetElement メソッドをオーバーライドして、リポジトリからレポート オブジェクトを取得します。
SetData メソッドをオーバーライドして、レポート データセットを設定し、受信パラメーター値を取得します。
レポート視覚化の HTML をレンダリングするには、 Render メソッドをオーバーライドします。
コード例: SharePoint でカスタム PerformancePoint サービス レポートのレンダラーを作成する
以下のコードサンプルのクラスは、サンプル フィルターから渡される株価情報を表示するレポート レンダラーを作成します。
このコード例をコンパイルする前に、「レンダラー クラスを作成して構成するには」で説明されているとおりに開発環境を設定する必要があります。
using System;
using System.Collections.Generic;
using System.Data;
using System.Web.UI;
using Microsoft.PerformancePoint.Scorecards;
using Microsoft.PerformancePoint.Scorecards.Server.Extensions;
using Microsoft.PerformancePoint.Scorecards.Store;
namespace Microsoft.PerformancePoint.SDK.Samples.SampleReport
{
// The class that define the sample report's renderer.
public class SampleReportRenderer : ParameterizableControl
{
private ReportView reportView;
private ReportView ReportView
{
get
{
// The GetElement method is used internally by this property, which is used
// in turn by the SetData method.
reportView = GetElement(ElementLocation) as ReportView;
return reportView;
}
}
// Initializes the current instance according to a standard interface. This method
// sets up the dataset.
public override void SetData(RepositoryLocation elementLocation, string resourcePath, string targetControlId, BIDataContainer dataContainer, bool accessibilityMode)
{
// The renderer must call the base implementation of the SetData method
// to set report properties.
base.SetData(elementLocation, resourcePath, targetControlId, dataContainer, accessibilityMode);
if (null != ReportView)
{
// If the report view's custom data represents a serialized object, deserialize
// it, and then use it to access a data source or other object.
string customData = ReportView.CustomData;
if (!string.IsNullOrEmpty(customData))
{
System.Diagnostics.Debug.WriteLine(string.Format("Report view '{0}' has the following custom data: {1}", ReportView.Name.Text, customData));
}
// Iterate through the user's selections sent by the filter.
// The MultiSelectTreeControl filter control can send multiple
// rows of data but other native controls send one message only.
foreach (ParameterMessage message in BIDataContainer.ParameterMessages)
{
// This line demonstrates how to do something with each incoming parameter message.
System.Diagnostics.Debug.WriteLine(string.Format("Parameter message: {0}", message.DisplayName));
}
}
}
// Render page content using the specified writer.
protected override void Render(HtmlTextWriter output)
{
try
{
if (null != ReportView && !string.IsNullOrEmpty(ReportView.CustomData))
{
output.RenderBeginTag(HtmlTextWriterTag.P);
output.RenderBeginTag(HtmlTextWriterTag.B);
// This line shows how to retrieve the content of the
// report's optional CustomData property. CustomData can store
// information that the report does not store elsewhere.
output.Write(string.Format("The ReportView "{0}" has CustomData information. The CustomData is "{1}"",
ReportView.Name.Text, ReportView.CustomData));
output.RenderEndTag(); // B
output.RenderEndTag(); // P
}
Dictionary<Guid, ParameterMessage> parametersIndex =
IndexParameterMessages(BIDataContainer.ParameterMessages.ToArray());
// Each connection gets a unique identifier.
foreach (Guid parameterMappingId in parametersIndex.Keys)
{
ParameterMessage message = parametersIndex[parameterMappingId];
output.RenderBeginTag(HtmlTextWriterTag.Table);
output.AddAttribute(HtmlTextWriterAttribute.Style, "ms-partline");
output.RenderBeginTag(HtmlTextWriterTag.Tr);
output.AddAttribute(HtmlTextWriterAttribute.Colspan, "5");
output.RenderBeginTag(HtmlTextWriterTag.Td);
output.RenderBeginTag(HtmlTextWriterTag.B);
output.Write(string.Format("EndPoint name is: {0}", message.Values.TableName));
output.RenderEndTag(); // B
output.RenderEndTag(); // Td
output.RenderEndTag(); // Tr
output.AddAttribute(HtmlTextWriterAttribute.Style, "\\"border-bottom:solid 10px #ffdd00; background:PapayaWhip\\"");
output.RenderBeginTag(HtmlTextWriterTag.Tr);
// Read the message.Values data table and print the column names.
foreach (DataColumn col in message.Values.Columns)
{
output.RenderBeginTag(HtmlTextWriterTag.Td);
output.Write(string.IsNullOrEmpty(col.Caption) ? "&nbsp;" : col.Caption);
output.RenderEndTag();
}
output.RenderEndTag(); // Tr
// Print the data from the Values property, which is a data table.
foreach (DataRow row in message.Values.Rows)
{
output.RenderBeginTag(HtmlTextWriterTag.Tr);
for (int i = 0; i < message.Values.Columns.Count; i++)
{
output.RenderBeginTag(HtmlTextWriterTag.Td);
output.Write(string.IsNullOrEmpty(row[i].ToString()) ? "&nbsp;" : row[i].ToString());
output.RenderEndTag();
}
output.RenderEndTag(); // Tr
}
output.RenderEndTag(); // table
}
}
catch (Exception e)
{
output.RenderBeginTag(HtmlTextWriterTag.H1);
output.Write("Error! An exception has occurred!");
output.RenderEndTag();
output.RenderBeginTag(HtmlTextWriterTag.P);
output.Write(e.Message);
output.RenderEndTag();
output.RenderBeginTag(HtmlTextWriterTag.P);
output.Write(e.StackTrace);
output.RenderEndTag();
}
}
// Get the report object.
protected override Element GetElement(RepositoryLocation elementLocation)
{
ReportView rv = null;
if (!RepositoryLocation.IsNullOrEmpty(elementLocation))
{
rv = SPDataStore.GlobalDataStore.GetReportViewForExecution(elementLocation);
}
return (rv);
}
}
}
次の手順
レポート レンダラーとレポート エディター (必要に応じてユーザー インターフェイスを含む) を作成した後、「方法: PerformancePoint Services拡張機能を手動で登録する」の説明に従って拡張機能をデプロイします。