SPDataStore.CreateIndicator method

Saves an indicator object as a content type in a SharePoint list.

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
)

Parameters

  • listUrl
    Type: System.String

    The server-relative URL of the SharePoint list to save the object to. Example: /BI Center/Lists/PerformancePoint Content.

  • newElement
    Type: Indicator

    The indicator object to save, which specifies a value for the required Name property.

Return value

Type: Indicator
The new object, which contains updated information such its location and version number.

Implements

IBIMonitoringStore.CreateIndicator(String, Indicator)

Examples

The following code example shows how to use a private method to create an indicator and to call CreateIndicator(String, Indicator) to save it to the repository. The example uses a helper method (GetImageAsString) to convert images from a resource file.

Before you can compile this code example, you must do the following:

  • Configure your development environment and create a C# class library project in Visual Studio. For information about configuring a development environment, see Set up a general development environment for SharePoint 2013.

  • Add the Microsoft.PerformancePoint.Scorecards.Client, Microsoft.PerformancePoint.Scorecards.ServerCommon, and Microsoft.PerformancePoint.Scorecards.Store, and System.Drawing DLLs as references to your Visual Studio project. For more information about PerformancePoint Services DLLs, see PerformancePoint Services DLLs Used in Development Scenarios.

  • Add the following using directives:

    using Microsoft.PerformancePoint.Scorecards.Indicators
    using Microsoft.PerformancePoint.Scorecards.Store;
    using System.Drawing;
    using System.IO;
    
  • Add an embedded resource file named Resource1 to your project that contains five image-type resources named nodata, red, orange, yellow, and green. These images represent the five states of the indicator.

// 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;
}

See also

Reference

SPDataStore class

SPDataStore members

Microsoft.PerformancePoint.Scorecards.Store namespace