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.

namespace Modlr.Plugins
{
public interface IModlrPlugin
{
string GetName();
List<IModlrPluginMenuOperation> ProvideOperations();
}
public interface IModlrPluginMenuOperation
{
string GetName();
void CheckEnableOrExecute(IEcoServiceProvider esp, bool execute, IEcoObject maincontext, IEcoObject subcontext,out bool enabled );
}
public enum CallbackEventKind {CodeGen,ForcedCodeGen };
public interface IModlrPluginImportantEventCallbackHandler
{
void ImportantEventAboutToHappen(IEcoServiceProvider esp, CallbackEventKind eventkind, ref bool stop, ref string message);
void ImportantEventHasHappend(IEcoServiceProvider esp, CallbackEventKind eventkind);
}
public interface IModlrPluginModelAccessOclType
{
/// <summary>
/// Possible usage - add custom ocl operations that can then be correctly executed by WECPOF and correctly evaluated in OCL design time
/// </summary>
void RuntimeModelAccess(IOclTypeService ocl);
}
}

I added an example in the demos folder called ModlrPluginCodeGenEventsAndCustomOCLOperations

Not going to repeat everything here but a few goodies.

namespace ModlrPluginCodeGenEventsAndCustomOCLOperations
{
public class Plugindemo : IModlrPlugin, IModlrPluginMenuOperation, IModlrPluginModelAccessOclType, IModlrPluginImportantEventCallbackHandler
{
public string GetName()
{
return "AnotherPlugin";
}

The IModlrPluginImportantEventCallback can do things on codegen>

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

But the brand new interface is the IModlrPluginModelAccessOclType>

public void RuntimeModelAccess(IOclTypeService ocl)
{
ocl.InstallOperation(new CustomOCL_SplitAtSemi());
}

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

public class CustomOCL_SplitAtSemi : OclOperationBase
{
public CustomOCL_SplitAtSemi()
{
}
protected override void Init()
{
InternalInit("SplitAtSemi", new IOclType[] { Support.StringType }, Support.StringType);
}
public override void Evaluate(IOclOperationParameters __Params)
{
string s = Support.GetAsString(__Params.Values[0]);
string[] ss=s.Split(';');
string first = "";
if (ss.Length > 0)
first = ss[0];
Support.MakeNewString(__Params.Result, first);
}
}

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

Modlr plugin - 1.png

Viewmodel columns that use the custom expression are evaluated correctly:

Modlr plugin - 2.png

CheckModel stays empty since everything is validated:

Modlr plugin - 3.png

And of course the prototyping actually executes your operations:

Modlr plugin - 4.png

This page was edited 47 days ago on 02/10/2024. What links here