Compartir a través de


Crear representaciones de informes para PerformancePoint Services en SharePoint

Aprenda a crear el componente de representación en una extensión de informe personalizada para PerformancePoint Services.

¿Qué son los representadores de informes personalizados para PerformancePoint Services?

En PerformancePoint Services, los representadores de informes personalizados son controles de servidor web que representan un informe personalizado en un elemento web. Un representador escribe el HTML para la visualización del informe (por ejemplo, una tabla o un gráfico), proporciona lógica para controlar parámetros de informes y recupera el objeto informe del repositorio.

Los siguientes procedimientos y ejemplos de código están basados en la clase SampleReportRenderer de la muestra de objetos personalizados. El representador representa una tabla y la rellena con valores recibidos de un filtro vinculado. Para obtener el código completo de la clase, vea Code example: Create a renderer for custom PerformancePoint Services reports in SharePoint.

Le recomendamos usar el representador de informes de muestra como plantilla. La muestra indica cómo invocar objetos en la API de PerformancePoint Services y señala las prácticas recomendadas para el desarrollo de PerformancePoint Services.

Crear representadores para informes de PerformancePoint Services personalizados

  1. Instale PerformancePoint Services o copie los DLL que la extensión usa (enumerados en el paso 3) en el equipo. Para más información, consulte Archivos DLL de PerformancePoint Services usados en escenarios de desarrollo.

  2. En Visual Studio, cree una biblioteca de clases de C#. Si ya ha creado una biblioteca de clases para su extensión, agregue una nueva clase de C#.

    Debe firmar su DLL con un nombre seguro. Además, asegúrese de que todos los ensamblados a los que su DLL hace referencia tengan nombres seguros. Para obtener información sobre cómo firmar un ensamblado con un nombre seguro y cómo crear un par de claves pública-privada, vea How to: Create a Public/Private Key Pair.

  3. Agregue los siguientes archivos DLL de PerformancePoint Services como referencias de ensamblado al proyecto:

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

    Según las funciones de su extensión, se podrán necesitar otras referencias de proyecto.

  4. En su clase de presentador, agregue directivas using para los siguientes espacios de nombres de PerformancePoint Services:

    Según las funciones de su extensión, se podrán necesitar otras directivas using.

  5. Herede desde la clase base ParameterizableControl .

  6. Invalide el método GetElement para recuperar el objeto informe del repositorio.

  7. Invalide el método SetData para configurar el conjunto de datos de informe y recuperar valores de parámetros entrantes.

  8. Invalide el método Render para representar el HTML para la visualización del informe.

Ejemplo de código: Crear un representador para informes de PerformancePoint Services personalizados en SharePoint

La clase del siguiente ejemplo de código crear un representador de informes que muestra información de existencias pasada desde el filtro de muestra.

Antes de poder compilar este ejemplo de código, necesita configurar su entorno de desarrollo como se describe en Para crear y configurar la clase representador.

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) ? "&amp;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()) ? "&amp;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);
        }
    }
}

Pasos siguientes

Una vez que cree un representador de informes y un editor de informes (incluida la interfaz de usuario, en caso necesario), implemente las extensiones como se describe en Procedimiento para registrar manualmente las extensiones de PerformancePoint Services.

Vea también