Changes

HowTo:Provide system definitions with a custom plugin

4,906 bytes added, 14:32, 26 November 2024
 
 
This tutorial explains how to provide any kind of preconfigured {{UBIK}} data (system definitions) using a custom plugin.
To understand the code, knowledge about the {{UBIK}} ER-model and the plugin injection mechanism is required.
 
[[Category:How-To|Provide system definitions with a custom plugin]]
[[Category:Module|Provide system definitions with a custom plugin]]
== Instructions ==
</syntaxhighlight>
</div></div>
 
= Create a system classification =
 
Here's an example for the definition of a system classification.
 
<div class="toccolours mw-collapsible mw-collapsed" style="width:100%; overflow:auto;">
<div style="font-weight:bold;line-height:1.6;">SystemClassification template code</div>
<div class="mw-collapsible-content">
<syntaxhighlight lang="csharp">
namespace UBIK.MyPlugin
{
public class MyClassification : SystemClassification
{
public static Guid GUID = new Guid("aa9cc5cb-f676-4b60-b39d-eab7a8bcc66e");
public MyClassification(UBIKEnvironment environment)
: base(GUID, environment)
{
this.CodedName = "MYCLS";
this.CodedNamespace = "System.MyPlugin";
this.CodedDescription = "My classification";
// Derives from SystemDesignMetaClass, see above for metaproperty definition
}
}
}
</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 Classifications
 
public override UBIKClassList<MetaClass> DefineSystemClassifications(UBIKEnvironment environment)
{
return new UBIKClassList<MetaClass>()
{
new MyClassification(environment)
};
}
 
#endregion System Classifications
// ...
}
}
</syntaxhighlight>
</div></div>
 
= Create a system SelectiveList =
 
Here's an example for the definition of a system selective list.
 
<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 Selective Lists
 
public override UBIKClassList<SelectiveList> DefineSystemSelectiveLists(UBIKEnvironment environment)
{
UBIKClassList<SelectiveList> selectiveLists = new UBIKClassList<SelectiveList>();
SystemSelectiveList fromEnum = new SystemSelectiveList(environment, typeof(MyEnumType)); // MyEnumType should be an integer enum
fromEnum.SetUID(GuidUtility.SLFROMENUM);
selectiveLists.Add(fromEnum);
SystemSelectiveList customList = new SystemSelectiveList(environment);
customList.SetItemValueType(PropertyTypes.String);
customList.AddSelectiveItem("any object of supported type", "description");
customList.Name = "SL_STR";
customList.SetUID(GuidUtility.SLSTR);
selectiveLists.Add(customList);
return selectiveLists;
}
 
#endregion System Selective Lists
// ...
}
}
</syntaxhighlight>
</div></div>
 
= Perform pre- or postprocessing scripts =
 
In some cases, one has to perform an action before the database is adjusted, or postprocess the upgrade.
It is also possible to execute code whenever the environment is initialized, even if no upgrade was necessary.
 
<div class="toccolours mw-collapsible mw-collapsed" style="width:100%; overflow:auto;">
<div style="font-weight:bold;line-height:1.6;">Scripting template code</div>
<div class="mw-collapsible-content">
<syntaxhighlight lang="csharp">
namespace UBIK.MyPlugin
{
public class MySystemDefinitions_V100 : SystemDefinitionsBase
{
// ...
public override void PreProcessDatabaseUpdate(Version previousVersion, UBIKEnvironment environment)
{
base.PreProcessDatabaseUpdate(previousVersion, environment);
// This code will be executed whenever the system is upgraded,
// before a schema upgrade for this SystemDefinitions package
}
 
public override void PostProcessDatabaseUpdate(Version previousVersion, UBIKEnvironment environment)
{
base.PostProcessDatabaseUpdate(previousVersion, environment);
// This code will be executed whenever the system is upgraded,
// after a schema upgrade and before content initialization and upgrade
// for this SystemDefinitions package
}
public override void InitializeSystemContent(UBIKEnvironment env)
{
base.InitializeSystemContent(env);
// This code will be executed whenever the system is initialized,
// after an optional schema upgrade and before an optional content adaptation
// for this SystemDefinitions package
}
public override void UpdateSystemContent(UBIKEnvironment env)
{
base.UpdateSystemContent(env);
// This code will be executed whenever the system is upgraded,
// after all other steps for this SystemDefinitions package
}
// ...
}
}
</syntaxhighlight>
</div></div>
 
<!-- DO NOT REMOVE THIS -->{{Template:HowTo/End}}<!-- DO NOT REMOVE THIS -->
* [[HowTo:Create_UBIK_Module|Create your own module]]
 
[[Category:How-To]]
[[Category:Module]]
[[Category:How-To|Provide system definitions with a custom plugin]]
[[Category:Module|Provide system definitions with a custom plugin]]
1,765
edits