Freigeben über


SPDataStore.CreateIndicator-Methode

Speichert ein Objekt Indikator als Inhaltstyp in einer SharePoint-Liste.

Namespace:  Microsoft.PerformancePoint.Scorecards.Store
Assembly:  Microsoft.PerformancePoint.Scorecards.Store (in Microsoft.PerformancePoint.Scorecards.Store.dll)

Syntax

'Declaration
Public Function CreateIndicator ( _
    listUrl As String, _
    newElement As Indicator _
) As Indicator
'Usage
Dim instance As SPDataStore
Dim listUrl As String
Dim newElement As Indicator
Dim returnValue As Indicator

returnValue = instance.CreateIndicator(listUrl, _
    newElement)
public Indicator CreateIndicator(
    string listUrl,
    Indicator newElement
)

Parameter

  • listUrl
    Typ: System.String

    Die serverrelative URL der SharePoint-Liste um das Objekt zu speichern. Beispiel: /BI Center/Lists/PerformancePoint Content.

  • newElement
    Typ: Indicator

    Der Indikator-Objekt zu speichern, das einen Wert für die erforderliche Name -Eigenschaft gibt an.

Rückgabewert

Typ: Indicator
Das neue Objekt, das enthält aktualisierte Informationen so ihre Nummer und Version.

Implementiert

IBIMonitoringStore.CreateIndicator(String, Indicator)

Beispiele

Im folgenden Codebeispiel wird veranschaulicht, wie Sie eine private Methode erstellen Sie einen Indikator und rufen Sie CreateIndicator(String, Indicator) , um es im Repository gespeichert werden. Im Beispiel wird eine Hilfsmethode (GetImageAsString), um Bilder aus einer Ressourcendatei konvertieren.

Bevor Sie dieses Codebeispiel kompilieren können, müssen Sie Folgendes tun:

  • Konfigurieren Sie die Entwicklungsumgebung, und erstellen Sie ein C#-Klassenbibliotheksprojekt in Visual Studio. Informationen zum Konfigurieren einer Entwicklungsumgebung finden Sie unter Einrichten einer allgemeinen Entwicklungsumgebung für SharePoint 2013.

  • Fügen Sie die Microsoft.PerformancePoint.Scorecards.Client, Microsoft.PerformancePoint.Scorecards.ServerCommon, und Microsoft.PerformancePoint.Scorecards.Store und System.Drawing-DLLs als Verweise auf das Projekt Visual Studio . Weitere Informationen zu PerformancePoint-Dienste DLLs finden Sie unter PerformancePoint Services DLLs Used in Development Scenarios.

  • Fügen Sie folgende using-Direktive hinzu.

    using Microsoft.PerformancePoint.Scorecards.Indicators
    using Microsoft.PerformancePoint.Scorecards.Store;
    using System.Drawing;
    using System.IO;
    
  • Fügen Sie eine eingebettete Ressourcendatei mit dem Namen Resource1 hinzu, die fünf Bildtyp Ressourcen mit dem Namen nodata, red, orange, yellowund greenenthält. Diese Bilder stellen die fünf Status des Indikators.

// Create an indicator, based on the following parameters:
//   - indicatorName is the name for the indicator.
//   - listUrl is the server-relative URL of the list to save the indicator to. Example: 
//      "/BI Center/Lists/PerformancePoint Content" 
// This method returns the new indicator.
private Indicator CreateIndicator(string indicatorName, string listUrl)
{
    if (String.IsNullOrEmpty(indicatorName))
        throw new ArgumentException("The name must not be null or empty.");
    if (String.IsNullOrEmpty(listUrl))
        throw new ArgumentException("The list URL must not be null or empty.");

    Indicator newIndicator = new Indicator();
    newIndicator.Name.Text = indicatorName;
    newIndicator.Description.Text = "Created with the SDK.";

    // A centered indicator type is used with "closer to target" scoring.
    newIndicator.IndicatorType = IndicatorType.Centered;  

    // Centered indicators need between four and 20 bands.
    // Use the GetImageAsString method to convert images from a resource file.
    IndicatorBand noData = new IndicatorBand();
    noData.BackColor = Color.Gray.ToArgb().ToString();
    noData.Color = Color.Black.ToArgb().ToString();
    noData.ImageData = GetImageAsString(Resource1.nodata);
    noData.ToolTip = "No Data";

    IndicatorBand redBand = new IndicatorBand();
    redBand.BackColor = Color.Red.ToArgb().ToString();
    redBand.Color = Color.Black.ToArgb().ToString();
    redBand.ImageData = GetImageAsString(Resource1.red);
    redBand.ToolTip = "Off Target";

    IndicatorBand orangeBand = new IndicatorBand();
    orangeBand.BackColor = Color.Orange.ToArgb().ToString();
    orangeBand.Color = Color.Black.ToArgb().ToString();
    orangeBand.ImageData = GetImageAsString(Resource1.orange);
    orangeBand.ToolTip = "Slightly Off Target";

    IndicatorBand yellowBand = new IndicatorBand();
    yellowBand.BackColor = Color.Yellow.ToArgb().ToString();
    yellowBand.Color = Color.Black.ToArgb().ToString();
    yellowBand.ImageData = GetImageAsString(Resource1.yellow);
    yellowBand.ToolTip = "Close to Target";

    IndicatorBand greenBand = new IndicatorBand();
    greenBand.BackColor = Color.Green.ToArgb().ToString();
    greenBand.Color = Color.Black.ToArgb().ToString();
    greenBand.ImageData = GetImageAsString(Resource1.green);
    greenBand.ToolTip = "On Target";

    newIndicator.NoDataIndicatorBand = noData;

    // Add the bands, starting with the worst (represents values that are lower than
    // the target and are getting increasingly closer to the target).
    newIndicator.IndicatorBands.Add(redBand);
    newIndicator.IndicatorBands.Add(orangeBand);
    newIndicator.IndicatorBands.Add(yellowBand);
    newIndicator.IndicatorBands.Add(greenBand);

    // Add the bands in reverse order (represents positive values getting increasingly
    // further from the target).
    newIndicator.IndicatorBands.Add(greenBand);
    newIndicator.IndicatorBands.Add(yellowBand);
    newIndicator.IndicatorBands.Add(orangeBand);
    newIndicator.IndicatorBands.Add(redBand);

    // Call the CreateIndicator method to save the new indicator to the specified list.
    // TODO: Handle exceptions from this call.
    return SPDataStore.GlobalDataStore.CreateIndicator(listUrl, newIndicator);
}

// Converts an Image object to its base64 string representation.
//   - image is an Image object (in this example from a resource file).
// This method returns a string that contains the base64 representation of the image.
private string GetImageAsString(Image image)
{
    string base64String;
    if (null == image)
    {
        throw new ArgumentNullException("image");
    }
    using (MemoryStream mStream = new MemoryStream())
    {
        image.Save(mStream, image.RawFormat);
        Byte[] bytes = mStream.ToArray();
        base64String = System.Convert.ToBase64String(bytes, 0, bytes.Length);
    }
    return base64String;
}

Siehe auch

Referenz

SPDataStore Klasse

SPDataStore-Member

Microsoft.PerformancePoint.Scorecards.Store-Namespace