Black Knight

Chameleon





C# Tutorial

To write a Chameleon plug-in in C#, follow these steps:

1. Create a new C# project in Visual Studio 2005 (or another .Net development environment)

2. Add a reference to Chameleon_Plugin.dll

3. Copy and paste the code skeleton below into your empty .cs file.

namespace Your.Namespace
{
    using System;
    using System.ComponentModel;
    using BKTech.Chameleon.Plugins;

    //You must implement IChameleonPlugin from
    //BKTech.Chameleon.Plugins (in Chameleon_Plugin.dll)
    public class YourPluginName : IChameleonPlugin
    {
        #region "Private Members"
        //the array of input files from the client
        private string[] myDataFiles;

        //a delegate that allows this plug-in to
        //send progress updates to the client
        private FeedBack.sendFeedBack myReporter;
        #endregion

        #region "Public Properties"

        //Returns author string for display in GUI
        //Browsable(false) prevents from showing up in custom property tab
        [Browsable(false)]
        public string Author
        {
            get { return ""; }
        }

        //Returns category string for display in GUI
        //no effect on plug-in placement in tree
        [Browsable(false)]
        public string Category
        {
            get { return ""; }
        }

        //Returns description string for display in GUI
        [Browsable(false)]
        public string Description
        {
            get
            {
                return "";
            }
        }

        //Returns expected input string for display in GUI
        [Browsable(false)]
        public string ExpectedInput
        {
            get { return ""; }
        }

        //Returns output string for display in GUI
        [Browsable(false)]
        public string Output
        {
            get { return ""; }
        }


        #endregion

        #region "Public Methods"
        
        /// <summary>
        /// Initializes this plug-in
        /// </summary>
        /// <param name="dataFiles">The array of
        /// input files from the client</param>
        /// <param name="reporter">A delegate for reporting status updates
        /// to the client</param>
        /// <returns>True if we are clear to begin execution, false if we have
        /// invalid input and need to abort</returns>
        public bool Initialize(string[] dataFiles,
                                    FeedBack.sendFeedBack reporter)
        {
            myDataFiles = dataFiles;
            myReporter = reporter;

            reporter("Initialized with " + myDataFiles.Length.ToString() +
                                        " files", FeedBack.ReturnCode.Success);

            return true;

        }

        
        /// <summary>
        /// The core logic of this plug-in
        /// </summary>
        /// <returns>True if executed successfully, false otherwise</returns>
        public bool Execute()
        {

            myReporter("YourPluginName has completed execution.",
                                                FeedBack.ReturnCode.Success);
            return true;
        }
        
        /// <summary>
        /// Loads saved custom properties
        /// </summary>
        /// <param name="loadValue">The value saved by the client in
        ///the .cham file for this plug-in</param>
        /// <returns>True if loaded successfully, false if there was
        /// a problem</returns>
        public bool Load(string loadValue)
        {
                return true;
        }
        
        /// <summary>
        /// Saves this plug-in's data
        /// </summary>
        public string Save()
        {
            return "";
        }
        
        /// <summary>
        /// Cleans up this plug-in
        /// </summary>
        public bool Clean()
        {
            return true;
        }
        #endregion
    }
}
                

4. Implement desired logic

5. Compile

6. Copy to the plug-ins directory

7. Start Chameleon