Nik's Technology Blog

Travels through programming, networks, and computers

Debugging Alterian CMC / Immediacy Plug-ins

Debugging an Alterian CMC/Immediacy plug-in isn’t that straight forward because when they don’t work there isn’t an easy way for a developer to determine the problem.

In the Editor you generally get an unhelpful pop-up message like this:

immediacy editor error

Which also means none of the plug-ins will be available for use.

There is an CMC log file that can be viewed by navigating to the following path on your web server.

C:\Program Files\Alterian\CMC 6.2\CMS\Logging\ViewLogFile.xml

immediacy-logs

But this isn’t as helpful as it may seem because if a plug-in has errors then they won’t generally get logged here or anywhere else it seems.

The other tool you have at your disposal is a special plug-ins page that enumerates the plug-ins installed or throws an error when one has broken.  This error can sometimes lead you to a fix for the problem.

Open Internet Explorer on your web server and navigate to:

http://localhost/_immediacy/editor/plugins.ashx

Note: This will only work locally on the web server, and will return some XML defining the properties for each installed plug-in.

immediacy-plugins

Developing Scheduled Tasks for Immediacy Management Console (Alterian CMC)

Immediacy Management Console Scheduled Tasks are useful for running tasks that need to occur automatically on a frequent basis which are independent of website visitor actions.

immediacy-mc

These scheduled tasks have the advantage of being able to hook up to the Immediacy API, allowing developers to perform tasks on Immediacy pages etc.

Scheduled tasks can have public properties if required, which are entered via a Plug-in Settings dialog box.

immediacy-mc-settings

Plug-in Development

Immediacy Management Console plug-ins are simply a .NET class library. The project should contain a C# or VB.NET file containing the plug-in and a separate class which defines the Plug-in Settings dialog.

The plug-in class needs to reference the following Immediacy namespaces.

Immediacy.Configuration;
Immediacy.Service.Interfaces;

Your plug-in class needs to inherit from:

Immediacy.Service.Interfaces.Plugin

And your class needs to have a few class attributes for Immediacy (CMC) to recognise your plug-in:

    [SettingsControlTypeAttribute(typeof(SiteMapSettings))]
    [GuidAttribute("XXXX8D90-XXXX-XXXX-XXXX-A3341127XXXX")]
    [PluginDetailsType("Name of Plug-in", "Description")]

Your plug-in class constructor needs to pass the settings to the base class as follows:

public Sitemap(ImcFile imcFile, StringDictionary settings) : base(imcFile, settings) { }

To build your plug-in you need to override the Execute() method and put your code in here.

Plug-in Settings Dialog Development


The plug-in settings dialog is created by another class, which inherits from Immediacy.Service.Interfaces.SettingsControl

This class is essentially a Windows Form code file without the form designer, so you’ll need to import the  System.Windows.Forms namespace.

You’ll need to add Windows.Forms Labels and TextBoxes to the dialog box to capture the public properties from the user who configures the plug-in while scheduling it.

Implement the abstract class like the example below:

 

namespace ImmPlugins.Sitemap

{

    public class SettingTest : Immediacy.Service.Interfaces.SettingsControl

    {

        private System.Windows.Forms.TextBox txtUrl;

  private System.Windows.Forms.Label lblUrl;

 

  private System.ComponentModel.Container components = null;

 

        public SiteMapSettings(Type pluginType)

            : base(pluginType)

        {

            InitializeComponent();

        }

 

        public override System.Collections.Specialized.StringDictionary Settings

        {

            get

            {

                StringDictionary retVal = new StringDictionary();

                retVal.Add("url", txtUrl.Text);

                return retVal;

            }

            set

            {

                txtUrl.Text = (string)value["url"];

            }       

  }

 

        public override bool SettingsAreValid

        {

            get {

                  if (txtUrl.Text == “”)

                  {

return false;

                  }

                  else

                  {

                        return true;

                  }

}

        }

 

        public override string SettingsAreValidVerbose

        {

            get {

string errorText = string.Empty;

                  if (txtUrl.Text == "")

                  {

errorText += "Please specify a URL \r\n";                 

}

return errorText;
}

        }

 

        private void InitializeComponent()

        {

            this.lblUrl = new System.Windows.Forms.Label();

            this.txtUrl = new System.Windows.Forms.TextBox();

 

            this.txtUrl.Location = new System.Drawing.Point(202, 59);

            this.txtUrl.Name = "txtUrl";

            this.txtUrl.Size = new System.Drawing.Size(160, 20);

            this.txtUrl.TabIndex = 2;

 

            this.lblUrl.Location = new System.Drawing.Point(8, 59);

            this.lblUrl.Name = "lblUrl";

            this.lblUrl.Size = new System.Drawing.Size(188, 16);

            this.lblUrl.TabIndex = 1;

            this.lblUrl.Text = "URL:";

 

this.ClientSize = new System.Drawing.Size(374, 183);

            this.Controls.Add(this.lblUrl);

            this.Controls.Add(this.txtUrl);

            this.Name = "PluginSettings";

            this.ResumeLayout(false);

            this.PerformLayout();

        }

 

        protected override void Dispose(bool disposing)

        {

            if (disposing)

            {

                if (components != null)

                {

                    components.Dispose();

                }

            }

            base.Dispose(disposing);

        }

    }

}

Plug-in Installation


Immediacy Management Console plug-ins are installed in the Immediacy CMS folder path.

Simply compile your .NET class library to a DLL and copy it to this directory.

e.g. C:\Program Files\Immediacy\CMS\6.1\Service\Plugins

(Note: This path maybe slightly different on your installation depending on Immediacy version, drive path etc)

If all has gone well your plug-in should show up in the list of tasks which can be scheduled in the Immediacy Management Console.

Creating an Immediacy (Alterian Content Manager) Plug-in

An Immediacy plug-in is a special type of ASP.NET User Control that allows you to extend the functionality of the core content management system. http://www.immediacy.net/

Follow these instructions to create a custom plug-in for the Immediacy/CMC CMS.

Instructions

Create a new directory within the Immediacy plug-ins directory for your plug-in. This new directory will hold the .ascx file for your user control plus your Immediacy editor dialogue UI (Which is a special web file that allows you to change the plug-in settings from within the Immediacy editor).

The name of your plug-in directory should have the same name as the “tagName” you use to register the User Control in Immediacy’s web.config file.

Build your ASP.NET User Control to perform your custom functionality making sure that you create public properties in your C#/VB.NET code for all the properties you would like configurable from within the Immediacy editor.

Add a reference to the Immediacy.Web assembly to your project.

Next, add these attributes to your User Control class.

[PluginDesigner(PluginDesignerType.Html, "PluginCmsDialogue.aspx", Height = 400, Width = 400)]
[ToolboxData("<{0}:PluginName runat=server></{0}:PluginName>")]
[PluginInfo("My First Plug-in", "CMS Plug-in Category", Description = "Description of my Plug-in")]
public partial class Comments : System.Web.UI.UserControl, INamingContainer
{
    // Your plug-in code here
}

If you don’t add these class attributes your plug-in properties will not be configurable from within Immediacy, but the plug-in will still work.
If you don’t have public properties that you want editors to be able to change you can skip creating a dialogue box for your plug-in.

Create an Editor Dialogue Pop-up

Create a CMS dialogue page which will allow Immediacy users to change the properties of your custom plug-in from within the editor. The name of this file is referenced in the class attributes above (e.g. PluginCmsDialogue.aspx) .

Your dialogue box can be either an HTML file with JavaScript or an ASP.NET web form. This example uses an HTML page with a .aspx extension, although it doesn’t contain any server-side code. 

In the HTML you need to reference the Helpers.js JavaScript file that resides in the Immediacy plug-ins folder.

<script type="text/javascript" src="../Helpers.js"></script>

Create a simple HTML form with form elements to match each public property of your plug-in class.

Add two HTML buttons, one for OK, one for Cancel. Give them IDs of ok and cancel respectively.

Create a JavaScript function called Init() as below.

<script type="text/javascript">
var Dialog;

function Init()
{
   Dialog=new DialogObject("name of plugin", 400, 400); Dialog.UniqueKeys=false;

   // Load each property and update the dialogue box
   Dialog.Load("property", function(value){document.getElementById("property").value=value;});

   // Add functionality to the OK and Cancel HTML buttons
   document.getElementById("ok").onclick=function(){Dialog.Ok();}
   document.getElementById("cancel").onclick=function(){Dialog.Cancel();}

   Dialog.Valid=function()
   {
     
// Perform validation here
      return true;
   }

   Dialog.Submit=function()
   {
     
// Save each property
      Dialog.Save("property",document.getElementById("property ").value);

      // Update the Immediacy control UI placeholder
      Dialog.InnerHTML="<div style='background:#DDDDDD; color:#000000; float:left; padding:10px; clear:both;'><strong>Comments Enabled : </strong>Status of Plug-in</div>";
   }
}
</script>

At the bottom of your dialogue HTML call the Init() function as below.

<script type="text/javascript">Init();</script>

Install the Plug-in

Register your ASP.NET User Control to Immediacy’s web.config under <pages><controls> as you would with an ordinary User Control. Ensure the “tagName” is the same as the plugin directory name for your plugin.

<add tagPrefix="MyUserControls" tagName="PluginName" src="~/plugins/ PluginName /test.ascx"/>

Build your project in Visual Studio.

Copy the .ascx and your dialogue box HTML file to the /plugins/PluginName folder.

Copy the .dll file to the Immediacy bin folder.