Share via


How to: Implement the DataSourceTemplateFactory Class

Implement the DataSourceTemplateFactory class to perform the following operations in PerformancePoint Dashboard Designer:

  • Add the data source to the Select a Data Source Template dialog box.

  • Create an instance of the data source.

  • Add the data source object to the Dashboard Designer workspace browser.

  • (Optional) Implement wizard pages that let users define the data source object.

The complete code example for this class is provided in the Example section.

Note

For information about creating the designer that appears when a data source object is selected in the workspace browser, see How to: Create Data Source Designers.

To implement the DataSourceTemplateFactory class

  1. Create the CustomDataSourceTemplateFactory class in the Extensions.Dashboard namespace.

  2. Add the following using directives.

    using System;
    using System.Collections.Generic;
    using Microsoft.PerformancePoint.Scorecards;
    using Microsoft.PerformancePoint.Scorecards.Modeler.Framework;
    using Microsoft.PerformancePoint.Scorecards.ModelerWorkspace;
    using Microsoft.PerformancePoint.Scorecards.ModelerPlugins.Templates;
    using Microsoft.PerformancePoint.Scorecards.ModelerPlugins.DataSources;
    
  3. Inherit from the DataSourceTemplateFactory class.

  4. Set custom identifiers for the class and template type.

  5. To return the unique string identifier for the custom data source template, override the GetTemplateTypeId method.

  6. To return the System.Type of the custom data source template, override the GetTemplateType method.

  7. To integrate your template into the Select a Data Source Template dialog box, override the GetTemplateItems method.

  8. To create the data source object, override the CreateTemplateItem method.

  9. To add the data source object to the Dashboard Designer workspace, implement the AddToWorkspace method.

  10. (Optional) To implement wizard pages so users can specify properties for the data source object, build Windows Forms panel and pages. Then, add code to the CustomDataSourceTemplateFactory class to open the wizard. These instructions are beyond the scope of this documentation.

Example

The class in the following code example creates a template for a custom data source.

using System;
using System.Collections.Generic;
using Microsoft.PerformancePoint.Scorecards;
using Microsoft.PerformancePoint.Scorecards.Modeler.Framework;
using Microsoft.PerformancePoint.Scorecards.ModelerWorkspace;
using Microsoft.PerformancePoint.Scorecards.ModelerPlugins.Templates;
using Microsoft.PerformancePoint.Scorecards.ModelerPlugins.DataSources;

namespace Extensions.Dashboard
{
    public class CustomDataSourceTemplateFactory : DataSourceTemplateFactory
    {

        // Set the identifier for the template type.
        public new static readonly string TemplateTypeId = "CustomDataSourceTemplateFactory";

        #region Methods
        // Get the identifier for the CustomDataSourceTemplateFactory class.
        // The identifier has identity with this factory, but not with
        // the templates that this factory creates.
        public override string GetTemplateTypeId()
        {
            return TemplateTypeId;
        }
        
        // Get the class type for the data source template.
        public override Type GetTemplateType()
        {
            return typeof(CustomDataSourceTemplateFactory);
        }
        
        // Get the available data source templates for the New Data Source wizard.
        // In this case, only this data source template is returned.
        public override List<TemplateItem> GetTemplateItems()
        {
            List<TemplateItem> items = new List<TemplateItem>();

            TemplateItem item1 = new TemplateItem();
            item1.Name = "Custom Data Source";
            item1.Folder = @"All\Custom";
            item1.Description =
                "<span style='font-size:8.0pt;font-family:\"MS Reference Sans Serif\",\"sans-serif\"'>" +
                "Custom Data Source<hr>This data source retrieves ..." +
                "</span>";
            item1.TemplateId = CustomDataSourceFactory.CustomDataSourceName;
            item1.TemplateTypeId = GetTemplateTypeId();
            items.Add(item1);

            return items;
        }
      
        // Create a new data source using the specified template.
        public override void CreateTemplateItem(TemplateItem item)
        {
            if (item.TemplateId == CustomDataSourceFactory.CustomDataSourceName)
                CreateDataSource(CustomDataSourceFactory.CustomDataSourceName);
        }
        
        private static void AddToWorkspace(DataSource dataSource)
        {
            if (null != dataSource)
            {
                ScorecardModel.GetInstance().DataSourcesInWorkspace.Add(dataSource);

                MainForm.GetInstance().
                    OpenWorkspaceItem
                    (typeof(DataSource), DataSourcesWorkspaceItemFactory.DataSourcesGuid, dataSource.Guid, true);

                ScorecardModel.GetInstance().
                    FireFirstClassElementChanged
                    (ScorecardModel.InternalWorkspaceItemUpdate, ScorecardModel.GetInstance().GetElement(dataSource.Guid) as FirstClassElement);
            }
        }
        #endregion

    }
}

See Also

Concepts

How to: Create Data Source Designers

Other Resources

Data Sources