CodeCarvings Piczard V1.2 Help
How To Develop A Custom Plugin
Send Feedback
Extending Piczard > Plugins > How To Develop A Custom Plugin

Glossary Item Box

CONTENTS

  1. Step 1 - Inherit from the Plugin abstract class
  2. Step 2 - Implement one of the available interfaces
  3. Step 3 - Use the Plugin

 

Please see:

  • The MyStaticLocalizationPlugin class contained in the ~/App_Code folder of ExampleSet A
  • The MyDynamicLocalizationPlugin class contained in the ~/App_Code folder of ExampleSet A
  • The Example A.301 - "Customize Piczard / Localize & customize texts"

 

 

Step 1 - Inherit from the Plugin abstract class

If you want to develop a custom Plugin then you have to write a class inheriting from the abstract class Plugin.

Your class must implement the following functions

Example:

An "empty" Plugin Copy Code
public class MyPlugin
   : Plugin
{
   
public MyPlugin(PluginConstructorArgs constructorArgs)
       :
base(constructorArgs)
   {
   }
   
protected override void Initialize(PluginInitializationArgs initializationArgs)
   {
   }
}
Please note that only the internal methods of Piczard can instantiate a Plugin class.

 

 

Step 2 - Implement one of the available interfaces

The second step is to implement one (or more) of the following interfaces (depending on which features you want to develop):

  1. IStaticLocalizationPlugin
  2. IDynamicLocalizationPlugin
  3. IImageArchiverPlugin
  4. IImageQuantizerPlugin

 

 

Every method of these interfaces expects 2 types of results:

In fact, a Plugin method can handle - or not handle - a particular method invocation.

Example: if a Piczard Plugin implements the IDynamicLocalizationPlugin interface, then it contains the following method:

PluginOperationResult<string> GetString(string key, string culture, string tag)

Supposing that such Plugin handles only the "fr" language, then there are 2 kind of results:

Example:

A Plugin implementing the IDynamicLocalizationPlugin interface Copy Code
public class MyPlugin
   : Plugin, IDynamicLocalizationPlugin
{
   
public MyDynamicLocalizationPlugin(PluginConstructorArgs constructorArgs)
       :
base(constructorArgs)
   {
   }
   
protected override void Initialize(PluginInitializationArgs initializationArgs)
   {
   }
   
public PluginOperationResult<string> GetString(string key, string culture, string tag)
   {
       
string result = null;
       
if (culture == "fr")
       {
           
// Manage the "fr" culture
  
           
switch (key)
           {
               
case "PT_MUI_Text_Details":
                   result =
"Dé;
                   
break;
               
case "PT_MUI_Text_Original":
                   result =
"Source:";
                   
break;
           }
       }
       
if (result != null)
       {
           
// Return the custom text
           
return base.GetHandledResult<string>(result);
       }
       
else
       {
           
// Use the default text
           
return base.GetNotHandledResult<string>();
       }
   }
}

 

 

Step 3 - Use the Plugin

It is mandatory to register a Plugin in the application configuration file in order to allow Piczard to use it.

The following example code shows how to register a Plugin in the application configuration file.
For more information please see:

Configuration file Copy Code
<?xml version="1.0"?>
 
<configuration>
   
<configSections>
     
<sectionGroup name="codeCarvings.piczard">
       
<section name="coreSettings" type="CodeCarvings.Piczard.Configuration.CoreSettingsSectionHandler, CodeCarvings.Piczard" requirePermission="false"/>
     
</sectionGroup>
   
</configSections>
   
<codeCarvings.piczard>
     
<coreSettings>
       
<plugins>
         
<plugin type="MyPlugin, App_Code" />
       
</plugins>
     
</coreSettings>
   
</codeCarvings.piczard>
</
configuration>

In most cases the use of a Plugin is transparent for the application.
For example, suppose that you register a Plugin (implementing the IImageArchiverPlugin interface) that allows to load the hypothetical image format FOO.
Then you want to load the image "MySourceIMage.FOO".
In this case your application can use the standard LoadImage method provided by Piczard (without any particular device!).
Example:

Load image example Copy Code
LoadedImage image = ImageArchiver.LoadImage("MySourceIMage.FOO")

Is the task of Piczard and the custom Plugin class to "understand" that the file to load is "FOO" (and therefore the custom Plugin has to handle the loading of that file).

©2013 Sergio Turolla. All Rights Reserved.