How to: Create a KPI Wizard Template
To create a KPI wizard template, your extension must:
Reference the Microsoft.PerformancePoint.Scorecards.ModelerPlugins DLL.
Reference the Microsoft.PerformancePoint.Scorecards.Client DLL.
Inherit from the TemplateFactory or KpiTemplateFactory class; both are in the ModelerPlugins DLL.
Override the GetTemplateTypeId, GetTemplateType, GetTemplateItems, and CreateTemplateItem methods.
The example in this topic inherits from the TemplateFactory class.
Implementing TemplateFactory to create a custom KPI
The following code example creates a KPI wizard template.
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using Microsoft.PerformancePoint.Scorecards.Modeler.Framework;
using Microsoft.PerformancePoint.Scorecards.WizardFramework;
using Microsoft.PerformancePoint.Scorecards;
using Microsoft.PerformancePoint.Scorecards.ModelerWorkspace;
using Microsoft.PerformancePoint.Scorecards.ModelerPlugins.Templates;
using Microsoft.PerformancePoint.Scorecards.ModelerPlugins.Indicators;
using Microsoft.PerformancePoint.Scorecards.ModelerPlugins.Controls;
using Microsoft.PerformancePoint.Scorecards.ModelerPlugins.DataSources;
using Microsoft.PerformancePoint.Scorecards.ModelerPlugins.Utilities;
using Microsoft.PerformancePoint.Scorecards.ModelerPlugins.Kpis;
namespace SampleKPITemplate
{
public class SampleKpiTemplateFactory : TemplateFactory
{
#region Member Data
// The identifier for the TemplateFactory class.
public static readonly string TemplateTypeId = "SampleKpiTemplateFactory";
public static readonly string SampleTemplateId = "KPISample";
#endregion
#region Methods
// Get the identifier for the TemplateFactory class.
public override string GetTemplateTypeId()
{
return TemplateTypeId;
}
// Get the type of TemplateFactory.
public override Type GetTemplateType()
{
return typeof(SampleKpiTemplateFactory);
}
// Get the available template items for the template
// creation wizard.
public override List<TemplateItem> GetTemplateItems()
{
List<TemplateItem> items = new List<TemplateItem>();
// Create a template item.
TemplateItem item1 = new TemplateItem();
// Set properties for the item.
item1.Name = "Sample KPI";
item1.Folder = @"Standard KPIs\SampleKPI";
// The image for the custom KPI template.
// Change the image name to reference your custom image.
item1.Image = Resource1.BeanmanQuest;
item1.TemplateId = SampleTemplateId;
item1.TemplateTypeId = GetTemplateTypeId();
item1.Description = "Sample KPI Description";
items.Add(item1);
return items;
}
// Create a new template item (KPI) using the template
// specified in the "item" parameter.
public override void CreateTemplateItem(TemplateItem item)
{
if (item.TemplateId == SampleTemplateId)
// Call the method that creates the template item (KPI).
// You must develop your own method to create the
// template item.
CreateSampleKpi();
}
private void CreateSampleKpi()
{
WizardForm form = new WizardForm();
form.Title = "Sample KPI";
// Instantiate the wizard and set properties for it.
CreateElementWizardPage pageElement = new CreateElementWizardPage(form, typeof(Kpi));
// Change the image name to your custom image.
pageElement.Logo = Resource1.BeanmanQuest;
pageElement.Headline = "Sample KPI Wizard";
pageElement.StepTitle = "Create Sample KPI";
form.AddPage(pageElement);
// Open the wizard.
form.Start(MainForm.GetInstance());
// Click finish to create the KPI.
if (form.DialogResult == DialogResult.OK)
{
// Create the KPI and set KPI properties.
Kpi kpi = new Kpi();
kpi.Guid = Guid.NewGuid();
kpi.CreatedDate = DateTime.Now;
pageElement.SetElement(kpi);
Indicator indicatorStandard = ScorecardModel.GetInstance().GetIndicator(IndicatorTemplateFactory.IndicatorStoplightGuid);
if (indicatorStandard == null)
indicatorStandard = IndicatorTemplateFactory.CreateStoplightIndicator();
GeneralUtilities.AddToWorkspace(indicatorStandard, false);
// Create the KPI target and set the banding
// pattern for the target.
Target target = new Target();
target.Guid = Guid.NewGuid();
target.Name.Text = "sampleTarget";
target.IndicatorId = IndicatorTemplateFactory.IndicatorStoplightGuid;
target.Pattern = KpiPattern.IncreasingIsBetter;
target.Banding.ActualWorst = 0;
target.Banding.Type = BandType.Normalized;
target.Banding.SpreadMaximum = 1.2M;
target.Banding.SpreadMinimum = 0;
target.Banding.CustomBoundary.Add(.50M);
target.Banding.CustomBoundary.Add(1M);
kpi.Targets.Add(target);
// Add the KPI to the workspace.
GeneralUtilities.AddToWorkspace(kpi, true);
}
form.Dispose();
}
#endregion
}
}
See Also
Tasks
How to: Install a Wizard Template