Share via


How to: Create a Scorecard Wizard Template

To create a scorecard wizard template, your extension must:

  • Reference the Microsoft.PerformancePoint.Scorecards.ModelerPlugins DLL.

  • Reference the Microsoft.PerformancePoint.Scorecards.Client DLL.

  • Inherit from the TemplateFactory or ScorecardTemplateFactory class; both classes are in the ModelerPlugins DLL.

  • Override the GetTemplateTypeId, GetTemplateType, GetTemplateItems, and CreateTemplateItem methods.

If the scorecard that your template creates has custom properties, you can implement the Implementing FiniteProgressPage class, but that class is not strictly required for all wizard template extensions.

The code examples that follow create a template for a scorecard that contains KPIs.

Implementing TemplateFactory to create a custom scorecard

The following code example inherits from the TemplateFactory class and creates a wizard template for a fixed-value scorecard or a blank scorecard.

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.Modeler.Framework.Utilities;
using Microsoft.PerformancePoint.Scorecards;
using Microsoft.PerformancePoint.Scorecards.ModelerWorkspace;
using Microsoft.PerformancePoint.Scorecards.ModelerPlugins.Templates;
using Microsoft.PerformancePoint.Scorecards.ModelerPlugins.Controls;
using Microsoft.PerformancePoint.Scorecards.ModelerPlugins.Properties;
using Microsoft.PerformancePoint.Scorecards.ModelerPlugins.DataSources;
using Microsoft.PerformancePoint.Scorecards.ModelerPlugins.Utilities;
using Microsoft.PerformancePoint.Scorecards.ModelerPlugins.Scorecards;

namespace SampleScorecardTemplate
{
    public class SampleTemplateFactory : TemplateFactory
    {
        #region Member Data

        // The identifier for the TemplateFactory class.
        public static readonly string TemplateTypeId = "SampleScorecardTemplateFixedValues"; 

        #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(ScorecardTemplateFactory);
        }

        // 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 Fixed SC";
            item1.Folder = @"All\FixedSamples";

            // The image for the custom scorecard template.
            // Change the image names to reference your custom images.
            item1.Image = Resource1.BeanmanQuest;
            item1.TemplateId = "SampleScorecardTemplateFixedValues";
            item1.TemplateTypeId = GetTemplateTypeId();
            item1.Description = "Sample Fixed Values Scorecard Template Description";
            items.Add(item1);

            TemplateItem item2 = new TemplateItem();
            item2.Name = "Sample Blank SC";
            item2.Folder = @"All\BlankSamples";
            item2.Image = Resource1.BeanmanQuest1;
            item2.TemplateId = ScorecardTemplateId.BlankTemplateId;
            item2.TemplateTypeId = GetTemplateTypeId();
            item2.Description = "Sample Blank Scorecard Template Description";
            items.Add(item2);

            return items;
        }

        // Create a new template item (dashboard) using the template 
        // specified in the "item" parameter.
        public override void CreateTemplateItem(TemplateItem item)
        {
            if (item.TemplateId == "SampleScorecardTemplateFixedValues")

            // Call the method that creates the template item 
            // (fixed values scorecard).
            // You must develop your own method to create the 
            // template item.
            CreateSampleFixedValuesScorecard();

else if (item.TemplateId == ScorecardTemplateId.BlankTemplateId)

            // Call the method that creates the template item 
            // (blank scorecard).
            // You must develop your own method to create the 
            // template item.
            CreateBlankScorecard();
        }

        private void CreateSampleFixedValuesScorecard()
        {
            WizardForm form = new WizardForm();
            form.Title = "Sample Fixed Values Wizard";

            // Instantiate the wizard and set properties for it.
            CreateElementWizardPage elementPage = new CreateElementWizardPage(form, typeof(Scorecard));

            // Change the image name to your custom image.
elementPage.Logo = Resource1.BeanmanQuest;
            elementPage.Headline = "Sample Scorecard Wizard";
            elementPage.StepTitle = "Create Sample Scorecard";
            form.AddPage(elementPage);

            CreateKpisWizardPage kpisPage = new CreateKpisWizardPage(form);
            form.AddPage(kpisPage);

            SampleFixedValuesWizardProgressPage progressPage = new SampleFixedValuesWizardProgressPage(form, elementPage, kpisPage);

            // Call the progress page.
            form.AddPage(progressPage);

            ConfirmationPage confirmationPage = new ConfirmationPage(form);

            // Change the image name to your custom image.
            confirmationPage.Logo = Resource1.BeanmanQuest;
            form.AddPage(confirmationPage);
            form.Start(MainForm.GetInstance());
            form.Dispose();
        }

        private void CreateBlankScorecard()
        {
            WizardForm form = new WizardForm();
            form.Title = "Blank Scorecard";

            // Instantiate the wizard and set properties for it.
            CreateElementWizardPage pageElement = new CreateElementWizardPage(form, typeof(Scorecard)); 

            // Change the image name to your custom image.
            pageElement.Logo = Resource1.BeanmanQuest1; 
            pageElement.Headline = "Blank SC Headlines";
            pageElement.StepTitle = "Blank SC Steplines";
            form.AddPage(pageElement);

            // Open the wizard.
            form.Start(MainForm.GetInstance());

            // Click finish to create the scorecard.
            if (form.DialogResult == DialogResult.OK) 
            {

                // Create the scorecard and set scorecard properties.
                Scorecard scorecard = new Scorecard();
                scorecard.Guid = Guid.NewGuid();
                scorecard.CreatedDate = DateTime.Now; 

                ConfiguredView view = ConfiguredView.CreateDefaultConfiguredView(
                    MainForm.GetInstance().Font, 
                    ModelerColors.CellFormatInfoBackColor, 
                    ModelerColors.CellFormatInfoForeColor, 
                    ModelerColors.ColumnHeaderFormatInfoBackColor, 
                    ModelerColors.RowHeaderFormatInfoBackColor);

                scorecard.ConfiguredViews.Add(view); 
                scorecard.InitBeginPoints();
                scorecard.InitEndPoints();
                 ScorecardModel.GetInstance().UpdateScorecardBeginPoints(scorecard); 
                pageElement.SetElement(scorecard);

                // Add the scorecard to the workspace.
                GeneralUtilities.AddToWorkspace(scorecard, true);
                }
                form.Dispose();
            }

        #endregion
    }
}

Implementing FiniteProgressPage

The following code example creates the wizard progress page, which in turn creates a scorecard instance that contains KPIs. The information that a user selects in this page is serialized and stored as an XML binary large object (BLOB) in the CustomData field of the object.

using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.ComponentModel;
using Microsoft.PerformancePoint.Scorecards.Modeler.Framework;
using Microsoft.PerformancePoint.Scorecards.Modeler.Framework.Controls;
using Microsoft.PerformancePoint.Scorecards.WizardFramework;
using Microsoft.PerformancePoint.Scorecards;
using Microsoft.PerformancePoint.Scorecards.ModelerWorkspace;
using Microsoft.PerformancePoint.Scorecards.ModelerPlugins.Controls;
using Microsoft.PerformancePoint.Scorecards.ModelerPlugins.Utilities;
using Microsoft.PerformancePoint.Scorecards.ModelerPlugins.Indicators;
using Microsoft.PerformancePoint.Scorecards.ModelerPlugins.Scorecards;

namespace SampleScorecardTemplate
{
    class SampleFixedValuesWizardProgressPage : FiniteProgressPage
    {
        CreateElementWizardPage createElementWizardPage;
        CreateKpisWizardPage createKpisWizardPage;

        public SampleFixedValuesWizardProgressPage(WizardForm form, CreateElementWizardPage createElementWizardPage, CreateKpisWizardPage createKpisWizardPage)
            : base(form)
        {
            this.createElementWizardPage = createElementWizardPage;
            this.createKpisWizardPage = createKpisWizardPage;
            this.Headline = "Sample Fixed Values Wizard";
            this.StepTitle = "Sample Fixed Values";
this.Logo = Resource1.PAWPRINT;
            this.EndStep = 300;
        }

        // Create the indicator.
        public override void Start()
        {
            base.Start();
            this.StatusText = "Creating Indicator ...";
  
            this.NextStep();
            Indicator indicatorStandard = ScorecardModel.GetInstance().GetIndicator(IndicatorTemplateFactory.IndicatorStoplightGuid);
 
            this.NextStep();
            Indicator indicatorCentered = ScorecardModel.GetInstance().GetIndicator(IndicatorTemplateFactory.IndicatorStoplightCenteredGuid);

            this.NextStep();
            if (indicatorStandard == null)
                indicatorStandard = IndicatorTemplateFactory.CreateStoplightIndicator();
 
            this.NextStep();
            if (indicatorCentered == null)
                indicatorCentered = IndicatorTemplateFactory.CreateStoplightCenteredIndicator();

            this.NextStep();
            AddAction("IndicatorCreated", string.Format("Created Indicator", indicatorStandard.Name), "", true, WizardActionStatus.CompleteWithSuccess);

            this.NextStep();
            AddAction("IndicatorCenteredCreated", string.Format("Created Indicator", indicatorCentered.Name), "", false, WizardActionStatus.CompleteWithSuccess);

            this.NextStep();
            GeneralUtilities.AddToWorkspace(indicatorStandard, false);

            this.NextStep();
            GeneralUtilities.AddToWorkspace(indicatorCentered, false);

            this.NextStep();
            this.StatusText = "Creating Scorecard...";

            this.NextStep();

            // Create the scorecard.
            Scorecard scorecard = new Scorecard();
            scorecard.Guid = Guid.NewGuid();
            scorecard.CreatedDate = DateTime.Now;
            CreateElementWizardPage.SetElement(scorecard, createElementWizardPage.ElementName, createElementWizardPage.ElementFolder, createElementWizardPage.ElementPublic);

            this.NextStep();
            AddAction("ScorecardCreated", string.Format("Created Scorecard", scorecard.Name), "", false, WizardActionStatus.CompleteWithSuccess);

            // Create the KPIs.
            this.NextStep();
            KpiCollection kpis = new KpiCollection();
            int index = 0;
            foreach (DataGridViewRow row in createKpisWizardPage.DataGridView.Rows)
            {
                this.NextStep();
                this.StatusText = "Creating Kpi...";
                Kpi kpi = new Kpi();
                kpis.Add(kpi);
                kpi.Guid = Guid.NewGuid();
                kpi.CreatedDate = DateTime.Now;
                CreateElementWizardPage.SetElement(kpi, createElementWizardPage.ElementName, createElementWizardPage.ElementFolder, createElementWizardPage.ElementPublic);
                kpi.Name.Text = row.Cells[0].Value as string;
                decimal actualValue = 1;
                decimal targetValue = 1;
                 decimal.TryParse(GeneralUtilities.FullWidthToHalfWidth(row.Cells[2].Value as string), out actualValue);
                kpi.Actual.ModelCurrent = actualValue;

                Target target = new Target();
                target.Guid = Guid.NewGuid();
                target.Name.Text = "Target";
                decimal.TryParse(GeneralUtilities.FullWidthToHalfWidth(row.Cells[3].Value as string), out targetValue);
                target.ModelCurrent = targetValue;

                if ("Increasing is Better" == row.Cells[1].Value as string)
                {
                    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);
                }
                else if ("Decreasing is Better" == row.Cells[1].Value as string)
                {
                    target.IndicatorId = IndicatorTemplateFactory.IndicatorStoplightGuid;
                    target.Pattern = KpiPattern.DecreasingIsBetter;
                    target.Banding.ActualWorst = 1000;
                    target.Banding.Type = BandType.Normalized;
                    target.Banding.SpreadMaximum = 1.2M;
                    target.Banding.SpreadMinimum = 0;
                    target.Banding.CustomBoundary.Add(.50M);
                    target.Banding.CustomBoundary.Add(1M);
                }
                else if ("Closer to Target is Better" == row.Cells[1].Value as string)
                {
                    target.IndicatorId = IndicatorTemplateFactory.IndicatorStoplightCenteredGuid;
                    target.Pattern = KpiPattern.CloserToTargetIsBetter;
                    target.Banding.ActualWorst = 0;
                    target.Banding.Type = BandType.Normalized;
                    target.Banding.SpreadMaximum = 2M;
                    target.Banding.SpreadMinimum = 0;
                    target.Banding.CustomBoundary.Add(.50M);
                    target.Banding.CustomBoundary.Add(0.9M);
                    target.Banding.CustomBoundary.Add(1M);
                    target.Banding.CustomBoundary.Add(1.1M);
                    target.Banding.CustomBoundary.Add(1.5M);
                }

                kpi.Targets.Add(target);
                GeneralUtilities.AddToWorkspace(kpi, false);
                AddAction("KpiCreated" + index, string.Format("Created Kpi", kpi.Name), "", index == createKpisWizardPage.DataGridView.Rows.Count - 1 ? false : true, WizardActionStatus.CompleteWithSuccess);
                index++;
            }

            this.NextStep();
            this.StatusText = "Linking...";

            this.NextStep();
            this.StatusText = "Creating Scorecard View...";

            this.NextStep();
            ConfiguredView view = new ConfiguredView();
            view.Guid = Guid.NewGuid();
            view.Name.Text = "DefaultView";
            view.GridViewDefinition.DefaultRollupIndicatorId = IndicatorTemplateFactory.IndicatorStoplightGuid;

            foreach (Kpi kpi in kpis)
            {
                this.NextStep();
                GridHeaderItem kpiHeader = GridHeaderItem.CreateKpiHeader(kpi.Guid);
                view.GridViewDefinition.RootRowHeader.Children.Add(kpiHeader);
            }

            this.NextStep();
            GridHeaderItem actualHeader = GridHeaderItem.CreateActualHeader("Actual");
            view.GridViewDefinition.RootColumnHeader.Children.Add(actualHeader);

            this.NextStep();
            GridHeaderItem targetHeader = GridHeaderItem.CreateTargetHeader("Target");
            targetHeader.TargetSettings.RollupType = RollupTypes.AverageWeighted;
            view.GridViewDefinition.RootColumnHeader.Children.Add(targetHeader);

            this.NextStep();
            scorecard.ConfiguredViews.Add(view);

            this.NextStep();
            AddAction("KpiScorecardConfiguredView", "Created View for Scorecard", "", false, WizardActionStatus.CompleteWithSuccess);

            this.NextStep();
            AddAction("KpiScorecardLink", "Linked", "", false, WizardActionStatus.CompleteWithSuccess);

            this.NextStep();
            GeneralUtilities.AddToWorkspace(scorecard, true);

            foreach (Kpi kpi in kpis)
            {
                this.NextStep();
                ScorecardModel.GetInstance().FireFirstClassElementChanged(ScorecardModel.InternalWorkspaceItemUpdate, kpi);
            }

            this.Stop();
            Wizard.OnNext();
        }
    }
}

See Also

Tasks

How to: Install a Wizard Template

Other Resources

Wizard Templates