This article was moved to MDriven Wiki – Modlr plugin
We added a plugin interface for Gaffr and ECO. We want to enable you to extend Modlr so that you can implement a special file format import, or export, or what have you.
This is how it works:
Given these two interfaces…
- namespace Modlr.Plugins
- {
- Public Interface IModlrPlugin
- {
- string GetName();
- List<IModlrPluginMenuOperation> ProvideOperations();
- }
- Public Interface IModlrPluginMenuOperation
- {
- string GetName();
- void CheckEnableOrExecute(IEcoServiceProvider esp, bool execute,
- }
- }
…you can implement a plugin in an assembly like this:
- public class Class1 : IModlrPlugin
- {
- #region IModlrPlugin Members
- public string GetName()
- {
- return “Demo plugin”;
- }
- public List<IModlrPluginMenuOperation> ProvideOperations()
- {
- List<IModlrPluginMenuOperation> ops = new List<IModlrPluginMenuOperation>();
- ops.Add(new OperationShowDialog());
- ops.Add(new OperationActOnClass());
- return ops;
- }
- #endregion
- }
The code above installs two Operations; OperationShowDialog and OperationActOnClass.
Looking closer on the operation ActOnClass:
- public class OperationActOnClass : IModlrPluginMenuOperation
- {
- #region IModlrPluginMenuAction Members
- public void CheckEnableOrExecute(IEcoServiceProvider esp,
- {
- enabled = false;
- if (maincontext != null && maincontext.AsIObject().AsObject is Eco.ModelLayer.Class)
- {
- enabled = true;
- if (execute)
- {
- (maincontext.AsIObject().AsObject as Eco.ModelLayer.Class).Name += “X”;
- }
- }
- }
- public string GetName()
- {
- return “Operation on class“;
- }
- #endregion
- }
The code checks that the context is a class, and if it is the code says that the operation should be enabled. If this was an “execute” call we perform the desired logic – in this case I just add an “X” to the back of the class name.
You can do a lot of stuff in a plugin. You get access to the IEcoServerProvider for the EcoModelLayer. The Modlr application is a standard ECO-built-application so you can use the IOCLService to get to any object, of any class that builds up your model content. You can access Diagrams, PlacedClasses, StateMachines etc. You can inspect and set TaggedValues, you can run thru every Attribute and check for spelling errors. You can create reports that you share with other ECO/Gaffr users…
So even if the interface is very small and simple, it is very powerful.
When you build your Plugin you will want to reference the following assemblies (found in the eco or gaffr install directory):
Compile your plugin and put the assembly in the folder %ProgramData%/CapableObjects/Plugins
Restart Gaffr.net or VisualStudio and you will find your plugin operations in the context menu:
Simple and powerful.