Changes

HowTo:Provide system definitions with a custom plugin

6,598 bytes added, 16:23, 26 November 2024
</div></div>
= Create a custom InterfaceAdmin =
 
This is one of the most complex things you can do in this topic.
That's because an InterfaceAdmin object has the following interesting aspects:
* It is an instance of the INTERFACE_ADMIN (Meta)MetaClass
* It is a MetaClass itself
* A custom implementation must derive from the INTERFACE_ADMIN_ROOT
* It produces special instances called InterfaceExecution
* Any functional InterfaceAdmin runtime object must be an instance of InterfaceAdministration
 
The last point is crucial, because this makes our task difficult.
After all, we use SystemDesignMetaClass to define MetaClasses, and this directly conflicts with the last requirement.
The way to solve this is to deliver a non-functional class we only use as a basis, and then derive a regular object from it.
 
 
<div class="toccolours mw-collapsible mw-collapsed" style="width:100%; overflow:auto;">
<div style="font-weight:bold;line-height:1.6;">InterfaceAdmin template code</div>
<div class="mw-collapsible-content">
<syntaxhighlight lang="csharp">
namespace UBIK.MyPlugin
{
public class MyInterfaceAdminBase : SystemDesignMetaClass
{
public static new Guid UID = GuidUtility.INTERFACE_ADMIN_UID_BASE;
private const string NAME = "BASE_IFA";
private const string NAMESPACE = "System.MyPlugin.Interface.Administration";
private const string DESCRIPTION = "Base Class of Custom Interface Admin";
 
 
public MyInterfaceAdminBase(UBIKEnvironment environment)
{
InitUidAndEnvironment(UID, environment);
InitStrings(NAME, NAMESPACE, DESCRIPTION);
 
SetModuleId(CustomInterfacePlugin.ID);
 
List<Guid> metaProperties = new List<Guid>();
DefineMetaProperties(metaProperties);
}
 
public override MetaClass MetaClass
{
get
{
// The current class is an instance of the Interface Admin MetaClass; an individual Interface Administration object.
return this.Environment.GetSystemMetaClass(SystemObjects.INTERFACE_ADMINISTRATION);
}
}
 
public override MetaClass Inheritance
{
get
{
// The current class derives from the default Interface Admin, which is also the MetaClass of all Interface Execution objects.
// Likewise, the current class is a MetaClass for Interface Execution objects.
return this.Environment.GetSystemMetaClass(SystemObjects.INTERFACE_EXECUTION);
}
set
{
throw new NotImplementedException();
}
}
 
public override MetaClassTypes ClassType
{
get
{
return MetaClassTypes.DEFINED_IN_PLUGIN;
}
set
{
// do nothing
}
}
 
public override string RuntimeTypeName => GetRuntimeType().FullName;
 
public override string SystemRuntimeTypeName => GetSystemRuntimeType().FullName;
 
public override Type GetSystemRuntimeType()
{
return typeof(MyInterfaceExecution);
}
 
public override Type GetRuntimeType()
{
return typeof(MyInterfaceExecution);
}
 
// Required for MetaClasses that have a very special MetaClass themselves
protected override MetaClass DeliverMetaMetaClassInstance()
{
return MetaClass;
}
}
}
</syntaxhighlight>
</div></div>
 
<div class="toccolours mw-collapsible mw-collapsed" style="width:100%; overflow:auto;">
<div style="font-weight:bold;line-height:1.6;">InterfaceExecution runtime type template code</div>
<div class="mw-collapsible-content">
<syntaxhighlight lang="csharp">
namespace UBIK.MyPlugin.InterfaceExecutors
{
public class MyInterfaceExecution : InterfaceExecution
{
protected override IInterfaceExecutor GetExternalDataReader()
{
return new ThirdPartySystemWebAPIClientReader(Environment);
}
 
protected override IInterfaceExecutor GetExternalDataWriter()
{
return new ThirdPartySystemWebAPIClientWriter(Environment);
}
 
protected override IInterfaceExecutor GetExternalPollingExecutor()
{
return new ThirdPartySystemWebAPIClientPoller(Environment);
}
 
protected override IInterfaceExecutor GetExportExecutor()
{
return new MyExportExecutor(Environment);
}
 
protected override IInterfaceExecutor GetImportExecutor()
{
return new MyImportExecutor(Environment);
}
}
}
</syntaxhighlight>
</div></div>
 
<div class="toccolours mw-collapsible mw-collapsed" style="width:100%; overflow:auto;">
<div style="font-weight:bold;line-height:1.6;">SystemDefinitions adaptations</div>
<div class="mw-collapsible-content">
<syntaxhighlight lang="csharp">
namespace UBIK.MyPlugin
{
public class MySystemDefinitions_V100 : SystemDefinitionsBase
{
// ...
 
#region System Content
 
public override void UpdateSystemContent(UBIKEnvironment environment)
{
base.UpdateSystemContent(environment);
 
// Create our own custom interface admin from the base class we described.
MetaClass mc = environment.GetSystemMetaClass(SystemObjects.INTERFACE_ADMINISTRATION);
InterfaceAdministration ifa = environment.UBIKDataFactory().GetBaseObject(mc, GuidUtility.INTERFACE_ADMIN_UID_CUSTOM) as InterfaceAdministration;
if (ifa == null)
{
ifa = (InterfaceAdministration)environment.UBIKDataFactory().MetaClass(GuidUtility.INTERFACE_ADMIN_UID_BASE).CreateNewDerivate(GuidUtility.INTERFACE_ADMIN_UID_CUSTOM);
ifa.Name = "MY_IFA";
ifa.Description = "Custom Interface Admin";
ifa.Namespace = "Custom.MyPlugin.Interface.Administration";
ifa.ClassType = MetaClassTypes.Inherited;
ifa.Save();
}
 
Relationship relation = environment.GetSystemRelation(SystemObjects.RELATION_INTERFACE_ADMIN_METAPROXY);
MetaProxy target = (MetaProxy)environment.UBIKDataFactory().MetaClass(GuidUtility.MY_PROXY);
if(ifa.IsAddRelationAllowed(relation, target))
{
ifa.AddRelation(relation, target);
ifa.Save();
}
}
 
#endregion System Content
 
// ...
}
}
</syntaxhighlight>
</div></div>
<!-- DO NOT REMOVE THIS -->{{Template:HowTo/End}}<!-- DO NOT REMOVE THIS -->
1,765
edits