Calling your own c# .net things from Turnkey–server side

This article was moved to MDriven Wiki Calling your own c# .net things from Turnkey–server side

As MDriven Turnkey works on your defined model and information you will have access to everything you need – until you don’t.

For example we had these use-cases that called for the ability to reach out from the standard turnkey implementation:

  1. Add a key generation algorithm that use advanced cryptography
  2. Call external web-api’s and wait for the result to add as data in the current model

Luckily there is an extension mechanism that allows for this – and once you have implemented it, it  is easy to call logic from your extensions straight from the model.

Assembly Eco.Interfaces
namespace Eco.Services
  // Summary:
  //     Allows you to supply domain object method implementations with late bound assembly
  public interface IExternalLateBoundService
    IElement Execute(IClassifier classifier, IObject theobject, IMethod method, IModifiableVariableList variableList);

Create a new class library with .net4.5. Set its output name to “TurnKey_ExternalLateBound.dll” (important)

Create a type in the assembly that implements the above interface IExternalLateBoundService.

In the Execute method – check the classifier and method name – like this:

    public Eco.ObjectRepresentation.IElement Execute(Eco.UmlRt.IClassifier classifier, 
                                                     Eco.ObjectRepresentation.IObject theobject, 
                                                     Eco.UmlRt.IMethod method, 
                                                     Eco.ObjectRepresentation.IModifiableVariableList variableList)
      if (theobject != null && method != null)
        if (theobject.UmlClass.Name == "SiteAsset")
          if (method.Name == "SendAsset")
            string res = "Sending asset: " + SendSiteAssetToTurnkeySite(theobject, variableList);
            return EcoServiceHelper.GetVariableFactoryService(theobject.ServiceProvider).CreateConstant(res);
        else if (theobject.UmlClass.Name == "RuntimeKey")
          if (method.Name == "GenerateKey")
            return RuntimeKey_GenerateKey(theobject, variableList);
            string res = "No logic for " + theobject.UmlClass.Name + "." + method.Name;
            return EcoServiceHelper.GetVariableFactoryService(theobject.ServiceProvider).CreateConstant(res);
      return null;

As you can see from the code above it simply checks if the sent in object is of a certain model class – if so is the method named a certain way – if so we do things given the parameters we got and we return a result.

In the actual implementation of my external logic I can access the parameters sent in to the method like this:


I can access properties of the object that own the method like this:

var pageStyle = viewoverride.Properties["PageStyle"].GetValue<string>();

I can navigate associations like this:

IObject Product = theobject.Properties["Product"].Element as IObject;

To make the logic available to your turnkey site you must upload the assembly – and all other assemblies it depends on – to the folder “EXT_LateBoundAssembly” that is under the root of your turnkey site.

In your model you define the methods on the classes and leave their implementation blank and you fill in a tagged value on the method Eco.ExternalLateBound=True:


Once you have followed these steps you can call your method from an action, a button or even from a derivation (if it the method is marked as a query) – and Turnkey will route the call to your assembly and execute your code.

This entry was posted in MDrivenTurnkey and tagged , , . Bookmark the permalink.

One Response to Calling your own c# .net things from Turnkey–server side

  1. Pingback: QR-Code to drive a workflow in any MDriven turnkey app | CapableObjects

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.