ObjectGears Help

           
Forum   ObjectGears (Version: 1.6.0.0)

Module implementation

ObjectGears is reading all the DLL libraries from the folder Modules after the start. It looks for a class inheriting IModuleInterface (resp. ModuleInterfaceBase) in each library. If the library has no child class, it is dropped.
When child is found, couple of module properties is determined - name, author, version...

These properties are determined by means of function GetPropertyString:

  •  Name
  •  Version
  •  Description
  •  Producer
  •  ProducerUrl
  •  SupportEmail

Indicaton, whether module supports direct sending of SMS is determined directly by module property:

  •  EnableSendSMS


After that the module is stored in the list of modules and initialized by method Initialization:

 module.Initialization(app);

This passes on binding to the ObjectGears system to the module, by which the module can read configuration parameters and call system functions. It is necessary to store reference to IApplication in method Initialization for further use.
At the same time it is necessary to perform module initialization, e.g. reading classes and columns for further fast processing.

    public IApplication App { get; private set; }

    public override void Initialization(IApplication application)
    {
        App = application;
    }

By this module initialization is finished.

Modules can be called by means of scripts. Therefore it is necessary to set a unique code for the module via web interface. It would not be possible to determine which module you want to use without the code.

Calling module from a script

Code is used for identification when calling a module.

var m = O.Module['module_code'];

Above example finds the requested module in the list of modules by the code. After that function GetScriptObject() is called in the module and its result is returned.
After that functions and methods of the module object can be called. You will find their meaning and use in the documentation from the given module vendor.

Basic list of functions and methods is displayed in the page Interface definition.

We recommend to decore every function and method by attribute DescriptionAttribute for a better description of an object returned from function GetScriptObject. Description defined here is displayed in page Interface definition.

    [Description("Description of my function.")]
    public DataRowList GetHolidays(ClassDef clHoliday)
    {
        ...
    }

Example of module implementation

1) Create a new project for "Class Library" in language C# in order to create a new module in Microsoft Visual Studio.
2) Add reference to library Com.ObjectGears.Common.dll. You can find it in ObjectGears system installation.
3) Create a public class ModuleInterface and insert into it this foundation code:

    public class ModuleInterface : ModuleInterfaceBase
    {
        public IApplication App { get; private set; }

        public override string GetPropertyString(string code)
        {
            switch (code)
            {
                case ModuleInterfaceProperty.Name: return "MyCompany.Module.ModuleName";
                case ModuleInterfaceProperty.Version: return "1";
                case ModuleInterfaceProperty.Producer: return "My company";
                case ModuleInterfaceProperty.ProducerUrl: return "http://www.mycompany.eu";
                case ModuleInterfaceProperty.Description: return "Elementary module description.";
            }

            return null;
        }

        public override int? GetPropertyInt(string code)
        {
            return null;
        }

        public override DateTime? GetPropertyDateTime(string code)
        {
            switch (code)
            {
                case ModuleInterfaceProperty.Created: return new DateTime(2016, 1, 1);
            }

            return null;
        }

        public override void Initialization(IApplication application)
        {
            App = application;
        }

        public override object GetScriptObject()
        {
            return new ModuleObject(this);
        }
    }

    public class ModuleObject
    {
        private ModuleInterface inter;

        public ModuleUtilities(ModuleInterface inter)
        {
            this.inter = inter;
        }

        //...my function for module solution
        public string GetValue()
        {
           //testing log entry.
           inter.App.Log.Write("Run GetValue");
           //...

           //example of reading data via interface
           DataRow dr = inter.App.DataRow.GetDataById( 100, 10);
           return dr.ShortDescription;
        }
      }
    }

4) Add property values and your requested functions
5) Compile the project
6) Copy the DLL library into folder Modules to a web application and windows service. You will have to stop the the application before copying in order the DLL file from previous deployment can be overwritten. After application start current dll file will be read and initialized.

This website is using cookies files to provide services and analyse visits. You agree with that by using this website.     Further information