Modlr plugin

A Plugin interface is an easy way to allow for you to add your own extensions.

We have now extended the Plugin with yet another interface to facilitate the adding of custom ocl operations. This way the design time functions like CheckModel, ViewModels and OclEditor can be made to recognize your custom operations.

  1. namespace Modlr.Plugins
  2. {
  3.     public interface IModlrPlugin
  4.     {
  5.         string GetName();
  6.         List<IModlrPluginMenuOperation> ProvideOperations();
  7.     }
  8.  
  9.     public interface IModlrPluginMenuOperation
  10.     {
  11.         string GetName();
  12.         void CheckEnableOrExecute(IEcoServiceProvider esp, bool execute, IEcoObject maincontext, IEcoObject subcontext,out bool enabled );
  13.     }
  14.  
  15.  
  16.     public enum CallbackEventKind {CodeGen,ForcedCodeGen };
  17.     public interface IModlrPluginImportantEventCallbackHandler
  18.     {
  19.         void ImportantEventAboutToHappen(IEcoServiceProvider esp, CallbackEventKind eventkind, ref bool stop, ref string message);
  20.         void ImportantEventHasHappend(IEcoServiceProvider esp, CallbackEventKind eventkind);
  21.     }
  22.  
  23.     public interface IModlrPluginModelAccessOclType
  24.     {
  25.       /// <summary>
  26.       /// Possible usage – add custom ocl operations that can then be correctly executed by WECPOF and correctly evaluated in OCL design time
  27.       /// </summary>
  28.       void RuntimeModelAccess(IOclTypeService ocl);
  29.     }
  30.  
  31.  
  32. }

 

I added an example in the demos folder called ModlrPluginCodeGenEventsAndCustomOCLOperations

Not going to repeat everything here but a few goodies.

  1. namespace ModlrPluginCodeGenEventsAndCustomOCLOperations
  2. {
  3.   public class Plugindemo : IModlrPlugin, IModlrPluginMenuOperation, IModlrPluginModelAccessOclType, IModlrPluginImportantEventCallbackHandler
  4.   {
  5.     public string GetName()
  6.     {
  7.       return "AnotherPlugin";
  8.     }

The IModlrPluginImportantEventCallback can do things on codegen>

  1. public void ImportantEventAboutToHappen(Eco.ObjectRepresentation.IEcoServiceProvider esp, CallbackEventKind eventkind, ref bool stop, ref string message)
  2. {
  3.   // Here you can perform checks before codegen, and optionally stop the codegen
  4.   System.Windows.Forms.MessageBox.Show("You are updating the code, this annoying message came from plugin ModlrPluginCodeGenEventsAndCustomOCLOperations");
  5. }

But the brand new interface is the IModlrPluginModelAccessOclType>

  1. public void RuntimeModelAccess(IOclTypeService ocl)
  2. {
  3.   ocl.InstallOperation(new CustomOCL_SplitAtSemi());
  4. }

And the operation (really a different subject) looks like this:

  1. public class CustomOCL_SplitAtSemi : OclOperationBase
  2. {
  3.   public CustomOCL_SplitAtSemi()
  4.   {
  5.   
  6.   }
  7.  
  8.   protected override void Init()
  9.   {
  10.     InternalInit("SplitAtSemi", new IOclType[] { Support.StringType }, Support.StringType);
  11.  
  12.   }
  13.  
  14.   public override void Evaluate(IOclOperationParameters __Params)
  15.   {
  16.     string s = Support.GetAsString(__Params.Values[0]);
  17.     string[] ss=s.Split(';');
  18.     string first = "";
  19.     if (ss.Length > 0)
  20.       first = ss[0];
  21.     Support.MakeNewString(__Params.Result, first);
  22.   }
  23. }

So this is really super because my model validates in design time even if I use the custom operation:

image

Viewmodel columns that use the custom expression are evaluated correctly:

image

CheckModel stays empty since everything is validated:

image

And of course the prototyping actually executes your operations:

image

This entry was posted in CO-Unique, Modlr, OCL, Plugin. Bookmark the permalink.

Leave a Reply to Anonymous Cancel reply

Your email address will not be published. Required fields are marked *

*