Compare commits
6 Commits
1c5e538b7d
...
6fe8dfa914
| Author | SHA1 | Date | |
|---|---|---|---|
| 6fe8dfa914 | |||
| 9e9c67d06a | |||
| 40dd9b4b76 | |||
| 70f5c03435 | |||
| 87ad532073 | |||
| 80127b4399 |
@ -1 +1 @@
|
||||
Subproject commit 75cdd15b4c62cab8f4279303c4e522387c14e0b3
|
||||
Subproject commit ce10750b3eafc2430bb52234592bf9937a0a7bfd
|
||||
@ -61,6 +61,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mocha.Modeling", "mocha-dot
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mocha.Modeling.Tests", "mocha-dotnet\tests\Mocha.Modeling.Tests\Mocha.Modeling.Tests.csproj", "{B2A51995-3440-45C5-BB84-FF49A26CF00B}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mocha.Core.Tests.Libraries.System", "mocha-dotnet\tests\Mocha.Core.Tests.Libraries.System\Mocha.Core.Tests.Libraries.System.csproj", "{9D10D57D-A059-4420-AA37-DDE6B8E882E5}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -131,6 +133,10 @@ Global
|
||||
{B2A51995-3440-45C5-BB84-FF49A26CF00B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B2A51995-3440-45C5-BB84-FF49A26CF00B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B2A51995-3440-45C5-BB84-FF49A26CF00B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{9D10D57D-A059-4420-AA37-DDE6B8E882E5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{9D10D57D-A059-4420-AA37-DDE6B8E882E5}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9D10D57D-A059-4420-AA37-DDE6B8E882E5}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9D10D57D-A059-4420-AA37-DDE6B8E882E5}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@ -162,6 +168,7 @@ Global
|
||||
{EA82944B-9720-4126-898F-3E3EDDAE44F4} = {11486802-8136-4958-8B32-FC34630B0306}
|
||||
{E3DB95D7-9B56-4624-9961-50B0CDAFDC78} = {A2C401E9-FED4-43BA-A928-566239894CEE}
|
||||
{B2A51995-3440-45C5-BB84-FF49A26CF00B} = {27C300F5-5172-4225-A6F7-3503B9007DD8}
|
||||
{9D10D57D-A059-4420-AA37-DDE6B8E882E5} = {27C300F5-5172-4225-A6F7-3503B9007DD8}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {D28A9CF8-0235-4F8F-865F-C460BDCAE16D}
|
||||
|
||||
@ -77,11 +77,18 @@ namespace Mocha.Core
|
||||
|
||||
return _ID == other._ID && !IsEmpty;
|
||||
}
|
||||
public bool Equals(IInstanceReference other)
|
||||
{
|
||||
if (IsEmpty && other.GetHandle().IsEmpty)
|
||||
return true;
|
||||
|
||||
return _ID == other.GetHandle()._ID && !IsEmpty;
|
||||
}
|
||||
public override bool Equals([NotNullWhen(true)] object? obj)
|
||||
{
|
||||
if (obj is InstanceHandle)
|
||||
if (obj is IInstanceReference)
|
||||
{
|
||||
return this.Equals(((InstanceHandle)obj));
|
||||
return this.Equals(((IInstanceReference)obj));
|
||||
}
|
||||
return base.Equals(obj);
|
||||
}
|
||||
|
||||
@ -103,7 +103,7 @@ namespace Mocha.Core
|
||||
{
|
||||
ClassIndex = ci;
|
||||
InstanceIndex = -1;
|
||||
SetDerivedDataString(split[1]);
|
||||
_derivedDataString = split[1];
|
||||
_isNotEmpty = true;
|
||||
}
|
||||
return;
|
||||
@ -124,11 +124,6 @@ namespace Mocha.Core
|
||||
throw new ArgumentException("must be a string containing two integers separated by a '$' or a '!'");
|
||||
}
|
||||
|
||||
private void SetDerivedDataString(string base64String)
|
||||
{
|
||||
_derivedDataString = base64String;
|
||||
}
|
||||
|
||||
public InstanceKey(int classIndex, int instanceIndex)
|
||||
{
|
||||
ClassIndex = classIndex;
|
||||
|
||||
@ -78,6 +78,11 @@ 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}");
|
||||
public static Guid Value { get; } = new Guid("{4d60b06a-0aa3-4530-af67-805feeeaced6}");
|
||||
|
||||
public static Guid PrimaryOperandValue { get; } = new Guid("{2e6b3528-f68d-40f8-80f3-4e0c463c00a5}"); // {fe327566-7657-4227-94aa-66bbc1d1afce}
|
||||
|
||||
public static Guid SecondaryOperandValue { get; } = new Guid("{253a04bb-feb7-474d-b608-43219a753ef8}"); // {e666aa75-6b53-47ea-9afa-369378e17b5d}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -241,7 +241,11 @@ namespace Mocha.Core
|
||||
public static Guid GetReferencedInstanceSetMethod { get; } = new Guid("{bcfd0d64-3eba-4a97-9622-f3a960877d24}"); // 26
|
||||
// BEM - Build Element Method - 29
|
||||
public static Guid BuildAttributeMethod { get; } = new Guid("{e5879955-0093-48c8-8042-813168578af2}"); // 30
|
||||
// CN - Calculate Numeric Method - 35
|
||||
/// <summary>
|
||||
/// CN - Calculate Numeric Method
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static Guid CalculateNumericMethod { get; } = new Guid("{0f1ab8e8-c718-4842-a26c-989472141d61}"); // 35
|
||||
/// <summary>
|
||||
/// GSI - Get Specified Instances Method
|
||||
/// Equivalent to YP: `static function $verb$name() : $returnType = $inst`
|
||||
@ -469,6 +473,20 @@ namespace Mocha.Core
|
||||
public static Guid GreaterThanOrEqualTo { get; } = new Guid("{3a4eb7be-f96b-45ac-b97a-bb8fbfc35923}");
|
||||
public static Guid LessThanOrEqualTo { get; } = new Guid("{528e5637-f995-4a6d-93c3-f5e1e62b4517}");
|
||||
}
|
||||
public static class ArithmeticOperators
|
||||
{
|
||||
// {7124b817-188d-4ee7-8e81-af595ae4055e}
|
||||
// {79565ea0-e181-445a-8d34-c8edc45786d4}
|
||||
public static Guid Add { get; internal set; } = new Guid("{04a1cf5e-a38f-46ef-9e34-c619a41866fa}");
|
||||
public static Guid Subtract { get; internal set; } = new Guid("{64ea1785-3a4d-4e20-b0f6-d90d189f9861}");
|
||||
public static Guid Multiply { get; internal set; } = new Guid("{246dfaf3-4caf-409e-8f74-99cd730f6ae3}");
|
||||
public static Guid Divide { get; internal set; } = new Guid("{abf2ce5e-c6c9-4789-8ebe-dab7d4973c55}");
|
||||
public static Guid Power { get; internal set; } = new Guid("{ed47da30-c066-4230-8aff-2efd2e0176df}");
|
||||
public static Guid Root { get; internal set; } = new Guid("{1773e5ff-29e5-445a-88cc-1ad9e56b4e29}");
|
||||
public static Guid LShift { get; internal set; } = new Guid("{1f3e720a-53a9-4251-a412-484f6441e57b}");
|
||||
public static Guid RShift { get; internal set; } = new Guid("{df716fc2-9d84-41fb-a853-7ac6e6f9d548}");
|
||||
public static Guid Logarithm { get; internal set; } = new Guid("{f8c9ef0a-c7ce-4442-8b83-ee6bd545992e}");
|
||||
}
|
||||
public static class Languages
|
||||
{
|
||||
public static Guid English { get; } = new Guid ("{68BB6038-A4B5-4EE1-AAE9-326494942062}");
|
||||
@ -501,6 +519,9 @@ namespace Mocha.Core
|
||||
public static class WorkSets
|
||||
{
|
||||
public static Guid TaskRelatedInstance { get; } = new Guid("{d3860252-491e-469e-939e-702d56d88063}");
|
||||
public static Guid AccessModifierNonsingular { get; } = new Guid("{686a3322-03a5-4da6-ab00-33548cc03b98}");
|
||||
public static Guid ParentClass { get; } = new Guid("{98da8ac1-1fea-4cb4-a278-0c5460e625fd}");
|
||||
public static Guid DestinationClassForRelationship { get; } = new Guid("{cc6bf015-ea36-4cc5-8855-5047095affee}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -77,7 +77,7 @@ namespace Mocha.Core
|
||||
public static Guid Translation_Value__for__Translation { get; } = new Guid("{458c218a-9965-44ba-884b-deda5bf2931d}");
|
||||
public static Guid Translation_Value__has__Language { get; } = new Guid("{3655AEC2-E2C9-4DDE-8D98-0C4D3CE1E569}");
|
||||
public static Guid Language__for__Translation_Value { get; } = new Guid("{bf885bb1-da84-447c-95dc-143ce9deac65}");
|
||||
|
||||
|
||||
public static Guid Application__has_title__Translation { get; } = new Guid("{17e7437a-95bb-472f-a068-c433b715c3e4}");
|
||||
public static Guid Translation__title_for__Application { get; } = new Guid("{79aca30e-ddf9-4d3b-8be7-80b4aaf82c1f}");
|
||||
|
||||
@ -161,7 +161,7 @@ namespace Mocha.Core
|
||||
public static Guid System_Instance_Set_Routine__used_by__Get_Instance_Set_by_System_Routine_Method { get; } = new Guid("{6fb6534c-2a46-4d6d-b9df-fd581f19efed}");
|
||||
|
||||
public static Guid Update_by_System_Routine_Method__uses__System_Update_Routine { get; } = new Guid("{9424a253-cb40-4c7d-bebd-0d0373458154}");
|
||||
|
||||
|
||||
public static Guid Get_Referenced_Instance_Set_Method__returns__Work_Set { get; } = new Guid("{72057f5b-9b49-497d-852f-cd7e5e258d6c}");
|
||||
public static Guid Get_Referenced_Instance_Set_Method__uses_reference__Executable_returning_Instance_Set { get; } = new Guid("{2978238f-7cb0-4ba3-8c6f-473df782cfef}");
|
||||
public static Guid Get_Referenced_Instance_Set_Method__uses_answer__Executable_returning_Instance_Set { get; } = new Guid("{6a65819e-c8cb-4575-9af8-ee221364049b}");
|
||||
@ -183,8 +183,8 @@ namespace Mocha.Core
|
||||
|
||||
public static Guid Assign_Attribute_Method__uses__Executable_returning_Attribute { get; } = new Guid("{9313f96e-58af-416f-852e-ef83725057fc}");
|
||||
public static Guid Executable_returning_Attribute__used_by__Assign_Attribute_Method { get; } = new Guid("{cd8fd04c-dcdd-4dc8-9d5c-e8f83d080cb8}");
|
||||
public static Guid Assign_Attribute_Method__assigns__Attribute { get; } = new Guid("{74061875-8a27-403b-9456-02e52cfd13b2}");
|
||||
public static Guid Attribute__assigned_by__Assign_Attribute_Method { get; } = new Guid("{d3b540e8-0f52-4595-bf52-1968637da59a}");
|
||||
public static Guid Assign_Attribute_Method__assigns__Attribute { get; } = new Guid("{74061875-8a27-403b-9456-02e52cfd13b2}");
|
||||
public static Guid Attribute__assigned_by__Assign_Attribute_Method { get; } = new Guid("{d3b540e8-0f52-4595-bf52-1968637da59a}");
|
||||
|
||||
public static Guid Prompt_Value__has__Prompt { get; } = new Guid("{7CD62362-DDCE-4BFC-87B9-B5499B0BC141}");
|
||||
|
||||
@ -223,10 +223,10 @@ namespace Mocha.Core
|
||||
public static Guid Tenant__has_company_logo_image__File { get; } = new Guid("{3540c81c-b229-4eac-b9b5-9d4b4c6ad1eb}");
|
||||
|
||||
public static Guid Menu_Item__has_title__Translation { get; } = new Guid("{65E3C87E-A2F7-4A33-9FA7-781EFA801E02}");
|
||||
|
||||
|
||||
public static Guid Menu__has__Menu_Item { get; } = new Guid("{5b659d7c-58f9-453c-9826-dd3205c3c97f}");
|
||||
public static Guid Menu_Item__for__Menu { get; } = new Guid("{a22d949f-f8d1-4dcc-a3eb-d9f910228dfd}");
|
||||
|
||||
|
||||
public static Guid Command_Menu_Item__has__Icon { get; } = new Guid("{8859DAEF-01F7-46FA-8F3E-7B2F28E0A520}");
|
||||
|
||||
public static Guid Instance_Menu_Item__has_target__Instance { get; } = new Guid("{C599C20E-F01A-4B12-A919-5DC3B0F545C2}");
|
||||
@ -272,7 +272,7 @@ namespace Mocha.Core
|
||||
public static Guid Tenant__has_login_header__Translation { get; } = new Guid("{41D66ACB-AFDE-4B6F-892D-E66255F10DEB}");
|
||||
public static Guid Tenant__has_login_footer__Translation { get; } = new Guid("{A6203B6B-5BEB-4008-AE49-DB5E7DDBA45B}");
|
||||
public static Guid Tenant__has_application_title__Translation { get; } = new Guid("{76683437-67ba-46d9-a5e7-2945be635345}");
|
||||
|
||||
|
||||
public static Guid Tenant__has_mega__Menu { get; } = new Guid("{cdd743cb-c74a-4671-9922-652c7db9f2d8}");
|
||||
public static Guid Menu__mega_for__Tenant { get; } = new Guid("{788db047-ed7f-4e0c-a8b0-68478d486da7}");
|
||||
|
||||
@ -288,7 +288,7 @@ namespace Mocha.Core
|
||||
public static Guid Method__provides_content_for__Content_Page_Component { get; } = new Guid("{5E75000D-2421-4AD4-9E5F-B9FDD9CB4744}");
|
||||
|
||||
public static Guid Securable_Item__secured_by__Method { get; } = new Guid("{15199c49-9595-4288-846d-13b0ad5dcd4b}");
|
||||
|
||||
|
||||
public static Guid Get_Relationship_Method__returns__Relationship { get; } = new Guid("{321581d6-60c1-4547-8344-9d5bda027adc}");
|
||||
public static Guid Relationship__returned_by__Get_Relationship_Method { get; } = new Guid("{174242ec-7615-42d9-9639-c70ff6e84e0d}");
|
||||
|
||||
@ -349,7 +349,7 @@ namespace Mocha.Core
|
||||
public static Guid Validation__for__Element_Content { get; } = new Guid("{3a4677e8-9c78-4149-80ad-46e5ac3b12f5}");
|
||||
|
||||
public static Guid Derived_Element_Content__update_with__Executable_returning_Work_Data { get; } = new Guid("{4151911a-485c-4488-8e19-1560f489d411}");
|
||||
public static Guid Executable_returning_Work_Data__used_by__Derived_Element_Content { get; } = new Guid("{75fdacf8-163c-45ac-86eb-80677ff738ad}");
|
||||
public static Guid Executable_returning_Work_Data__used_by__Derived_Element_Content { get; } = new Guid("{75fdacf8-163c-45ac-86eb-80677ff738ad}");
|
||||
|
||||
public static Guid Instance__has__Instance_Definition { get; } = new Guid("{329c54ee-17b8-4550-ae80-be5dee9ac53c}");
|
||||
|
||||
@ -438,7 +438,7 @@ namespace Mocha.Core
|
||||
|
||||
public static Guid Process_Updates_Method__has__PUM_Process { get; } = new Guid("{0ffaf08e-dbb5-49d0-8de9-d253ce6cbe7c}");
|
||||
public static Guid PUM_Process__invokes__Execute_Update_Method_Binding { get; } = new Guid("{d3e83c17-fd38-46a0-a055-66281eabe9b0}");
|
||||
|
||||
|
||||
public static Guid BEM_Process__uses_loop__Executable_returning_Instance_Set { get; } = new Guid("{0fb2b538-eacb-418a-b7d8-43a584b85952}");
|
||||
|
||||
public static Guid Get_Instances_Method__returns__Work_Set { get; } = new Guid("{7d0f93b1-8c93-464e-a44d-d674f910b589}");
|
||||
@ -446,5 +446,10 @@ namespace Mocha.Core
|
||||
public static Guid Method_Binding__uses_super__Return_Instance_Set_Method_Binding { get; } = new Guid("{444279f1-3bf9-4d1f-848e-e7bf33fa0fd7}");
|
||||
|
||||
public static Guid Metadata_With_Access_Modifier__has__Access_Modifier { get; } = new Guid("{c8551fb1-6dc5-47cb-8b8f-204d49e6007e}");
|
||||
|
||||
public static Guid Calculate_Numeric_Method__returns__Numeric_Attribute { get; } = new Guid("{9f9a9341-f2d6-4152-8879-e91f574ca309}");
|
||||
public static Guid Numeric_Attribute__returned_by__Calculate_Numeric_Method { get; } = new Guid("{03275ef5-c9cf-4816-a4f5-4f3aaf0f9479}");
|
||||
|
||||
public static Guid Arithmetic_Calculation__has__Arithmetic_Operator { get; } = new Guid("{f286edc6-0875-41bf-8fe9-127b8c0664ae}");
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,85 @@
|
||||
// Copyright (C) 2024 Michael Becker <alcexhim@gmail.com>
|
||||
//
|
||||
// This file is part of Mocha.NET.
|
||||
//
|
||||
// Mocha.NET is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Mocha.NET is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Mocha.NET. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
using System.Diagnostics;
|
||||
using Microsoft.VisualBasic;
|
||||
using Mocha.Core.Oop;
|
||||
|
||||
namespace Mocha.Core.MethodImplementations;
|
||||
|
||||
public class CalculateNumericMethodImplementation : MethodImplementation
|
||||
{
|
||||
public override Guid MethodClassGuid => KnownInstanceGuids.MethodClasses.CalculateNumericMethod;
|
||||
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.Calculate_Numeric_Method__returns__Numeric_Attribute));
|
||||
InstanceHandle arithmeticOperator = oms.GetRelatedInstance(method, oms.GetInstance(KnownRelationshipGuids.Arithmetic_Calculation__has__Arithmetic_Operator));
|
||||
|
||||
if (returnsAttribute == InstanceHandle.Empty)
|
||||
{
|
||||
throw new InvalidOperationException("no return Attribute specified for method");
|
||||
}
|
||||
if (arithmeticOperator == InstanceHandle.Empty)
|
||||
{
|
||||
throw new InvalidOperationException("no Arithmetic Operator specified for Arithmetic Calculation");
|
||||
}
|
||||
|
||||
decimal primaryOperandValue = oms.GetAttributeValue<decimal>(method, oms.GetInstance(KnownAttributeGuids.Numeric.PrimaryOperandValue));
|
||||
decimal secondaryOperandValue = oms.GetAttributeValue<decimal>(method, oms.GetInstance(KnownAttributeGuids.Numeric.SecondaryOperandValue));
|
||||
|
||||
decimal value = 0.0M;
|
||||
if (arithmeticOperator.Equals(ArithmeticOperator.Add))
|
||||
{
|
||||
value = primaryOperandValue + secondaryOperandValue;
|
||||
}
|
||||
else if (arithmeticOperator.Equals(ArithmeticOperator.Subtract))
|
||||
{
|
||||
value = primaryOperandValue - secondaryOperandValue;
|
||||
}
|
||||
else if (arithmeticOperator.Equals(ArithmeticOperator.Multiply))
|
||||
{
|
||||
value = primaryOperandValue * secondaryOperandValue;
|
||||
}
|
||||
else if (arithmeticOperator.Equals(ArithmeticOperator.Divide))
|
||||
{
|
||||
value = primaryOperandValue / secondaryOperandValue;
|
||||
}
|
||||
else if (arithmeticOperator.Equals(ArithmeticOperator.Power))
|
||||
{
|
||||
value = (decimal)Math.Pow((double)primaryOperandValue, (double)secondaryOperandValue);
|
||||
}
|
||||
else if (arithmeticOperator.Equals(ArithmeticOperator.Root))
|
||||
{
|
||||
value = (decimal)Math.Pow((double)primaryOperandValue, (double)(1 / secondaryOperandValue));
|
||||
}
|
||||
else if (arithmeticOperator.Equals(ArithmeticOperator.LShift))
|
||||
{
|
||||
value = (int)primaryOperandValue << (int)secondaryOperandValue;
|
||||
}
|
||||
else if (arithmeticOperator.Equals(ArithmeticOperator.RShift))
|
||||
{
|
||||
value = (int)primaryOperandValue >> (int)secondaryOperandValue;
|
||||
}
|
||||
else if (arithmeticOperator.Equals(ArithmeticOperator.Logarithm))
|
||||
{
|
||||
value = (decimal) Math.Log((double)primaryOperandValue, (double)secondaryOperandValue);
|
||||
}
|
||||
context.SetWorkData(returnsAttribute, value);
|
||||
return returnsAttribute;
|
||||
}
|
||||
}
|
||||
@ -266,6 +266,7 @@ public abstract class Oms
|
||||
// !!! THIS IS PROBABLY NOT THREAD-SAFE. BE VERY VERY CAREFUL !!!
|
||||
UpdateSyntacticSugar<AccessModifier>(typeof(KnownInstanceGuids.AccessModifiers));
|
||||
UpdateSyntacticSugar<RelationalOperator>(typeof(KnownInstanceGuids.RelationalOperators));
|
||||
UpdateSyntacticSugar<ArithmeticOperator>(typeof(KnownInstanceGuids.ArithmeticOperators));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1193,14 +1194,44 @@ public abstract class Oms
|
||||
{
|
||||
return Execute(context, methodBinding.GetHandle());
|
||||
}
|
||||
public object? ExecuteReturningAttributeValue(OmsContext context, ReturnAttributeMethodBinding methodBinding)
|
||||
public object? ExecuteReturningAttributeValue(OmsContext context, ReturnAttributeMethodBinding methodBinding, KeyValuePair<InstanceHandle, object>[]? parms)
|
||||
{
|
||||
// override any specified parms we have
|
||||
Dictionary<InstanceHandle, object>? oldParms = null;
|
||||
if (parms != null)
|
||||
{
|
||||
oldParms = new Dictionary<InstanceHandle, object>();
|
||||
foreach (KeyValuePair<InstanceHandle, object> kvp in parms)
|
||||
{
|
||||
if (context.HasWorkData(kvp.Key))
|
||||
{
|
||||
oldParms[kvp.Key] = context.GetWorkData(kvp.Key);
|
||||
}
|
||||
else
|
||||
{
|
||||
oldParms[kvp.Key] = null;
|
||||
}
|
||||
|
||||
context.SetWorkData(kvp.Key, kvp.Value);
|
||||
}
|
||||
}
|
||||
|
||||
// call the internal MethodImplementation
|
||||
InstanceHandle workData = Execute(context, methodBinding.GetHandle());
|
||||
|
||||
// restore the original parms
|
||||
if (oldParms != null)
|
||||
{
|
||||
foreach (KeyValuePair<InstanceHandle, object> kvp in oldParms)
|
||||
{
|
||||
context.SetWorkData(kvp.Key, kvp.Value);
|
||||
}
|
||||
}
|
||||
return context.GetWorkData(workData);
|
||||
}
|
||||
public T ExecuteReturningAttributeValue<T>(OmsContext context, ReturnAttributeMethodBinding methodBinding, T defaultValue = default(T))
|
||||
public T ExecuteReturningAttributeValue<T>(OmsContext context, ReturnAttributeMethodBinding methodBinding, T defaultValue = default(T), KeyValuePair<InstanceHandle, object>[]? parms = null)
|
||||
{
|
||||
object? value = ExecuteReturningAttributeValue(context, methodBinding);
|
||||
object? value = ExecuteReturningAttributeValue(context, methodBinding, parms);
|
||||
if (value is T)
|
||||
{
|
||||
return (T)value;
|
||||
|
||||
@ -61,6 +61,10 @@ public class OmsContext
|
||||
|
||||
private Dictionary<InstanceHandle, object?> _WorkData = new Dictionary<InstanceHandle, object?>();
|
||||
private Dictionary<InstanceHandle, object?> _GlobalData = new Dictionary<InstanceHandle, object?>();
|
||||
public bool HasWorkData(IInstanceReference parm)
|
||||
{
|
||||
return _WorkData.ContainsKey(parm.GetHandle());
|
||||
}
|
||||
public object? GetWorkData(IInstanceReference parm)
|
||||
{
|
||||
if (_WorkData.ContainsKey(parm.GetHandle()))
|
||||
|
||||
@ -381,4 +381,14 @@ public class OmsMethodBuilder
|
||||
InstanceHandle ihCase = CreateConditionalSelectAttributeCase(cas);
|
||||
Oms.AssignRelationship(method.GetHandle(), Oms.GetInstance(KnownRelationshipGuids.Conditional_Select_Attribute_Method__has__Conditional_Select_Attribute_Case), ihCase);
|
||||
}
|
||||
|
||||
public CalculateNumericMethod CreateCalculateNumericMethod(InstanceHandle clasz, string verb, string name, AccessModifier accessModifier, bool isStatic, IInstanceReference returnsAttribute, decimal primaryOperand, ArithmeticOperator oper, decimal secondaryOperand)
|
||||
{
|
||||
InstanceHandle method = CreateMethodBase(Oms.GetInstance(KnownInstanceGuids.MethodClasses.CalculateNumericMethod), clasz, verb, name, accessModifier, isStatic);
|
||||
Oms.SetAttributeValue(method, Oms.GetInstance(KnownAttributeGuids.Numeric.PrimaryOperandValue), primaryOperand);
|
||||
Oms.AssignRelationship(method, Oms.GetInstance(KnownRelationshipGuids.Arithmetic_Calculation__has__Arithmetic_Operator), oper.GetHandle());
|
||||
Oms.SetAttributeValue(method, Oms.GetInstance(KnownAttributeGuids.Numeric.SecondaryOperandValue), secondaryOperand);
|
||||
Oms.AssignRelationship(method, Oms.GetInstance(KnownRelationshipGuids.Calculate_Numeric_Method__returns__Numeric_Attribute), returnsAttribute.GetHandle());
|
||||
return new CalculateNumericMethod(method);
|
||||
}
|
||||
}
|
||||
@ -21,5 +21,15 @@ namespace Mocha.Core.Oop;
|
||||
public class ArithmeticOperator : ConcreteInstanceWrapper
|
||||
{
|
||||
public override Guid ClassId => KnownInstanceGuids.Classes.ArithmeticOperator;
|
||||
internal ArithmeticOperator(InstanceHandle handle) : base(handle) { }
|
||||
internal ArithmeticOperator(InstanceHandle handle) : base(handle) { }
|
||||
|
||||
public static ArithmeticOperator Add { get; internal set; } = null;
|
||||
public static ArithmeticOperator Subtract { get; internal set; } = null;
|
||||
public static ArithmeticOperator Multiply { get; internal set; } = null;
|
||||
public static ArithmeticOperator Divide { get; internal set; } = null;
|
||||
public static ArithmeticOperator Power { get; internal set; } = null;
|
||||
public static ArithmeticOperator Root { get; internal set; } = null;
|
||||
public static ArithmeticOperator LShift { get; internal set; } = null;
|
||||
public static ArithmeticOperator RShift { get; internal set; } = null;
|
||||
public static ArithmeticOperator Logarithm { get; internal set; } = null;
|
||||
}
|
||||
@ -26,6 +26,33 @@ public abstract class InstanceWrapper : IInstanceReference
|
||||
{
|
||||
return GetHandleInternal();
|
||||
}
|
||||
|
||||
public static bool operator ==(InstanceWrapper left, IInstanceReference right)
|
||||
{
|
||||
if ((object)left == null && (object)right == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if ((object)left == null || (object)right == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return left.GetHandle().Equals(right.GetHandle());
|
||||
}
|
||||
public static bool operator !=(InstanceWrapper left, IInstanceReference right)
|
||||
{
|
||||
if ((object)left == null && (object)right == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if ((object)left == null || (object)right == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return !left.GetHandle().Equals(right.GetHandle());
|
||||
}
|
||||
}
|
||||
public static class InstanceWrapperArrayExtensions
|
||||
{
|
||||
|
||||
@ -0,0 +1,8 @@
|
||||
|
||||
namespace Mocha.Core.Oop.Methods;
|
||||
|
||||
public class CalculateNumericMethod : Method
|
||||
{
|
||||
public override Guid ClassId => KnownInstanceGuids.MethodClasses.CalculateNumericMethod;
|
||||
internal CalculateNumericMethod(InstanceHandle handle) : base(handle) { }
|
||||
}
|
||||
@ -121,7 +121,46 @@ public class CSharpCodeGenerator : DotNetCodeGenerator
|
||||
}
|
||||
else if (item is Method m)
|
||||
{
|
||||
sb.Append(GenerateCode(m.AccessModifier));
|
||||
if (m.AccessModifier != AccessModifier.None)
|
||||
{
|
||||
sb.Append(' ');
|
||||
}
|
||||
if (m.IsOverride)
|
||||
{
|
||||
sb.Append("override ");
|
||||
}
|
||||
if (m.ReturnType != null)
|
||||
{
|
||||
sb.Append(m.ReturnType);
|
||||
sb.Append(' ');
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.Append("void ");
|
||||
}
|
||||
sb.Append(m.Name);
|
||||
sb.Append('(');
|
||||
for (int i = 0; i < m.Parameters.Count; i++)
|
||||
{
|
||||
MethodParameter parm = m.Parameters[i];
|
||||
sb.Append(BuildObjectReference(parm.DataType.ObjectNames));
|
||||
sb.Append(' ');
|
||||
sb.Append(parm.Name);
|
||||
if (i < m.Parameters.Count - 1)
|
||||
{
|
||||
sb.Append(',');
|
||||
}
|
||||
}
|
||||
sb.Append(')');
|
||||
|
||||
sb.Append('{');
|
||||
foreach (IMethodMember member in m.Items)
|
||||
{
|
||||
sb.Append(GenerateCode(member));
|
||||
sb.Append(';');
|
||||
}
|
||||
sb.Append('}');
|
||||
}
|
||||
else if (item is CreateInstance ci)
|
||||
{
|
||||
@ -151,6 +190,19 @@ public class CSharpCodeGenerator : DotNetCodeGenerator
|
||||
sb.Append(BuildParameterList(mc.Parameters));
|
||||
sb.Append(')');
|
||||
}
|
||||
else if (item is PropertyAssignment pa)
|
||||
{
|
||||
sb.Append(BuildObjectReference(pa.ObjectReference.ObjectNames));
|
||||
sb.Append(" = ");
|
||||
if (pa.Value != null)
|
||||
{
|
||||
sb.Append(pa.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.Append("null");
|
||||
}
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
@ -239,6 +291,57 @@ public class CSharpCodeGenerator : DotNetCodeGenerator
|
||||
pp.SetMethod = new Method();
|
||||
}
|
||||
}
|
||||
else if (pi.PropertyType == typeof(int))
|
||||
{
|
||||
pp.GetMethod = new Method(new IMethodMember[]
|
||||
{
|
||||
new Return(new MethodCall(new string[] { "this", "Oms" }, "GetAttributeValue", new object[]
|
||||
{
|
||||
new MethodCall(new string[] { "this", "Oms" }, "GetInstance", new object[] { new ObjectReference(new string[] { "this", "GlobalIdentifier" })}),
|
||||
new MethodCall(new string[] { "this", "Oms" }, "GetInstance", new object[] { new CreateInstance(new string[] { "System", "Guid" }, new object[] { "{9153A637-992E-4712-ADF2-B03F0D9EDEA6}" })})
|
||||
}) { GenericParameters = [ new ObjectReference(["int"]) ]})
|
||||
});
|
||||
// GetAttributeValue<T>(InstanceKey source, InstanceHandle attribute, T defaultValue = default(T), DateTime? effectiveDate = null)
|
||||
|
||||
if (pi.GetSetMethod() != null)
|
||||
{
|
||||
pp.SetMethod = new Method();
|
||||
}
|
||||
}
|
||||
else if (pi.PropertyType == typeof(decimal))
|
||||
{
|
||||
pp.GetMethod = new Method(new IMethodMember[]
|
||||
{
|
||||
new Return(new MethodCall(new string[] { "this", "Oms" }, "GetAttributeValue", new object[]
|
||||
{
|
||||
new MethodCall(new string[] { "this", "Oms" }, "GetInstance", new object[] { new ObjectReference(new string[] { "this", "GlobalIdentifier" })}),
|
||||
new MethodCall(new string[] { "this", "Oms" }, "GetInstance", new object[] { new CreateInstance(new string[] { "System", "Guid" }, new object[] { "{9153A637-992E-4712-ADF2-B03F0D9EDEA6}" })})
|
||||
}) { GenericParameters = [ new ObjectReference(["decimal"]) ]})
|
||||
});
|
||||
// GetAttributeValue<T>(InstanceKey source, InstanceHandle attribute, T defaultValue = default(T), DateTime? effectiveDate = null)
|
||||
|
||||
if (pi.GetSetMethod() != null)
|
||||
{
|
||||
pp.SetMethod = new Method();
|
||||
}
|
||||
}
|
||||
else if (pi.PropertyType == typeof(DateTime))
|
||||
{
|
||||
pp.GetMethod = new Method(new IMethodMember[]
|
||||
{
|
||||
new Return(new MethodCall(new string[] { "this", "Oms" }, "GetAttributeValue", new object[]
|
||||
{
|
||||
new MethodCall(new string[] { "this", "Oms" }, "GetInstance", new object[] { new ObjectReference(new string[] { "this", "GlobalIdentifier" })}),
|
||||
new MethodCall(new string[] { "this", "Oms" }, "GetInstance", new object[] { new CreateInstance(new string[] { "System", "Guid" }, new object[] { "{9153A637-992E-4712-ADF2-B03F0D9EDEA6}" })})
|
||||
}) { GenericParameters = [ new ObjectReference(["System.DateTime"]) ]})
|
||||
});
|
||||
// GetAttributeValue<T>(InstanceKey source, InstanceHandle attribute, T defaultValue = default(T), DateTime? effectiveDate = null)
|
||||
|
||||
if (pi.GetSetMethod() != null)
|
||||
{
|
||||
pp.SetMethod = new Method();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// generate dynamic getters and setters for GetRelatedInstance and AssignRelationship
|
||||
|
||||
@ -20,9 +20,13 @@ namespace Mocha.Modeling.CodeGeneration;
|
||||
public class Method : IClassMember
|
||||
{
|
||||
public string? Name { get; set; } = null;
|
||||
public AccessModifier AccessModifier { get; set; } = AccessModifier.None;
|
||||
public ObjectReference? ReturnType { get; set; } = null;
|
||||
|
||||
public List<IMethodMember> Items { get; } = new List<IMethodMember>();
|
||||
public List<MethodParameter> Parameters { get; } = new List<MethodParameter>();
|
||||
|
||||
public bool IsOverride { get; set; } = false;
|
||||
|
||||
public Method(IEnumerable<IMethodMember>? items = null) : this(null, items)
|
||||
{
|
||||
|
||||
|
||||
@ -56,7 +56,6 @@ public class OmsObjectFactory<TOmsClass> : CSharpCodeGenerator where TOmsClass :
|
||||
if ((o?.GetType().IsAssignableTo(typeof(TOmsClass))).GetValueOrDefault())
|
||||
{
|
||||
TOmsClass db = (TOmsClass)o;
|
||||
|
||||
return db;
|
||||
}
|
||||
throw new TypeInitializationException(typeof(TOmsClass).Name, null);
|
||||
@ -82,7 +81,6 @@ public class OmsObjectFactory<TOmsClass> : CSharpCodeGenerator where TOmsClass :
|
||||
if ((o?.GetType().IsAssignableTo(typeof(TOmsClass))).GetValueOrDefault())
|
||||
{
|
||||
TOmsClass db = (TOmsClass)o;
|
||||
|
||||
return db;
|
||||
}
|
||||
throw new TypeInitializationException(typeof(TOmsClass).Name, null);
|
||||
@ -104,9 +102,18 @@ public class OmsObjectFactory<TOmsClass> : CSharpCodeGenerator where TOmsClass :
|
||||
Type t = typeof(TOmsClass);
|
||||
|
||||
Namespace ns = new Namespace(new string[] { "Mocha", "Modeling", "Models", t.Name });
|
||||
|
||||
Mocha.Modeling.CodeGeneration.Class cl = GenerateClass(t, globalIdentifier);
|
||||
ns.Items.Add(cl);
|
||||
|
||||
|
||||
if (t.IsAssignableTo(typeof(IOmsDatabase)))
|
||||
{
|
||||
Mocha.Modeling.CodeGeneration.Class cl = GenerateDatabase(t);
|
||||
ns.Items.Add(cl);
|
||||
}
|
||||
else
|
||||
{
|
||||
Mocha.Modeling.CodeGeneration.Class cl = GenerateClass(t, globalIdentifier);
|
||||
ns.Items.Add(cl);
|
||||
}
|
||||
|
||||
return GenerateCode(ns);
|
||||
}
|
||||
@ -132,7 +139,7 @@ public class OmsObjectFactory<TOmsClass> : CSharpCodeGenerator where TOmsClass :
|
||||
cl.Items.Add(new CodeGeneration.Method("Initialize", new MethodParameter[] { new MethodParameter("oms", new ObjectReference(["Mocha", "Core", "Oms"]))}, new IMethodMember[]
|
||||
{
|
||||
new PropertyAssignment(new ObjectReference(["this", "Oms"]), "oms")
|
||||
}));
|
||||
}) { AccessModifier = CodeGeneration.AccessModifier.Public});
|
||||
|
||||
return cl;
|
||||
}
|
||||
|
||||
@ -0,0 +1,62 @@
|
||||
using Mocha.Testing;
|
||||
|
||||
namespace Mocha.Core.Tests.Libraries.System;
|
||||
|
||||
public class GetInstanceText : OmsTestsBase
|
||||
{
|
||||
private string GetInstanceTextTest(Guid guid)
|
||||
{
|
||||
InstanceHandle ihClass = Oms.GetInstance(guid);
|
||||
string text = Oms.GetInstanceText(ihClass);
|
||||
return text;
|
||||
}
|
||||
|
||||
public static IEnumerable<TestCaseData> Attributes__Cases
|
||||
{
|
||||
get
|
||||
{
|
||||
yield return new TestCaseData(KnownAttributeGuids.Text.Name).Returns("Name");
|
||||
yield return new TestCaseData(KnownAttributeGuids.Boolean.UseAnyCondition).Returns("Use Any Condition");
|
||||
yield return new TestCaseData(KnownAttributeGuids.Numeric.DebugDefinitionLineNumber).Returns("Source Definition Line Number");
|
||||
yield return new TestCaseData(KnownAttributeGuids.Text.IPAddress).Returns("IP Address");
|
||||
}
|
||||
}
|
||||
[TestCaseSource(nameof(Attributes__Cases))]
|
||||
public string Attributes(Guid guid)
|
||||
{
|
||||
return GetInstanceTextTest(guid);
|
||||
}
|
||||
|
||||
public static IEnumerable<TestCaseData> Method_Classes__Cases
|
||||
{
|
||||
get
|
||||
{
|
||||
yield return new TestCaseData(KnownInstanceGuids.MethodClasses.AssignAttributeMethod).Returns("AA - Assign Attribute Method");
|
||||
yield return new TestCaseData(KnownInstanceGuids.MethodClasses.BuildAttributeMethod).Returns("BA - Build Attribute Method");
|
||||
yield return new TestCaseData(KnownInstanceGuids.MethodClasses.GetRelationshipMethod).Returns("GR - Get Relationship Method");
|
||||
yield return new TestCaseData(KnownInstanceGuids.MethodClasses.CalculateNumericMethod).Returns("CN - Calculate Numeric Method");
|
||||
}
|
||||
}
|
||||
[TestCaseSource(nameof(Method_Classes__Cases))]
|
||||
public string Method_Classes(Guid guid)
|
||||
{
|
||||
return GetInstanceTextTest(guid);
|
||||
}
|
||||
|
||||
public static IEnumerable<TestCaseData> Work_Sets__Cases
|
||||
{
|
||||
get
|
||||
{
|
||||
yield return new TestCaseData(KnownInstanceGuids.WorkSets.TaskRelatedInstance).Returns("Task Related Instance");
|
||||
yield return new TestCaseData(KnownInstanceGuids.WorkSets.ParentClass).Returns("Parent Class");
|
||||
yield return new TestCaseData(KnownInstanceGuids.WorkSets.AccessModifierNonsingular).Returns("Access Modifier [Nonsingular]");
|
||||
yield return new TestCaseData(KnownInstanceGuids.WorkSets.DestinationClassForRelationship).Returns("Destination Class for Relationship");
|
||||
}
|
||||
}
|
||||
[TestCaseSource(nameof(Work_Sets__Cases))]
|
||||
public string Work_Sets(Guid guid)
|
||||
{
|
||||
return GetInstanceTextTest(guid);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1 @@
|
||||
global using NUnit.Framework;
|
||||
@ -0,0 +1,21 @@
|
||||
using Mocha.Testing;
|
||||
|
||||
namespace Mocha.Core.Tests.Libraries.System;
|
||||
|
||||
public class Method__get__Method_Abbreviation : OmsTestsBase
|
||||
{
|
||||
[Test]
|
||||
public void CN__Calculate_Numeric_Method()
|
||||
{
|
||||
InstanceHandle ihClass = Oms.GetInstance(KnownInstanceGuids.MethodClasses.CalculateNumericMethod);
|
||||
|
||||
Oop.MethodReturningAttribute ihMethod = (Oop.MethodReturningAttribute) Oms.GetMethod(Oms.GetInstance(KnownInstanceGuids.Classes.Method), "get", "Method Type");
|
||||
Oop.ReturnAttributeMethodBinding ramb = ihMethod.CreateMethodBinding(Oms);
|
||||
OmsContext ctx = Oms.CreateContext();
|
||||
string text = Oms.ExecuteReturningAttributeValue<string>(ctx, ramb, null, new KeyValuePair<InstanceHandle, object>[]
|
||||
{
|
||||
new KeyValuePair<InstanceHandle, object>(Oms.GetInstance(KnownInstanceGuids.Classes.Method), ihClass)
|
||||
});
|
||||
Assert.That(text, Is.EqualTo("CN - Calculate Numeric Method"));
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,27 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
|
||||
<PackageReference Include="NUnit" Version="3.13.3" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
|
||||
<PackageReference Include="NUnit.Analyzers" Version="3.6.1" />
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="../../../framework-dotnet/framework-dotnet/src/lib/MBS.Core/MBS.Core.csproj" />
|
||||
<ProjectReference Include="../../src/lib/Mocha.Core/Mocha.Core.csproj" />
|
||||
<ProjectReference Include="../../src/lib/Mocha.Testing/Mocha.Testing.csproj" />
|
||||
<ProjectReference Include="../../src/plugins/Mocha.Plugins.Libraries.McxMini/Mocha.Plugins.Libraries.McxMini.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@ -0,0 +1,166 @@
|
||||
// Copyright (C) 2024 Michael Becker <alcexhim@gmail.com>
|
||||
//
|
||||
// This file is part of Mocha.NET.
|
||||
//
|
||||
// Mocha.NET is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Mocha.NET is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Mocha.NET. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
using Mocha.Core.Oop;
|
||||
using Mocha.Core.Oop.Methods;
|
||||
|
||||
namespace Mocha.Core.Tests.MethodTests
|
||||
{
|
||||
|
||||
public class CalculateNumericMethodTests : MethodTestsBase
|
||||
{
|
||||
[Test]
|
||||
public void Add_Two_Literal_Numbers_Test()
|
||||
{
|
||||
InstanceHandle irTestClass = Oms.GetInstance(TEST_CLASS_GUID);
|
||||
InstanceHandle irTestClassInstance = Oms.CreateInstanceOf(irTestClass);
|
||||
decimal test_value = 1.0M;
|
||||
decimal test_addition = 3.0M;
|
||||
decimal test_result = test_value + test_addition;
|
||||
|
||||
OmsMethodBuilder builder = new OmsMethodBuilder(Oms);
|
||||
|
||||
CalculateNumericMethod ih_CN = builder.CreateCalculateNumericMethod(irTestClass, "build", "Test Attribute", AccessModifier.Public, true, Oms.GetInstance(KnownAttributeGuids.Numeric.Index), test_value, ArithmeticOperator.Add, test_addition);
|
||||
|
||||
OmsContext context = Oms.CreateContext();
|
||||
InstanceHandle ih_test = Oms.Execute(context, ih_CN);
|
||||
object value = context.GetWorkData(ih_test);
|
||||
|
||||
Assert.That(value, Is.EqualTo(test_result));
|
||||
}
|
||||
[Test]
|
||||
public void Subtract_Two_Literal_Numbers_Test()
|
||||
{
|
||||
InstanceHandle irTestClass = Oms.GetInstance(TEST_CLASS_GUID);
|
||||
InstanceHandle irTestClassInstance = Oms.CreateInstanceOf(irTestClass);
|
||||
decimal test_1 = 6.0M;
|
||||
decimal test_2 = 4.0M;
|
||||
decimal test_result = test_2 - test_1;
|
||||
|
||||
OmsMethodBuilder builder = new OmsMethodBuilder(Oms);
|
||||
|
||||
CalculateNumericMethod ih_CN = builder.CreateCalculateNumericMethod(irTestClass, "build", "Test Attribute", AccessModifier.Public, true, Oms.GetInstance(KnownAttributeGuids.Numeric.Index), test_2, ArithmeticOperator.Subtract, test_1);
|
||||
|
||||
OmsContext context = Oms.CreateContext();
|
||||
InstanceHandle ih_test = Oms.Execute(context, ih_CN);
|
||||
object value = context.GetWorkData(ih_test);
|
||||
|
||||
Assert.That(value, Is.EqualTo(test_result));
|
||||
}
|
||||
[Test]
|
||||
public void Multiply_Two_Literal_Numbers_Test()
|
||||
{
|
||||
InstanceHandle irTestClass = Oms.GetInstance(TEST_CLASS_GUID);
|
||||
InstanceHandle irTestClassInstance = Oms.CreateInstanceOf(irTestClass);
|
||||
decimal test_1 = 3.0M;
|
||||
decimal test_2 = 9.0M;
|
||||
decimal test_result = test_1 * test_2;
|
||||
|
||||
OmsMethodBuilder builder = new OmsMethodBuilder(Oms);
|
||||
|
||||
CalculateNumericMethod ih_CN = builder.CreateCalculateNumericMethod(irTestClass, "build", "Test Attribute", AccessModifier.Public, true, Oms.GetInstance(KnownAttributeGuids.Numeric.Index), test_1, ArithmeticOperator.Multiply, test_2);
|
||||
|
||||
OmsContext context = Oms.CreateContext();
|
||||
InstanceHandle ih_test = Oms.Execute(context, ih_CN);
|
||||
object value = context.GetWorkData(ih_test);
|
||||
|
||||
Assert.That(value, Is.EqualTo(test_result));
|
||||
}
|
||||
[Test]
|
||||
public void Divide_Two_Literal_Numbers_Test()
|
||||
{
|
||||
InstanceHandle irTestClass = Oms.GetInstance(TEST_CLASS_GUID);
|
||||
InstanceHandle irTestClassInstance = Oms.CreateInstanceOf(irTestClass);
|
||||
decimal test_1 = 28.0M;
|
||||
decimal test_2 = 7.0M;
|
||||
decimal test_result = test_1 / test_2;
|
||||
|
||||
OmsMethodBuilder builder = new OmsMethodBuilder(Oms);
|
||||
|
||||
CalculateNumericMethod ih_CN = builder.CreateCalculateNumericMethod(irTestClass, "build", "Test Attribute", AccessModifier.Public, true, Oms.GetInstance(KnownAttributeGuids.Numeric.Index), test_1, ArithmeticOperator.Divide, test_2);
|
||||
|
||||
OmsContext context = Oms.CreateContext();
|
||||
InstanceHandle ih_test = Oms.Execute(context, ih_CN);
|
||||
object value = context.GetWorkData(ih_test);
|
||||
|
||||
Assert.That(value, Is.EqualTo(test_result));
|
||||
}
|
||||
[Test]
|
||||
public void Power_Two_Literal_Numbers_Test()
|
||||
{
|
||||
InstanceHandle irTestClass = Oms.GetInstance(TEST_CLASS_GUID);
|
||||
InstanceHandle irTestClassInstance = Oms.CreateInstanceOf(irTestClass);
|
||||
decimal test_1 = 4.0M;
|
||||
decimal test_2 = 3.0M;
|
||||
decimal test_result = (decimal)Math.Pow((double)test_1, (double)test_2);
|
||||
decimal test_result2 = (test_1 * test_1 * test_1);
|
||||
Assert.That(test_result, Is.EqualTo(test_result2));
|
||||
|
||||
OmsMethodBuilder builder = new OmsMethodBuilder(Oms);
|
||||
|
||||
CalculateNumericMethod ih_CN = builder.CreateCalculateNumericMethod(irTestClass, "build", "Test Attribute", AccessModifier.Public, true, Oms.GetInstance(KnownAttributeGuids.Numeric.Index), test_1, ArithmeticOperator.Power, test_2);
|
||||
|
||||
OmsContext context = Oms.CreateContext();
|
||||
InstanceHandle ih_test = Oms.Execute(context, ih_CN);
|
||||
object value = context.GetWorkData(ih_test);
|
||||
|
||||
Assert.That(value, Is.EqualTo(test_result));
|
||||
}
|
||||
[Test]
|
||||
public void Root_Two_Literal_Numbers_Test()
|
||||
{
|
||||
InstanceHandle irTestClass = Oms.GetInstance(TEST_CLASS_GUID);
|
||||
InstanceHandle irTestClassInstance = Oms.CreateInstanceOf(irTestClass);
|
||||
decimal test_1 = 4.0M;
|
||||
decimal test_2 = 2.0M;
|
||||
decimal test_result = (decimal)Math.Sqrt((double)test_1);
|
||||
decimal test_result2 = 2;
|
||||
Assert.That(test_result, Is.EqualTo(test_result2));
|
||||
|
||||
OmsMethodBuilder builder = new OmsMethodBuilder(Oms);
|
||||
|
||||
CalculateNumericMethod ih_CN = builder.CreateCalculateNumericMethod(irTestClass, "build", "Test Attribute", AccessModifier.Public, true, Oms.GetInstance(KnownAttributeGuids.Numeric.Index), test_1, ArithmeticOperator.Root, test_2);
|
||||
|
||||
OmsContext context = Oms.CreateContext();
|
||||
InstanceHandle ih_test = Oms.Execute(context, ih_CN);
|
||||
object value = context.GetWorkData(ih_test);
|
||||
|
||||
Assert.That(value, Is.EqualTo(test_result));
|
||||
}
|
||||
[Test]
|
||||
public void Logarithm_Two_Literal_Numbers_Test()
|
||||
{
|
||||
InstanceHandle irTestClass = Oms.GetInstance(TEST_CLASS_GUID);
|
||||
InstanceHandle irTestClassInstance = Oms.CreateInstanceOf(irTestClass);
|
||||
decimal test_1 = 100.0M;
|
||||
decimal test_2 = 10.0M;
|
||||
decimal test_result = 2;
|
||||
Assert.That(test_result, Is.EqualTo(test_result));
|
||||
|
||||
OmsMethodBuilder builder = new OmsMethodBuilder(Oms);
|
||||
|
||||
CalculateNumericMethod ih_CN = builder.CreateCalculateNumericMethod(irTestClass, "build", "Test Attribute", AccessModifier.Public, true, Oms.GetInstance(KnownAttributeGuids.Numeric.Index), test_1, ArithmeticOperator.Logarithm, test_2);
|
||||
|
||||
OmsContext context = Oms.CreateContext();
|
||||
InstanceHandle ih_test = Oms.Execute(context, ih_CN);
|
||||
object value = context.GetWorkData(ih_test);
|
||||
|
||||
Assert.That(value, Is.EqualTo(test_result));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -46,6 +46,32 @@ public class SystemRoutineTests : MethodTestsBase
|
||||
Assert.That(value, Is.EqualTo(TEST_SYSTEM_ATTRIBUTE_ROUTINE_VALUE));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PassParmViaSystemRoutineTest()
|
||||
{
|
||||
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 (Oms oms, OmsContext context)
|
||||
{
|
||||
string value = context.GetWorkData<string>(oms.GetInstance(KnownAttributeGuids.Text.Token));
|
||||
return TEST_SYSTEM_ATTRIBUTE_ROUTINE_VALUE + value;
|
||||
});
|
||||
|
||||
GetAttributeBySystemRoutineMethod gasMethod = methodBuilder.CreateGetAttributeBySystemRoutineMethod(irTestClass, "get", "Test System Routine Text Attribute", AccessModifier.Public, true, Oms.GetInstance(KnownAttributeGuids.Text.Value), testSystemAttributeRoutine);
|
||||
ReturnAttributeMethodBinding gasMethodRamb = methodBuilder.CreateReturnAttributeMethodBinding(gasMethod);
|
||||
|
||||
OmsContext context = Oms.CreateContext();
|
||||
string value = Oms.ExecuteReturningAttributeValue<string>(context, gasMethodRamb, null, new KeyValuePair<InstanceHandle, object>[]
|
||||
{
|
||||
// !!! WARNING: do not use 'Value' here as it is the return type attribute of the GAS method and WILL be overwritten after execution !!!
|
||||
new KeyValuePair<InstanceHandle, object>(Oms.GetInstance(KnownAttributeGuids.Text.Token), "pqdms")
|
||||
});
|
||||
|
||||
Assert.That(value, Is.EqualTo(TEST_SYSTEM_ATTRIBUTE_ROUTINE_VALUE + "pqdms"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetRandomNumberTest()
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user