Template plug-in sample

The template plug-in lets you customize template settings and interact with the job through the IPluginHost interface. The plug-in also lets you add or remove files from the template output when the template is published.

The following code sample demonstrates how to add the default template parameter control to Microsoft Expression Encoder with several lines of XAML. It also implements a custom-script-command–creation feature that shows how the template plug-in can interact with the current job by adding a script command at the current playhead position of the selected MediaItem.

In Expression Encoder, every template receives a template plug-in. If the template doesn't specify one, a default one will be assigned. A template plug-in derives from the TemplatePlugin class, which in turn derives from the EncoderPlugin class.

public abstract class EncoderPlugin : MarshalByRefObject
      public void InitPublishingHost(IPluginHost host);
      protected IPluginHost PublishingHost{get;}
      public virtual void OnEncodeStart(JobBase job, MediaItem[] items)

InitPublishingHost   Sets the publishing host when called from the Expression Encoder UI.

PublishingHost   Returns the current publishing host or a null value if not set.

OnEncodeStart   Cancels the encoding operation and displays an error message. Called at the start of an encode operation.

public abstract class TemplatePlugin : EncoderPlugin
      public virtual TemplateParameterProperties DataModal{get;}
      public virtual object CreatePreviewControl(){get}
      public virtual object CreateUserInterface(){get;}
      public virtual string[] CreateFileList(string destinationRoot, string[] currentFiles);
      public TemplateParameterDictionary TemplateParameters{get;}

DataModel   Defines the data model for the plug-in. Is derived from TemplateParameterProperties. A data model class is a class that has a series of properties on it. These properties will be merged with the template parameters defined in the template at run time.

CreatePreviewControl   Returns the object that is used for the preview control. Returning a URI will use that URL in a web browser. This is a special case that prevents the web browser control from being destroyed and recreated multiple times.

CreateUserInterface   Returns the user control that is used in the template parameter control. The default implementation returns DefaultTemplateParameterUI, which can be used in the XAML as this sample does to show the default TemplateParameterUI.

CreateFileList   Allows the plug-in to add or remove files from the list of files to be published.

TemplateParameters   Is a dictionary object that enables template parameters to be set. For example, TemplateParameters[param] = "foo".

Besides deriving from the TemplatePlugin class, a template plug-in requires the following code addition for the connection to occur between the job in the Expression Encoder UI and the template. The template to be customized through the plug-in must have the following extra line in Default.html.

<$@ Options Plugin="{Plugin namespace}.{Plugin class}, {Full path of Plugin DLL}"$>

For example, the extra line in the template provided in this example (ModifiedSL3Standard) is.

<$@ Options Plugin="TemplatePlugin.TheTemplatePlugin, templateplugin.dll"$>

To run the Template Plugin sample

  1. Build the template plug-in.

  2. Copy the sample template found in the Templates directory of the ModifiedSL3Standard sample to the Expression Encoder Templates directory.

  3. Copy the built plug-in DLL (TemplatePlugin.dll) in the same directory.

  4. Open Expression Encoder.

  5. Click the Output tab. On the Job Output pane, in the Template drop-down list, select Modified Silverlight 3 Default for Template Plugin Sample, and then expand the settings.

  6. Type a name in the Command Name text box and click Create Custom Script Command to generate a new script command at the current playhead position.

  7. Select Template Parameters to use the embedded template parameter control.

   © 2011 Microsoft Corporation. All rights reserved.

Community Additions