如何:为 PerformancePoint Services 报告创建呈现器
上次修改时间: 2011年8月30日
在 Microsoft SharePoint Server 2010 中的 PerformancePoint Services 中,报告呈现器是用于在 Web 部件中呈现报告的 Web 服务器控件。呈现器可为报告可视化(如表和图)编写 HTML,提供用于处理报告参数的逻辑以及从存储库中检索报告对象。
适用范围: SharePoint Server 2010
本主题中的过程和代码示例基于自定义对象示例中的 SampleReportRenderer 类。该呈现器会呈现一个表并用从链接的筛选器接收的值填充该表。本主题的中"示例"一节提供了该类的完整代码。
备注
建议您将示例报告呈现器用作模板。该示例说明如何调用 PerformancePoint Services API 中的对象,并演示针对 PerformancePoint Services 开发的最佳实践。
可通过执行两个基本过程来创建报告呈现器,如下所示:
创建和配置呈现器类
定义呈现器功能
若要创建自定义呈现器,请先创建呈现器类。
创建和配置呈现器类
安装 PerformancePoint Services,或将您的扩展使用的 DLL(步骤 3 中已列出)复制到计算机上。有关详细信息,请参阅 开发方案中使用的 PerformancePoint Services DLL。
在 Visual Studio 中创建 C# 类库。如果已经为您的扩展创建了类库,则添加一个新的 C# 类。
添加下面的 PerformancePoint Services DLL 作为对项目的程序集引用:
Microsoft.PerformancePoint.Scorecards.Client.dll
Microsoft.PerformancePoint.Scorecards.Server.dll
Microsoft.PerformancePoint.Scorecards.Store.dll
根据扩展的功能不同,可能需要其他项目引用。
在呈现器类中,为以下 PerformancePoint Services 命名空间添加 using 指令:
根据扩展的功能不同,可能需要其他 using 指令。
从 ParameterizableControl 基类继承。
在创建和配置呈现器类后,必须定义呈现器的功能。
定义呈现器功能
重写 GetElement 方法,以从存储库中检索报告对象。
重写 SetData 方法,以设置报告数据集并检索传入的参数值。
重写 Render 方法,以呈现报告可视化的 HTML。
**下一步:**在创建报表呈现器和报表编辑器(如果需要,包括其用户界面)后,部署扩展,如如何:手动注册 PerformancePoint Services 扩展中所述。有关如何安装和配置示例报表扩展的说明,请参阅代码示例:自定义报表、筛选器和表格数据源对象中的"安装示例报表、筛选器和数据源对象"一节。
示例
以下代码示例中的类将创建一个报告呈现器,该呈现器显示从示例筛选器传入的库存信息。
备注
您必须先按创建和配置呈现器类中所述配置开发环境,然后才能编译此代码示例。
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) ? " " : 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()) ? " " : 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);
}
}
}
编译代码
您必须先按创建和配置呈现器类中所述配置开发环境,然后才能编译此代码示例。
安全性
您必须使用强名称对 DLL 进行签名。此外,确保 DLL 引用的所有程序集都具有强名称。有关如何使用强名称对程序集进行签名以及如何创建公钥/私钥对的信息,请参阅How to: Create a Public/Private Key Pair。
请参阅
任务
如何:为 PerformancePoint Services 报告创建编辑器