Calling your own c - sharp .net things from Turnkey–server side
No edit summary
No edit summary
Line 18: Line 18:
<p>Create a new class library with .net4.5. Set its output name to “TurnKey_ExternalLateBound.dll” (important)</p>
<p>Create a new class library with .net4.5. Set its output name to “TurnKey_ExternalLateBound.dll” (important)</p>
<p>Create a type in the assembly that implements the above interface IExternalLateBoundService.</p>
<p>Create a type in the assembly that implements the above interface IExternalLateBoundService.</p>
<p>In the Execute method – check the classifier and method name – like this:</p><pre class="code"><span style="background: white; color: black">    </span><span style="background: white; color: blue">public </span><span style="background: white; color: black">Eco.ObjectRepresentation.</span><span style="background: white; color: #2b91af">IElement </span><span style="background: white; color: black">Execute(Eco.UmlRt.</span><span style="background: white; color: #2b91af">IClassifier </span><span style="background: white; color: black">classifier, <br>                                                    Eco.ObjectRepresentation.</span><span style="background: white; color: #2b91af">IObject </span><span style="background: white; color: black">theobject, <br>                                                    Eco.UmlRt.</span><span style="background: white; color: #2b91af">IMethod </span><span style="background: white; color: black">method, <br>                                                    Eco.ObjectRepresentation.</span><span style="background: white; color: #2b91af">IModifiableVariableList </span><span style="background: white; color: black">variableList)
<p>In the Execute method – check the classifier and method name – like this:</p>
 
<html>
<pre class="code"><span style="background: white; color: black">    </span><span style="background: white; color: blue">public </span><span style="background: white; color: black">Eco.ObjectRepresentation.</span><span style="background: white; color: #2b91af">IElement </span><span style="background: white; color: black">Execute(Eco.UmlRt.</span><span style="background: white; color: #2b91af">IClassifier </span><span style="background: white; color: black">classifier, <br>                                                    Eco.ObjectRepresentation.</span><span style="background: white; color: #2b91af">IObject </span><span style="background: white; color: black">theobject, <br>                                                    Eco.UmlRt.</span><span style="background: white; color: #2b91af">IMethod </span><span style="background: white; color: black">method, <br>                                                    Eco.ObjectRepresentation.</span><span style="background: white; color: #2b91af">IModifiableVariableList </span><span style="background: white; color: black">variableList)
     {
     {
       </span><span style="background: white; color: blue">if </span><span style="background: white; color: black">(theobject != </span><span style="background: white; color: blue">null </span><span style="background: white; color: black">&amp;&amp; method != </span><span style="background: white; color: blue">null</span><span style="background: white; color: black">)
       </span><span style="background: white; color: blue">if </span><span style="background: white; color: black">(theobject != </span><span style="background: white; color: blue">null </span><span style="background: white; color: black">&amp;&amp; method != </span><span style="background: white; color: blue">null</span><span style="background: white; color: black">)
Line 43: Line 46:
            
            
         }
         }
</span></pre><pre class="code"><span style="background: white; color: black">        }
</span></pre>
 
<pre class="code"><span style="background: white; color: black">        }
       }
       }
       </span><span style="background: white; color: blue">return null</span><span style="background: white; color: black">;
       </span><span style="background: white; color: blue">return null</span><span style="background: white; color: black">;
     }</span></pre>
     }</span></pre>
</html>
<p>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.</p>
<p>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.</p>
<p>In the actual implementation of my external logic I can access the parameters sent in to the method like this:</p><pre class="code"><span style="background: white; color: black">variableList[</span><span style="background: white; color: #a31515">"vStartPart"</span><span style="background: white; color: black">].Element.GetValue&lt;</span><span style="background: white; color: blue">string</span><span style="background: white; color: black">&gt;()</span></pre>
<p>In the actual implementation of my external logic I can access the parameters sent in to the method like this:</p>
 
<html>
 
<pre class="code"><span style="background: white; color: black">variableList[</span><span style="background: white; color: #a31515">"vStartPart"</span><span style="background: white; color: black">].Element.GetValue&lt;</span><span style="background: white; color: blue">string</span><span style="background: white; color: black">&gt;()</span></pre>
<p>I can access properties of the object that own the method like this:</p><pre class="code"><span style="background: white; color: blue">var </span><span style="background: white; color: black">pageStyle = viewoverride.Properties[</span><span style="background: white; color: #a31515">"PageStyle"</span><span style="background: white; color: black">].GetValue&lt;</span><span style="background: white; color: blue">string</span><span style="background: white; color: black">&gt;();</span></pre>
<p>I can access properties of the object that own the method like this:</p><pre class="code"><span style="background: white; color: blue">var </span><span style="background: white; color: black">pageStyle = viewoverride.Properties[</span><span style="background: white; color: #a31515">"PageStyle"</span><span style="background: white; color: black">].GetValue&lt;</span><span style="background: white; color: blue">string</span><span style="background: white; color: black">&gt;();</span></pre>
<p><span style="background: white; color: black">I can navigate associations like this:</span></p><pre class="code"><span style="background: white; color: #2b91af">IObject </span><span style="background: white; color: black">Product = theobject.Properties[</span><span style="background: white; color: #a31515">"Product"</span><span style="background: white; color: black">].Element </span><span style="background: white; color: blue">as </span><span style="background: white; color: #2b91af">IObject</span><span style="background: white; color: black">;
<p><span style="background: white; color: black">I can navigate associations like this:</span></p><pre class="code"><span style="background: white; color: #2b91af">IObject </span><span style="background: white; color: black">Product = theobject.Properties[</span><span style="background: white; color: #a31515">"Product"</span><span style="background: white; color: black">].Element </span><span style="background: white; color: blue">as </span><span style="background: white; color: #2b91af">IObject</span><span style="background: white; color: black">;
</span></pre><pre class="code"><span style="background: white; color: black">
</span></pre><pre class="code"><span style="background: white; color: black">
</span></pre>
</span></pre>
</html>
<p>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.</p>
<p>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.</p>
<p>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:</p>
<p>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:</p>
<p><a href="//www.capableobjects.com/wp-content/uploads/2016/07/image17.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="//www.capableobjects.com/wp-content/uploads/2016/07/image_thumb17.png" width="602" height="484"></a></p>
<p><a href="//www.capableobjects.com/wp-content/uploads/2016/07/image17.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="//www.capableobjects.com/wp-content/uploads/2016/07/image_thumb17.png" width="602" height="484"></a></p>
<p>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.</p>
<p>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.</p>

Revision as of 18:51, 28 October 2018


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); } } else { 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:

variableList["vStartPart"].Element.GetValue<string>()

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:

<a href="//www.capableobjects.com/wp-content/uploads/2016/07/image17.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="//www.capableobjects.com/wp-content/uploads/2016/07/image_thumb17.png" width="602" height="484"></a>

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 page was edited 89 days ago on 02/10/2024. What links here