Gewusst wie: Erstellen von Editoren für PerformancePoint Services-Filter
Letzte Änderung: Dienstag, 30. August 2011
In PerformancePoint Services in Microsoft SharePoint Server 2010 können Benutzer mithilfe von benutzerdefinierten Editoren Eigenschaften für benutzerdefinierte Objekte festlegen. Diese Editoren enthalten Bearbeitungssteuerelemente und Funktionalität, um benutzerdefinierte Objekte im Repository abzurufen und zu aktualisieren. Weitere Informationen zu Anforderungen und Funktionalität des Editors finden Sie unter Editoren für benutzerdefinierte PerformancePoint Services-Objekte.
Gilt für: SharePoint Server 2010
Mit Filter-Editoren muss auch die BeginPoints-Eigenschaft eines Filters initialisiert werden, die den Filteranfangspunkt definiert, der Parameterwerte für Scorecard- und Berichtsconsumer enthält.
Die Prozeduren und Beispiele in diesem Thema basieren auf der SampleFilterEditor-Klasse im Beispiel für benutzerdefinierte Objekte. Der Editor ist eine schlanke Webanwendung, mit der Benutzer den Namen und die Beschreibung des Filters ändern und die zugrunde liegende Datenquelle auswählen können. Der vollständige Code für die Klasse befindet sich in diesem Thema im Abschnitt "Beispiel".
![]() |
---|
Es wird empfohlen, den Beispieleditor als Vorlage zu verwenden. Im Beispiel sehen Sie, wie Sie Objekte in der PerformancePoint Services-API aufrufen, welche Hilfsobjekte Sie zur Vereinfachung von Aufrufen für Repositoryvorgänge (z. B. zum Erstellen und Aktualisieren von Objekten) verwenden können und welche Best Practices bei der PerformancePoint Services-Entwicklung zu beachten sind. |
Zum Erstellen eines Filter-Editors führen Sie die folgenden beiden grundlegenden Verfahren aus:
Erstellen und Konfigurieren der Editorklasse
Definieren der Bearbeitungsfunktionalität
Zum Erzeugen eines benutzerdefinierten Editors erstellen Sie zunächst die Editorklasse.
So erstellen und konfigurieren Sie die Editorklasse
Installieren Sie PerformancePoint Services, oder kopieren Sie die von der Erweiterung verwendeten DLLs (siehe Schritt 3) auf den Computer. Weitere Informationen finden Sie unter PerformancePoint-Dienste-DLLs in Entwicklungsszenarios.
Erstellen Sie in Visual Studio eine C#-Klassenbibliothek. Sollten Sie bereits eine Klassenbibliothek für die Erweiterung erstellt haben, fügen Sie eine neue C#-Klasse hinzu.
Fügen Sie dem Projekt die folgenden PerformancePoint Services- und SharePoint Server 2010-DLLs als Assemblyverweise hinzu:
Microsoft.PerformancePoint.Scorecards.Client.dll
Microsoft.PerformancePoint.Scorecards.ServerCommon.dll
Microsoft.PerformancePoint.Scorecards.ServerRendering.dll
Microsoft.PerformancePoint.Scorecards.Store.dll (von Hilfsklassen verwendet)
Microsoft.SharePoint.dll (von Hilfsklassen verwendet)
Der Beispieleditor enthält ebenfalls Assemblyverweise auf System.Web.dll und System.Web.Services.dll. Je nach Funktionalität Ihrer Erweiterung sind u. U. weitere Projektverweise erforderlich.
Fügen Sie dem Projekt die folgenden Klassen aus dem Beispiel hinzu. Der Editor verwendet diese Hilfsklassen für die Interaktion mit dem PerformancePoint Services-Repository:
DataSourceConsumerHelper.cs
ExtensionRepositoryHelper.cs
FilterRepositoryHelper.cs
IDataSourceConsumer.cs
Fügen Sie in der Editorklasse using-Direktiven für die folgenden PerformancePoint Services-Namespaces hinzu:
Microsoft.PerformancePoint.Scorecards
Microsoft.PerformancePoint.Scorecards.ServerCommon
Microsoft.PerformancePoint.Scorecards.ServerRendering
Je nach Funktionalität der Erweiterung sind u. U. andere using-Direktiven erforderlich.
Erben Sie von der Basisklasse, die Ihre Editorimplementierung unterstützt. Da es sich beim Beispiel-Filter-Editor um eine Webanwendung handelt, wird von der Page-Klasse geerbt. Andere Implementierungen können von Basisklassen wie z. B. der UserControl- oder WebPart-Klasse abgeleitet werden.
Nachdem Sie die Editorklasse erstellt und konfiguriert haben, müssen Sie die Funktionalität des Editors definieren.
So definieren Sie die Bearbeitungsfunktionalität
Definieren Sie Steuerelemente, mit denen die Eigenschaften verfügbar gemacht werden, die die Benutzer anzeigen oder ändern sollen. Mit dem Beispiel-Filter-Editor werden zunächst Variablen für die Webserversteuerelemente deklariert, die in der Benutzeroberflächenkomponente definiert sind, wobei es sich um eine ASPX-Seite handelt. Außerdem wird mit dem Beispieleditor ein Schaltflächensteuerelement definiert, mit dem Benutzer Änderungen senden können. Anschließend ruft der Editor die CreateChildControls()-Methode auf, um die Steuerelemente auf der Seite verfügbar zu machen.
Hinweis
Im Editor wird die Programmierlogik separat von der Benutzeroberfläche definiert. Anweisungen zum Erstellen der Benutzeroberflächenkomponenten würden den Rahmen dieser Dokumentation sprengen.
Legen Sie die AllowUnsafeUpdates-Eigenschaft auf true fest. Dadurch können mit dem Filter-Editor Daten in das Repository geschrieben werden, ohne POST-Vorgänge des Formulars zu verwenden.
Der Beispiel-Filter-Editor führt die Schritte 2 bis 6 der Page_Load-Methode aus. Page_Load wird auch zum Initialisieren und Überprüfen von Variablen und Steuerelementen, zum Auffüllen von Steuerelementen sowie zum Speichern der Statusinformationen für den benutzerdefinierten Filter und für Hilfsobjekte verwendet.
Rufen Sie die Parameter aus der Abfragezeichenfolge ab, und legen Sie sie als Werte für lokale Variablen fest, wie im folgenden Codebeispiel dargestellt.
// The URL of the site collection that contains the PerformancePoint Services repository. string server = Request.QueryString[ClickOnceLaunchKeys.SiteCollectionUrl]; // The location of the filter in the repository. string itemLocation = Request.QueryString[ClickOnceLaunchKeys.ItemLocation]; // The operation to perform: OpenItem or CreateItem. string action = Request.QueryString[ClickOnceLaunchKeys.LaunchOperation];
' The URL of the site collection that contains the PerformancePoint Services repository. Dim server As String = Request.QueryString(ClickOnceLaunchKeys.SiteCollectionUrl) ' The location of the filter in the repository. Dim itemLocation As String = Request.QueryString(ClickOnceLaunchKeys.ItemLocation) ' The operation to perform: OpenItem or CreateItem. Dim action As String = Request.QueryString(ClickOnceLaunchKeys.LaunchOperation)
Informationen zu den Abfragezeichenfolgenparametern finden Sie unter Editoren für benutzerdefinierte PerformancePoint Services-Objekte.
Rufen Sie das FilterRepositoryHelper-Objekt ab, das für Aufrufe an das Repository verwendet wird, wie im folgenden Codebeispiel illustriert.
filterRepositoryHelper = new FilterRepositoryHelper();
filterRepositoryHelper = New FilterRepositoryHelper()
Legen Sie wie im folgenden Codebeispiel dargestellt den Filter für die Datenquelle basierend auf dem Abfragezeichenfolgen-Parameter fest.
RepositoryLocation repositoryFilterLocation = RepositoryLocation.CreateFromUriString(itemLocation);
Dim repositoryFilterLocation As RepositoryLocation = RepositoryLocation.CreateFromUriString(itemLocation)
Rufen Sie wie im folgenden Codebeispiel dargestellt den auszuführenden Vorgang (OpenItem oder CreateItem) aus der Abfragezeichenfolge ab, und rufen Sie dann den benutzerdefinierten Filter ab, oder erstellen Sie ihn.
if (ClickOnceLaunchValues.OpenItem.Equals(action, StringComparison.OrdinalIgnoreCase)) { // Use the repository-helper object to retrieve the filter. filter = filterRepositoryHelper.Get(repositoryFilterLocation); if (filter == null) { displayError("Could not retrieve the filter for editing."); return; } } else if (ClickOnceLaunchValues.CreateItem.Equals(action, StringComparison.OrdinalIgnoreCase)) { filter = new Filter { RendererClassName = typeof(MultiSelectTreeViewControl).AssemblyQualifiedName, SubTypeId = "SampleFilter" }; }
If ClickOnceLaunchValues.OpenItem.Equals(action, StringComparison.OrdinalIgnoreCase) Then ' Use the repository-helper object to retrieve the filter. filter = filterRepositoryHelper.Get(repositoryFilterLocation) If filter Is Nothing Then displayError("Could not retrieve the filter for editing.") Return End If ElseIf ClickOnceLaunchValues.CreateItem.Equals(action, StringComparison.OrdinalIgnoreCase) Then filter = New Filter With {.RendererClassName = GetType(MultiSelectTreeViewControl).AssemblyQualifiedName, .SubTypeId = "SampleFilter"} End If
Verwenden Sie die FilterRepositoryHelper.Get-Methode zum Abrufen des benutzerdefinierten Filters.
Verwenden Sie zum Erstellen des benutzerdefinierten Filters den Filter()-Konstruktor, und definieren Sie die Eigenschaften Name, RendererClassName und SubTypeId des Filters. SubTypeId ist der eindeutige Bezeichner für den Filter und muss mit dem subType-Attribut übereinstimmen, das Sie für Ihren benutzerdefinierten Filter in der PerformancePoint Services-Datei web.config angeben. RendererClassName ist der vollqualifizierte Name der Klasse, mit der das Renderer-Webserversteuerelement definiert wird. Ohne diese Angabe im Editor wird für diesen Wert standardmäßig die in der Datei web.config angegebene Rendererklasse verwendet.
Hinweis
Standardmäßig ist es den Benutzern nur möglich, benutzerdefinierte Objekte über den PerformancePoint Dashboard-Designer zu erstellen. Damit sie auch außerhalb von Dashboard-Designer benutzerdefinierte Objekte erstellen können, müssen Sie ein Menüelement hinzufügen, das vom Inhaltstyp im Repository eine CreateItem-Anforderung an den Editor sendet. Weitere Informationen finden Sie unter Editoren für benutzerdefinierte PerformancePoint Services-Objekte.
Rufen Sie die zugrunde liegende Datenquelle des Filters aus dem Repository ab. Der Beispiel-Filter-Editor verwendet die FilterRepositoryHelper.DataSourceHelper-Eigenschaft zum Abrufen der DataSourceConsumerHelper.GetDataSource-Methode, mit der die Datenquelle anhand ihres Speicherorts im Repository abgerufen wird. Dies wird im folgenden Codebeispiel demonstriert.
if (!string.IsNullOrEmpty(filter.DataSourceLocation.ItemUrl)) { RepositoryLocation repositoryDatasourceLocation = RepositoryLocation.CreateFromUriString(filter.DataSourceLocation.ItemUrl); datasource = filterRepositoryHelper.DataSourceHelper.GetDataSource(repositoryDatasourceLocation); }
If Not String.IsNullOrEmpty(filter.DataSourceLocation.ItemUrl) Then Dim repositoryDatasourceLocation As RepositoryLocation = RepositoryLocation.CreateFromUriString(filter.DataSourceLocation.ItemUrl) datasource = filterRepositoryHelper.DataSourceHelper.GetDataSource(repositoryDatasourceLocation) End If
Füllen Sie das Auswahlsteuerelement mit PerformancePoint Services-Datenquellen auf, damit Benutzer eine Datenquelle für den Filter auswählen können. Mit der PopulateDataSourceDropDown-Methode im Beispiel-Filter-Editor wird die DataSourceConsumerHelper.GetDataSourcesBySourceNames-Methode zum Abrufen der Datenquellen aufgerufen. Dies wird im folgenden Codebeispiel demonstriert.
// The parameter contains the default server-relative URL to the PerformancePoint Data Connections Library. // Edit this value if you are not using the default path. A leading forward slash may not be needed. ICollection dataSourceCollection = filterRepositoryHelper.DataSourceHelper.GetDataSourcesBySourceNames ("/BICenter/Data%20Connections%20for%20PerformancePoint/", new[] { "WSTabularDataSource", DataSourceNames.ExcelWorkbook });
' The parameter contains the default server-relative URL to the PerformancePoint Data Connections Library. ' Edit this value if you are not using the default path. A leading forward slash may not be needed. Dim dataSourceCollection As ICollection = filterRepositoryHelper.DataSourceHelper.GetDataSourcesBySourceNames ("("/BICenter/Data%20Connections%20for%20PerformancePoint/", { "WSTabularDataSource", DataSourceNames.ExcelWorkbook })
Mit dem Beispiel-Filter werden nur zwei Datenquellentypen abgerufen. Sie können jedoch diese Methode ändern, sodass andere Datenquellentypen unterstützt werden oder der Benutzer zur Eingabe des abzurufenden Datenquellentyps aufgefordert wird. Zur Angabe einer systemeigenen Datenquelle eines bestimmten Typs verwenden Sie die SourceName-Eigenschaft, mit der ein Feld aus der DataSourceNames-Klasse zurückgegeben wird. Zur Angabe einer benutzerdefinierten Datenquelle verwenden Sie die SubTypeId-Eigenschaft der Datenquelle, wobei es sich um denselben Wert wie das subType-Attribut handelt, das in der PerformancePoint Services-Datei web.config für die Datenquellenerweiterung registriert ist.
Wenn Sie diese Methode ändern, müssen Sie die entsprechende Änderung für die GetDisplayDataInternal-Methode im Datenanbieter des Beispielfilters vornehmen.
Definieren Sie den Filteranfangspunkt, der durch die BeginPoints-Eigenschaft dargestellt wird. Hiermit wird die Quelle der Filterwerte definiert. Dies ist erforderlich, damit der Filter Daten an Scorecards und Berichte senden kann.
Erstellen Sie ein ParameterDefinition-Objekt. BeginPoints gibt ein ParameterDefinitionCollection-Objekt zurück, das nur ein ParameterDefinition-Objekt enthält.
Legen Sie zum Angeben des Datenanbieters des Filters für die ParameterProviderId-Eigenschaft den eindeutigen Bezeichner des Datenanbieters fest. Dieser Wert muss mit dem Wert übereinstimmen, der von der GetId()-Methode des Datenanbieters zurückgegeben wird.
Zur Angabe der Quelle der Schlüsselbezeichner für die Filterwerte legen Sie für die KeyColumn-Eigenschaft die Spalte in der Anzeigedatentabelle fest, die die Schlüsselbezeichner enthält. Für den Beispiel-Filter-Editor wird diese Eigenschaft als Symbol-Spalte definiert.
Zur Angabe der Quelle der Anzeigewerte für das Filtersteuerelement legen Sie für die DisplayColumn-Eigenschaft die Spalte in der Anzeigedatentabelle fest, die die Anzeigewerte enthält. Für den Beispiel-Filter-Editor wird diese Eigenschaft als Symbol-Spalte definiert.
Hinweis
Die Anzeigedatentabelle wird von der DisplayValues-Eigenschaft zurückgegeben, und sie wird initialisiert, wenn der Filterdatenanbieter die GetDisplayDataInternal-Methode aufruft. Falls die Datentabelle andere Spalten enthält, können Sie andere Spaltenzuordnungen definieren, um zusätzliche Funktionalität anzubieten.
if (0 == filter.BeginPoints.Count) { ParameterDefinition paramDef = new ParameterDefinition(); // Reference the data provider. paramDef.ParameterProviderId = "SampleFilterDataProvider"; paramDef.DefaultPostFormula = string.Empty; // Specify the column that contains the key identifiers and the column // that contains the display values. The sample uses the same column // for both purposes. // These values must match the structure of the data table that is // returned by the ParameterDefinition.DisplayValues property. paramDef.KeyColumn = "Symbol"; paramDef.DisplayColumn = "Symbol"; // You can use this property to store custom information for this filter. paramDef.CustomDefinition = string.Empty; filter.BeginPoints.Add(paramDef); }
If 0 = filter.BeginPoints.Count Then Dim paramDef As New ParameterDefinition() ' Reference the data provider. paramDef.ParameterProviderId = "SampleFilterDataProvider" paramDef.DefaultPostFormula = String.Empty ' Specify the column that contains the key identifiers and the column ' that contains the display values. The sample uses the same column ' for both purposes. ' These values must match the structure of the data table that is ' returned by the ParameterDefinition.DisplayValues property. paramDef.KeyColumn = "Symbol" paramDef.DisplayColumn = "Symbol" ' You can use this property to store custom information for this filter. paramDef.CustomDefinition = String.Empty filter.BeginPoints.Add(paramDef) End If
Der Anfangspunkt für den Beispieleditor wird in der VerifyFilter-Methode definiert. Mithilfe von VerifyFilter wird außerdem überprüft, ob erforderliche Eigenschaften festgelegt sind, und der Auswahlmodus wird definiert, bei dem es sich um eine optionale Eigenschaft handelt.
Initialisieren Sie den Filter, indem Sie die Abfrage des Filters ausführen und Daten aus der Datenquelle abrufen. Mit der buttonOK_Click-Methode im Beispiel-Filter-Editor wird die FilterRepositoryHelper.GetParameterDisplayData-Methode zum Initialisieren des Filters aufgerufen.
Hinweis
Der Editor muss FilterRepositoryHelper.GetParameterDisplayData mindestens einmal aufrufen, bevor das Filterobjekt aktualisiert wird.
Aktualisieren Sie den Filter mit benutzerdefinierten Änderungen. Mit der buttonOK_Click-Methode im Beispiel-Filter-Editor wird die FilterRepositoryHelper.Update-Methode zum Aktualisieren der Eigenschaften Name, Description und DataSourceLocation des Filters im Repository aufgerufen. Darüber hinaus werden mit buttonOK_Click die Inhalte der Steuerelemente überprüft und Statusinformationen für den benutzerdefinierten Filter und das Hilfsobjekt abgerufen.
Hinweis
Benutzer können die Eigenschaften Name, Description und Owner (Verantwortliche Person) eines benutzerdefinierten Objekts festlegen und benutzerdefinierte Objekte direkt in Dashboard-Designer und im PerformancePoint Services-Repository löschen.
Nächster Schritt: Nachdem Sie einen Filter-Editor (einschließlich ggf. der zugehörigen Benutzeroberfläche) und einen Datenanbieter erstellt haben, stellen Sie die Erweiterung wie unter Gewusst wie: Manuelles Registrieren von PerformancePoint-Dienste-Erweiterungen beschrieben bereit. Anweisungen zum Installieren und Konfigurieren der Beispielfiltererweiterung finden Sie im Abschnitt "Installieren der Beispielobjekte für Berichte, Filter und Datenquellen" unter Codebeispiel: Benutzerdefinierte Objekte für Berichte, Filter und tabulierte Datenquellen.
Beispiel
Im folgenden Codebeispiel werden benutzerdefinierte Filter im Repository erstellt, abgerufen und aktualisiert sowie die Programmierlogik für die auf einer ASPX-Seite definierten Steuerelemente bereitgestellt.
![]() |
---|
Bevor Sie dieses Codebeispiel kompilieren können, müssen Sie die Entwicklungsumgebung wie unter So erstellen und konfigurieren Sie die Editorklasse beschrieben konfigurieren. |
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.PerformancePoint.Scorecards;
using Microsoft.PerformancePoint.Scorecards.ServerCommon;
using Microsoft.PerformancePoint.Scorecards.ServerRendering;
namespace Microsoft.PerformancePoint.SDK.Samples.SampleFilter
{
// Represents the class that defines the sample filter editor.
public class SampleFilterEditor : 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 DropDownList dropdownlistDataSource;
private Button buttonOK;
private ListBox listboxStocks;
// 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 == dropdownlistDataSource)
dropdownlistDataSource = FindControl("dropdownlistDataSource") as DropDownList;
if (null == labelErrorMessage)
labelErrorMessage = FindControl("labelErrorMessage") as Label;
if (null==buttonOK)
buttonOK = FindControl("buttonOK") as Button;
if (null==listboxStocks)
listboxStocks = FindControl("listboxStocks") as ListBox;
}
// 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();
FilterRepositoryHelper filterRepositoryHelper = 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.
filterRepositoryHelper =
new FilterRepositoryHelper();
// Set the filter location.
RepositoryLocation repositoryFilterLocation = RepositoryLocation.CreateFromUriString(itemLocation);
Filter filter;
DataSource datasource = null;
// Retrieve or create the filter object, depending on the operation
// passed in the query string (OpenItem or CreateItem).
if (ClickOnceLaunchValues.OpenItem.Equals(action, StringComparison.OrdinalIgnoreCase))
{
// Retrieve the filter object by using the repository-helper object.
filter = filterRepositoryHelper.Get(repositoryFilterLocation);
if (filter == null)
{
displayError("Could not retrieve the filter for editing.");
return;
}
}
else if (ClickOnceLaunchValues.CreateItem.Equals(action, StringComparison.OrdinalIgnoreCase))
{
// Create a filter.
// 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.
filter = new Filter
{
// Specify the class that defines the renderer
// Web server control. The sample filter uses a native
// PerformancePoint Services renderer.
// Defaults to the value specified in the web.config file
RendererClassName = typeof(MultiSelectTreeViewControl).AssemblyQualifiedName,
// Specify the unique identifier for the filter.
// The SubTypeId property must match the
// subType attribute in the web.config file.
SubTypeId = "SampleFilter"
};
}
else
{
displayError("Invalid Action.");
return;
}
VerifyFilter(filter);
// Retrieve filter's underlying data source.
if (!string.IsNullOrEmpty(filter.DataSourceLocation.ItemUrl))
{
RepositoryLocation repositoryDatasourceLocation =
RepositoryLocation.CreateFromUriString(filter.DataSourceLocation.ItemUrl);
datasource =
// Gets a PerformancePoint Services data source by using the
// DataSourceHelper property to call the
// DataSourceConsumerHelper.GetDataSource method.
filterRepositoryHelper.DataSourceHelper.GetDataSource(repositoryDatasourceLocation);
}
// Save the original filter and helper objects across page postbacks.
ViewState["action"] = action;
ViewState["filter"] = filter;
ViewState["filterrepositoryhelper"] = filterRepositoryHelper;
ViewState["itemlocation"] = itemLocation;
// Populate the child controls.
textboxName.Text = filter.Name.ToString();
textboxDescription.Text = filter.Description.ToString();
// Populate the dropdownlistDataSource control with data sources of specific
// types from the PerformancePoint Services repository.
// This method looks up the passed data source in the data sources
// that are registered in the web.config file.
// Although the sample retrieves data sources of two specific types,
// you can modify it to prompt the user for a data source type.
PopulateDataSourceDropDown(datasource);
// Call the SelectedIndexChanged event directly to populate the
// listbox control with preview data.
dropdownlistDataSource_SelectedIndexChanged(null, null);
}
catch (Exception ex)
{
displayError("An error has occurred. Please contact your administrator for more information.");
if (filterRepositoryHelper != null)
{
// Add the exception detail to the server event log.
filterRepositoryHelper.HandleException(ex);
}
}
}
}
// Handles the SelectedIndexChanged event of the dropdownlistDataSource control.
protected void dropdownlistDataSource_SelectedIndexChanged(object sender, EventArgs e)
{
EnsureChildControls();
// Check if a valid data source is selected.
if (null != dropdownlistDataSource.SelectedItem &&
!string.IsNullOrEmpty(dropdownlistDataSource.SelectedItem.Text))
{
// Retrieve the data source object.
FilterRepositoryHelper filterRepositoryHelper =
(FilterRepositoryHelper)ViewState["filterrepositoryhelper"];
string selectedDataSourceItemUrl = dropdownlistDataSource.SelectedItem.Value;
RepositoryLocation repositoryDatasourceLocation =
RepositoryLocation.CreateFromUriString(selectedDataSourceItemUrl);
DataSource datasource = filterRepositoryHelper.DataSourceHelper.GetDataSource(repositoryDatasourceLocation);
ViewState["datasource"] = datasource;
// Populate the listboxStocks control with the preview data for the selected
// data source.
PopulateListBoxData(datasource);
}
else
{
ClearStocksListBox();
}
}
// Clears the listboxStocks control.
// The sample filter works with a Web service that provides stock information.
private void ClearStocksListBox()
{
listboxStocks.DataSource = null;
listboxStocks.DataBind();
listboxStocks.Items.Clear();
}
// Handles the Click event of the buttonOK control.
protected void buttonOK_Click(object sender, EventArgs e)
{
EnsureChildControls();
// Verify that the controls contain values.
if (string.IsNullOrEmpty(textboxName.Text))
{
labelErrorMessage.Text = "A filter name is required.";
return;
}
if (dropdownlistDataSource.SelectedIndex == 0)
{
labelErrorMessage.Text = "A data source is required.";
return;
}
// Clear any pre-existing error message.
labelErrorMessage.Text = string.Empty;
// Retrieve the filter, data source, and helper objects from view state.
string action = (string)ViewState["action"];
string itemLocation = (string) ViewState["itemlocation"];
Filter filter = (Filter)ViewState["filter"];
DataSource datasource = (DataSource)ViewState["datasource"];
FilterRepositoryHelper filterRepositoryHelper = (FilterRepositoryHelper)ViewState["filterrepositoryhelper"];
// Update the filter object with form changes.
filter.Name.Text = textboxName.Text;
filter.Description.Text = textboxDescription.Text;
filter.DataSourceLocation = datasource.Location;
foreach (ParameterDefinition parameterDefinition in filter.BeginPoints)
{
parameterDefinition.DisplayName = filter.Name.Text;
}
// Initialize the filter. This method runs the filter's query and retrieves preview data.
filterRepositoryHelper.GetParameterDisplayData(ref filter);
// Save the filter object to the PerformancePoint Services repository.
try
{
filter.Validate();
if (ClickOnceLaunchValues.CreateItem.Equals(action,StringComparison.OrdinalIgnoreCase))
{
Filter newFilter = filterRepositoryHelper.Create(
string.IsNullOrEmpty(filter.Location.ItemUrl) ? itemLocation : filter.Location.ItemUrl, filter);
ViewState["filter"] = newFilter;
ViewState["action"] = ClickOnceLaunchValues.OpenItem;
}
else
{
filterRepositoryHelper.Update(filter);
}
}
catch (Exception ex)
{
displayError("An error has occurred. Please contact your administrator for more information.");
if (filterRepositoryHelper != null)
{
// Add the exception detail to the server event log.
filterRepositoryHelper.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 filter object are set.
static void VerifyFilter(Filter filter)
{
if (null != filter)
{
// Verify that all required properties are set.
if (string.IsNullOrEmpty(filter.SubTypeId))
{
// This value must match the subType attribute specified
// in the web.config file.
filter.SubTypeId = "SampleFilter";
}
if (string.IsNullOrEmpty(filter.RendererClassName))
{
filter.RendererClassName = typeof (MultiSelectTreeViewControl).AssemblyQualifiedName;
}
// Define the BeginPoints property so the filter can send a parameter value to
// scorecards and reports.
// The value must be from the KeyColumn of the display
// DataTable object, which is defined in the data provider. The data table is
// returned by the FilterRepositoryHelper.GetParameterDisplayData method.
// A filter has one beginpoint only, and it is represented by a
// ParameterDefinition object. The ParameterDefinition object defines how
// the filter accesses the data.
if (0 == filter.BeginPoints.Count)
{
ParameterDefinition paramDef = new ParameterDefinition
{
// This value must match the value returned
// by the data provider's GetId method.
ParameterProviderId = "SampleFilterDataProvider",
// Reference the data provider.
DefaultPostFormula = string.Empty,
// Specify the column that contains
// the key identifiers and the column
// that contains the display values.
// The sample uses the same column
// for both purposes.
// These values must match the structure
// of the data table that is returned
// by the ParameterDefinition.DisplayValues property.
KeyColumn = "Symbol",
DisplayColumn = "Symbol",
// You can use this property to store
// extra information for this filter.
CustomDefinition = string.Empty
};
filter.BeginPoints.Add(paramDef);
}
// Set optional properties. The renderer can return multiple values.
filter.SelectionMode = FilterSelectionMode.MultiSelect;
}
}
// Populates the dropdownlistDataSource control.
void PopulateDataSourceDropDown(DataSource filterDataSource)
{
EnsureChildControls();
FilterRepositoryHelper filterRepositoryHelper =
(FilterRepositoryHelper)ViewState["filterrepositoryhelper"];
// Retrieve data sources from the repository by using the DataSourceHelper
// property to call the DataSourceConsumerHelper object.
// If you modify the types of data source to retrieve, you must make the corresponding
// change in the filter's data provider.
// The parameter contains the default server-relative URL to the PerformancePoint Data Connections Library.
// Edit this value if you are not using the default path. A leading forward slash may not be needed.
ICollection dataSourceCollection = filterRepositoryHelper.DataSourceHelper.GetDataSourcesBySourceNames("/BICenter/Data%20Connections%20for%20PerformancePoint/",
new[] { "WSTabularDataSource", DataSourceNames.ExcelWorkbook });
if (null == dataSourceCollection)
{
displayError("No available data sources were found.");
return;
}
// Create a list of name/value pairs for the dropdownlistDataSource control.
var dataSources = new List<KeyValuePair<string, string>>();
int selectedIndex = 0;
int i = 1;
dataSources.Add(new KeyValuePair<string, string>(string.Empty, string.Empty));
foreach (DataSource ds in dataSourceCollection)
{
dataSources.Add(new KeyValuePair<string, string>(ds.Name.Text, ds.Location.ItemUrl));
// Check if the entry is the originally selected data source.
if ((filterDataSource != null) &&
(string.Compare(ds.Name.Text, filterDataSource.Name.Text) == 0))
{
selectedIndex = i;
}
++i;
}
dropdownlistDataSource.DataSource = dataSources;
dropdownlistDataSource.DataTextField = "Key";
dropdownlistDataSource.DataValueField = "Value";
dropdownlistDataSource.DataBind();
dropdownlistDataSource.SelectedIndex = selectedIndex;
}
// Populate the list box data.
void PopulateListBoxData(DataSource datasource)
{
EnsureChildControls();
ClearStocksListBox();
FilterRepositoryHelper filterRepositoryHelper =
(FilterRepositoryHelper)ViewState["filterrepositoryhelper"];
// Retrieve the first 100 rows of the preview data from the data source
DataSet dataSet = filterRepositoryHelper.DataSourceHelper.GetDataSet(100, datasource);
if (null != dataSet && null != dataSet.Tables[0])
{
listboxStocks.DataTextField = "Symbol";
listboxStocks.DataValueField = "Value";
listboxStocks.DataSource = dataSet.Tables[0];
listboxStocks.DataBind();
}
}
}
}
'INSTANT VB NOTE: This code snippet uses implicit typing. You will need to set 'Option Infer On' in the VB file or set 'Option Infer' at the project level:
Imports System
Imports System.Collections
Imports System.Collections.Generic
Imports System.Data
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports Microsoft.PerformancePoint.Scorecards
Imports Microsoft.PerformancePoint.Scorecards.ServerCommon
Imports Microsoft.PerformancePoint.Scorecards.ServerRendering
Namespace Microsoft.PerformancePoint.SDK.Samples.SampleFilter
' Represents the class that defines the sample filter editor.
Public Class SampleFilterEditor
Inherits 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 textboxName As TextBox
Private textboxDescription As TextBox
Private labelErrorMessage As Label
Private dropdownlistDataSource As DropDownList
Private buttonOK As Button
Private listboxStocks As ListBox
' Make the controls available to this class.
Protected Overrides Sub CreateChildControls()
MyBase.CreateChildControls()
If Nothing Is textboxName Then
textboxName = TryCast(FindControl("textboxName"), TextBox)
End If
If Nothing Is textboxDescription Then
textboxDescription = TryCast(FindControl("textboxDescription"), TextBox)
End If
If Nothing Is dropdownlistDataSource Then
dropdownlistDataSource = TryCast(FindControl("dropdownlistDataSource"), DropDownList)
End If
If Nothing Is labelErrorMessage Then
labelErrorMessage = TryCast(FindControl("labelErrorMessage"), Label)
End If
If Nothing Is buttonOK Then
buttonOK = TryCast(FindControl("buttonOK"), Button)
End If
If Nothing Is listboxStocks Then
listboxStocks = TryCast(FindControl("listboxStocks"), ListBox)
End If
End Sub
' 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 Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
' 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 Not IsPostBack Then
EnsureChildControls()
Dim filterRepositoryHelper As FilterRepositoryHelper = Nothing
Try
' Get information from the query string parameters.
Dim server As String = Request.QueryString(ClickOnceLaunchKeys.SiteCollectionUrl)
Dim itemLocation As String = Request.QueryString(ClickOnceLaunchKeys.ItemLocation)
Dim action As String = Request.QueryString(ClickOnceLaunchKeys.LaunchOperation)
' Validate the query string parameters.
If String.IsNullOrEmpty(server) OrElse String.IsNullOrEmpty(itemLocation) OrElse String.IsNullOrEmpty(action) Then
displayError("Invalid URL.")
Return
End If
' Retrieve the repository-helper object.
filterRepositoryHelper = New FilterRepositoryHelper()
' Set the filter location.
Dim repositoryFilterLocation As RepositoryLocation = RepositoryLocation.CreateFromUriString(itemLocation)
Dim filter As Filter
Dim datasource As DataSource = Nothing
' Retrieve or create the filter object, depending on the operation
' passed in the query string (OpenItem or CreateItem).
If ClickOnceLaunchValues.OpenItem.Equals(action, StringComparison.OrdinalIgnoreCase) Then
' Retrieve the filter object by using the repository-helper object.
filter = filterRepositoryHelper.Get(repositoryFilterLocation)
If filter Is Nothing Then
displayError("Could not retrieve the filter for editing.")
Return
End If
ElseIf ClickOnceLaunchValues.CreateItem.Equals(action, StringComparison.OrdinalIgnoreCase) Then
' Create a filter.
' 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.
filter = New Filter With {.RendererClassName = GetType(MultiSelectTreeViewControl).AssemblyQualifiedName, .SubTypeId = "SampleFilter"}
' Specify the class that defines the renderer
' Web server control. The sample filter uses a native
' PerformancePoint Services renderer.
' Defaults to the value specified in the web.config file
' Specify the unique identifier for the filter.
' The SubTypeId property must match the
' subType attribute in the web.config file.
Else
displayError("Invalid Action.")
Return
End If
VerifyFilter(filter)
' Retrieve filter's underlying data source.
If Not String.IsNullOrEmpty(filter.DataSourceLocation.ItemUrl) Then
Dim repositoryDatasourceLocation As RepositoryLocation = RepositoryLocation.CreateFromUriString(filter.DataSourceLocation.ItemUrl)
' Gets a PerformancePoint Services data source by using the
' DataSourceHelper property to call the
' DataSourceConsumerHelper.GetDataSource method.
datasource = filterRepositoryHelper.DataSourceHelper.GetDataSource(repositoryDatasourceLocation)
End If
' Save the original filter and helper objects across page postbacks.
ViewState("action") = action
ViewState("filter") = filter
ViewState("filterrepositoryhelper") = filterRepositoryHelper
ViewState("itemlocation") = itemLocation
' Populate the child controls.
textboxName.Text = filter.Name.ToString()
textboxDescription.Text = filter.Description.ToString()
' Populate the dropdownlistDataSource control with data sources of specific
' types from the PerformancePoint Services repository.
' This method looks up the passed data source in the data sources
' that are registered in the web.config file.
' Although the sample retrieves data sources of two specific types,
' you can modify it to prompt the user for a data source type.
PopulateDataSourceDropDown(datasource)
' Call the SelectedIndexChanged event directly to populate the
' listbox control with preview data.
dropdownlistDataSource_SelectedIndexChanged(Nothing, Nothing)
Catch ex As Exception
displayError("An error has occurred. Please contact your administrator for more information.")
If filterRepositoryHelper IsNot Nothing Then
' Add the exception detail to the server event log.
filterRepositoryHelper.HandleException(ex)
End If
End Try
End If
End Sub
' Handles the SelectedIndexChanged event of the dropdownlistDataSource control.
Protected Sub dropdownlistDataSource_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
EnsureChildControls()
' Check if a valid data source is selected.
If Nothing IsNot dropdownlistDataSource.SelectedItem AndAlso (Not String.IsNullOrEmpty(dropdownlistDataSource.SelectedItem.Text)) Then
' Retrieve the data source object.
Dim filterRepositoryHelper As FilterRepositoryHelper = CType(ViewState("filterrepositoryhelper"), FilterRepositoryHelper)
Dim selectedDataSourceItemUrl As String = dropdownlistDataSource.SelectedItem.Value
Dim repositoryDatasourceLocation As RepositoryLocation = RepositoryLocation.CreateFromUriString(selectedDataSourceItemUrl)
Dim datasource As DataSource = filterRepositoryHelper.DataSourceHelper.GetDataSource(repositoryDatasourceLocation)
ViewState("datasource") = datasource
' Populate the listboxStocks control with the preview data for the selected
' data source.
PopulateListBoxData(datasource)
Else
ClearStocksListBox()
End If
End Sub
' Clears the listboxStocks control.
' The sample filter works with a Web service that provides stock information.
Private Sub ClearStocksListBox()
listboxStocks.DataSource = Nothing
listboxStocks.DataBind()
listboxStocks.Items.Clear()
End Sub
' Handles the Click event of the buttonOK control.
Protected Sub buttonOK_Click(ByVal sender As Object, ByVal e As EventArgs)
EnsureChildControls()
' Verify that the controls contain values.
If String.IsNullOrEmpty(textboxName.Text) Then
labelErrorMessage.Text = "A filter name is required."
Return
End If
If dropdownlistDataSource.SelectedIndex = 0 Then
labelErrorMessage.Text = "A data source is required."
Return
End If
' Clear any pre-existing error message.
labelErrorMessage.Text = String.Empty
' Retrieve the filter, data source, and helper objects from view state.
Dim action As String = CStr(ViewState("action"))
Dim itemLocation As String = CStr(ViewState("itemlocation"))
Dim filter As Filter = CType(ViewState("filter"), Filter)
Dim datasource As DataSource = CType(ViewState("datasource"), DataSource)
Dim filterRepositoryHelper As FilterRepositoryHelper = CType(ViewState("filterrepositoryhelper"), FilterRepositoryHelper)
' Update the filter object with form changes.
filter.Name.Text = textboxName.Text
filter.Description.Text = textboxDescription.Text
filter.DataSourceLocation = datasource.Location
For Each parameterDefinition As ParameterDefinition In filter.BeginPoints
parameterDefinition.DisplayName = filter.Name.Text
Next parameterDefinition
' Initialize the filter. This method runs the filter's query and retrieves preview data.
filterRepositoryHelper.GetParameterDisplayData(filter)
' Save the filter object to the PerformancePoint Services repository.
Try
filter.Validate()
If ClickOnceLaunchValues.CreateItem.Equals(action, StringComparison.OrdinalIgnoreCase) Then
Dim newFilter As Filter = filterRepositoryHelper.Create(If(String.IsNullOrEmpty(filter.Location.ItemUrl), itemLocation, filter.Location.ItemUrl), filter)
ViewState("filter") = newFilter
ViewState("action") = ClickOnceLaunchValues.OpenItem
Else
filterRepositoryHelper.Update(filter)
End If
Catch ex As Exception
displayError("An error has occurred. Please contact your administrator for more information.")
If filterRepositoryHelper IsNot Nothing Then
' Add the exception detail to the server event log.
filterRepositoryHelper.HandleException(ex)
End If
End Try
End Sub
' Displays the error string in the labelErrorMessage label.
Private Sub displayError(ByVal msg As String)
EnsureChildControls()
labelErrorMessage.Text = msg
' Disable the OK button because the page is in an error state.
buttonOK.Enabled = False
Return
End Sub
' Verifies that the properties for the filter object are set.
Private Shared Sub VerifyFilter(ByVal filter As Filter)
If Nothing IsNot filter Then
' Verify that all required properties are set.
If String.IsNullOrEmpty(filter.SubTypeId) Then
' This value must match the subType attribute specified
' in the web.config file.
filter.SubTypeId = "SampleFilter"
End If
If String.IsNullOrEmpty(filter.RendererClassName) Then
filter.RendererClassName = GetType(MultiSelectTreeViewControl).AssemblyQualifiedName
End If
' Define the BeginPoints property so the filter can send a parameter value to
' scorecards and reports.
' The value must be from the KeyColumn of the display
' DataTable object, which is defined in the data provider. The data table is
' returned by the FilterRepositoryHelper.GetParameterDisplayData method.
' A filter has one beginpoint only, and it is represented by a
' ParameterDefinition object. The ParameterDefinition object defines how
' the filter accesses the data.
If 0 = filter.BeginPoints.Count Then
Dim paramDef As ParameterDefinition = New ParameterDefinition With {.ParameterProviderId = "SampleFilterDataProvider", .DefaultPostFormula = String.Empty, .KeyColumn = "Symbol", .DisplayColumn = "Symbol", .CustomDefinition = String.Empty}
' This value must match the value returned
' by the data provider's GetId method.
' Reference the data provider.
' Specify the column that contains
' the key identifiers and the column
' that contains the display values.
' The sample uses the same column
' for both purposes.
' These values must match the structure
' of the data table that is returned
' by the ParameterDefinition.DisplayValues property.
' You can use this property to store
' extra information for this filter.
filter.BeginPoints.Add(paramDef)
End If
' Set optional properties. The renderer can return multiple values.
filter.SelectionMode = FilterSelectionMode.MultiSelect
End If
End Sub
' Populates the dropdownlistDataSource control.
Private Sub PopulateDataSourceDropDown(ByVal filterDataSource As DataSource)
EnsureChildControls()
Dim filterRepositoryHelper As FilterRepositoryHelper = CType(ViewState("filterrepositoryhelper"), FilterRepositoryHelper)
' Retrieve data sources from the repository by using the DataSourceHelper
' property to call the DataSourceConsumerHelper object.
' If you modify the types of data source to retrieve, you must make the corresponding
' change in the filter's data provider.
' The parameter contains the default server-relative URL to the PerformancePoint Data Connections Library.
' Edit this value if you are not using the default path. A leading forward slash may not be needed.
Dim dataSourceCollection As ICollection = filterRepositoryHelper.DataSourceHelper.GetDataSourcesBySourceNames("/BICenter/Data%20Connections%20for%20PerformancePoint/", {"WSTabularDataSource", DataSourceNames.ExcelWorkbook})
If Nothing Is dataSourceCollection Then
displayError("No available data sources were found.")
Return
End If
' Create a list of name/value pairs for the dropdownlistDataSource control.
Dim dataSources = New List(Of KeyValuePair(Of String, String))()
Dim selectedIndex As Integer = 0
Dim i As Integer = 1
dataSources.Add(New KeyValuePair(Of String, String)(String.Empty, String.Empty))
For Each ds As DataSource In dataSourceCollection
dataSources.Add(New KeyValuePair(Of String, String)(ds.Name.Text, ds.Location.ItemUrl))
' Check if the entry is the originally selected data source.
If (filterDataSource IsNot Nothing) AndAlso (String.Compare(ds.Name.Text, filterDataSource.Name.Text) = 0) Then
selectedIndex = i
End If
i += 1
Next ds
dropdownlistDataSource.DataSource = dataSources
dropdownlistDataSource.DataTextField = "Key"
dropdownlistDataSource.DataValueField = "Value"
dropdownlistDataSource.DataBind()
dropdownlistDataSource.SelectedIndex = selectedIndex
End Sub
' Populate the list box data.
Private Sub PopulateListBoxData(ByVal datasource As DataSource)
EnsureChildControls()
ClearStocksListBox()
Dim filterRepositoryHelper As FilterRepositoryHelper = CType(ViewState("filterrepositoryhelper"), FilterRepositoryHelper)
' Retrieve the first 100 rows of the preview data from the data source
Dim dataSet As DataSet = filterRepositoryHelper.DataSourceHelper.GetDataSet(100, datasource)
If Nothing IsNot dataSet AndAlso Nothing IsNot dataSet.Tables(0) Then
listboxStocks.DataTextField = "Symbol"
listboxStocks.DataValueField = "Value"
listboxStocks.DataSource = dataSet.Tables(0)
listboxStocks.DataBind()
End If
End Sub
End Class
End Namespace
Code wird kompiliert
Bevor Sie dieses Codebeispiel kompilieren können, müssen Sie die Entwicklungsumgebung wie unter So erstellen und konfigurieren Sie die Editorklasse beschrieben konfigurieren.
Sicherheit
Sie müssen die DLL mit einem starken Namen signieren. Stellen Sie außerdem sicher, dass alle Assemblys, auf die von der DLL verwiesen wird, ebenfalls starke Namen haben. Informationen dazu, wie Sie eine Assembly mit einem starken Namen signieren und ein öffentliches/privates Schlüsselpaar erstellen, finden Sie unter How to: Create a Public/Private Key Pair.
Siehe auch
Aufgaben
Gewusst wie: Erstellen von Datenanbietern für PerformancePoint Services-Filter
Konzepte
Editoren für benutzerdefinierte PerformancePoint Services-Objekte
PerformancePoint Services-Filter
Weitere Ressourcen
Erstellen von benutzerdefinierten Objekten für PerformancePoint Services
Codebeispiele für PerformancePoint Services in SharePoint Server 2010