Template plug-in

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 only 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 play head position of the selected MediaItem.

Within 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   Called from user interface (UI) to set the publishing host (called only from the Expression Encoder UI).

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

OnEncodeStart   Called at the start of an encode operation. If this method throws, the encode operation is canceled and an error message is displayed.

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

DataModal   A type derived from TemplateParameterProperties that defines the data modal for the plug-in. A data modal 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 runtime.

CreatePreviewControl   Returns the object that is used for the preview control. Returning a URI will use that URL in a web browser. This is special cased so the web browser control isn’t 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   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 two code additions for the connection to occur between the job in the Expression Encoder UI and the template:

  1. The template to be customized through the plug-in needs 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 (ModifiedClassic) is:

    <!-- <$@ Options Plugin="TemplatePlugin.TheTemplatePlugin, templateplugin.dll"$> -->
    
  2. The UserControl tag in the XAML needs the following line:

    xmlns:ns="clr-namespace:Microsoft.Expression.Encoder.Plugins.Templates;assembly=Microsoft.Expression.Encoder"
    

To run the Template Plugin sample

  1. Build the template plug-in.

  2. Copy the sample template found in the Templates directory of the ModifiedClassic 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 dropdown list, select Modified Classic for Template Plugin Sample and then expand the settings.

  6. Fill 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.

See also

Other resources

Expression Encoder 2 SDK