more massive updates
This commit is contained in:
parent
5fdb5d0f2c
commit
d43bb7dac5
@ -10,6 +10,7 @@ namespace Mocha.Core
|
||||
public static Guid Value { get; } = new Guid("{041DD7FD-2D9C-412B-8B9D-D7125C166FE0}");
|
||||
public static Guid CSSValue { get; } = new Guid("{C0DD4A42-F503-4EB3-8034-7C428B1B8803}");
|
||||
public static Guid RelationshipType { get; } = new Guid("{71106B12-1934-4834-B0F6-D894637BAEED}");
|
||||
public static Guid Order { get; } = new Guid("{49423f66-8837-430d-8cac-7892ebdcb1fe}");
|
||||
|
||||
public static Guid TargetURL { get; } = new Guid("{970F79A0-9EFE-4E7D-9286-9908C6F06A67}");
|
||||
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
namespace Mocha.Core
|
||||
{
|
||||
public static class KnownInstanceGuids
|
||||
@ -23,6 +24,8 @@ namespace Mocha.Core
|
||||
public static Guid Element { get; } = new Guid("{91929595-3dbd-4eae-8add-6120a49797c7}");
|
||||
public static Guid ElementContent { get; } = new Guid("{f85d4f5e-c69f-4498-9913-7a8554e233a4}");
|
||||
|
||||
public static Guid OMS { get; } = new Guid("{1ddf9a56-ebb8-4992-ab68-1820acf6bfc8}");
|
||||
|
||||
public static Guid File { get; } = new Guid("{5D081079-E136-406A-A728-7472937A6E5E}");
|
||||
|
||||
public static Guid Translation { get; } = new Guid("{04A53CC8-3206-4A97-99C5-464DB8CAA6E6}");
|
||||
@ -80,6 +83,10 @@ namespace Mocha.Core
|
||||
|
||||
public static Guid Module { get; } = new Guid("{e009631d-6b9d-445c-95df-79f4ef8c8fff}");
|
||||
|
||||
public static Guid SystemRoutine { get; } = new Guid("{6e5265af-f73d-420c-b9d5-cf2fdc90363d}");
|
||||
public static Guid SystemInstanceSetRoutine { get; } = new Guid("{d17a6d27-da03-4b5d-9256-f67f978f403d}");
|
||||
public static Guid SystemAttributeRoutine { get; } = new Guid("{117f4b9c-2678-4747-aced-78d93c25dcd7}");
|
||||
|
||||
public static Guid Report { get; } = new Guid("{19D947B6-CE82-4EEE-92EC-A4E01E27F2DB}");
|
||||
public static Guid ReportColumn { get; } = new Guid("{BEFE99A1-B2EB-4365-A2C9-061C6609037B}");
|
||||
public static Guid StandardReport { get; } = new Guid("{FDF4A498-DE83-417D-BA01-707372125C8D}");
|
||||
@ -172,7 +179,11 @@ namespace Mocha.Core
|
||||
// GEP - Get Element from Parameters Method - 63
|
||||
// GAP - Get Attribute from Parameters Method - 64
|
||||
public static Guid GetInstanceSetBySystemRoutineMethod { get; } = new Guid("{7bdc53a1-81f0-458d-96f4-5637e6e1cf49}"); // 65
|
||||
// GAS - Get Attribute by System Routine Method - 66
|
||||
/// <summary>
|
||||
/// GAS - Get Attribute by System Routine Method [1$66]
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static Guid GetAttributeBySystemRoutineMethod { get; } = new Guid("{9d45eb8c-1fb5-4260-a69c-f99a8f7a70b8}");
|
||||
// GES - Get Element by System Routine Method - 67
|
||||
// US - Update by System Routine Method - 68
|
||||
// CS - Compare Instance Sets Method - 91
|
||||
@ -187,6 +198,11 @@ namespace Mocha.Core
|
||||
public static Guid ConditionalSelectAttributeMethod { get; } = new Guid("{d534a369-321e-4c32-bd7f-8ff2017f191e}"); // 13038
|
||||
// SSC - Conditional Select from Instance Set Method - 13039
|
||||
}
|
||||
public static class SystemAttributeRoutines
|
||||
{
|
||||
public static Guid GetRuntimeVersion { get; } = new Guid("{dc4e6c8d-936d-457f-90e9-af47e229b80c}");
|
||||
// public static Guid SystemInstanceSetRoutine { get; } = new Guid("{d17a6d27-da03-4b5d-9256-f67f978f403d}");
|
||||
}
|
||||
public static class PromptValueClasses
|
||||
{
|
||||
public static Guid InstancePromptValue { get; } = new Guid("{0A6E2CF2-97B6-4339-B1DA-1DBBFE9806C6}");
|
||||
@ -257,6 +273,15 @@ namespace Mocha.Core
|
||||
public static Guid Width { get; } = new Guid("{7a84cf37-c445-4e75-ab1a-075bb99067f2}");
|
||||
}
|
||||
|
||||
[ExportEntities(Prefix = "IDI_AccessModifier_", Suffix = null)]
|
||||
public static class AccessModifiers
|
||||
{
|
||||
public static Guid Private { get; } = new Guid("{82bef402-2a8b-45d2-bfef-0de3a355bd22}");
|
||||
public static Guid Protected { get; } = new Guid("{23e264b2-e8a0-4d0c-96c2-308586a46eaa}");
|
||||
public static Guid Public { get; } = new Guid("{68be791f-f64b-4eeb-bc6a-2f040c4e90d2}");
|
||||
public static Guid RootA2 { get; } = new Guid("{286bcf7a-9dcb-4c83-9a5c-09a31dc8f10b}");
|
||||
}
|
||||
|
||||
[ExportEntities(Prefix = "IDI_Orientation_", Suffix = null)]
|
||||
public static class Orientation
|
||||
{
|
||||
|
||||
@ -64,7 +64,7 @@ namespace Mocha.Core
|
||||
public static Guid Instance_Attribute_String_Component__has__Attribute { get; } = new Guid("{E15D4277-69FB-4F19-92DB-8D087F361484}");
|
||||
public static Guid String_Component__has_source__Method { get; } = new Guid("{1ef1c965-e120-48be-b682-aa040573b5fb}");
|
||||
|
||||
public static Guid Class__instance_labeled_by__String { get; } = new Guid("{F52FC851-D655-48A9-B526-C5FE0D7A29D2}");
|
||||
public static Guid Class__instance_labeled_by__Return_Attribute_Method_Binding { get; } = new Guid("{F52FC851-D655-48A9-B526-C5FE0D7A29D2}");
|
||||
public static Guid Class__has_summary__Report_Field { get; } = new Guid("{D11050AD-7376-4AB7-84DE-E8D0336B74D2}");
|
||||
public static Guid Class__has_related__Task { get; } = new Guid("{4D8670E1-2AF1-4E7C-9C87-C910BD7B319B}");
|
||||
|
||||
@ -114,9 +114,17 @@ namespace Mocha.Core
|
||||
public static Guid Validation__has_failure_message__Translation { get; } = new Guid("{E15A97DD-2A1D-4DC0-BD6B-A957B63D9802}");
|
||||
public static Guid Translation__failure_message_for__Validation { get; } = new Guid("{46a7dfcb-8848-47d5-9ad3-d27fbd8b423f}");
|
||||
|
||||
public static Guid Build_Attribute_Method__returns__Attribute { get; } = new Guid("{dadbf0f3-7af0-4387-a6b7-a1724a216d88}");
|
||||
public static Guid Attribute__returned_by__Build_Attribute_Method { get; } = new Guid("{d5a6062b-2e84-46a1-8f54-da630ef6a48c}");
|
||||
|
||||
public static Guid Get_Attribute_Method__returns__Attribute { get; } = new Guid("{5eca9b3f-be75-4f6e-8495-781480774833}");
|
||||
public static Guid Attribute__returned_by__Get_Attribute_Method { get; } = new Guid("{e82ace2e-84b7-4912-89ed-7b8efd63bb5d}");
|
||||
|
||||
public static Guid Get_Attribute_by_System_Routine_Method__returns__Attribute { get; } = new Guid("{e19cf181-b5bf-4595-b5c6-b9098a7a41bb}");
|
||||
public static Guid Attribute__returned_by__Get_Attribute_by_System_Routine_Method { get; } = new Guid("{b6f2981f-d324-4d4a-b2df-1d866825e75e}");
|
||||
public static Guid Get_Attribute_by_System_Routine_Method__uses__System_Attribute_Routine { get; } = new Guid("{f7aaac2c-0bfd-4b31-8c8c-3a76e9522574}");
|
||||
public static Guid System_Attribute_Routine__used_by__Get_Attribute_by_System_Routine_Method { get; } = new Guid("{57b3a574-9f0c-4723-a32f-bde523d7e773}");
|
||||
|
||||
public static Guid Get_Referenced_Instance_Set_Method__loop_on__Instance_Set { get; } = new Guid("{2978238f-7cb0-4ba3-8c6f-473df782cfef}");
|
||||
public static Guid Get_Referenced_Instance_Set_Method__has_relationship__Method { get; } = new Guid("{6a65819e-c8cb-4575-9af8-ee221364049b}");
|
||||
|
||||
|
||||
29
mocha-dotnet/src/lib/Mocha.Core/MethodImplementation.cs
Normal file
29
mocha-dotnet/src/lib/Mocha.Core/MethodImplementation.cs
Normal file
@ -0,0 +1,29 @@
|
||||
namespace Mocha.Core;
|
||||
|
||||
public abstract class MethodImplementation
|
||||
{
|
||||
public abstract Guid MethodClassGuid { get; }
|
||||
|
||||
protected abstract InstanceHandle ExecuteInternal(Oms oms, OmsContext context, InstanceHandle method);
|
||||
public InstanceHandle Execute(Oms oms, OmsContext context, InstanceHandle method)
|
||||
{
|
||||
return ExecuteInternal(oms, context, method);
|
||||
}
|
||||
|
||||
protected InstanceHandle r_Method__for__Class;
|
||||
|
||||
public bool Initialized { get; private set; } = false;
|
||||
protected virtual void InitializeInternal(Oms oms)
|
||||
{
|
||||
r_Method__for__Class = oms.GetInstance(KnownRelationshipGuids.Method__for__Class);
|
||||
}
|
||||
public void Initialize(Oms oms)
|
||||
{
|
||||
if (Initialized)
|
||||
return;
|
||||
|
||||
InitializeInternal(oms);
|
||||
Initialized = true;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
namespace Mocha.Core.MethodImplementations;
|
||||
|
||||
public class BuildAttributeMethodImplementation : MethodImplementation
|
||||
{
|
||||
public override Guid MethodClassGuid => KnownInstanceGuids.MethodClasses.BuildAttributeMethod;
|
||||
protected override InstanceHandle ExecuteInternal(Oms oms, OmsContext context, InstanceHandle method)
|
||||
{
|
||||
InstanceHandle irForClass = oms.GetRelatedInstance(method, oms.GetInstance(KnownRelationshipGuids.Method__for__Class));
|
||||
InstanceHandle returnsAttribute = oms.GetRelatedInstance(method, oms.GetInstance(KnownRelationshipGuids.Build_Attribute_Method__returns__Attribute));
|
||||
|
||||
if (returnsAttribute == InstanceHandle.Empty)
|
||||
{
|
||||
throw new InvalidOperationException("no return Attribute specified for method");
|
||||
}
|
||||
|
||||
// InstanceHandle forInstance = (InstanceHandle) context.GetWorkData(irForClass);
|
||||
object? value = oms.UnsafeGetAttributeValue(method, oms.GetInstance(KnownAttributeGuids.Text.Value));
|
||||
context.SetWorkData(returnsAttribute, value);
|
||||
return returnsAttribute;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
namespace Mocha.Core.MethodImplementations;
|
||||
|
||||
public class GetAttributeBySystemRoutineMethodImplementation : MethodImplementation
|
||||
{
|
||||
public override Guid MethodClassGuid => KnownInstanceGuids.MethodClasses.GetAttributeBySystemRoutineMethod;
|
||||
protected override InstanceHandle ExecuteInternal(Oms oms, OmsContext context, InstanceHandle method)
|
||||
{
|
||||
InstanceHandle irForClass = oms.GetRelatedInstance(method, oms.GetInstance(KnownRelationshipGuids.Method__for__Class));
|
||||
InstanceHandle returnsAttribute = oms.GetRelatedInstance(method, oms.GetInstance(KnownRelationshipGuids.Get_Attribute_by_System_Routine_Method__returns__Attribute));
|
||||
InstanceHandle usesSystemAttributeRoutine = oms.GetRelatedInstance(method, oms.GetInstance(KnownRelationshipGuids.Get_Attribute_by_System_Routine_Method__uses__System_Attribute_Routine));
|
||||
|
||||
if (returnsAttribute == InstanceHandle.Empty)
|
||||
{
|
||||
throw new InvalidOperationException("no return Attribute specified for method");
|
||||
}
|
||||
|
||||
object? value = oms.ExecuteSystemRoutine(usesSystemAttributeRoutine);
|
||||
context.SetWorkData(returnsAttribute, value);
|
||||
return returnsAttribute;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
namespace Mocha.Core.MethodImplementations;
|
||||
|
||||
public class GetAttributeMethodImplementation : MethodImplementation
|
||||
{
|
||||
public override Guid MethodClassGuid => KnownInstanceGuids.MethodClasses.GetAttributeMethod;
|
||||
protected override InstanceHandle ExecuteInternal(Oms oms, OmsContext context, InstanceHandle method)
|
||||
{
|
||||
InstanceHandle irForClass = oms.GetRelatedInstance(method, oms.GetInstance(KnownRelationshipGuids.Method__for__Class));
|
||||
InstanceHandle returnsAttribute = oms.GetRelatedInstance(method, oms.GetInstance(KnownRelationshipGuids.Get_Attribute_Method__returns__Attribute));
|
||||
|
||||
if (returnsAttribute == InstanceHandle.Empty)
|
||||
{
|
||||
throw new InvalidOperationException("no Work Set specified for method");
|
||||
}
|
||||
|
||||
InstanceHandle forInstance = (InstanceHandle) context.GetWorkData(irForClass);
|
||||
object? value = oms.UnsafeGetAttributeValue(forInstance, returnsAttribute);
|
||||
context.SetWorkData(returnsAttribute, value);
|
||||
return returnsAttribute;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,27 @@
|
||||
namespace Mocha.Core.MethodImplementations;
|
||||
|
||||
public class GetSpecifiedInstancesMethodImplementation : MethodImplementation
|
||||
{
|
||||
public override Guid MethodClassGuid => KnownInstanceGuids.MethodClasses.GetSpecifiedInstancesMethod;
|
||||
protected InstanceHandle r_Get_Specified_Instances_Method__returns__Work_Set, r_Get_Specified_Instances_Method__uses__Instance;
|
||||
protected override void InitializeInternal(Oms oms)
|
||||
{
|
||||
base.InitializeInternal(oms);
|
||||
r_Get_Specified_Instances_Method__returns__Work_Set = oms.GetInstance(KnownRelationshipGuids.Get_Specified_Instances_Method__returns__Work_Set);
|
||||
r_Get_Specified_Instances_Method__uses__Instance = oms.GetInstance(KnownRelationshipGuids.Get_Specified_Instances_Method__uses__Instance);
|
||||
}
|
||||
protected override InstanceHandle ExecuteInternal(Oms oms, OmsContext context, InstanceHandle method)
|
||||
{
|
||||
InstanceHandle irForClass = oms.GetRelatedInstance(method, r_Method__for__Class);
|
||||
InstanceHandle returnsWorkSet = oms.GetRelatedInstance(method, r_Get_Specified_Instances_Method__returns__Work_Set);
|
||||
IReadOnlyCollection<InstanceHandle> irUsesInstance = oms.GetRelatedInstances(method, r_Get_Specified_Instances_Method__uses__Instance);
|
||||
|
||||
if (returnsWorkSet == InstanceHandle.Empty)
|
||||
{
|
||||
throw new InvalidOperationException("no Work Set specified for method");
|
||||
}
|
||||
|
||||
context.SetWorkData(returnsWorkSet, irUsesInstance);
|
||||
return returnsWorkSet;
|
||||
}
|
||||
}
|
||||
@ -1,19 +1,85 @@
|
||||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
using MBS.Core.Reflection;
|
||||
|
||||
namespace Mocha.Core.Modeling;
|
||||
|
||||
public class OmsClass
|
||||
{
|
||||
internal OmsDatabase omsdb { get; set; }
|
||||
public Guid GlobalIdentifier { get; internal set; } = Guid.Empty;
|
||||
|
||||
protected object GetAttributeValue()
|
||||
private Dictionary<Guid, object> _attributeValuesTemp = new Dictionary<Guid, object>();
|
||||
|
||||
protected object GetAttributeValue(object defaultValue = null)
|
||||
{
|
||||
StackTrace st = new StackTrace();
|
||||
StackFrame frame = st.GetFrame(0);
|
||||
return 1;
|
||||
if (st.FrameCount > 1)
|
||||
{
|
||||
StackFrame frame0 = st.GetFrame(0);
|
||||
StackFrame frame1 = st.GetFrame(1);
|
||||
|
||||
MethodBase mi = frame1.GetMethod();
|
||||
PropertyInfo? pi = mi.GetProperty();
|
||||
if (pi != null)
|
||||
{
|
||||
Guid propertyGlobalIdentifier = OmsDatabase.GetGlobalIdentifierForProperty(pi);
|
||||
if (propertyGlobalIdentifier != Guid.Empty)
|
||||
{
|
||||
if (GlobalIdentifier != Guid.Empty)
|
||||
{
|
||||
if (pi.PropertyType == typeof(string))
|
||||
{
|
||||
return omsdb.Oms.GetAttributeValue<string>(omsdb.Oms.GetInstance(GlobalIdentifier), omsdb.Oms.GetInstance(propertyGlobalIdentifier));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_attributeValuesTemp.ContainsKey(propertyGlobalIdentifier))
|
||||
{
|
||||
return _attributeValuesTemp[propertyGlobalIdentifier];
|
||||
}
|
||||
else
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
protected void SetAttributeValue(object value)
|
||||
{
|
||||
StackTrace st = new StackTrace();
|
||||
if (st.FrameCount > 1)
|
||||
{
|
||||
StackFrame frame0 = st.GetFrame(0);
|
||||
StackFrame frame1 = st.GetFrame(1);
|
||||
|
||||
MethodBase mi = frame1.GetMethod();
|
||||
PropertyInfo? pi = mi.GetProperty();
|
||||
if (pi != null)
|
||||
{
|
||||
Guid propertyGlobalIdentifier = OmsDatabase.GetGlobalIdentifierForProperty(pi);
|
||||
if (propertyGlobalIdentifier != Guid.Empty)
|
||||
{
|
||||
if (GlobalIdentifier != Guid.Empty)
|
||||
{
|
||||
if (pi.PropertyType == typeof(string))
|
||||
{
|
||||
omsdb.Oms.SetAttributeValue(omsdb.Oms.GetInstance(GlobalIdentifier), omsdb.Oms.GetInstance(propertyGlobalIdentifier), value);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_attributeValuesTemp[propertyGlobalIdentifier] = value;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
}
|
||||
@ -267,4 +267,17 @@ public class OmsDatabase
|
||||
_classesByHandle[ih] = item;
|
||||
_handlesByClass[item] = ih;
|
||||
}
|
||||
|
||||
public static Guid GetGlobalIdentifierForProperty(PropertyInfo pi)
|
||||
{
|
||||
object[] attrs = pi.GetCustomAttributes(false);
|
||||
foreach (object attr in attrs)
|
||||
{
|
||||
if (attr is OmsGlobalIdentifierAttribute)
|
||||
{
|
||||
return ((OmsGlobalIdentifierAttribute)attr).GlobalIdentifier;
|
||||
}
|
||||
}
|
||||
return Guid.Empty;
|
||||
}
|
||||
}
|
||||
@ -89,6 +89,7 @@ public class OmsInstanceList<T> : OmsInstanceList, IList<T> where T : OmsClass
|
||||
Guid localInstanceGuid = Guid.NewGuid();
|
||||
|
||||
omsdb.CreateClass(item, localClassGuid, localInstanceGuid);
|
||||
item.omsdb = omsdb;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -3,12 +3,20 @@
|
||||
using System.Collections.Frozen;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Data.SqlTypes;
|
||||
using System.Net;
|
||||
using System.Numerics;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using MBS.Core;
|
||||
using Mocha.Core.MethodImplementations;
|
||||
using Mocha.Core.Oop;
|
||||
|
||||
public abstract class Oms
|
||||
{
|
||||
public Version RuntimeVersion { get; } = new Version(2, 0, 38762, 5);
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the base path to which URLs are made relative.
|
||||
/// </summary>
|
||||
@ -17,7 +25,7 @@ public abstract class Oms
|
||||
|
||||
public string TenantName { get; set; } = String.Empty;
|
||||
|
||||
protected bool ValidateConstraints { get; set; } = true;
|
||||
public bool ValidateConstraints { get; protected set; } = true;
|
||||
|
||||
protected virtual void InitializeInternal()
|
||||
{
|
||||
@ -25,6 +33,12 @@ public abstract class Oms
|
||||
public void Initialize()
|
||||
{
|
||||
InitializeInternal();
|
||||
|
||||
MethodImplementation[] methodImplementations = MBS.Core.Reflection.TypeLoader.GetAvailableTypes<MethodImplementation>(new System.Reflection.Assembly[] { Assembly.GetExecutingAssembly() });
|
||||
foreach (MethodImplementation impl in methodImplementations)
|
||||
{
|
||||
RegisterMethodImplementation(GetInstance(impl.MethodClassGuid), impl);
|
||||
}
|
||||
}
|
||||
|
||||
private Dictionary<string, TenantHandle> _tenantsByName = new Dictionary<string, TenantHandle>();
|
||||
@ -132,15 +146,31 @@ public abstract class Oms
|
||||
ClearRelationshipInternal(source, relationship);
|
||||
}
|
||||
|
||||
protected abstract InstanceHandle GetInstanceInternal(Guid globalIdentifier);
|
||||
protected abstract InstanceHandle GetInstanceInternal(InstanceKey ik);
|
||||
protected abstract bool TryGetInstanceInternal(Guid globalIdentifier, out InstanceHandle inst);
|
||||
public bool TryGetInstance(Guid globalIdentifier, out InstanceHandle inst)
|
||||
{
|
||||
return TryGetInstanceInternal(globalIdentifier, out inst);
|
||||
}
|
||||
protected abstract bool TryGetInstanceInternal(InstanceKey ik, out InstanceHandle inst);
|
||||
public bool TryGetInstance(InstanceKey ik, out InstanceHandle inst)
|
||||
{
|
||||
return TryGetInstanceInternal(ik, out inst);
|
||||
}
|
||||
public InstanceHandle GetInstance(Guid globalIdentifier)
|
||||
{
|
||||
return GetInstanceInternal(globalIdentifier);
|
||||
if (TryGetInstance(globalIdentifier, out InstanceHandle ih))
|
||||
{
|
||||
return ih;
|
||||
}
|
||||
throw new KeyNotFoundException();
|
||||
}
|
||||
public InstanceHandle GetInstance(InstanceKey ik)
|
||||
{
|
||||
return GetInstanceInternal(ik);
|
||||
if (TryGetInstance(ik, out InstanceHandle ih))
|
||||
{
|
||||
return ih;
|
||||
}
|
||||
throw new KeyNotFoundException();
|
||||
}
|
||||
|
||||
protected abstract IReadOnlyCollection<InstanceHandle> GetRelatedInstancesInternal(InstanceHandle source, InstanceHandle relationship, DateTime effectiveDate);
|
||||
@ -237,7 +267,7 @@ public abstract class Oms
|
||||
return HasAttributeValueInternal(source, attribute, effectiveDate.GetValueOrDefault(DateTime.Now));
|
||||
}
|
||||
protected abstract object? GetAttributeValueInternal(InstanceHandle source, InstanceHandle attribute, DateTime effectiveDate);
|
||||
protected object? UnsafeGetAttributeValue(InstanceHandle source, InstanceHandle attribute, DateTime? effectiveDate = null)
|
||||
protected internal object? UnsafeGetAttributeValue(InstanceHandle source, InstanceHandle attribute, DateTime? effectiveDate = null)
|
||||
{
|
||||
object? val = GetAttributeValueInternal(source, attribute, effectiveDate.GetValueOrDefault(DateTime.Now));
|
||||
return val;
|
||||
@ -279,19 +309,20 @@ public abstract class Oms
|
||||
|
||||
private void ValidateConstraintsForAttribute(InstanceHandle source, InstanceHandle attribute, object value)
|
||||
{
|
||||
if (!ValidateConstraints)
|
||||
return;
|
||||
|
||||
InstanceHandle a_TextAttribute = GetInstance(KnownInstanceGuids.Classes.TextAttribute);
|
||||
InstanceHandle a_BooleanAttribute = GetInstance(KnownInstanceGuids.Classes.BooleanAttribute);
|
||||
InstanceHandle a_NumericAttribute = GetInstance(KnownInstanceGuids.Classes.NumericAttribute);
|
||||
InstanceHandle a_DateAttribute = GetInstance(KnownInstanceGuids.Classes.DateAttribute);
|
||||
|
||||
if (ValidateConstraints)
|
||||
{
|
||||
InstanceHandle sourceParentClass = GetParentClass(source);
|
||||
|
||||
if (!RecursiveClassHasAttribute(sourceParentClass, attribute))
|
||||
{
|
||||
throw new ArgumentException("The specified attribute is not defined for the given instance.");
|
||||
}
|
||||
string name = GetAttributeValue<string>(attribute, GetInstance(KnownAttributeGuids.Text.Name));
|
||||
throw new ArgumentException(String.Format("Undefined attribute `{0}` on class {1}", name, GetGlobalIdentifier(sourceParentClass)));
|
||||
}
|
||||
|
||||
if (IsInstanceOf(attribute, a_TextAttribute))
|
||||
@ -370,10 +401,32 @@ public abstract class Oms
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool IsInstanceOf(InstanceHandle instance, InstanceHandle parentClass)
|
||||
private bool RecursiveClassHasSuperclass(InstanceHandle clasz, InstanceHandle superclasz)
|
||||
{
|
||||
IEnumerable<InstanceHandle> inheritedClasses = GetRelatedInstances(clasz, GetInstance(KnownRelationshipGuids.Class__has_super__Class));
|
||||
foreach (InstanceHandle ih in inheritedClasses)
|
||||
{
|
||||
if (ih.Equals(superclasz))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (RecursiveClassHasSuperclass(ih, superclasz))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool IsInstanceOf(InstanceHandle instance, InstanceHandle parentClass, bool exactMatch = false)
|
||||
{
|
||||
InstanceHandle parentClass1 = GetParentClass(instance);
|
||||
return Object.Equals(parentClass1, parentClass);
|
||||
bool value = Object.Equals(parentClass1, parentClass);
|
||||
if (!value && !exactMatch)
|
||||
{
|
||||
return RecursiveClassHasSuperclass(parentClass1, parentClass);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public string GetAttachmentUrl(InstanceHandle fileInstance)
|
||||
@ -512,22 +565,52 @@ public abstract class Oms
|
||||
return c_new;
|
||||
}
|
||||
|
||||
public InstanceHandle ExecuteInstanceMethod(OmsContext context, InstanceHandle instance, InstanceHandle methodBinding)
|
||||
public InstanceHandle ExecuteInstanceMethod(OmsContext context, InstanceHandle instance, MethodBinding methodBinding)
|
||||
{
|
||||
InstanceHandle method = GetRelatedInstance(methodBinding, GetInstance(KnownRelationshipGuids.Method_Binding__executes__Method));
|
||||
InstanceHandle method = GetRelatedInstance(methodBinding.Handle, GetInstance(KnownRelationshipGuids.Method_Binding__executes__Method));
|
||||
InstanceHandle forClass = GetRelatedInstance(method, GetInstance(KnownRelationshipGuids.Method__for__Class));
|
||||
context.SetWorkData(forClass, instance);
|
||||
return Execute(context, methodBinding);
|
||||
return Execute(context, methodBinding.Handle);
|
||||
}
|
||||
public object? ExecuteInstanceMethodReturningAttribute(OmsContext context, InstanceHandle instance, InstanceHandle methodBinding)
|
||||
public object? ExecuteInstanceMethodReturningAttribute(OmsContext context, InstanceHandle instance, MethodBinding methodBinding)
|
||||
{
|
||||
InstanceHandle workSet = ExecuteInstanceMethod(context, instance, methodBinding);
|
||||
object? value = context.GetWorkData(workSet);
|
||||
return value;
|
||||
}
|
||||
|
||||
public InstanceHandle Execute(OmsContext context, InstanceHandle methodOrMethodBinding)
|
||||
private Dictionary<InstanceHandle, MethodImplementation> methodImplementations = new Dictionary<InstanceHandle, MethodImplementation>();
|
||||
private void RegisterMethodImplementation(InstanceHandle methodClass, MethodImplementation implementation)
|
||||
{
|
||||
methodImplementations[methodClass] = implementation;
|
||||
implementation.Initialize(this);
|
||||
}
|
||||
|
||||
public InstanceHandle Execute(OmsContext context, Method method)
|
||||
{
|
||||
return Execute(context, method.Handle);
|
||||
}
|
||||
public InstanceHandle Execute(OmsContext context, ReturnInstanceSetMethodBinding methodBinding)
|
||||
{
|
||||
return Execute(context, methodBinding.Handle);
|
||||
}
|
||||
public object? ExecuteReturningAttributeValue(OmsContext context, ReturnAttributeMethodBinding methodBinding)
|
||||
{
|
||||
InstanceHandle workData = Execute(context, methodBinding.Handle);
|
||||
return context.GetWorkData(workData);
|
||||
}
|
||||
public T ExecuteReturningAttributeValue<T>(OmsContext context, ReturnAttributeMethodBinding methodBinding, T defaultValue = default(T))
|
||||
{
|
||||
object? value = ExecuteReturningAttributeValue(context, methodBinding);
|
||||
if (value is T)
|
||||
{
|
||||
return (T)value;
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
private InstanceHandle Execute(OmsContext context, InstanceHandle methodOrMethodBinding)
|
||||
{
|
||||
InstanceHandle parentClass = GetParentClass(methodOrMethodBinding);
|
||||
if (IsInstanceOf(methodOrMethodBinding, GetInstance(KnownInstanceGuids.Classes.ReturnAttributeMethodBinding))
|
||||
|| IsInstanceOf(methodOrMethodBinding, GetInstance(KnownInstanceGuids.Classes.ReturnInstanceSetMethodBinding)))
|
||||
{
|
||||
@ -535,37 +618,12 @@ public abstract class Oms
|
||||
}
|
||||
else
|
||||
{
|
||||
if (IsInstanceOf(methodOrMethodBinding, GetInstance(KnownInstanceGuids.MethodClasses.GetAttributeMethod)))
|
||||
if (methodImplementations.ContainsKey(parentClass))
|
||||
{
|
||||
InstanceHandle irForClass = GetRelatedInstance(methodOrMethodBinding, GetInstance(KnownRelationshipGuids.Method__for__Class));
|
||||
InstanceHandle returnsAttribute = GetRelatedInstance(methodOrMethodBinding, GetInstance(KnownRelationshipGuids.Get_Attribute_Method__returns__Attribute));
|
||||
|
||||
if (returnsAttribute == InstanceHandle.Empty)
|
||||
{
|
||||
throw new InvalidOperationException("no Work Set specified for method");
|
||||
}
|
||||
|
||||
InstanceHandle forInstance = (InstanceHandle) context.GetWorkData(irForClass);
|
||||
object? value = UnsafeGetAttributeValue(forInstance, returnsAttribute);
|
||||
context.SetWorkData(returnsAttribute, value);
|
||||
return returnsAttribute;
|
||||
}
|
||||
else if (IsInstanceOf(methodOrMethodBinding, GetInstance(KnownInstanceGuids.MethodClasses.GetSpecifiedInstancesMethod)))
|
||||
{
|
||||
InstanceHandle irForClass = GetRelatedInstance(methodOrMethodBinding, GetInstance(KnownRelationshipGuids.Method__for__Class));
|
||||
InstanceHandle returnsWorkSet = GetRelatedInstance(methodOrMethodBinding, GetInstance(KnownRelationshipGuids.Get_Specified_Instances_Method__returns__Work_Set));
|
||||
IReadOnlyCollection<InstanceHandle> irUsesInstance = GetRelatedInstances(methodOrMethodBinding, GetInstance(KnownRelationshipGuids.Get_Specified_Instances_Method__uses__Instance));
|
||||
|
||||
if (returnsWorkSet == InstanceHandle.Empty)
|
||||
{
|
||||
throw new InvalidOperationException("no Work Set specified for method");
|
||||
}
|
||||
|
||||
context.SetWorkData(returnsWorkSet, irUsesInstance);
|
||||
return returnsWorkSet;
|
||||
return methodImplementations[parentClass].Execute(this, context, methodOrMethodBinding);
|
||||
}
|
||||
}
|
||||
throw new NotImplementedException();
|
||||
throw new NotImplementedException(String.Format("method implementation not found for method class {0}", GetGlobalIdentifier(parentClass)));
|
||||
}
|
||||
|
||||
private InstanceHandle ExecuteMethodBinding(OmsContext context, InstanceHandle methodBinding)
|
||||
@ -579,9 +637,9 @@ public abstract class Oms
|
||||
return new OmsContext(this);
|
||||
}
|
||||
|
||||
public IReadOnlyCollection<InstanceHandle> ExecuteStaticMethodReturningInstanceSet(OmsContext context, InstanceHandle methodBinding)
|
||||
public IReadOnlyCollection<InstanceHandle> ExecuteStaticMethodReturningInstanceSet(OmsContext context, ReturnInstanceSetMethodBinding methodBinding)
|
||||
{
|
||||
InstanceHandle method = GetRelatedInstance(methodBinding, GetInstance(KnownRelationshipGuids.Method_Binding__executes__Method));
|
||||
InstanceHandle method = GetRelatedInstance(methodBinding.Handle, GetInstance(KnownRelationshipGuids.Method_Binding__executes__Method));
|
||||
if (TryGetAttributeValue<bool>(method, GetInstance(KnownAttributeGuids.Boolean.Static), out bool is_static))
|
||||
{
|
||||
if (is_static)
|
||||
@ -598,11 +656,11 @@ public abstract class Oms
|
||||
throw new InvalidOperationException("cannot call a non-static Method in a static context");
|
||||
}
|
||||
|
||||
public InstanceHandle CreateWorkSet(string name)
|
||||
public WorkSet CreateWorkSet(string name)
|
||||
{
|
||||
return CreateWorkSet(name, false, new InstanceHandle[0]);
|
||||
}
|
||||
public InstanceHandle CreateWorkSet(string name, bool singular, ICollection<InstanceHandle> validClasses)
|
||||
public WorkSet CreateWorkSet(string name, bool singular, ICollection<InstanceHandle> validClasses)
|
||||
{
|
||||
InstanceHandle workSet = CreateInstanceOf(GetInstance(KnownInstanceGuids.Classes.WorkSet));
|
||||
SetAttributeValue(workSet, GetInstance(KnownAttributeGuids.Text.Name), name);
|
||||
@ -612,7 +670,7 @@ public abstract class Oms
|
||||
{
|
||||
AssignRelationship(workSet, GetInstance(KnownRelationshipGuids.Work_Set__has_valid__Class), validClasses);
|
||||
}
|
||||
return workSet;
|
||||
return new WorkSet(workSet);
|
||||
}
|
||||
|
||||
public void AddAttribute(InstanceHandle targetInstance, InstanceHandle attributeInstance)
|
||||
@ -634,4 +692,107 @@ public abstract class Oms
|
||||
IReadOnlyCollection<InstanceHandle> insts = GetRelatedInstances(classInstance, GetInstance(KnownRelationshipGuids.Class__has__Instance));
|
||||
return insts;
|
||||
}
|
||||
|
||||
public string GetInstanceText(InstanceWrapper inst)
|
||||
{
|
||||
return GetInstanceText(inst.Handle);
|
||||
}
|
||||
public string GetInstanceText(InstanceHandle inst)
|
||||
{
|
||||
InstanceHandle parentClass = GetParentClass(inst);
|
||||
InstanceHandle ihLabeledByRAMB = InstanceHandle.Empty;
|
||||
|
||||
if (TryGetInstance(KnownRelationshipGuids.Class__instance_labeled_by__Return_Attribute_Method_Binding, out ihLabeledByRAMB))
|
||||
{
|
||||
InstanceHandle ramb = GetRelatedInstance(parentClass, ihLabeledByRAMB);
|
||||
|
||||
OmsContext context = CreateContext();
|
||||
object value = Execute(context, ramb);
|
||||
if (value is string)
|
||||
{
|
||||
return (string)value;
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: remove when we have Class@get Instance Text implemented
|
||||
return _GetInstanceTextHack(inst);
|
||||
}
|
||||
private string _GetInstanceTextHack(InstanceHandle inst)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (IsInstanceOf(inst, GetInstance(KnownInstanceGuids.Classes.Class)))
|
||||
{
|
||||
string name = GetAttributeValue<string>(inst, GetInstance(KnownAttributeGuids.Text.Name));
|
||||
sb.Append(name);
|
||||
}
|
||||
else if (IsInstanceOf(inst, GetInstance(KnownInstanceGuids.Classes.Method)))
|
||||
{
|
||||
InstanceHandle forClass = GetRelatedInstance(inst, GetInstance(KnownRelationshipGuids.Method__for__Class));
|
||||
string verb = GetAttributeValue<string>(inst, GetInstance(KnownAttributeGuids.Text.Verb));
|
||||
string name = GetAttributeValue<string>(inst, GetInstance(KnownAttributeGuids.Text.Name));
|
||||
bool is_static = GetAttributeValue<bool>(inst, GetInstance(KnownAttributeGuids.Boolean.Static));
|
||||
|
||||
sb.Append(GetInstanceText(forClass));
|
||||
sb.Append('@');
|
||||
sb.Append(verb);
|
||||
sb.Append(' ');
|
||||
sb.Append(name);
|
||||
if (is_static)
|
||||
{
|
||||
sb.Append("*S");
|
||||
}
|
||||
}
|
||||
else if (IsInstanceOf(inst, GetInstance(KnownInstanceGuids.Classes.ReturnAttributeMethodBinding)))
|
||||
{
|
||||
InstanceHandle executesMethod = GetRelatedInstance(inst, GetInstance(KnownRelationshipGuids.Method_Binding__executes__Method));
|
||||
sb.Append(GetInstanceText(executesMethod));
|
||||
sb.Append("[ramb]");
|
||||
}
|
||||
else if (IsInstanceOf(inst, GetInstance(KnownInstanceGuids.Classes.ReturnInstanceSetMethodBinding)))
|
||||
{
|
||||
InstanceHandle executesMethod = GetRelatedInstance(inst, GetInstance(KnownRelationshipGuids.Method_Binding__executes__Method));
|
||||
sb.Append(GetInstanceText(executesMethod));
|
||||
sb.Append("[rsmb]");
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public Dictionary<InstanceHandle, SystemRoutine> _systemRoutinesByInstance = new Dictionary<InstanceHandle, SystemRoutine>();
|
||||
internal void RegisterSystemRoutine(InstanceHandle handle, SystemRoutine routine)
|
||||
{
|
||||
_systemRoutinesByInstance[handle] = routine;
|
||||
}
|
||||
public object? ExecuteSystemRoutine(InstanceHandle handle)
|
||||
{
|
||||
object? value = _systemRoutinesByInstance[handle].Execute();
|
||||
return value;
|
||||
}
|
||||
public T ExecuteSystemRoutine<T>(InstanceHandle handle, T defaultValue = default(T))
|
||||
{
|
||||
object? value = ExecuteSystemRoutine(handle);
|
||||
if (value is T)
|
||||
{
|
||||
return (T)value;
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public Method GetMethod(InstanceHandle forClass, string verb, string name, AccessModifier? accessModifier = null, bool? is_static = null)
|
||||
{
|
||||
// this really needs to be super fast...
|
||||
InstanceHandle a_Verb = GetInstance(KnownAttributeGuids.Text.Verb);
|
||||
InstanceHandle a_Name = GetInstance(KnownAttributeGuids.Text.Name);
|
||||
|
||||
IEnumerable<InstanceHandle> methods = GetRelatedInstances(forClass, GetInstance(KnownRelationshipGuids.Class__has__Method));
|
||||
foreach (InstanceHandle method in methods)
|
||||
{
|
||||
string _verb = GetAttributeValue<string>(method, a_Verb);
|
||||
string _name = GetAttributeValue<string>(method, a_Name);
|
||||
if (_verb.Equals(verb) && _name.Equals(name))
|
||||
{
|
||||
return Method.CreateFromInstance(this, method);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
|
||||
using System.Linq.Expressions;
|
||||
using Mocha.Core.Oop;
|
||||
|
||||
namespace Mocha.Core;
|
||||
|
||||
@ -12,6 +13,10 @@ public class OmsContext
|
||||
}
|
||||
|
||||
private Dictionary<InstanceHandle, object?> _WorkData = new Dictionary<InstanceHandle, object?>();
|
||||
public object? GetWorkData(WorkSet parm)
|
||||
{
|
||||
return GetWorkData(parm.Handle);
|
||||
}
|
||||
public object? GetWorkData(InstanceHandle parm)
|
||||
{
|
||||
if (_WorkData.ContainsKey(parm))
|
||||
@ -20,6 +25,11 @@ public class OmsContext
|
||||
Console.Error.WriteLine("work data not found for parm {0}", oms.GetGlobalIdentifier(parm));
|
||||
return null;
|
||||
}
|
||||
|
||||
public void SetWorkData(WorkSet parm, object? value)
|
||||
{
|
||||
SetWorkData(parm.Handle, value);
|
||||
}
|
||||
public void SetWorkData(InstanceHandle parm, object? value)
|
||||
{
|
||||
if (oms.IsInstanceOf(parm, oms.GetInstance(KnownInstanceGuids.Classes.WorkSet)))
|
||||
|
||||
@ -29,13 +29,25 @@ public class MemoryOms : Oms
|
||||
return InstanceKey.Empty;
|
||||
}
|
||||
|
||||
public InstanceHandle GetInstance(Guid globalIdentifier)
|
||||
public bool TryGetInstance(Guid globalIdentifier, out InstanceHandle ih)
|
||||
{
|
||||
return _instancesByGuid[globalIdentifier];
|
||||
if (_instancesByGuid.ContainsKey(globalIdentifier))
|
||||
{
|
||||
ih = _instancesByGuid[globalIdentifier];
|
||||
return true;
|
||||
}
|
||||
public InstanceHandle GetInstance(InstanceKey ik)
|
||||
ih = InstanceHandle.Empty;
|
||||
return false;
|
||||
}
|
||||
public bool TryGetInstance(InstanceKey ik, out InstanceHandle ih)
|
||||
{
|
||||
return _instancesByKey[ik];
|
||||
if (_instancesByKey.ContainsKey(ik))
|
||||
{
|
||||
ih = _instancesByKey[ik];
|
||||
return true;
|
||||
}
|
||||
ih = InstanceHandle.Empty;
|
||||
return false;
|
||||
}
|
||||
|
||||
public void SetInstanceKey(InstanceHandle c_File, InstanceKey instanceKey)
|
||||
@ -226,19 +238,19 @@ public class MemoryOms : Oms
|
||||
return ik;
|
||||
}
|
||||
|
||||
protected override InstanceHandle GetInstanceInternal(Guid globalIdentifier)
|
||||
protected override bool TryGetInstanceInternal(Guid globalIdentifier, out InstanceHandle ih)
|
||||
{
|
||||
if (_CurrentTenant == null)
|
||||
throw new InvalidOperationException("Please select a tenant first.");
|
||||
|
||||
return _CurrentTenant.GetInstance(globalIdentifier);
|
||||
return _CurrentTenant.TryGetInstance(globalIdentifier, out ih);
|
||||
}
|
||||
protected override InstanceHandle GetInstanceInternal(InstanceKey ik)
|
||||
protected override bool TryGetInstanceInternal(InstanceKey ik, out InstanceHandle ih)
|
||||
{
|
||||
if (_CurrentTenant == null)
|
||||
throw new InvalidOperationException("Please select a tenant first.");
|
||||
|
||||
return _CurrentTenant.GetInstance(ik);
|
||||
return _CurrentTenant.TryGetInstance(ik, out ih);
|
||||
}
|
||||
|
||||
protected override void SetInstanceKeyInternal(InstanceHandle source, InstanceKey instanceKey)
|
||||
|
||||
@ -9,10 +9,10 @@ using MBS.Core;
|
||||
public class MiniOms : MemoryOms
|
||||
{
|
||||
private TenantHandle t_super;
|
||||
private InstanceHandle c_Class, c_Attribute, c_Relationship, c_TextAttribute, c_BooleanAttribute, c_NumericAttribute, c_DateAttribute, c_WorkSet, c_Instance, c_File;
|
||||
private InstanceHandle c_Class, c_Attribute, c_Relationship, c_TextAttribute, c_BooleanAttribute, c_NumericAttribute, c_DateAttribute, c_WorkSet, c_Instance, c_OMS, c_File;
|
||||
private InstanceHandle r_Class__has__Instance, r_Instance__for__Class;
|
||||
private InstanceHandle r_Relationship__has_source__Class, r_Relationship__has_destination__Class, r_Relationship__has_sibling__Relationship;
|
||||
private InstanceHandle a_Name, a_Value, a_ContentType, a_RelationshipType, a_Singular;
|
||||
private InstanceHandle a_Name, a_Order, a_Value, a_ContentType, a_RelationshipType, a_Singular;
|
||||
private InstanceHandle a_MinimumLength, a_MaximumLength, a_MinimumValue, a_MaximumValue;
|
||||
private InstanceHandle i_SignonLogo;
|
||||
|
||||
@ -63,6 +63,7 @@ public class MiniOms : MemoryOms
|
||||
c_DateAttribute = CreateInstanceOf(c_Class, KnownInstanceGuids.Classes.DateAttribute);
|
||||
|
||||
a_Name = CreateInstanceOf(c_TextAttribute, KnownAttributeGuids.Text.Name);
|
||||
a_Order = CreateInstanceOf(c_TextAttribute, KnownAttributeGuids.Text.Order);
|
||||
a_Value = CreateInstanceOf(c_TextAttribute, KnownAttributeGuids.Text.Value);
|
||||
a_ContentType = CreateInstanceOf(c_TextAttribute, KnownAttributeGuids.Text.ContentType);
|
||||
a_RelationshipType = CreateInstanceOf(c_TextAttribute, KnownAttributeGuids.Text.RelationshipType);
|
||||
@ -139,6 +140,8 @@ public class MiniOms : MemoryOms
|
||||
c_Instance = CreateClass("Instance", KnownInstanceGuids.Classes.Instance);
|
||||
SetInstanceKey(c_Instance, new InstanceKey(1, 17));
|
||||
|
||||
c_OMS = CreateClass("OMS", KnownInstanceGuids.Classes.OMS);
|
||||
|
||||
// ?============ MODULES ============?
|
||||
foreach (MiniOmsModule module in Modules)
|
||||
{
|
||||
|
||||
@ -2,6 +2,7 @@ namespace Mocha.Core.OmsImplementations.Mini;
|
||||
|
||||
using System;
|
||||
using MBS.Core;
|
||||
using Mocha.Core.Oop;
|
||||
|
||||
/// <summary>
|
||||
/// Builds additional support for Executables and Methods. These must be defined in order to call
|
||||
@ -9,10 +10,13 @@ using MBS.Core;
|
||||
/// </summary>
|
||||
public class MethodsModule : MiniOmsModule
|
||||
{
|
||||
private InstanceHandle c_OMS;
|
||||
private InstanceHandle c_Method, c_MethodBinding;
|
||||
private InstanceHandle a_Name, a_Verb, a_Static;
|
||||
private InstanceHandle a_Name, a_Order, a_Verb, a_Static;
|
||||
private InstanceHandle c_ReturnAttributeMethodBinding, c_ReturnInstanceSetMethodBinding;
|
||||
private InstanceHandle c_GetAttributeMethod, c_GetSpecifiedInstancesMethod;
|
||||
private InstanceHandle c_BuildAttributeMethod, c_GetAttributeMethod, c_GetSpecifiedInstancesMethod, c_GetAttributeBySystemRoutineMethod;
|
||||
private InstanceHandle c_AccessModifier, i_AccessModifier_Private, i_AccessModifier_Protected, i_AccessModifier_Public, i_AccessModifier_RootA2;
|
||||
private InstanceHandle c_SystemRoutine, c_SystemAttributeRoutine, c_SystemInstanceSetRoutine;
|
||||
|
||||
protected override void BuildInternal(Oms oms)
|
||||
{
|
||||
@ -22,12 +26,43 @@ public class MethodsModule : MiniOmsModule
|
||||
c_ReturnInstanceSetMethodBinding = oms.CreateClass("Return Instance Set Method Binding", KnownInstanceGuids.Classes.ReturnInstanceSetMethodBinding);
|
||||
|
||||
a_Name = oms.GetInstance(KnownAttributeGuids.Text.Name);
|
||||
a_Order = oms.GetInstance(KnownAttributeGuids.Text.Order);
|
||||
a_Verb = oms.CreateInstanceOf(c_TextAttribute, KnownAttributeGuids.Text.Verb);
|
||||
a_Static = oms.CreateInstanceOf(c_BooleanAttribute, KnownAttributeGuids.Boolean.Static);
|
||||
|
||||
c_AccessModifier = oms.CreateInstanceOf(c_Class, KnownInstanceGuids.Classes.AccessModifier);
|
||||
oms.AddAttribute(c_AccessModifier, a_Name);
|
||||
oms.AddAttribute(c_AccessModifier, a_Order);
|
||||
|
||||
i_AccessModifier_Private = oms.CreateInstanceOf(c_AccessModifier, KnownInstanceGuids.AccessModifiers.Private);
|
||||
oms.SetAttributeValue(i_AccessModifier_Private, a_Name, "Private");
|
||||
oms.SetAttributeValue(i_AccessModifier_Private, a_Order, "a");
|
||||
|
||||
i_AccessModifier_Protected = oms.CreateInstanceOf(c_AccessModifier, KnownInstanceGuids.AccessModifiers.Protected);
|
||||
oms.SetAttributeValue(i_AccessModifier_Protected, a_Name, "Protected");
|
||||
oms.SetAttributeValue(i_AccessModifier_Protected, a_Order, "b");
|
||||
|
||||
i_AccessModifier_Public = oms.CreateInstanceOf(c_AccessModifier, KnownInstanceGuids.AccessModifiers.Public);
|
||||
oms.SetAttributeValue(i_AccessModifier_Public, a_Name, "Public");
|
||||
oms.SetAttributeValue(i_AccessModifier_Public, a_Order, "c");
|
||||
|
||||
i_AccessModifier_RootA2 = oms.CreateInstanceOf(c_AccessModifier, KnownInstanceGuids.AccessModifiers.RootA2);
|
||||
oms.SetAttributeValue(i_AccessModifier_RootA2, a_Name, "Root (A2)");
|
||||
oms.SetAttributeValue(i_AccessModifier_RootA2, a_Order, "z");
|
||||
|
||||
AccessModifier.Private = new AccessModifier(i_AccessModifier_Private);
|
||||
AccessModifier.Protected = new AccessModifier(i_AccessModifier_Protected);
|
||||
AccessModifier.Public = new AccessModifier(i_AccessModifier_Public);
|
||||
AccessModifier.RootA2 = new AccessModifier(i_AccessModifier_RootA2);
|
||||
|
||||
oms.CreateRelationship(c_Class, "has", c_Method, KnownRelationshipGuids.Class__has__Method, false, "for", KnownRelationshipGuids.Method__for__Class);
|
||||
oms.CreateRelationship(c_MethodBinding, "executes", c_Method, KnownRelationshipGuids.Method_Binding__executes__Method, true, "executed by", KnownRelationshipGuids.Method__executed_by__Method_Binding);
|
||||
|
||||
c_BuildAttributeMethod = oms.CreateClass("BA - Build Attribute Method", KnownInstanceGuids.MethodClasses.BuildAttributeMethod);
|
||||
oms.AddAttribute(c_BuildAttributeMethod, oms.GetInstance(KnownAttributeGuids.Text.Value));
|
||||
oms.CreateRelationship(c_BuildAttributeMethod, "returns", c_Attribute, KnownRelationshipGuids.Build_Attribute_Method__returns__Attribute, true, "returned by", KnownRelationshipGuids.Attribute__returned_by__Build_Attribute_Method);
|
||||
oms.AddSuperClass(c_BuildAttributeMethod, c_Method);
|
||||
|
||||
c_GetAttributeMethod = oms.CreateClass("GA - Get Attribute Method", KnownInstanceGuids.MethodClasses.GetAttributeMethod);
|
||||
oms.CreateRelationship(c_GetAttributeMethod, "returns", c_Attribute, KnownRelationshipGuids.Get_Attribute_Method__returns__Attribute, true, "returned by", KnownRelationshipGuids.Attribute__returned_by__Get_Attribute_Method);
|
||||
oms.AddSuperClass(c_GetAttributeMethod, c_Method);
|
||||
@ -37,8 +72,27 @@ public class MethodsModule : MiniOmsModule
|
||||
oms.CreateRelationship(c_GetSpecifiedInstancesMethod, "uses", c_Instance, KnownRelationshipGuids.Get_Specified_Instances_Method__uses__Instance, false, "used by", KnownRelationshipGuids.Instance__used_by__Get_Specified_Instances_Method);
|
||||
oms.AddSuperClass(c_GetSpecifiedInstancesMethod, c_Method);
|
||||
|
||||
c_SystemRoutine = oms.CreateClass("System Routine", KnownInstanceGuids.Classes.SystemRoutine);
|
||||
|
||||
c_SystemAttributeRoutine = oms.CreateClass("System Attribute Routine", KnownInstanceGuids.Classes.SystemAttributeRoutine);
|
||||
oms.AddSuperClass(c_SystemAttributeRoutine, c_SystemRoutine);
|
||||
|
||||
c_SystemInstanceSetRoutine = oms.CreateClass("System Instance Set Routine", KnownInstanceGuids.Classes.SystemInstanceSetRoutine);
|
||||
oms.AddSuperClass(c_SystemInstanceSetRoutine, c_SystemRoutine);
|
||||
|
||||
c_GetAttributeBySystemRoutineMethod = oms.CreateClass("GAS - Get Attribute by System Routine Method", KnownInstanceGuids.MethodClasses.GetAttributeBySystemRoutineMethod);
|
||||
oms.CreateRelationship(c_GetAttributeBySystemRoutineMethod, "returns", c_Attribute, KnownRelationshipGuids.Get_Attribute_by_System_Routine_Method__returns__Attribute, true, "returned by", KnownRelationshipGuids.Attribute__returned_by__Get_Attribute_by_System_Routine_Method);
|
||||
oms.CreateRelationship(c_GetAttributeBySystemRoutineMethod, "uses", c_Instance, KnownRelationshipGuids.Get_Attribute_by_System_Routine_Method__uses__System_Attribute_Routine, false, "used by", KnownRelationshipGuids.System_Attribute_Routine__used_by__Get_Attribute_by_System_Routine_Method);
|
||||
oms.AddSuperClass(c_GetAttributeBySystemRoutineMethod, c_Method);
|
||||
|
||||
oms.AddAttribute(c_Method, a_Name);
|
||||
oms.AddAttribute(c_Method, a_Verb);
|
||||
oms.AddAttribute(c_Method, a_Static);
|
||||
|
||||
c_OMS = oms.GetInstance(KnownInstanceGuids.Classes.OMS);
|
||||
OmsMethodBuilder mb = new OmsMethodBuilder(oms);
|
||||
OmsSystemRoutineBuilder srb = new OmsSystemRoutineBuilder(oms);
|
||||
SystemAttributeRoutine sr = srb.CreateSystemAttributeRoutine(KnownInstanceGuids.SystemAttributeRoutines.GetRuntimeVersion, new Func<object?>(delegate () { return oms.RuntimeVersion.ToString(); }));
|
||||
mb.CreateGetAttributeBySystemRoutineMethod(c_OMS, "get", "Runtime Version", null, true, oms.GetInstance(KnownAttributeGuids.Text.Value), sr);
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,9 @@
|
||||
|
||||
|
||||
|
||||
using Mocha.Core.Oop;
|
||||
using Mocha.Core.Oop.Methods;
|
||||
|
||||
namespace Mocha.Core;
|
||||
|
||||
public class OmsMethodBuilder
|
||||
@ -15,48 +19,71 @@ public class OmsMethodBuilder
|
||||
c_ReturnInstanceSetMethodBinding = Oms.GetInstance(KnownInstanceGuids.Classes.ReturnInstanceSetMethodBinding);
|
||||
}
|
||||
|
||||
public InstanceHandle CreateReturnAttributeMethodBinding(InstanceHandle method)
|
||||
public ReturnAttributeMethodBinding CreateReturnAttributeMethodBinding(Method method)
|
||||
{
|
||||
InstanceHandle methodBinding = Oms.CreateInstanceOf(c_ReturnAttributeMethodBinding);
|
||||
Oms.AssignRelationship(methodBinding, Oms.GetInstance(KnownRelationshipGuids.Method_Binding__executes__Method), method);
|
||||
return methodBinding;
|
||||
Oms.AssignRelationship(methodBinding, Oms.GetInstance(KnownRelationshipGuids.Method_Binding__executes__Method), method.Handle);
|
||||
return new ReturnAttributeMethodBinding(methodBinding);
|
||||
}
|
||||
|
||||
public InstanceHandle CreateReturnInstanceSetMethodBinding(InstanceHandle method)
|
||||
public ReturnInstanceSetMethodBinding CreateReturnInstanceSetMethodBinding(Method method)
|
||||
{
|
||||
InstanceHandle methodBinding = Oms.CreateInstanceOf(c_ReturnInstanceSetMethodBinding);
|
||||
Oms.AssignRelationship(methodBinding, Oms.GetInstance(KnownRelationshipGuids.Method_Binding__executes__Method), method);
|
||||
return methodBinding;
|
||||
Oms.AssignRelationship(methodBinding, Oms.GetInstance(KnownRelationshipGuids.Method_Binding__executes__Method), method.Handle);
|
||||
return new ReturnInstanceSetMethodBinding(methodBinding);
|
||||
}
|
||||
|
||||
public InstanceHandle CreateGetAttributeMethod(InstanceHandle forClassInstance, string verb, string name, InstanceHandle attributeInstance)
|
||||
public GetAttributeMethod CreateGetAttributeMethod(InstanceHandle forClassInstance, string verb, string name, InstanceHandle attributeInstance)
|
||||
{
|
||||
return CreateGetAttributeMethod(forClassInstance, verb, name, null, false, attributeInstance);
|
||||
}
|
||||
public InstanceHandle CreateGetAttributeMethod(InstanceHandle forClassInstance, string verb, string name, object accessModifier, bool isStatic, InstanceHandle attributeInstance)
|
||||
public GetAttributeMethod CreateGetAttributeMethod(InstanceHandle forClassInstance, string verb, string name, AccessModifier accessModifier, bool isStatic, InstanceHandle attributeInstance)
|
||||
{
|
||||
InstanceHandle method = Oms.CreateInstanceOf(Oms.GetInstance(KnownInstanceGuids.MethodClasses.GetAttributeMethod));
|
||||
Oms.AssignRelationship(method, Oms.GetInstance(KnownRelationshipGuids.Method__for__Class), forClassInstance);
|
||||
Oms.SetAttributeValue(method, Oms.GetInstance(KnownAttributeGuids.Text.Verb), verb);
|
||||
Oms.SetAttributeValue(method, Oms.GetInstance(KnownAttributeGuids.Text.Name), name);
|
||||
Oms.SetAttributeValue(method, Oms.GetInstance(KnownAttributeGuids.Boolean.Static), isStatic);
|
||||
InstanceHandle method = CreateMethodBase(Oms.GetInstance(KnownInstanceGuids.MethodClasses.GetAttributeMethod), forClassInstance, verb, name, accessModifier, isStatic);
|
||||
Oms.AssignRelationship(method, Oms.GetInstance(KnownRelationshipGuids.Get_Attribute_Method__returns__Attribute), attributeInstance);
|
||||
return method;
|
||||
return new GetAttributeMethod(method);
|
||||
}
|
||||
|
||||
public InstanceHandle CreateGetSpecifiedInstancesMethod(InstanceHandle forClassInstance, string verb, string name, InstanceHandle returnsWorkSet, InstanceHandle[] specifiedInstances)
|
||||
public GetSpecifiedInstancesMethod CreateGetSpecifiedInstancesMethod(InstanceHandle forClassInstance, string verb, string name, WorkSet returnsWorkSet, InstanceHandle[] specifiedInstances)
|
||||
{
|
||||
return CreateGetSpecifiedInstancesMethod(forClassInstance, verb, name, null, false, returnsWorkSet, specifiedInstances);
|
||||
}
|
||||
public InstanceHandle CreateGetSpecifiedInstancesMethod(InstanceHandle forClassInstance, string verb, string name, object accessModifier, bool isStatic, InstanceHandle returnsWorkSet, InstanceHandle[] specifiedInstances)
|
||||
public GetSpecifiedInstancesMethod CreateGetSpecifiedInstancesMethod(InstanceHandle forClassInstance, string verb, string name, AccessModifier accessModifier, bool isStatic, WorkSet returnsWorkSet, InstanceHandle[] specifiedInstances)
|
||||
{
|
||||
InstanceHandle method = Oms.CreateInstanceOf(Oms.GetInstance(KnownInstanceGuids.MethodClasses.GetSpecifiedInstancesMethod));
|
||||
InstanceHandle method = CreateMethodBase(Oms.GetInstance(KnownInstanceGuids.MethodClasses.GetSpecifiedInstancesMethod), forClassInstance, verb, name, accessModifier, isStatic);
|
||||
Oms.AssignRelationship(method, Oms.GetInstance(KnownRelationshipGuids.Get_Specified_Instances_Method__returns__Work_Set), returnsWorkSet.Handle);
|
||||
Oms.AssignRelationship(method, Oms.GetInstance(KnownRelationshipGuids.Get_Specified_Instances_Method__uses__Instance), specifiedInstances);
|
||||
return new GetSpecifiedInstancesMethod(method);
|
||||
}
|
||||
|
||||
private InstanceHandle CreateMethodBase(InstanceHandle methodClassInstance, InstanceHandle forClassInstance, string verb, string name, AccessModifier accessModifier, bool isStatic)
|
||||
{
|
||||
InstanceHandle method = Oms.CreateInstanceOf(methodClassInstance);
|
||||
Oms.AssignRelationship(method, Oms.GetInstance(KnownRelationshipGuids.Method__for__Class), forClassInstance);
|
||||
if (!Oms.ValidateConstraints)
|
||||
{
|
||||
// sibling relationships aren't being generated automatically
|
||||
Oms.AssignRelationship(forClassInstance, Oms.GetInstance(KnownRelationshipGuids.Class__has__Method), method);
|
||||
}
|
||||
Oms.SetAttributeValue(method, Oms.GetInstance(KnownAttributeGuids.Text.Verb), verb);
|
||||
Oms.SetAttributeValue(method, Oms.GetInstance(KnownAttributeGuids.Text.Name), name);
|
||||
Oms.SetAttributeValue(method, Oms.GetInstance(KnownAttributeGuids.Boolean.Static), isStatic);
|
||||
Oms.AssignRelationship(method, Oms.GetInstance(KnownRelationshipGuids.Get_Specified_Instances_Method__returns__Work_Set), returnsWorkSet);
|
||||
Oms.AssignRelationship(method, Oms.GetInstance(KnownRelationshipGuids.Get_Specified_Instances_Method__uses__Instance), specifiedInstances);
|
||||
return method;
|
||||
}
|
||||
|
||||
public BuildAttributeMethod CreateBuildAttributeMethod(InstanceHandle forClassInstance, string verb, string name, AccessModifier accessModifier, bool isStatic, InstanceHandle returnsAttribute, string initialValue = "")
|
||||
{
|
||||
InstanceHandle method = CreateMethodBase(Oms.GetInstance(KnownInstanceGuids.MethodClasses.BuildAttributeMethod), forClassInstance, verb, name, accessModifier, isStatic);
|
||||
Oms.AssignRelationship(method, Oms.GetInstance(KnownRelationshipGuids.Build_Attribute_Method__returns__Attribute), returnsAttribute);
|
||||
Oms.SetAttributeValue(method, Oms.GetInstance(KnownAttributeGuids.Text.Value), initialValue);
|
||||
return new BuildAttributeMethod(method);
|
||||
}
|
||||
|
||||
public GetAttributeBySystemRoutineMethod CreateGetAttributeBySystemRoutineMethod(InstanceHandle forClassInstance, string verb, string name, AccessModifier accessModifier, bool isStatic, InstanceHandle returnsAttribute, SystemAttributeRoutine usesSystemAttributeRoutine)
|
||||
{
|
||||
InstanceHandle method = CreateMethodBase(Oms.GetInstance(KnownInstanceGuids.MethodClasses.GetAttributeBySystemRoutineMethod), forClassInstance, verb, name, accessModifier, isStatic);
|
||||
Oms.AssignRelationship(method, Oms.GetInstance(KnownRelationshipGuids.Get_Attribute_by_System_Routine_Method__returns__Attribute), returnsAttribute);
|
||||
Oms.AssignRelationship(method, Oms.GetInstance(KnownRelationshipGuids.Get_Attribute_by_System_Routine_Method__uses__System_Attribute_Routine), usesSystemAttributeRoutine.Handle);
|
||||
return new GetAttributeBySystemRoutineMethod(method);
|
||||
}
|
||||
}
|
||||
45
mocha-dotnet/src/lib/Mocha.Core/OmsSystemRoutineBuilder.cs
Normal file
45
mocha-dotnet/src/lib/Mocha.Core/OmsSystemRoutineBuilder.cs
Normal file
@ -0,0 +1,45 @@
|
||||
using Mocha.Core.Oop;
|
||||
|
||||
namespace Mocha.Core;
|
||||
|
||||
public class OmsSystemRoutineBuilder
|
||||
{
|
||||
public Oms Oms { get; }
|
||||
public OmsSystemRoutineBuilder(Oms oms)
|
||||
{
|
||||
Oms = oms;
|
||||
}
|
||||
|
||||
public SystemAttributeRoutine CreateSystemAttributeRoutine(Guid globalIdentifier, Func<object?> func)
|
||||
{
|
||||
InstanceHandle handle = Oms.CreateInstanceOf(Oms.GetInstance(KnownInstanceGuids.Classes.SystemAttributeRoutine), globalIdentifier);
|
||||
|
||||
SystemAttributeRoutine routine = new SystemAttributeRoutine(handle, func);
|
||||
Oms.RegisterSystemRoutine(handle, routine);
|
||||
return routine;
|
||||
}
|
||||
public SystemAttributeRoutine<T> CreateSystemAttributeRoutine<T>(Guid globalIdentifier, Func<T> func)
|
||||
{
|
||||
InstanceHandle handle = Oms.CreateInstanceOf(Oms.GetInstance(KnownInstanceGuids.Classes.SystemAttributeRoutine), globalIdentifier);
|
||||
|
||||
SystemAttributeRoutine<T> routine = new SystemAttributeRoutine<T>(handle, func);
|
||||
Oms.RegisterSystemRoutine(handle, routine);
|
||||
return routine;
|
||||
}
|
||||
public SystemInstanceSetRoutine CreateSystemInstanceSetRoutine(Guid globalIdentifier, Func<InstanceHandle> func)
|
||||
{
|
||||
InstanceHandle handle = Oms.CreateInstanceOf(Oms.GetInstance(KnownInstanceGuids.Classes.SystemInstanceSetRoutine), globalIdentifier);
|
||||
|
||||
SystemInstanceSetRoutine routine = new SystemInstanceSetRoutine(handle, func);
|
||||
Oms.RegisterSystemRoutine(handle, routine);
|
||||
return routine;
|
||||
}
|
||||
public SystemInstanceSetRoutine<T> CreateSystemInstanceSetRoutine<T>(Guid globalIdentifier, Func<T> func) where T : InstanceWrapper
|
||||
{
|
||||
InstanceHandle handle = Oms.CreateInstanceOf(Oms.GetInstance(KnownInstanceGuids.Classes.SystemInstanceSetRoutine), globalIdentifier);
|
||||
|
||||
SystemInstanceSetRoutine<T> routine = new SystemInstanceSetRoutine<T>(handle, func);
|
||||
Oms.RegisterSystemRoutine(handle, routine);
|
||||
return routine;
|
||||
}
|
||||
}
|
||||
11
mocha-dotnet/src/lib/Mocha.Core/Oop/AccessModifier.cs
Normal file
11
mocha-dotnet/src/lib/Mocha.Core/Oop/AccessModifier.cs
Normal file
@ -0,0 +1,11 @@
|
||||
namespace Mocha.Core.Oop;
|
||||
|
||||
public class AccessModifier : ConcreteInstanceWrapper
|
||||
{
|
||||
internal AccessModifier(InstanceHandle handle) : base(handle) { }
|
||||
|
||||
public static AccessModifier Public { get; internal set; } = null;
|
||||
public static AccessModifier Private { get; internal set; } = null;
|
||||
public static AccessModifier Protected { get; internal set; } = null;
|
||||
public static AccessModifier RootA2 { get; internal set; } = null;
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
namespace Mocha.Core.Oop;
|
||||
|
||||
public class ConcreteInstanceWrapper : InstanceWrapper
|
||||
{
|
||||
private InstanceHandle TheHandle { get; }
|
||||
internal ConcreteInstanceWrapper(InstanceHandle handle)
|
||||
{
|
||||
TheHandle = handle;
|
||||
}
|
||||
|
||||
protected override InstanceHandle GetHandleInternal()
|
||||
{
|
||||
return TheHandle;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,17 @@
|
||||
namespace Mocha.Core.Oop;
|
||||
|
||||
public class DeferredInstanceWrapper : InstanceWrapper
|
||||
{
|
||||
private Oms oms;
|
||||
private Guid globalIdentifier;
|
||||
public DeferredInstanceWrapper(Oms oms, Guid globalIdentifier)
|
||||
{
|
||||
this.oms = oms;
|
||||
this.globalIdentifier = globalIdentifier;
|
||||
}
|
||||
|
||||
protected override InstanceHandle GetHandleInternal()
|
||||
{
|
||||
return oms.GetInstance(globalIdentifier);
|
||||
}
|
||||
}
|
||||
19
mocha-dotnet/src/lib/Mocha.Core/Oop/InstanceWrapper.cs
Normal file
19
mocha-dotnet/src/lib/Mocha.Core/Oop/InstanceWrapper.cs
Normal file
@ -0,0 +1,19 @@
|
||||
namespace Mocha.Core.Oop;
|
||||
|
||||
public abstract class InstanceWrapper
|
||||
{
|
||||
private InstanceHandle _Handle = InstanceHandle.Empty;
|
||||
protected abstract InstanceHandle GetHandleInternal();
|
||||
|
||||
internal InstanceHandle Handle
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_Handle == InstanceHandle.Empty)
|
||||
{
|
||||
_Handle = GetHandleInternal();
|
||||
}
|
||||
return _Handle;
|
||||
}
|
||||
}
|
||||
}
|
||||
26
mocha-dotnet/src/lib/Mocha.Core/Oop/Method.cs
Normal file
26
mocha-dotnet/src/lib/Mocha.Core/Oop/Method.cs
Normal file
@ -0,0 +1,26 @@
|
||||
|
||||
using Mocha.Core.Oop.Methods;
|
||||
|
||||
namespace Mocha.Core.Oop;
|
||||
|
||||
public abstract class Method : ConcreteInstanceWrapper
|
||||
{
|
||||
public abstract Guid MethodClassGuid { get; }
|
||||
internal Method(InstanceHandle handle) : base(handle) { }
|
||||
|
||||
internal static Method CreateFromInstance(Oms oms, InstanceHandle methodInstance)
|
||||
{
|
||||
Type[] methodTypes = MBS.Core.Reflection.TypeLoader.GetAvailableTypes(new Type[] { typeof(Method) }, new System.Reflection.Assembly[] { System.Reflection.Assembly.GetExecutingAssembly() });
|
||||
InstanceHandle parentClass = oms.GetParentClass(methodInstance);
|
||||
|
||||
foreach (Type methodType in methodTypes)
|
||||
{
|
||||
Method m = (Method)methodType.Assembly.CreateInstance(methodType.FullName, false, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance, null, new object[] { methodInstance }, null, null);
|
||||
if (m.MethodClassGuid == oms.GetGlobalIdentifier(parentClass))
|
||||
{
|
||||
return m;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
14
mocha-dotnet/src/lib/Mocha.Core/Oop/MethodBinding.cs
Normal file
14
mocha-dotnet/src/lib/Mocha.Core/Oop/MethodBinding.cs
Normal file
@ -0,0 +1,14 @@
|
||||
namespace Mocha.Core.Oop;
|
||||
|
||||
public abstract class MethodBinding : ConcreteInstanceWrapper
|
||||
{
|
||||
internal MethodBinding(InstanceHandle handle) : base(handle) { }
|
||||
}
|
||||
public class ReturnAttributeMethodBinding : MethodBinding
|
||||
{
|
||||
internal ReturnAttributeMethodBinding(InstanceHandle handle) : base(handle) { }
|
||||
}
|
||||
public class ReturnInstanceSetMethodBinding : MethodBinding
|
||||
{
|
||||
internal ReturnInstanceSetMethodBinding(InstanceHandle handle) : base(handle) { }
|
||||
}
|
||||
@ -0,0 +1,8 @@
|
||||
|
||||
namespace Mocha.Core.Oop.Methods;
|
||||
|
||||
public class BuildAttributeMethod : Method
|
||||
{
|
||||
public override Guid MethodClassGuid => KnownInstanceGuids.MethodClasses.BuildAttributeMethod;
|
||||
internal BuildAttributeMethod(InstanceHandle handle) : base(handle) { }
|
||||
}
|
||||
@ -0,0 +1,8 @@
|
||||
|
||||
namespace Mocha.Core.Oop.Methods;
|
||||
|
||||
public class GetAttributeBySystemRoutineMethod : Method
|
||||
{
|
||||
public override Guid MethodClassGuid => KnownInstanceGuids.MethodClasses.GetAttributeBySystemRoutineMethod;
|
||||
internal GetAttributeBySystemRoutineMethod(InstanceHandle handle) : base(handle) { }
|
||||
}
|
||||
@ -0,0 +1,8 @@
|
||||
|
||||
namespace Mocha.Core.Oop.Methods;
|
||||
|
||||
public class GetAttributeMethod : Method
|
||||
{
|
||||
public override Guid MethodClassGuid => KnownInstanceGuids.MethodClasses.GetAttributeMethod;
|
||||
internal GetAttributeMethod(InstanceHandle handle) : base(handle) { }
|
||||
}
|
||||
@ -0,0 +1,8 @@
|
||||
|
||||
namespace Mocha.Core.Oop.Methods;
|
||||
|
||||
public class GetSpecifiedInstancesMethod : Method
|
||||
{
|
||||
public override Guid MethodClassGuid => KnownInstanceGuids.MethodClasses.GetSpecifiedInstancesMethod;
|
||||
internal GetSpecifiedInstancesMethod(InstanceHandle handle) : base(handle) { }
|
||||
}
|
||||
22
mocha-dotnet/src/lib/Mocha.Core/Oop/SystemRoutine.cs
Normal file
22
mocha-dotnet/src/lib/Mocha.Core/Oop/SystemRoutine.cs
Normal file
@ -0,0 +1,22 @@
|
||||
namespace Mocha.Core.Oop;
|
||||
|
||||
public abstract class SystemRoutine : ConcreteInstanceWrapper
|
||||
{
|
||||
internal SystemRoutine(InstanceHandle handle) : base(handle) { }
|
||||
|
||||
protected abstract object? ExecuteInternal();
|
||||
public object? Execute()
|
||||
{
|
||||
return ExecuteInternal();
|
||||
}
|
||||
|
||||
public T Execute<T>(T defaultValue = default(T))
|
||||
{
|
||||
object? value = Execute();
|
||||
if (value is T)
|
||||
{
|
||||
return (T)value;
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,22 @@
|
||||
namespace Mocha.Core.Oop;
|
||||
|
||||
public class SystemAttributeRoutine : SystemRoutine
|
||||
{
|
||||
private Func<object?> Func { get; }
|
||||
internal SystemAttributeRoutine(InstanceHandle handle, Func<object?> func) : base(handle)
|
||||
{
|
||||
Func = func;
|
||||
}
|
||||
|
||||
protected override object? ExecuteInternal()
|
||||
{
|
||||
object? value = Func?.Invoke();
|
||||
return value;
|
||||
}
|
||||
}
|
||||
public class SystemAttributeRoutine<T> : SystemAttributeRoutine
|
||||
{
|
||||
internal SystemAttributeRoutine(InstanceHandle handle, Func<T> func) : base(handle, new Func<object?>(delegate() { return func(); }))
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,20 @@
|
||||
namespace Mocha.Core.Oop;
|
||||
|
||||
public class SystemInstanceSetRoutine : SystemRoutine
|
||||
{
|
||||
private Func<InstanceHandle> Func { get; }
|
||||
internal SystemInstanceSetRoutine(InstanceHandle handle, Func<InstanceHandle> func) : base(handle)
|
||||
{
|
||||
Func = func;
|
||||
}
|
||||
|
||||
protected override object? ExecuteInternal()
|
||||
{
|
||||
object? value = Func?.Invoke();
|
||||
return value;
|
||||
}
|
||||
}
|
||||
public class SystemInstanceSetRoutine<T> : SystemInstanceSetRoutine where T : InstanceWrapper
|
||||
{
|
||||
internal SystemInstanceSetRoutine(InstanceHandle handle, Func<T> func) : base(handle, new Func<InstanceHandle>(delegate() { return func()?.Handle ?? InstanceHandle.Empty; })) { }
|
||||
}
|
||||
6
mocha-dotnet/src/lib/Mocha.Core/Oop/WorkSet.cs
Normal file
6
mocha-dotnet/src/lib/Mocha.Core/Oop/WorkSet.cs
Normal file
@ -0,0 +1,6 @@
|
||||
namespace Mocha.Core.Oop;
|
||||
|
||||
public class WorkSet : ConcreteInstanceWrapper
|
||||
{
|
||||
internal WorkSet(InstanceHandle handle) : base(handle) { }
|
||||
}
|
||||
@ -1,5 +1,8 @@
|
||||
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Mocha.Core.OmsImplementations.Mini;
|
||||
using Mocha.Core.Oop;
|
||||
using Mocha.Core.Oop.Methods;
|
||||
|
||||
namespace Mocha.Core.Tests;
|
||||
|
||||
@ -10,14 +13,29 @@ public class MethodTests : OmsTestsBase
|
||||
return new MiniOms(new MiniOmsModule[] { new MethodsModule() });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BuildAttributeMethodTest()
|
||||
{
|
||||
InstanceHandle irTestClass = Oms.GetInstance(TEST_CLASS_GUID);
|
||||
InstanceHandle irTestClassInstance = Oms.CreateInstanceOf(irTestClass);
|
||||
string test_value = "Jackdaws love my big sphinx of quartz.";
|
||||
|
||||
OmsMethodBuilder builder = new OmsMethodBuilder(Oms);
|
||||
|
||||
BuildAttributeMethod ih_BA = builder.CreateBuildAttributeMethod(irTestClass, "build", "Test Attribute", Oms.GetInstance(KnownInstanceGuids.AccessModifiers.Public), true, Oms.GetInstance(KnownAttributeGuids.Text.Name), test_value);
|
||||
|
||||
OmsContext context = Oms.CreateContext();
|
||||
InstanceHandle ih_test = Oms.Execute(context, ih_BA);
|
||||
object value = context.GetWorkData(ih_test);
|
||||
|
||||
Assert.That(value, Is.EqualTo(test_value));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAttributeMethodTest()
|
||||
{
|
||||
InstanceHandle irTestClass = Oms.GetInstance(TEST_CLASS_GUID);
|
||||
Assert.That(irTestClass, Is.Not.EqualTo(InstanceHandle.Empty));
|
||||
|
||||
InstanceHandle irTestClassInstance = Oms.CreateInstanceOf(irTestClass);
|
||||
Assert.That(irTestClassInstance, Is.Not.EqualTo(InstanceHandle.Empty));
|
||||
|
||||
InstanceHandle irTestAttribute = Oms.CreateInstanceOf(Oms.GetInstance(KnownInstanceGuids.Classes.TextAttribute), TEST_ATTR_GUID);
|
||||
Assert.That(irTestAttribute, Is.Not.EqualTo(InstanceHandle.Empty));
|
||||
@ -32,10 +50,10 @@ public class MethodTests : OmsTestsBase
|
||||
// let's make sure that calling a GA- Get Attribute method on TestClass returns the same
|
||||
OmsMethodBuilder methodBuilder = new OmsMethodBuilder(Oms);
|
||||
|
||||
InstanceHandle gaMethod = methodBuilder.CreateGetAttributeMethod(irTestClass, "get", "Test Attribute", irTestAttribute);
|
||||
GetAttributeMethod gaMethod = methodBuilder.CreateGetAttributeMethod(irTestClass, "get", "Test Attribute", irTestAttribute);
|
||||
// Method is: `Test Class@get Test Attribute(GA)`
|
||||
|
||||
InstanceHandle gaMethodRamb = methodBuilder.CreateReturnAttributeMethodBinding(gaMethod);
|
||||
ReturnAttributeMethodBinding gaMethodRamb = methodBuilder.CreateReturnAttributeMethodBinding(gaMethod);
|
||||
|
||||
OmsContext context = Oms.CreateContext();
|
||||
|
||||
@ -51,12 +69,12 @@ public class MethodTests : OmsTestsBase
|
||||
Assert.That(irTestClass, Is.Not.EqualTo(InstanceHandle.Empty));
|
||||
|
||||
// create a Work Set to hold our data
|
||||
InstanceHandle ws = Oms.CreateWorkSet("Test Work Set");
|
||||
WorkSet ws = Oms.CreateWorkSet("Test Work Set");
|
||||
|
||||
OmsMethodBuilder methodBuilder = new OmsMethodBuilder(Oms);
|
||||
|
||||
InstanceHandle dummyMethod = methodBuilder.CreateGetSpecifiedInstancesMethod(irTestClass, "get", "Empty Set", null, false, ws, new InstanceHandle[0]);
|
||||
InstanceHandle dummyMethodRsmb = methodBuilder.CreateReturnInstanceSetMethodBinding(dummyMethod);
|
||||
GetSpecifiedInstancesMethod dummyMethod = methodBuilder.CreateGetSpecifiedInstancesMethod(irTestClass, "get", "Empty Set", null, false, ws, new InstanceHandle[0]);
|
||||
ReturnInstanceSetMethodBinding dummyMethodRsmb = methodBuilder.CreateReturnInstanceSetMethodBinding(dummyMethod);
|
||||
|
||||
OmsContext context = Oms.CreateContext();
|
||||
|
||||
@ -78,12 +96,14 @@ public class MethodTests : OmsTestsBase
|
||||
OmsMethodBuilder methodBuilder = new OmsMethodBuilder(Oms);
|
||||
|
||||
// create a Work Set to hold our data
|
||||
InstanceHandle ws = Oms.CreateWorkSet("Test Work Set", true, new InstanceHandle[] { irTestClass });
|
||||
WorkSet ws = Oms.CreateWorkSet("Test Work Set", true, new InstanceHandle[] { irTestClass });
|
||||
|
||||
InstanceHandle gsiMethod = methodBuilder.CreateGetSpecifiedInstancesMethod(irTestClass, "get", "Test Class Instance", null, true, ws, new InstanceHandle[] { irTestClassInstance });
|
||||
GetSpecifiedInstancesMethod gsiMethod = methodBuilder.CreateGetSpecifiedInstancesMethod(irTestClass, "get", "Test Class Instance", null, true, ws, new InstanceHandle[] { irTestClassInstance });
|
||||
string nom = Oms.GetInstanceText(gsiMethod);
|
||||
// Method is: `Test Class@get Test Class Instance(GSI)*S`
|
||||
|
||||
InstanceHandle gsiMethodRsmb = methodBuilder.CreateReturnInstanceSetMethodBinding(gsiMethod);
|
||||
ReturnInstanceSetMethodBinding gsiMethodRsmb = methodBuilder.CreateReturnInstanceSetMethodBinding(gsiMethod);
|
||||
nom = Oms.GetInstanceText(gsiMethodRsmb);
|
||||
|
||||
OmsContext context = Oms.CreateContext();
|
||||
IReadOnlyCollection<InstanceHandle> specifiedInstances = Oms.ExecuteStaticMethodReturningInstanceSet(context, gsiMethodRsmb);
|
||||
@ -91,4 +111,45 @@ public class MethodTests : OmsTestsBase
|
||||
Assert.That(specifiedInstances, Contains.Item(irTestClassInstance));
|
||||
}
|
||||
|
||||
private Guid TEST_SYSTEM_ATTRIBUTE_ROUTINE_GUID = new Guid("{fd726a89-86b3-46ea-b65b-20681358ea92}");
|
||||
private string TEST_SYSTEM_ATTRIBUTE_ROUTINE_VALUE = "Picadilly Circus";
|
||||
|
||||
[Test]
|
||||
public void GetAttributeBySystemRoutineTest()
|
||||
{
|
||||
InstanceHandle irTestClass = Oms.GetInstance(TEST_CLASS_GUID);
|
||||
OmsMethodBuilder methodBuilder = new OmsMethodBuilder(Oms);
|
||||
OmsSystemRoutineBuilder systemRoutineBuilder = new OmsSystemRoutineBuilder(Oms);
|
||||
|
||||
SystemAttributeRoutine<string> testSystemAttributeRoutine = systemRoutineBuilder.CreateSystemAttributeRoutine(TEST_SYSTEM_ATTRIBUTE_ROUTINE_GUID, delegate()
|
||||
{
|
||||
return TEST_SYSTEM_ATTRIBUTE_ROUTINE_VALUE;
|
||||
});
|
||||
|
||||
GetAttributeBySystemRoutineMethod gasMethod = methodBuilder.CreateGetAttributeBySystemRoutineMethod(irTestClass, "get", "Test System Routine Text Attribute", null, true, Oms.GetInstance(KnownAttributeGuids.Text.Value), testSystemAttributeRoutine);
|
||||
ReturnAttributeMethodBinding gasMethodRamb = methodBuilder.CreateReturnAttributeMethodBinding(gasMethod);
|
||||
|
||||
OmsContext context = Oms.CreateContext();
|
||||
string value = Oms.ExecuteReturningAttributeValue<string>(context, gasMethodRamb);
|
||||
|
||||
Assert.That(value, Is.EqualTo(TEST_SYSTEM_ATTRIBUTE_ROUTINE_VALUE));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RuntimeVersionMatches()
|
||||
{
|
||||
InstanceHandle c_OMS = Oms.GetInstance(KnownInstanceGuids.Classes.OMS);
|
||||
|
||||
//*** Wow, this actually works!!! ***//
|
||||
// ... but I wonder how long it would actually take to sift through 1000s of methods...
|
||||
Method m = Oms.GetMethod(c_OMS, "get", "Runtime Version");
|
||||
|
||||
OmsContext context = Oms.CreateContext();
|
||||
InstanceHandle workData = Oms.Execute(context, m);
|
||||
object? value = context.GetWorkData(workData);
|
||||
|
||||
Assert.That(value is string);
|
||||
Assert.That((string)value, Is.EqualTo(Oms.RuntimeVersion.ToString()));
|
||||
}
|
||||
|
||||
}
|
||||
@ -15,7 +15,7 @@ public class VehicleForHireDB : OmsDatabase
|
||||
}
|
||||
|
||||
[OmsGlobalIdentifier("{9153A637-992E-4712-ADF2-B03F0D9EDEA6}")]
|
||||
public readonly string Name;
|
||||
public string Name { get { return (string)GetAttributeValue(""); } set { SetAttributeValue(value); } }
|
||||
|
||||
/// <summary>
|
||||
/// Business.has Driver
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
|
||||
using System.Xml.Serialization;
|
||||
using Mocha.Core.OmsImplementations.Mini;
|
||||
using Mocha.Core.Oop;
|
||||
|
||||
namespace Mocha.Core.Tests;
|
||||
|
||||
@ -19,7 +20,7 @@ public class WorkSetTests : OmsTestsBase
|
||||
InstanceHandle c_Class = Oms.GetInstance(KnownInstanceGuids.Classes.Class);
|
||||
InstanceHandle c_Attribute = Oms.GetInstance(KnownInstanceGuids.Classes.Class);
|
||||
|
||||
InstanceHandle workSet = Oms.CreateWorkSet("Dummy Work Set");
|
||||
WorkSet workSet = Oms.CreateWorkSet("Dummy Work Set");
|
||||
|
||||
OmsContext context = Oms.CreateContext();
|
||||
Assert.That(delegate ()
|
||||
@ -35,7 +36,7 @@ public class WorkSetTests : OmsTestsBase
|
||||
InstanceHandle c_Class = Oms.GetInstance(KnownInstanceGuids.Classes.Class);
|
||||
InstanceHandle c_TextAttribute = Oms.GetInstance(KnownInstanceGuids.Classes.TextAttribute);
|
||||
|
||||
InstanceHandle workSet = Oms.CreateWorkSet("Dummy Work Set", true, new InstanceHandle[]
|
||||
WorkSet workSet = Oms.CreateWorkSet("Dummy Work Set", true, new InstanceHandle[]
|
||||
{
|
||||
c_TextAttribute
|
||||
});
|
||||
@ -58,7 +59,7 @@ public class WorkSetTests : OmsTestsBase
|
||||
InstanceHandle a_Value = Oms.GetInstance(KnownAttributeGuids.Text.Value);
|
||||
InstanceHandle a_Singular = Oms.GetInstance(KnownAttributeGuids.Boolean.Singular);
|
||||
|
||||
InstanceHandle workSet = Oms.CreateWorkSet("Dummy Work Set", true, new InstanceHandle[]
|
||||
WorkSet workSet = Oms.CreateWorkSet("Dummy Work Set", true, new InstanceHandle[]
|
||||
{
|
||||
c_TextAttribute,
|
||||
c_BooleanAttribute
|
||||
@ -98,7 +99,7 @@ public class WorkSetTests : OmsTestsBase
|
||||
InstanceHandle a_Value = Oms.GetInstance(KnownAttributeGuids.Text.Value);
|
||||
InstanceHandle a_Singular = Oms.GetInstance(KnownAttributeGuids.Boolean.Singular);
|
||||
|
||||
InstanceHandle workSet = Oms.CreateWorkSet("Dummy Work Set", false, new InstanceHandle[]
|
||||
WorkSet workSet = Oms.CreateWorkSet("Dummy Work Set", false, new InstanceHandle[]
|
||||
{
|
||||
c_TextAttribute,
|
||||
c_BooleanAttribute
|
||||
@ -130,7 +131,7 @@ public class WorkSetTests : OmsTestsBase
|
||||
public void LiteralValueAssignedToWorkSet()
|
||||
{
|
||||
// no valid class constraints - we should be able to put anything in here
|
||||
InstanceHandle workSet = Oms.CreateWorkSet("Dummy Work Set");
|
||||
WorkSet workSet = Oms.CreateWorkSet("Dummy Work Set");
|
||||
|
||||
OmsContext context = Oms.CreateContext();
|
||||
Assert.That(delegate ()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user