SPDataStore.CreateIndicator - Méthode

Enregistre un objet indicateur sous la forme d'un type de contenu dans une liste SharePoint.

Espace de noms :  Microsoft.PerformancePoint.Scorecards.Store
Assembly :  Microsoft.PerformancePoint.Scorecards.Store (dans Microsoft.PerformancePoint.Scorecards.Store.dll)

Syntaxe

'Déclaration
Public Function CreateIndicator ( _
    listUrl As String, _
    newElement As Indicator _
) As Indicator
'Utilisation
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
)

Paramètres

  • listUrl
    Type : System.String

    L'URL relative de serveur de la liste SharePoint pour enregistrer l'objet. Exemple : /BI Center/Lists/PerformancePoint Content.

  • newElement
    Type : Indicator

    L'objet indicateur pour enregistrer, qui spécifie une valeur pour la propriété obligatoire Name .

Valeur renvoyée

Type : Indicator
Le nouvel objet, qui contient des informations mises à jour ce son numéro de version et d'emplacement.

Implémentations

IBIMonitoringStore.CreateIndicator(String, Indicator)

Exemples

L'exemple de code suivant montre comment utiliser une méthode privée pour créer un indicateur et d'appeler CreateIndicator(String, Indicator) pour l'enregistrer dans le référentiel. L'exemple utilise une méthode d'assistance (GetImageAsString) pour convertir des images à partir d'un fichier de ressources.

Pour pouvoir compiler cet exemple de code, vous procédez comme suit :

  • Configurer votre environnement de développement et créer un projet de bibliothèque de classes c# dans Visual Studio. Pour plus d'informations sur la configuration d'un environnement de développement, voir Configurer un environnement de développement général pour SharePoint 2013.

  • Ajoutez le Microsoft.PerformancePoint.Scorecards.Client, Microsoft.PerformancePoint.Scorecards.ServerCommon, Microsoft.PerformancePoint.Scorecards.Store et des fichiers DLL System.Drawing en tant que références à votre projet Visual Studio . Pour plus d'informations sur PerformancePoint Services DLL, voir PerformancePoint Services DLLs Used in Development Scenarios.

  • Ajoutez les directives using suivantes.

    using Microsoft.PerformancePoint.Scorecards.Indicators
    using Microsoft.PerformancePoint.Scorecards.Store;
    using System.Drawing;
    using System.IO;
    
  • Ajoutez un fichier de ressource incorporée nommé Resource1 à votre projet qui contient les ressources de type image cinq nommées nodata, red, orange, yellowet green. Ces images représentent les cinq États de l'indicateur.

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

Voir aussi

Référence

SPDataStore classe

SPDataStore - Membres

Microsoft.PerformancePoint.Scorecards.Store - Espace de noms