Modlr plugin

This article was moved to MDriven Wiki 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.     public interface IModlrPluginMenuOperation
  9.     {
  10.         string GetName();
  11.         void CheckEnableOrExecute(IEcoServiceProvider esp, bool execute, IEcoObject maincontext, IEcoObject subcontext,out bool enabled );
  12.     }
  13.     public enum CallbackEventKind {CodeGen,ForcedCodeGen };
  14.     public interface IModlrPluginImportantEventCallbackHandler
  15.     {
  16.         void ImportantEventAboutToHappen(IEcoServiceProvider esp, CallbackEventKind eventkind, ref bool stop, ref string message);
  17.         void ImportantEventHasHappend(IEcoServiceProvider esp, CallbackEventKind eventkind);
  18.     }
  19.     public interface IModlrPluginModelAccessOclType
  20.     {
  21.       /// <summary>
  22.       /// Possible usage – add custom ocl operations that can then be correctly executed by WECPOF and correctly evaluated in OCL design time
  23.       /// </summary>
  24.       void RuntimeModelAccess(IOclTypeService ocl);
  25.     }
  26. }


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.   protected override void Init()
  7.   {
  8.     InternalInit(“SplitAtSemi”, new IOclType[] { Support.StringType }, Support.StringType);
  9.   }
  10.   public override void Evaluate(IOclOperationParameters __Params)
  11.   {
  12.     string s = Support.GetAsString(__Params.Values[0]);
  13.     string[] ss=s.Split(‘;’);
  14.     string first = “”;
  15.     if (ss.Length > 0)
  16.       first = ss[0];
  17.     Support.MakeNewString(__Params.Result, first);
  18.   }
  19. }

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


Viewmodel columns that use the custom expression are evaluated correctly:


CheckModel stays empty since everything is validated:


And of course the prototyping actually executes your operations:


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

7 Responses to Modlr plugin

  1. Pingback: GB Bilder » Modlr plugin | CapableObjects

  2. Rick W says:

    Can I download the samples somewhere or do I just have to wait for the next daily build? I have 5580 from 5/20, but do not have this sample – I assume you just added it.

  3. Rick W says:

    Hmmm, just tried the latest daily build listed and still no IModlrPluginModelAccessOclType defined or sample listed.

  4. Rick W says:

    Did you ever check to see if this worked with the PM Validate Model and at runtime?

    • Rick W says:

      I had a problem, but I see how I caused it. The important thing for people to know is that you must add the custom ocl operation class to your EcoSpace in addition to providing it to this new plug-in feature.

  5. guest00 says:

    Hi Hans,
    Could you please explain how to register custom EAL operation using this really useful plugin functionality?
    Thank you

Leave a Reply

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


This site uses Akismet to reduce spam. Learn how your comment data is processed.