From 51bd45bfad03e405f081ae99ccd7c056f6db4370 Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Fri, 2 Aug 2024 22:53:09 -0400 Subject: [PATCH] pass Oms and OmsContext to system routines, and add `Common Numeric@get Random Number(GAS)*S(public)` --- .../src/lib/Mocha.Core/KnownAttributeGuids.cs | 2 + .../src/lib/Mocha.Core/KnownInstanceGuids.cs | 11 ++++- ...buteBySystemRoutineMethodImplementation.cs | 2 +- mocha-dotnet/src/lib/Mocha.Core/Oms.cs | 14 ++----- .../Mini/Modules/MethodsModule.cs | 42 ++++++++++++++----- .../src/lib/Mocha.Core/OmsMethodBuilder.cs | 8 +++- .../lib/Mocha.Core/OmsSystemRoutineBuilder.cs | 14 ++----- .../Mocha.Core/Oop/ConcreteInstanceWrapper.cs | 5 +++ .../GetAttributeBySystemRoutineMethod.cs | 2 +- .../src/lib/Mocha.Core/Oop/SystemRoutine.cs | 10 ++--- .../SystemRoutines/SystemAttributeRoutine.cs | 10 ++--- .../SystemInstanceSetRoutine.cs | 12 ++---- .../ConditionalSelectAttributeMethodTests.cs | 25 +++++++++++ .../MethodTests/SystemRoutineTests.cs | 16 ++++++- 14 files changed, 116 insertions(+), 57 deletions(-) diff --git a/mocha-dotnet/src/lib/Mocha.Core/KnownAttributeGuids.cs b/mocha-dotnet/src/lib/Mocha.Core/KnownAttributeGuids.cs index 21fea54..7d02596 100755 --- a/mocha-dotnet/src/lib/Mocha.Core/KnownAttributeGuids.cs +++ b/mocha-dotnet/src/lib/Mocha.Core/KnownAttributeGuids.cs @@ -43,6 +43,7 @@ namespace Mocha.Core } public static class Numeric { + public static Guid Seed { get; } = new Guid("{ee6f8b91-e471-4281-8bbe-ad858388bcc2}"); public static Guid Index { get; } = new Guid("{0f31b9ca-e3e2-4c62-8c9e-b55f16eafbf9}"); public static Guid Level { get; } = new Guid("{8C528FB0-4063-47B0-BC56-85E387A41BD2}"); public static Guid DebugDefinitionLineNumber { get; } = new Guid("{822be9b7-531d-4aa1-818a-6e4de1609057}"); @@ -53,6 +54,7 @@ namespace Mocha.Core public static Guid MinimumValue { get; } = new Guid("{bc90ffdf-9b6e-444a-a484-f9d06d7f3c31}"); public static Guid MaximumValue { get; } = new Guid("{b9353b1c-2597-4097-96eb-449a6fafcdab}"); + public static Guid RandomNumber { get; } = new Guid("{1e18b839-5a53-495e-a240-8ec03b6b9c0d}"); } } } diff --git a/mocha-dotnet/src/lib/Mocha.Core/KnownInstanceGuids.cs b/mocha-dotnet/src/lib/Mocha.Core/KnownInstanceGuids.cs index 243dc70..70e59a8 100755 --- a/mocha-dotnet/src/lib/Mocha.Core/KnownInstanceGuids.cs +++ b/mocha-dotnet/src/lib/Mocha.Core/KnownInstanceGuids.cs @@ -139,8 +139,11 @@ namespace Mocha.Core public static Guid Theme { get; } = new Guid("{7c2cc4b5-8323-4478-863b-1759d7adf62e}"); - public static Guid CommonBoolean { get; } = new Guid("{5b025da3-b7bd-45a9-b084-48c4a922bf72}"); + public static Guid CommonText { get; } = new Guid("{a48a5fb2-f80c-47f9-bc47-7adef34d061b}"); + public static Guid CommonBoolean { get; } = new Guid("{5b025da3-b7bd-45a9-b084-48c4a922bf72}"); + public static Guid CommonNumeric { get; } = new Guid("{553c196e-0439-4be9-b8fb-4dee6f0530fd}"); public static Guid CommonInstanceSet { get; } = new Guid("{3382da21-4fc5-45dc-bbd1-f7ba3ece1a1b}"); + public static Guid CommonDate { get; } = new Guid("{cb077f5b-f58d-4f6a-aa01-659bea754b6e}"); public static Guid BooleanOperator { get; } = new Guid("{fb85933c-e2ad-4b1c-ac2a-f92c9cc57e1c}"); public static Guid RelationalOperator { get; } = new Guid("{f1b5d26f-2347-49cb-8aae-d80dd706fce2}"); @@ -168,6 +171,11 @@ namespace Mocha.Core public static Guid Method__get__Method_Abbreviation { get; } = new Guid("{f0c64709-385d-481b-8f58-83e507fb261c}"); public static Guid Method_Binding__get__Method_Binding_Abbreviation { get; } = new Guid("{7154cb08-0f80-4af4-bca5-c2c12e54479a}"); } + public static class GetAttributeBySystemRoutine + { + public static Guid OMS__get__Runtime_Version { get; } = new Guid("{58835bd3-21e2-43bb-a069-7f8befe9bf5d}"); + public static Guid Common_Numeric__get__Random_Number { get; } = new Guid("{84b8b8eb-a2a5-4f87-9e7e-237658fa1c1f}"); + } } [ExportEntities(Prefix = "IDC_", Suffix = null)] @@ -229,6 +237,7 @@ namespace Mocha.Core { 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 Guid GetRandomNumber { get; } = new Guid("{8f7945da-4cad-49cb-9838-85f3524a5adb}"); } public static class SystemInstanceSetRoutines { diff --git a/mocha-dotnet/src/lib/Mocha.Core/MethodImplementations/GetAttributeBySystemRoutineMethodImplementation.cs b/mocha-dotnet/src/lib/Mocha.Core/MethodImplementations/GetAttributeBySystemRoutineMethodImplementation.cs index 7f2dd83..64be577 100644 --- a/mocha-dotnet/src/lib/Mocha.Core/MethodImplementations/GetAttributeBySystemRoutineMethodImplementation.cs +++ b/mocha-dotnet/src/lib/Mocha.Core/MethodImplementations/GetAttributeBySystemRoutineMethodImplementation.cs @@ -14,7 +14,7 @@ public class GetAttributeBySystemRoutineMethodImplementation : MethodImplementat throw new InvalidOperationException("no return Attribute specified for method"); } - object? value = oms.ExecuteSystemRoutine(usesSystemAttributeRoutine); + object? value = oms.ExecuteSystemRoutine(context, usesSystemAttributeRoutine); context.SetWorkData(returnsAttribute, value); return returnsAttribute; } diff --git a/mocha-dotnet/src/lib/Mocha.Core/Oms.cs b/mocha-dotnet/src/lib/Mocha.Core/Oms.cs index c7bc83f..3b09e07 100644 --- a/mocha-dotnet/src/lib/Mocha.Core/Oms.cs +++ b/mocha-dotnet/src/lib/Mocha.Core/Oms.cs @@ -847,20 +847,12 @@ public abstract class Oms { _systemRoutinesByInstance[handle] = routine; } - public object? ExecuteSystemRoutine(InstanceHandle handle) + + internal object? ExecuteSystemRoutine(OmsContext context, InstanceHandle handle) { - object? value = _systemRoutinesByInstance[handle].Execute(); + object? value = _systemRoutinesByInstance[handle].Execute(this, context); return value; } - public T ExecuteSystemRoutine(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) { diff --git a/mocha-dotnet/src/lib/Mocha.Core/OmsImplementations/Mini/Modules/MethodsModule.cs b/mocha-dotnet/src/lib/Mocha.Core/OmsImplementations/Mini/Modules/MethodsModule.cs index ba25f63..f749b26 100644 --- a/mocha-dotnet/src/lib/Mocha.Core/OmsImplementations/Mini/Modules/MethodsModule.cs +++ b/mocha-dotnet/src/lib/Mocha.Core/OmsImplementations/Mini/Modules/MethodsModule.cs @@ -16,6 +16,7 @@ public class MethodsModule : MiniOmsModule private InstanceHandle c_ParameterAssignment, c_Method, c_MethodBinding; private InstanceHandle a_Name, a_Order, a_Singular, a_Verb, a_Static, a_UseAnyCondition, a_Value; private InstanceHandle c_ReturnAttributeMethodBinding, c_ReturnInstanceSetMethodBinding; + private InstanceHandle c_CommonText, c_CommonBoolean, c_CommonNumeric, c_CommonDate, c_CommonInstanceSet; private InstanceHandle c_ConditionGroup; private InstanceHandle c_BuildAttributeMethod, c_GetAttributeMethod, c_GetSpecifiedInstancesMethod, c_GetAttributeBySystemRoutineMethod, c_AssignAttributeMethod, c_GetRelationshipMethod, c_GetReferencedAttributeMethod, c_SelectFromInstanceSetMethod, c_ConditionalSelectFromInstanceSetCase, c_ConditionalSelectFromInstanceSetMethod, c_ConditionalSelectAttributeMethod, c_ConditionalSelectAttributeCase, c_EvaluateBooleanExpressionMethod; private InstanceHandle c_AccessModifier, i_AccessModifier_Private, i_AccessModifier_Protected, i_AccessModifier_Public, i_AccessModifier_RootA2; @@ -187,6 +188,12 @@ public class MethodsModule : MiniOmsModule oms.CreateRelationship(c_EvaluateBooleanExpressionMethod, "has target", c_Instance, KnownRelationshipGuids.Evaluate_Boolean_Expression_Method__has_target__Executable_returning_Work_Data, true, "target for", KnownRelationshipGuids.Executable_returning_Work_Data__target_for__Evaluate_Boolean_Expression_Method); oms.AddSuperClass(c_EvaluateBooleanExpressionMethod, c_Method); + c_CommonText = oms.CreateClass("Common Text", KnownInstanceGuids.Classes.CommonText); + c_CommonBoolean = oms.CreateClass("Common Boolean", KnownInstanceGuids.Classes.CommonBoolean); + c_CommonNumeric = oms.CreateClass("Common Numeric", KnownInstanceGuids.Classes.CommonNumeric); + c_CommonDate = oms.CreateClass("Common Date", KnownInstanceGuids.Classes.CommonDate); + c_CommonInstanceSet = oms.CreateClass("Common Instance Set", KnownInstanceGuids.Classes.CommonInstanceSet); + oms.AddAttribute(c_Method, a_Name); oms.AddAttribute(c_Method, a_Verb); oms.AddAttribute(c_Method, a_Static); @@ -194,11 +201,26 @@ public class MethodsModule : MiniOmsModule 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(delegate () { return oms.RuntimeVersion.ToString(); })); - mb.CreateGetAttributeBySystemRoutineMethod(c_OMS, "get", "Runtime Version", null, true, oms.GetInstance(KnownAttributeGuids.Text.Value), sr); + SystemAttributeRoutine sr = srb.CreateSystemAttributeRoutine(KnownInstanceGuids.SystemAttributeRoutines.GetRuntimeVersion, new Func(delegate (Oms oms, OmsContext context) { return oms.RuntimeVersion.ToString(); })); + mb.CreateGetAttributeBySystemRoutineMethod(c_OMS, "get", "Runtime Version", null, true, KnownInstanceGuids.Methods.GetAttributeBySystemRoutine.OMS__get__Runtime_Version, oms.GetInstance(KnownAttributeGuids.Text.Value), sr); mb.CreateGetRelationshipMethod(c_Instance, "get", "Parent Class", AccessModifier.Public, false, KnownInstanceGuids.Methods.GetRelationship.Instance__get__Parent_Class, oms.GetInstance(KnownRelationshipGuids.Instance__for__Class)); + InstanceHandle a_Seed = oms.CreateInstanceOf(oms.GetInstance(KnownInstanceGuids.Classes.NumericAttribute), KnownAttributeGuids.Numeric.Seed); + oms.SetAttributeValue(a_Seed, a_Name, "Seed"); + + InstanceHandle a_RandomNumber = oms.CreateInstanceOf(oms.GetInstance(KnownInstanceGuids.Classes.NumericAttribute), KnownAttributeGuids.Numeric.RandomNumber); + mb.CreateGetAttributeBySystemRoutineMethod(c_CommonNumeric, "get", "Random Number", AccessModifier.Public, true, KnownInstanceGuids.Methods.GetAttributeBySystemRoutine.Common_Numeric__get__Random_Number, a_RandomNumber, srb.CreateSystemAttributeRoutine(KnownInstanceGuids.SystemAttributeRoutines.GetRandomNumber, new Func(delegate (Oms oms, OmsContext context) + { + object? seedO = context.GetWorkData(a_Seed); + if (seedO is decimal) + { + decimal seed = (decimal)seedO; + return (decimal)(new Random((int)seed)).NextDouble(); + } + return (decimal)(new Random()).NextDouble(); + }))); + CreateGetMethodAbbreviation(oms); CreateGetMethodBindingAbbreviation(oms); } @@ -214,21 +236,19 @@ public class MethodsModule : MiniOmsModule }); BuildAttributeMethod Method__get__SAC_Method_Suffix = mb.CreateBuildAttributeMethod(c_Method, "get", "SAC Method Suffix", AccessModifier.Public, true, a_Value, "SAC"); - ReturnAttributeMethodBinding Method__get__SAC_Method_Suffix_ramb = Method__get__SAC_Method_Suffix.CreateMethodBinding(oms); - EvaluateBooleanExpressionMethod Method__is__Conditional_Select_Attribute_Method = mb.CreateEvaluateBooleanExpressionMethod(c_Method, "is", "SAC", AccessModifier.Public, false, oms.GetInstance(KnownAttributeGuids.Boolean.MethodIsOfTypeSpecified), Instance__get__Parent_Class_rsmb.Handle, RelationalOperator.InSelectionList, oms.GetInstance(KnownInstanceGuids.MethodClasses.ConditionalSelectAttributeMethod)); - ReturnAttributeMethodBinding Method__is__Conditional_Select_Attribute_Method_ramb = Method__is__Conditional_Select_Attribute_Method.CreateMethodBinding(oms); - - BuildAttributeMethod Method__get__GR_Method_Suffix = mb.CreateBuildAttributeMethod(c_Method, "get", "GR Method Suffix", AccessModifier.Public, true, a_Value, "GR"); - ReturnAttributeMethodBinding Method__get__GR_Method_Suffix_ramb = Method__get__GR_Method_Suffix.CreateMethodBinding(oms); + BuildAttributeMethod Method__get__GAS_Method_Suffix = mb.CreateBuildAttributeMethod(c_Method, "get", "GAS Method Suffix", AccessModifier.Public, true, a_Value, "GAS"); + EvaluateBooleanExpressionMethod Method__is__Get_Attribute_by_System_Routine_Method = mb.CreateEvaluateBooleanExpressionMethod(c_Method, "is", "GAS", AccessModifier.Public, false, oms.GetInstance(KnownAttributeGuids.Boolean.MethodIsOfTypeSpecified), Instance__get__Parent_Class_rsmb.Handle, RelationalOperator.InSelectionList, oms.GetInstance(KnownInstanceGuids.MethodClasses.GetAttributeBySystemRoutineMethod)); + + BuildAttributeMethod Method__get__GR_Method_Suffix = mb.CreateBuildAttributeMethod(c_Method, "get", "GR Method Suffix", AccessModifier.Public, true, a_Value, "GR"); EvaluateBooleanExpressionMethod Method__is__Get_Relationship_Method = mb.CreateEvaluateBooleanExpressionMethod(c_Method, "is", "GR", AccessModifier.Public, false, oms.GetInstance(KnownAttributeGuids.Boolean.MethodIsOfTypeSpecified), Instance__get__Parent_Class_rsmb.Handle, RelationalOperator.InSelectionList, oms.GetInstance(KnownInstanceGuids.MethodClasses.GetRelationshipMethod)); - ReturnAttributeMethodBinding Method__is__Get_Relationship_Method_ramb = Method__is__Get_Relationship_Method.CreateMethodBinding(oms); mb.CreateConditionalSelectAttributeMethod(c_Method, "get", "Method Abbreviation", AccessModifier.Public, false, KnownInstanceGuids.Methods.ConditionalSelectAttribute.Method__get__Method_Abbreviation, a_Value, new ConditionalSelectAttributeCase[] { - new ConditionalSelectAttributeCase(new IExecutableReturningAttribute[] { Method__is__Get_Relationship_Method_ramb }, null, false, Method__get__GR_Method_Suffix_ramb), - new ConditionalSelectAttributeCase(new IExecutableReturningAttribute[] { Method__is__Conditional_Select_Attribute_Method_ramb }, null, false, Method__get__SAC_Method_Suffix_ramb) + new ConditionalSelectAttributeCase(new IExecutableReturningAttribute[] { Method__is__Get_Attribute_by_System_Routine_Method.CreateMethodBinding(oms) }, null, false, Method__get__GAS_Method_Suffix.CreateMethodBinding(oms)), + new ConditionalSelectAttributeCase(new IExecutableReturningAttribute[] { Method__is__Get_Relationship_Method.CreateMethodBinding(oms) }, null, false, Method__get__GR_Method_Suffix.CreateMethodBinding(oms)), + new ConditionalSelectAttributeCase(new IExecutableReturningAttribute[] { Method__is__Conditional_Select_Attribute_Method.CreateMethodBinding(oms) }, null, false, Method__get__SAC_Method_Suffix.CreateMethodBinding(oms)) }); } diff --git a/mocha-dotnet/src/lib/Mocha.Core/OmsMethodBuilder.cs b/mocha-dotnet/src/lib/Mocha.Core/OmsMethodBuilder.cs index 3bb1d73..0cc4e4d 100644 --- a/mocha-dotnet/src/lib/Mocha.Core/OmsMethodBuilder.cs +++ b/mocha-dotnet/src/lib/Mocha.Core/OmsMethodBuilder.cs @@ -83,9 +83,13 @@ public class OmsMethodBuilder return new BuildAttributeMethod(method); } - public GetAttributeBySystemRoutineMethod CreateGetAttributeBySystemRoutineMethod(InstanceHandle forClassInstance, string verb, string name, AccessModifier accessModifier, bool isStatic, InstanceHandle returnsAttribute, SystemAttributeRoutine usesSystemAttributeRoutine) + public GetAttributeBySystemRoutineMethod CreateGetAttributeBySystemRoutineMethod(InstanceHandle forClassInstance, string verb, string name, AccessModifier accessModifier, bool isStatic, InstanceHandle returnsAttribute, SystemAttributeRoutine usesSystemAttributeRoutine) + { + return CreateGetAttributeBySystemRoutineMethod(forClassInstance, verb, name, accessModifier, isStatic, Guid.NewGuid(), returnsAttribute, usesSystemAttributeRoutine); + } + public GetAttributeBySystemRoutineMethod CreateGetAttributeBySystemRoutineMethod(InstanceHandle forClassInstance, string verb, string name, AccessModifier accessModifier, bool isStatic, Guid globalIdentifier, InstanceHandle returnsAttribute, SystemAttributeRoutine usesSystemAttributeRoutine) { - InstanceHandle method = CreateMethodBase(Oms.GetInstance(KnownInstanceGuids.MethodClasses.GetAttributeBySystemRoutineMethod), forClassInstance, verb, name, accessModifier, isStatic); + InstanceHandle method = CreateMethodBase(Oms.GetInstance(KnownInstanceGuids.MethodClasses.GetAttributeBySystemRoutineMethod), forClassInstance, verb, name, accessModifier, isStatic, globalIdentifier); 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); diff --git a/mocha-dotnet/src/lib/Mocha.Core/OmsSystemRoutineBuilder.cs b/mocha-dotnet/src/lib/Mocha.Core/OmsSystemRoutineBuilder.cs index 4db7830..4c71ada 100644 --- a/mocha-dotnet/src/lib/Mocha.Core/OmsSystemRoutineBuilder.cs +++ b/mocha-dotnet/src/lib/Mocha.Core/OmsSystemRoutineBuilder.cs @@ -10,7 +10,7 @@ public class OmsSystemRoutineBuilder Oms = oms; } - public SystemAttributeRoutine CreateSystemAttributeRoutine(Guid globalIdentifier, Func func) + public SystemAttributeRoutine CreateSystemAttributeRoutine(Guid globalIdentifier, Func func) { InstanceHandle handle = Oms.CreateInstanceOf(Oms.GetInstance(KnownInstanceGuids.Classes.SystemAttributeRoutine), globalIdentifier); @@ -18,7 +18,7 @@ public class OmsSystemRoutineBuilder Oms.RegisterSystemRoutine(handle, routine); return routine; } - public SystemAttributeRoutine CreateSystemAttributeRoutine(Guid globalIdentifier, Func func) + public SystemAttributeRoutine CreateSystemAttributeRoutine(Guid globalIdentifier, Func func) { InstanceHandle handle = Oms.CreateInstanceOf(Oms.GetInstance(KnownInstanceGuids.Classes.SystemAttributeRoutine), globalIdentifier); @@ -26,7 +26,7 @@ public class OmsSystemRoutineBuilder Oms.RegisterSystemRoutine(handle, routine); return routine; } - public SystemInstanceSetRoutine CreateSystemInstanceSetRoutine(Guid globalIdentifier, Func func) + public SystemInstanceSetRoutine CreateSystemInstanceSetRoutine(Guid globalIdentifier, Func> func) { InstanceHandle handle = Oms.CreateInstanceOf(Oms.GetInstance(KnownInstanceGuids.Classes.SystemInstanceSetRoutine), globalIdentifier); @@ -34,12 +34,4 @@ public class OmsSystemRoutineBuilder Oms.RegisterSystemRoutine(handle, routine); return routine; } - public SystemInstanceSetRoutine CreateSystemInstanceSetRoutine(Guid globalIdentifier, Func func) where T : InstanceWrapper - { - InstanceHandle handle = Oms.CreateInstanceOf(Oms.GetInstance(KnownInstanceGuids.Classes.SystemInstanceSetRoutine), globalIdentifier); - - SystemInstanceSetRoutine routine = new SystemInstanceSetRoutine(handle, func); - Oms.RegisterSystemRoutine(handle, routine); - return routine; - } } \ No newline at end of file diff --git a/mocha-dotnet/src/lib/Mocha.Core/Oop/ConcreteInstanceWrapper.cs b/mocha-dotnet/src/lib/Mocha.Core/Oop/ConcreteInstanceWrapper.cs index 33201b6..5deae21 100644 --- a/mocha-dotnet/src/lib/Mocha.Core/Oop/ConcreteInstanceWrapper.cs +++ b/mocha-dotnet/src/lib/Mocha.Core/Oop/ConcreteInstanceWrapper.cs @@ -44,4 +44,9 @@ public abstract class ConcreteInstanceWrapper : InstanceWrapper } return null; } + + public override string ToString() + { + return TheHandle.ToString(); + } } \ No newline at end of file diff --git a/mocha-dotnet/src/lib/Mocha.Core/Oop/Methods/GetAttributeBySystemRoutineMethod.cs b/mocha-dotnet/src/lib/Mocha.Core/Oop/Methods/GetAttributeBySystemRoutineMethod.cs index 1048287..33fabf3 100644 --- a/mocha-dotnet/src/lib/Mocha.Core/Oop/Methods/GetAttributeBySystemRoutineMethod.cs +++ b/mocha-dotnet/src/lib/Mocha.Core/Oop/Methods/GetAttributeBySystemRoutineMethod.cs @@ -1,7 +1,7 @@ namespace Mocha.Core.Oop.Methods; -public class GetAttributeBySystemRoutineMethod : Method +public class GetAttributeBySystemRoutineMethod : MethodReturningAttribute { public override Guid ClassId => KnownInstanceGuids.MethodClasses.GetAttributeBySystemRoutineMethod; internal GetAttributeBySystemRoutineMethod(InstanceHandle handle) : base(handle) { } diff --git a/mocha-dotnet/src/lib/Mocha.Core/Oop/SystemRoutine.cs b/mocha-dotnet/src/lib/Mocha.Core/Oop/SystemRoutine.cs index 0e4efbb..2161cb1 100644 --- a/mocha-dotnet/src/lib/Mocha.Core/Oop/SystemRoutine.cs +++ b/mocha-dotnet/src/lib/Mocha.Core/Oop/SystemRoutine.cs @@ -4,15 +4,15 @@ public abstract class SystemRoutine : ConcreteInstanceWrapper { internal SystemRoutine(InstanceHandle handle) : base(handle) { } - protected abstract object? ExecuteInternal(); - public object? Execute() + protected abstract object? ExecuteInternal(Oms oms, OmsContext context); + public object? Execute(Oms oms, OmsContext context) { - return ExecuteInternal(); + return ExecuteInternal(oms, context); } - public T Execute(T defaultValue = default(T)) + public T Execute(Oms oms, OmsContext context, T defaultValue = default(T)) { - object? value = Execute(); + object? value = Execute(oms, context); if (value is T) { return (T)value; diff --git a/mocha-dotnet/src/lib/Mocha.Core/Oop/SystemRoutines/SystemAttributeRoutine.cs b/mocha-dotnet/src/lib/Mocha.Core/Oop/SystemRoutines/SystemAttributeRoutine.cs index 5b896a8..108a7c8 100644 --- a/mocha-dotnet/src/lib/Mocha.Core/Oop/SystemRoutines/SystemAttributeRoutine.cs +++ b/mocha-dotnet/src/lib/Mocha.Core/Oop/SystemRoutines/SystemAttributeRoutine.cs @@ -3,21 +3,21 @@ namespace Mocha.Core.Oop; public class SystemAttributeRoutine : SystemRoutine { public override Guid ClassId => KnownInstanceGuids.Classes.SystemAttributeRoutine; - private Func Func { get; } - internal SystemAttributeRoutine(InstanceHandle handle, Func func) : base(handle) + private Func Func { get; } + internal SystemAttributeRoutine(InstanceHandle handle, Func func) : base(handle) { Func = func; } - protected override object? ExecuteInternal() + protected override object? ExecuteInternal(Oms oms, OmsContext context) { - object? value = Func?.Invoke(); + object? value = Func?.Invoke(oms, context); return value; } } public class SystemAttributeRoutine : SystemAttributeRoutine { - internal SystemAttributeRoutine(InstanceHandle handle, Func func) : base(handle, new Func(delegate() { return func(); })) + internal SystemAttributeRoutine(InstanceHandle handle, Func func) : base(handle, new Func(delegate(Oms oms, OmsContext context) { return func(oms, context); })) { } } diff --git a/mocha-dotnet/src/lib/Mocha.Core/Oop/SystemRoutines/SystemInstanceSetRoutine.cs b/mocha-dotnet/src/lib/Mocha.Core/Oop/SystemRoutines/SystemInstanceSetRoutine.cs index 9ac630d..fd1bef1 100644 --- a/mocha-dotnet/src/lib/Mocha.Core/Oop/SystemRoutines/SystemInstanceSetRoutine.cs +++ b/mocha-dotnet/src/lib/Mocha.Core/Oop/SystemRoutines/SystemInstanceSetRoutine.cs @@ -3,19 +3,15 @@ namespace Mocha.Core.Oop; public class SystemInstanceSetRoutine : SystemRoutine { public override Guid ClassId => KnownInstanceGuids.Classes.SystemInstanceSetRoutine; - private Func Func { get; } - internal SystemInstanceSetRoutine(InstanceHandle handle, Func func) : base(handle) + private Func> Func { get; } + internal SystemInstanceSetRoutine(InstanceHandle handle, Func> func) : base(handle) { Func = func; } - protected override object? ExecuteInternal() + protected override object? ExecuteInternal(Oms oms, OmsContext context) { - object? value = Func?.Invoke(); + object? value = Func?.Invoke(oms, context); return value; } } -public class SystemInstanceSetRoutine : SystemInstanceSetRoutine where T : InstanceWrapper -{ - internal SystemInstanceSetRoutine(InstanceHandle handle, Func func) : base(handle, new Func(delegate() { return func()?.Handle ?? InstanceHandle.Empty; })) { } -} diff --git a/mocha-dotnet/tests/Mocha.Core.Tests/MethodTests/ConditionalSelectAttributeMethodTests.cs b/mocha-dotnet/tests/Mocha.Core.Tests/MethodTests/ConditionalSelectAttributeMethodTests.cs index a021866..3e57045 100644 --- a/mocha-dotnet/tests/Mocha.Core.Tests/MethodTests/ConditionalSelectAttributeMethodTests.cs +++ b/mocha-dotnet/tests/Mocha.Core.Tests/MethodTests/ConditionalSelectAttributeMethodTests.cs @@ -43,6 +43,26 @@ public class ConditionalSelectAttributeMethodTests : MethodTestsBase Assert.That(value, Is.Not.EqualTo("SAC")); } + [Test] + public void Test__Get_Method_Abbreviation__GAS() + { + InstanceHandle c_Method = Oms.GetInstance(KnownInstanceGuids.Classes.Method); + + ConditionalSelectAttributeMethod sac = Oms.GetInstance(KnownInstanceGuids.Methods.ConditionalSelectAttribute.Method__get__Method_Abbreviation); + ReturnAttributeMethodBinding ramb = sac.CreateMethodBinding(Oms); + + GetAttributeBySystemRoutineMethod OMS__get__Runtime_Version = Oms.GetInstance(KnownInstanceGuids.Methods.GetAttributeBySystemRoutine.OMS__get__Runtime_Version); + + OmsContext context = Oms.CreateContext(); + context.SetWorkData(c_Method, OMS__get__Runtime_Version); + + InstanceHandle wd = Oms.Execute(context, ramb); + object? value = context.GetWorkData(wd); + + Assert.That(value, Is.EqualTo("GAS")); + Assert.That(value, Is.Not.EqualTo("SAC")); + } + [Test] public void Test__Get_Method_Binding_Abbreviation__RAMB() { @@ -82,4 +102,9 @@ public class ConditionalSelectAttributeMethodTests : MethodTestsBase Assert.That(value, Is.Not.EqualTo("ramb")); } + // TODO: create a method to return a randomly-selected value from a Set + // e.g. Set@select random singular Instance + // using a GAS - Get Attribute by System Routine method + + } \ No newline at end of file diff --git a/mocha-dotnet/tests/Mocha.Core.Tests/MethodTests/SystemRoutineTests.cs b/mocha-dotnet/tests/Mocha.Core.Tests/MethodTests/SystemRoutineTests.cs index 1bb0544..206c146 100644 --- a/mocha-dotnet/tests/Mocha.Core.Tests/MethodTests/SystemRoutineTests.cs +++ b/mocha-dotnet/tests/Mocha.Core.Tests/MethodTests/SystemRoutineTests.cs @@ -15,7 +15,7 @@ public class SystemRoutineTests : MethodTestsBase OmsMethodBuilder methodBuilder = new OmsMethodBuilder(Oms); OmsSystemRoutineBuilder systemRoutineBuilder = new OmsSystemRoutineBuilder(Oms); - SystemAttributeRoutine testSystemAttributeRoutine = systemRoutineBuilder.CreateSystemAttributeRoutine(TEST_SYSTEM_ATTRIBUTE_ROUTINE_GUID, delegate () + SystemAttributeRoutine testSystemAttributeRoutine = systemRoutineBuilder.CreateSystemAttributeRoutine(TEST_SYSTEM_ATTRIBUTE_ROUTINE_GUID, delegate (Oms oms, OmsContext context) { return TEST_SYSTEM_ATTRIBUTE_ROUTINE_VALUE; }); @@ -28,4 +28,18 @@ public class SystemRoutineTests : MethodTestsBase Assert.That(value, Is.EqualTo(TEST_SYSTEM_ATTRIBUTE_ROUTINE_VALUE)); } + + [Test] + public void GetRandomNumberTest() + { + GetAttributeBySystemRoutineMethod Common_Numeric__get__Random_Number = Oms.GetInstance(KnownInstanceGuids.Methods.GetAttributeBySystemRoutine.Common_Numeric__get__Random_Number); + ReturnAttributeMethodBinding ramb = Common_Numeric__get__Random_Number.CreateMethodBinding(Oms); + + OmsContext context = Oms.CreateContext(); + context.SetWorkData(Oms.GetInstance(KnownAttributeGuids.Numeric.Seed), (decimal)25112); + decimal value = Oms.ExecuteReturningAttributeValue(context, ramb); + + // we respect the value of the `Seed` attribute, so we can unit test this + Assert.That(value, Is.EqualTo(0.87073318747372M)); + } } \ No newline at end of file