Compare commits
3 Commits
5351fe7735
...
09023ddc86
| Author | SHA1 | Date | |
|---|---|---|---|
| 09023ddc86 | |||
| 243b9b4217 | |||
| 99ec3f703f |
@ -1 +1 @@
|
||||
Subproject commit 152eb33273ba12ccad4f3a2e98c514617e11bcff
|
||||
Subproject commit 2cedd6600d418723ec97f51b28cd9e1c31ff8d30
|
||||
@ -70,6 +70,7 @@ namespace Mocha.Core
|
||||
public static Guid SelectionFunction { get; } = new Guid("{bdaef55d-9905-4d24-84c2-7439d43a79df}");
|
||||
|
||||
// public static Guid MethodCall { get; } = new Guid("{084A6D58-32C9-4A5F-9D2B-86C46F74E522}");
|
||||
public static Guid BEMProcess { get; } = new Guid("{a4c5ffb4-bf37-49f3-9190-dc329d035b46}");
|
||||
|
||||
public static Guid ConditionGroup { get; } = new Guid("{df2059e6-650c-49a8-8188-570ccbe4fd2d}");
|
||||
public static Guid ConditionalEvaluationCase { get; } = new Guid("{ba18abdc-11ae-46af-850a-eb30280b0ffa}");
|
||||
@ -211,8 +212,8 @@ namespace Mocha.Core
|
||||
public static Guid Instance__get__Parent_Class { get; } = new Guid("{bac8c59f-8994-41e8-b0c0-659ec8efc4e2}");
|
||||
|
||||
public static Guid Instance__get__Parent_Class__for__Method_Binding__HACK { get; set; }
|
||||
// public static Guid Method__get__Parent_Class__HACK { get; } = new Guid("{89034a1c-50e5-47a1-abb8-076ece5343a8}");
|
||||
}
|
||||
// public static Guid Method__get__Parent_Class__HACK { get; } = new Guid("{89034a1c-50e5-47a1-abb8-076ece5343a8}");
|
||||
}
|
||||
public static class ConditionalSelectAttribute
|
||||
{
|
||||
// public static Guid Method__get__Abbreviation { get; } = new Guid("{f0c64709-385d-481b-8f58-83e507fb261c}");
|
||||
@ -231,6 +232,7 @@ namespace Mocha.Core
|
||||
{
|
||||
public static Guid BuildDynamicInstanceOp { get; } = new Guid("{622edf0d-5e3d-49fd-9764-33aa304addf4}");
|
||||
public static Guid FilterByTypeOp { get; } = new Guid("{8344a933-bb49-4d1c-b92a-a044fc9b9611}");
|
||||
public static Guid CombineSetsOp { get; } = new Guid("{a98844a5-ede8-4b4d-a94e-5f6f15db75c0}");
|
||||
}
|
||||
|
||||
[ExportEntities(Prefix = "IDC_", Suffix = null)]
|
||||
@ -242,13 +244,16 @@ namespace Mocha.Core
|
||||
/// </summary>
|
||||
public static Guid ProcessUpdatesMethod { get; } = new Guid("{f042c68d-8187-4dd6-93fa-7119bb949a16}");
|
||||
public static Guid GetAttributeMethod { get; } = new Guid("{c3ecf8c9-597f-417b-ad65-fae0401719c6}"); // 12
|
||||
// Perform System Routine Method - 13
|
||||
// Perform System Routine Method - 13
|
||||
public static Guid GetReferencedAttributeMethod { get; } = new Guid("{9205c54e-921a-484c-9be2-3d3deb877474}"); // 18
|
||||
public static Guid SelectFromInstanceSetMethod { get; } = new Guid("{130637B4-17A7-4394-8F4D-E83A79114E6C}"); // 19
|
||||
public static Guid EvaluateBooleanExpressionMethod { get; } = new Guid("{e1529108-2f84-4a4c-89b3-a647bc3e41d7}"); // 24
|
||||
// AR - Assign Relationship Method - 25
|
||||
// AR - Assign Relationship Method - 25
|
||||
public static Guid GetReferencedInstanceSetMethod { get; } = new Guid("{bcfd0d64-3eba-4a97-9622-f3a960877d24}"); // 26
|
||||
// BEM - Build Element Method - 29
|
||||
/// <summary>
|
||||
/// BEM - Build Element Method [1$29]
|
||||
/// </summary>
|
||||
public static Guid BuildElementMethod { get; } = new Guid("{c8f25550-0895-4e05-b4a0-f319a7ffcc4c}");
|
||||
public static Guid BuildAttributeMethod { get; } = new Guid("{e5879955-0093-48c8-8042-813168578af2}"); // 30
|
||||
/// <summary>
|
||||
/// CN - Calculate Numeric Method
|
||||
@ -294,17 +299,17 @@ namespace Mocha.Core
|
||||
public static Guid AssignAttributeMethod { get; } = new Guid("{3312A789-3B7A-4478-B329-4FF781504F9C}");
|
||||
// CS - Compare Instance Sets Method - 91
|
||||
public static Guid CalculateDateMethod { get; } = new Guid("{1e58e284-56eb-42b4-88b9-e0a691559fa6}"); // 92
|
||||
// EC - Evaluate Conditions Method - 94
|
||||
// SIM - Spawn Internal Message Method - 169
|
||||
// BWSR - Build Web Service Response Method - 171
|
||||
// GRE - Get Referenced Element Method - 197
|
||||
// EC - Evaluate Conditions Method - 94
|
||||
// SIM - Spawn Internal Message Method - 169
|
||||
// BWSR - Build Web Service Response Method - 171
|
||||
// GRE - Get Referenced Element Method - 197
|
||||
public static Guid GetRelationshipMethod { get; } = new Guid("{d53c9232-89ef-4cca-8520-261da6787450}"); // 207
|
||||
// IWS - Invoke Web Service Method - 208
|
||||
// IWS - Invoke Web Service Method - 208
|
||||
public static Guid InstanceOpMethod { get; } = new Guid("{4c814982-938f-4116-bdc1-827bae6a5f71}");
|
||||
public static Guid ConditionalSelectAttributeMethod { get; } = new Guid("{d534a369-321e-4c32-bd7f-8ff2017f191e}"); // 13038
|
||||
// SSC - Conditional Select from Instance Set Method - 13039
|
||||
// SSC - Conditional Select from Instance Set Method - 13039
|
||||
public static Guid ConditionalSelectFromInstanceSetMethod { get; } = new Guid("{ffea8e52-06e5-4e95-8c40-da3ba54ce95f}"); // 13039
|
||||
}
|
||||
}
|
||||
public static class SystemAttributeRoutines
|
||||
{
|
||||
public static Guid GetRuntimeVersion { get; } = new Guid("{dc4e6c8d-936d-457f-90e9-af47e229b80c}");
|
||||
@ -314,7 +319,7 @@ namespace Mocha.Core
|
||||
public static Guid GetIPAddress { get; } = new Guid("{45411e57-ef6e-44f5-8801-603e567d73d4}");
|
||||
public static Guid UpdateMochafile { get; } = new Guid("{9c3ae605-b8a0-4e68-9225-96674a9fb34e}");
|
||||
public static Guid GetGlobalIdentifier { get; } = new Guid("{1a7ebec3-dc02-4c9b-a5df-0c72646453c9}");
|
||||
}
|
||||
}
|
||||
public static class SystemInstanceSetRoutines
|
||||
{
|
||||
// public static Guid SystemInstanceSetRoutine { get; } = new Guid("{d17a6d27-da03-4b5d-9256-f67f978f403d}");
|
||||
@ -498,14 +503,14 @@ namespace Mocha.Core
|
||||
}
|
||||
public static class Languages
|
||||
{
|
||||
public static Guid English { get; } = new Guid ("{68BB6038-A4B5-4EE1-AAE9-326494942062}");
|
||||
public static Guid Spanish { get; } = new Guid ("{6dc357cb-37c3-43ed-ae13-6259fb109213}");
|
||||
public static Guid French { get; } = new Guid ("{6bf0cf09-87c9-4e21-b360-7eb5a1c279de}");
|
||||
public static Guid German { get; } = new Guid ("{c7c1d740-0d3c-493f-ab0b-fe1b42546d0a}");
|
||||
public static Guid Italian { get; } = new Guid ("{cf165170-0680-4a41-8f88-88f34b2b1986}");
|
||||
public static Guid Chinese { get; } = new Guid ("{6f908a9b-7464-4a16-aed9-7eccb8d39032}");
|
||||
public static Guid Japanese { get; } = new Guid ("{1e16de9d-0e49-4a79-b690-4905c46a94cc}");
|
||||
public static Guid Korean { get; } = new Guid ("{d03a795e-906b-49ee-87ea-c1bef4b8ee9a}");
|
||||
public static Guid English { get; } = new Guid("{68BB6038-A4B5-4EE1-AAE9-326494942062}");
|
||||
public static Guid Spanish { get; } = new Guid("{6dc357cb-37c3-43ed-ae13-6259fb109213}");
|
||||
public static Guid French { get; } = new Guid("{6bf0cf09-87c9-4e21-b360-7eb5a1c279de}");
|
||||
public static Guid German { get; } = new Guid("{c7c1d740-0d3c-493f-ab0b-fe1b42546d0a}");
|
||||
public static Guid Italian { get; } = new Guid("{cf165170-0680-4a41-8f88-88f34b2b1986}");
|
||||
public static Guid Chinese { get; } = new Guid("{6f908a9b-7464-4a16-aed9-7eccb8d39032}");
|
||||
public static Guid Japanese { get; } = new Guid("{1e16de9d-0e49-4a79-b690-4905c46a94cc}");
|
||||
public static Guid Korean { get; } = new Guid("{d03a795e-906b-49ee-87ea-c1bef4b8ee9a}");
|
||||
}
|
||||
public static class GroupLayoutOptions
|
||||
{
|
||||
@ -532,6 +537,15 @@ namespace Mocha.Core
|
||||
public static Guid ParentClass { get; } = new Guid("{98da8ac1-1fea-4cb4-a278-0c5460e625fd}");
|
||||
public static Guid DestinationClassForRelationship { get; } = new Guid("{cc6bf015-ea36-4cc5-8855-5047095affee}");
|
||||
public static Guid Set { get; } = new Guid("{40565aa8-892b-4a36-9a8e-54d55d1c6efe}");
|
||||
public static Guid SetA { get; } = new Guid("{6a41b0e4-6089-45f6-8996-901e66d36f53}");
|
||||
public static Guid SetB { get; } = new Guid("{4c7f240f-dd51-451d-afe9-73ba42971214}");
|
||||
}
|
||||
public static class SetFunctions
|
||||
{
|
||||
public static Guid Union { get; } = new Guid("{62f000a2-9b51-44ba-89dc-1d4735eb0015}");
|
||||
public static Guid Intersection { get; } = new Guid("{3445c281-271d-405f-ba7d-65ea1fdff0f0}");
|
||||
public static Guid Complement { get; } = new Guid("{fa69b904-315b-4bb1-80a6-c71708fbfde5}");
|
||||
public static Guid Difference { get; } = new Guid("{ec67f62d-387c-4179-9b03-0d9b70195688}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -147,6 +147,9 @@ namespace Mocha.Core
|
||||
public static Guid Build_Attribute_Method__builds_with__Build_Attribute_Method_Component { get; } = new Guid("{b4fad1b8-711c-4e84-82d0-e9a9e41e8aa7}");
|
||||
public static Guid Build_Attribute_Method_Component__uses__Executable_returning_Attribute { get; } = new Guid("{9d2acd01-5c6d-4a95-b77e-5261ba109540}");
|
||||
|
||||
public static Guid Build_Element_Method__has__BEM_Process { get; } = new Guid("{6f1811b0-4e58-4e66-8318-083b62aac5de}");
|
||||
public static Guid Build_Element_Method__returns__Element { get; } = new Guid("{4d13d021-7363-4131-b74a-241698c3f1d0}");
|
||||
|
||||
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}");
|
||||
|
||||
@ -310,8 +313,12 @@ namespace Mocha.Core
|
||||
public static Guid Audit_Line__has__Instance { get; } = new Guid("{c91807ed-0d73-4729-990b-d90750764fb5}");
|
||||
public static Guid Audit_Line__has__User { get; } = new Guid("{7c1e048d-3dcb-4473-9f2e-e21014a76aa5}");
|
||||
|
||||
public static Guid Method__has__Method_Parameter { get; } = new Guid("{c455dc79-ba9b-4a7c-af8e-9ca59dbe511f}");
|
||||
public static Guid Method_Parameter__for__Method { get; } = new Guid("{0bcb6e5b-5885-4747-843c-ed4c3d3dc234}");
|
||||
public static Guid Method_with_Static_and_Parms__uses_parm__Work_Data { get; } = new Guid("{5c7eafbe-952e-4720-b2ab-553414c274fc}");
|
||||
public static Guid Work_Data__parm_used_by__Method_with_Static_and_Parms { get; } = new Guid("{b11e9dfb-0755-4d59-bd26-f53c2f4f2454}");
|
||||
|
||||
public static Guid Method_with_Static_and_Parms__uses_required_parm__Work_Data { get; } = new Guid("{eeb6d2b5-48a7-4323-a9b0-e062010f681a}");
|
||||
public static Guid Work_Data__required_parm_used_by__Method_with_Static_and_Parms { get; } = new Guid("{d39ddadf-1497-4c7b-b29a-7c7668a6298a}");
|
||||
|
||||
public static Guid Method__returns__Attribute { get; } = new Guid("{eb015d32-0d4f-4647-b9b8-715097f4434b}");
|
||||
|
||||
public static Guid Detail_Page_Component__has_caption__Translation { get; } = new Guid("{4a15fa44-fb7b-4e26-8ce2-f36652792b48}");
|
||||
@ -440,6 +447,7 @@ namespace Mocha.Core
|
||||
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 BEM_Process__uses_order__Executable_returning_Attribute { get; } = new Guid("{0e1e6e71-e0ee-4b94-a912-ba1c6bebed2b}");
|
||||
|
||||
public static Guid Get_Instances_Method__returns__Work_Set { get; } = new Guid("{7d0f93b1-8c93-464e-a44d-d674f910b589}");
|
||||
public static Guid Get_Instances_Method__selects_instances_of__Class { get; } = new Guid("{c0b85d90-de8c-44c2-9420-c5e724ccdf2c}");
|
||||
@ -462,5 +470,7 @@ namespace Mocha.Core
|
||||
public static Guid Build_Dynamic_Instance_Op__assigns_instance_data_from__Parameter_Assignment { get; } = new Guid("{f5b1f747-fae3-4318-958b-a64f7cdd8b42}");
|
||||
|
||||
public static Guid Filter_By_Type_Op__uses__Class { get; } = new Guid("{2f5fddc8-5ab0-4c59-8a83-536a2ce0a30c}");
|
||||
|
||||
public static Guid Combine_Sets_Op__uses__Set_Function { get; } = new Guid("{b20e54d4-2535-44c0-8c99-0411f27a69df}");
|
||||
}
|
||||
}
|
||||
|
||||
@ -31,34 +31,51 @@ public class BuildAttributeMethodImplementation : MethodImplementation
|
||||
}
|
||||
|
||||
// InstanceHandle forInstance = (InstanceHandle) context.GetWorkData(irForClass);
|
||||
object? value = oms.UnsafeGetAttributeValue(method, oms.GetInstance(KnownAttributeGuids.Text.Value)); // initial value
|
||||
|
||||
if (value is string)
|
||||
if (oms.IsInstanceOf(returnsAttribute, oms.GetInstance(KnownInstanceGuids.Classes.TextAttribute)))
|
||||
{
|
||||
IEnumerable<InstanceHandle> buildsWithRambs = oms.GetRelatedInstances(method, oms.GetInstance(KnownRelationshipGuids.Build_Attribute_Method__builds_with__Build_Attribute_Method_Component));
|
||||
foreach (InstanceHandle ihComponent in buildsWithRambs)
|
||||
object? value = oms.UnsafeGetAttributeValue(method, oms.GetInstance(KnownAttributeGuids.Text.Value)); // initial value
|
||||
|
||||
if (value is string)
|
||||
{
|
||||
InstanceHandle ihRamb = oms.GetRelatedInstance(ihComponent, oms.GetInstance(KnownRelationshipGuids.Build_Attribute_Method_Component__uses__Executable_returning_Attribute));
|
||||
object? val = null;
|
||||
IEnumerable<InstanceHandle> buildsWithRambs = oms.GetRelatedInstances(method, oms.GetInstance(KnownRelationshipGuids.Build_Attribute_Method__builds_with__Build_Attribute_Method_Component));
|
||||
foreach (InstanceHandle ihComponent in buildsWithRambs)
|
||||
{
|
||||
InstanceHandle ihRamb = oms.GetRelatedInstance(ihComponent, oms.GetInstance(KnownRelationshipGuids.Build_Attribute_Method_Component__uses__Executable_returning_Attribute));
|
||||
object? val = null;
|
||||
|
||||
if (oms.IsInstanceOf(ihRamb, oms.GetInstance(KnownInstanceGuids.Classes.Attribute)))
|
||||
{
|
||||
val = null;
|
||||
}
|
||||
else if (oms.IsInstanceOf(ihRamb, oms.GetInstance(KnownInstanceGuids.Classes.Executable)))
|
||||
{
|
||||
InstanceHandle wd = oms.Execute(context, ihRamb);
|
||||
val = context.GetWorkData(wd);
|
||||
}
|
||||
if (oms.IsInstanceOf(ihRamb, oms.GetInstance(KnownInstanceGuids.Classes.Attribute)))
|
||||
{
|
||||
val = null;
|
||||
}
|
||||
else if (oms.IsInstanceOf(ihRamb, oms.GetInstance(KnownInstanceGuids.Classes.Executable)))
|
||||
{
|
||||
InstanceHandle wd = oms.Execute(context, ihRamb);
|
||||
val = context.GetWorkData(wd);
|
||||
}
|
||||
|
||||
if (val is string)
|
||||
{
|
||||
value = ((string)value) + (string)val;
|
||||
if (val is string)
|
||||
{
|
||||
value = ((string)value) + (string)val;
|
||||
}
|
||||
}
|
||||
}
|
||||
context.SetWorkData(returnsAttribute, value);
|
||||
}
|
||||
else if (oms.IsInstanceOf(returnsAttribute, oms.GetInstance(KnownInstanceGuids.Classes.NumericAttribute)))
|
||||
{
|
||||
object? value = oms.UnsafeGetAttributeValue(method, oms.GetInstance(KnownAttributeGuids.Numeric.Value)); // initial value
|
||||
|
||||
if (value is decimal)
|
||||
{
|
||||
context.SetWorkData(returnsAttribute, value);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
context.SetWorkData(returnsAttribute, value);
|
||||
return returnsAttribute;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,165 @@
|
||||
|
||||
using System.Text.Json.Nodes;
|
||||
using System.Threading.Tasks.Dataflow;
|
||||
using Mocha.Core.Oop;
|
||||
using Mocha.Core.UI;
|
||||
|
||||
namespace Mocha.Core.MethodImplementations;
|
||||
|
||||
public class BuildElementMethodImplementation : MethodImplementation
|
||||
{
|
||||
|
||||
public override Guid MethodClassGuid => KnownInstanceGuids.MethodClasses.BuildElementMethod;
|
||||
|
||||
protected override InstanceHandle ExecuteInternal(Oms oms, OmsContext context, InstanceHandle method)
|
||||
{
|
||||
InstanceHandle element = oms.GetRelatedInstance(method, oms.GetInstance(KnownRelationshipGuids.Build_Element_Method__returns__Element));
|
||||
InstanceHandle layout = oms.GetRelatedInstance(element, oms.GetInstance(KnownRelationshipGuids.Element__has__Layout));
|
||||
|
||||
if (oms.IsInstanceOf(layout, oms.GetInstance(KnownInstanceGuids.Classes.GroupLayout)))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
InstanceHandle bemProcess = oms.GetRelatedInstance(method, oms.GetInstance(KnownRelationshipGuids.Build_Element_Method__has__BEM_Process));
|
||||
|
||||
InstanceHandle loopInstanceSet = oms.GetRelatedInstance(bemProcess, oms.GetInstance(KnownRelationshipGuids.BEM_Process__uses_loop__Executable_returning_Instance_Set));
|
||||
object? instanceSet = oms.Evaluate(context, loopInstanceSet, InstanceHandle.Empty);
|
||||
if (instanceSet is IEnumerable<InstanceHandle> ihs)
|
||||
{
|
||||
JsonObject obj = BuildGrid(oms, element, ihs);
|
||||
context.SetWorkData(element, obj);
|
||||
}
|
||||
|
||||
return element;
|
||||
}
|
||||
|
||||
private JsonObject BuildGrid(Oms oms, InstanceHandle element, IEnumerable<InstanceHandle> instances)
|
||||
{
|
||||
IEnumerable<InstanceHandle> ihCols = oms.GetRelatedInstances(element, oms.GetInstance(KnownRelationshipGuids.Element__has__Element_Content));
|
||||
JsonObject obj = new JsonObject();
|
||||
obj.Add("widget", "grid");
|
||||
obj.Add("iid", oms.GetInstanceKey(element).ToString());
|
||||
obj.Add("enabled", false);
|
||||
|
||||
int j = 1;
|
||||
JsonArray aryCols = new JsonArray();
|
||||
foreach (InstanceHandle ihCol in ihCols)
|
||||
{
|
||||
JsonObject objCol = BuildGridColumn(oms, ihCol, j);
|
||||
aryCols.Add(objCol);
|
||||
j++;
|
||||
}
|
||||
obj.Add("columns", aryCols);
|
||||
|
||||
JsonArray aryRows = new JsonArray();
|
||||
int i = 1;
|
||||
foreach (InstanceHandle ih in instances)
|
||||
{
|
||||
JsonObject objRow = new JsonObject();
|
||||
objRow.Add("widget", "row");
|
||||
objRow.Add("iid", oms.GetInstanceKey(element).ToString());
|
||||
objRow.Add("enabled", false);
|
||||
objRow.Add("rowIndex", i);
|
||||
|
||||
JsonObject objCells = new JsonObject();
|
||||
j = 1;
|
||||
foreach (InstanceHandle ihCol in ihCols)
|
||||
{
|
||||
JsonObject objCell = BuildGridCell(oms, ih, ihCol);
|
||||
objCells.Add("46." + j.ToString(), objCell);
|
||||
j++;
|
||||
}
|
||||
|
||||
objRow.Add("cellsMap", objCells);
|
||||
aryRows.Add(objRow);
|
||||
|
||||
i++;
|
||||
}
|
||||
obj.Add("rows", aryRows);
|
||||
return obj;
|
||||
}
|
||||
|
||||
private JsonObject BuildGridColumn(Oms oms, InstanceHandle elementContent, int index)
|
||||
{
|
||||
JsonObject objCol = new JsonObject();
|
||||
objCol.Add("widget", "column");
|
||||
objCol.Add("ecid", oms.GetInstanceKey(elementContent).ToString());
|
||||
|
||||
InstanceHandle elementContentInstance = oms.GetRelatedInstance(elementContent, oms.GetInstance(KnownRelationshipGuids.Element_Content__has__Instance));
|
||||
if (elementContentInstance != InstanceHandle.Empty)
|
||||
{
|
||||
objCol.Add("iid", oms.GetInstanceKey(elementContentInstance).ToString());
|
||||
}
|
||||
objCol.Add("enabled", false);
|
||||
objCol.Add("label", oms.GetLabelForUIElement(elementContent));
|
||||
|
||||
JsonObject objCellShell = new JsonObject();
|
||||
objCellShell.Add("widget", "monikerList");
|
||||
objCol.Add("cellShell", objCellShell);
|
||||
|
||||
objCol.Add("columnId", "46." + index.ToString());
|
||||
objCol.Add("sortableAndFilterable", true);
|
||||
// objCol.Add("propertyName", "");
|
||||
return objCol;
|
||||
}
|
||||
|
||||
private JsonObject BuildGridCell(Oms oms, InstanceHandle targetInstance, InstanceHandle elementContent)
|
||||
{
|
||||
JsonObject objCell = new JsonObject();
|
||||
objCell.Add("ecid", oms.GetInstanceKey(elementContent).ToString());
|
||||
|
||||
InstanceHandle ecInst = oms.GetRelatedInstance(elementContent, oms.GetInstance(KnownRelationshipGuids.Element_Content__has__Instance));
|
||||
objCell.Add("iid", oms.GetInstanceKey(ecInst).ToString());
|
||||
|
||||
objCell.Add("label", oms.GetLabelForUIElement(elementContent));
|
||||
//objCell.Add("propertyName", "");
|
||||
|
||||
InstanceHandle do_NotEnterable = oms.GetInstance(KnownInstanceGuids.ElementContentDisplayOptions.NotEnterable);
|
||||
|
||||
IEnumerable<InstanceHandle> displayOptions = oms.GetRelatedInstances(elementContent, oms.GetInstance(KnownRelationshipGuids.Element_Content__has__Element_Content_Display_Option));
|
||||
if (displayOptions.Contains(do_NotEnterable))
|
||||
{
|
||||
objCell.Add("enabled", false);
|
||||
}
|
||||
// objCell.Add("helpText", "blah blah");
|
||||
|
||||
if (oms.IsInstanceOf(ecInst, oms.GetInstance(KnownInstanceGuids.Classes.TextAttribute)))
|
||||
{
|
||||
objCell.Add("widget", "text");
|
||||
objCell.Add("value", oms.GetAttributeValue<string>(targetInstance, ecInst));
|
||||
}
|
||||
else if (oms.IsInstanceOf(ecInst, oms.GetInstance(KnownInstanceGuids.Classes.BooleanAttribute)))
|
||||
{
|
||||
objCell.Add("widget", "checkBox");
|
||||
objCell.Add("value", oms.GetAttributeValue<bool>(targetInstance, ecInst));
|
||||
objCell.Add("text", oms.GetAttributeValue<bool>(targetInstance, ecInst) ? "Yes" : "No");
|
||||
}
|
||||
else if (oms.IsInstanceOf(ecInst, oms.GetInstance(KnownInstanceGuids.Classes.NumericAttribute)))
|
||||
{
|
||||
objCell.Add("widget", "number");
|
||||
objCell.Add("value", oms.GetAttributeValue<decimal>(targetInstance, ecInst));
|
||||
objCell.Add("text", oms.GetAttributeValue<decimal>(targetInstance, ecInst).ToString());
|
||||
objCell.Add("precision", 6);
|
||||
objCell.Add("format", "#0.######");
|
||||
}
|
||||
else if (oms.IsInstanceOf(ecInst, oms.GetInstance(KnownInstanceGuids.Classes.DateAttribute)))
|
||||
{
|
||||
objCell.Add("widget", "date");
|
||||
|
||||
DateTime dt = oms.GetAttributeValue<DateTime>(targetInstance, ecInst);
|
||||
JsonObject objDate = new JsonObject();
|
||||
objDate.Add("Y", dt.Year.ToString());
|
||||
objDate.Add("M", dt.Month.ToString().PadLeft(2, '0'));
|
||||
objDate.Add("D", dt.Day.ToString().PadLeft(2, '0'));
|
||||
objCell.Add("value", objDate);
|
||||
objCell.Add("text", dt.ToString());
|
||||
objCell.Add("dateTimePrecision", "DAY");
|
||||
}
|
||||
else
|
||||
{
|
||||
objCell.Add("widget", "monikerList");
|
||||
}
|
||||
return objCell;
|
||||
}
|
||||
}
|
||||
@ -15,6 +15,8 @@
|
||||
// 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.Text.Json.Nodes;
|
||||
|
||||
namespace Mocha.Core.MethodImplementations;
|
||||
|
||||
public class BuildUIResponseMethodImplementation : MethodImplementation
|
||||
@ -30,6 +32,45 @@ public class BuildUIResponseMethodImplementation : MethodImplementation
|
||||
throw new InvalidOperationException("no return Element specified for method");
|
||||
}
|
||||
|
||||
return returnsElement;
|
||||
InstanceHandle element = oms.Execute(context, returnsElement);
|
||||
object? data = context.GetWorkData(element);
|
||||
if (data is JsonObject objChild)
|
||||
{
|
||||
JsonObject objRoot = new JsonObject();
|
||||
objRoot.Add("widget", "root");
|
||||
objRoot.Add("body", objChild);
|
||||
|
||||
JsonObject objTitle = new JsonObject();
|
||||
// task like 2501$6 (View Organization) has EC which has display option `Display as Page Title`, in which
|
||||
// the title widget is a titleMonikerList with the sole instance being the organization currently being viewed
|
||||
objTitle.Add("widget", "titleMonikerList");
|
||||
objTitle.Add("label", "Page Title"); // this is the title as displayed in the Web browser title bar
|
||||
objTitle.Add("text", "Page Title"); // same as 'label'
|
||||
|
||||
InstanceHandle inst = oms.GetInstance(KnownAttributeGuids.Text.Token);
|
||||
|
||||
JsonArray ary = new JsonArray();
|
||||
JsonObject obj = CreateMoniker(oms, inst);
|
||||
ary.Add(obj);
|
||||
objTitle.Add("instances", ary);
|
||||
|
||||
objRoot.Add("title", objTitle);
|
||||
context.SetWorkData(element, objRoot);
|
||||
}
|
||||
|
||||
return element;
|
||||
}
|
||||
|
||||
private JsonObject CreateMoniker(Oms oms, InstanceHandle inst)
|
||||
{
|
||||
JsonObject obj = new JsonObject();
|
||||
obj.Add("widget", "moniker");
|
||||
obj.Add("instanceId", oms.GetInstanceKey(inst).ToString());
|
||||
obj.Add("text", oms.GetInstanceText(inst));
|
||||
obj.Add("rt", true); // whether Related Tasks should be shown
|
||||
obj.Add("pv", true); // whether Preview should be enabled
|
||||
obj.Add("v", true); // ???
|
||||
obj.Add("uxiTags", "ml-feedback-id="); // ???, something new
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
@ -69,6 +69,33 @@ public class InstanceOpMethodImplementation : MethodImplementation
|
||||
|
||||
context.SetWorkData(workSet, list);
|
||||
}
|
||||
else if (oms.IsInstanceOf(op, oms.GetInstance(KnownInstanceGuids.InstanceOpClasses.CombineSetsOp)))
|
||||
{
|
||||
InstanceHandle setFunction = oms.GetRelatedInstance(op, oms.GetInstance(KnownRelationshipGuids.Combine_Sets_Op__uses__Set_Function));
|
||||
InstanceHandle ihSetA = oms.GetInstance(KnownInstanceGuids.WorkSets.SetA);
|
||||
InstanceHandle ihSetB = oms.GetInstance(KnownInstanceGuids.WorkSets.SetB);
|
||||
|
||||
object? oSetA = oms.Evaluate(context, context.GetWorkData(ihSetA), InstanceHandle.Empty);
|
||||
object? oSetB = oms.Evaluate(context, context.GetWorkData(ihSetB), InstanceHandle.Empty);
|
||||
if (oSetA is IEnumerable<InstanceHandle> setA && oSetB is IEnumerable<InstanceHandle> setB)
|
||||
{
|
||||
if (setFunction == oms.GetInstance(KnownInstanceGuids.SetFunctions.Union))
|
||||
{
|
||||
IEnumerable<InstanceHandle> ih = setA.Union(setB);
|
||||
context.SetWorkData(workSet, ih);
|
||||
}
|
||||
else if (setFunction == oms.GetInstance(KnownInstanceGuids.SetFunctions.Intersection))
|
||||
{
|
||||
IEnumerable<InstanceHandle> ih = setA.Intersect(setB);
|
||||
context.SetWorkData(workSet, ih);
|
||||
}
|
||||
else if (setFunction == oms.GetInstance(KnownInstanceGuids.SetFunctions.Difference))
|
||||
{
|
||||
IEnumerable<InstanceHandle> ih = setA.Except(setB);
|
||||
context.SetWorkData(workSet, ih);
|
||||
}
|
||||
}
|
||||
}
|
||||
return workSet;
|
||||
}
|
||||
}
|
||||
|
||||
@ -26,6 +26,7 @@ using MBS.Core.Collections;
|
||||
using MBS.Core.Extensibility;
|
||||
using Mocha.Core.Logging;
|
||||
using Mocha.Core.Oop;
|
||||
using Mocha.Core.Oop.Methods;
|
||||
using Mocha.Core.Responses;
|
||||
using Mocha.Core.UI;
|
||||
|
||||
@ -266,6 +267,7 @@ public abstract class Oms
|
||||
UpdateSyntacticSugar<AccessModifier>(typeof(KnownInstanceGuids.AccessModifiers));
|
||||
UpdateSyntacticSugar<RelationalOperator>(typeof(KnownInstanceGuids.RelationalOperators));
|
||||
UpdateSyntacticSugar<ArithmeticOperator>(typeof(KnownInstanceGuids.ArithmeticOperators));
|
||||
UpdateSyntacticSugar<LogicalOperator>(typeof(KnownInstanceGuids.LogicalOperators));
|
||||
}
|
||||
}
|
||||
|
||||
@ -2175,6 +2177,10 @@ public abstract class Oms
|
||||
}
|
||||
}
|
||||
|
||||
public string GetLabelForUIElement(ElementContent parentElementContent)
|
||||
{
|
||||
return GetLabelForUIElement(parentElementContent.GetHandle());
|
||||
}
|
||||
public string GetLabelForUIElement(InstanceHandle parentElementContent)
|
||||
{
|
||||
InstanceHandle parentInstance = GetRelatedInstance(parentElementContent, GetInstance(KnownRelationshipGuids.Element_Content__has__Instance));
|
||||
@ -2451,8 +2457,7 @@ public abstract class Oms
|
||||
{
|
||||
foreach (InstanceHandle trueCondition in trueConditions)
|
||||
{
|
||||
InstanceHandle ret = Execute(context, trueCondition);
|
||||
object? retval = context.GetWorkData(ret);
|
||||
object? retval = Evaluate(context, trueCondition, InstanceHandle.Empty);
|
||||
if (retval is bool && ((bool)retval))
|
||||
{
|
||||
value = true;
|
||||
@ -2594,64 +2599,88 @@ public abstract class Oms
|
||||
throw new FormatException();
|
||||
}
|
||||
|
||||
public object? Evaluate(OmsContext context, InstanceHandle workDataInstance, InstanceHandle sourceInstance, object? defaultValue = null)
|
||||
public object? Evaluate(OmsContext context, object? workDataObject, InstanceHandle sourceInstance, object? defaultValue = null)
|
||||
{
|
||||
object? value = defaultValue;
|
||||
if (IsInstanceOf(workDataInstance, GetInstance(KnownInstanceGuids.Classes.TextAttribute)))
|
||||
if (workDataObject is InstanceHandle workDataInstance)
|
||||
{
|
||||
if (sourceInstance != InstanceHandle.Empty)
|
||||
if (IsInstanceOf(workDataInstance, GetInstance(KnownInstanceGuids.Classes.TextAttribute)))
|
||||
{
|
||||
// first check our target instance for the attribute. this MAY be empty
|
||||
value = GetAttributeValue<string>(sourceInstance, workDataInstance);
|
||||
if (sourceInstance != InstanceHandle.Empty)
|
||||
{
|
||||
// first check our target instance for the attribute. this MAY be empty
|
||||
value = GetAttributeValue<string>(sourceInstance, workDataInstance);
|
||||
}
|
||||
else
|
||||
{
|
||||
value = context.GetWorkData<string>(workDataInstance);
|
||||
}
|
||||
}
|
||||
else if (IsInstanceOf(workDataInstance, GetInstance(KnownInstanceGuids.Classes.BooleanAttribute)))
|
||||
{
|
||||
if (sourceInstance != InstanceHandle.Empty)
|
||||
{
|
||||
// first check our target instance for the attribute. this MAY be empty
|
||||
value = GetAttributeValue<bool>(sourceInstance, workDataInstance);
|
||||
}
|
||||
else
|
||||
{
|
||||
value = context.GetWorkData<bool>(workDataInstance);
|
||||
}
|
||||
}
|
||||
else if (IsInstanceOf(workDataInstance, GetInstance(KnownInstanceGuids.Classes.NumericAttribute)))
|
||||
{
|
||||
if (sourceInstance != InstanceHandle.Empty)
|
||||
{
|
||||
// first check our target instance for the attribute. this MAY be empty
|
||||
value = GetAttributeValue<decimal>(sourceInstance, workDataInstance);
|
||||
}
|
||||
else
|
||||
{
|
||||
value = context.GetWorkData<decimal>(workDataInstance);
|
||||
}
|
||||
}
|
||||
else if (IsInstanceOf(workDataInstance, GetInstance(KnownInstanceGuids.Classes.DateAttribute)))
|
||||
{
|
||||
if (sourceInstance != InstanceHandle.Empty)
|
||||
{
|
||||
// first check our target instance for the attribute. this MAY be empty
|
||||
value = GetAttributeValue<DateTime>(sourceInstance, workDataInstance);
|
||||
}
|
||||
else
|
||||
{
|
||||
value = context.GetWorkData<DateTime>(workDataInstance);
|
||||
}
|
||||
}
|
||||
else if (IsInstanceOf(workDataInstance, GetInstance(KnownInstanceGuids.Classes.WorkSet)))
|
||||
{
|
||||
if (sourceInstance != InstanceHandle.Empty)
|
||||
{
|
||||
// first check our target instance for the attribute. this MAY be empty
|
||||
// value = GetAttributeValue<DateTime>(sourceInstance, workDataInstance);
|
||||
}
|
||||
else
|
||||
{
|
||||
value = context.GetWorkData(workDataInstance);
|
||||
}
|
||||
}
|
||||
else if (IsInstanceOf(workDataInstance, GetInstance(KnownInstanceGuids.Classes.Executable)))
|
||||
{
|
||||
InstanceHandle workSet = Execute(context, workDataInstance);
|
||||
value = context.GetWorkData(workSet);
|
||||
}
|
||||
else
|
||||
{
|
||||
value = context.GetWorkData<string>(workDataInstance);
|
||||
}
|
||||
}
|
||||
else if (IsInstanceOf(workDataInstance, GetInstance(KnownInstanceGuids.Classes.BooleanAttribute)))
|
||||
{
|
||||
if (sourceInstance != InstanceHandle.Empty)
|
||||
{
|
||||
// first check our target instance for the attribute. this MAY be empty
|
||||
value = GetAttributeValue<bool>(sourceInstance, workDataInstance);
|
||||
}
|
||||
else
|
||||
{
|
||||
value = context.GetWorkData<bool>(workDataInstance);
|
||||
}
|
||||
}
|
||||
else if (IsInstanceOf(workDataInstance, GetInstance(KnownInstanceGuids.Classes.NumericAttribute)))
|
||||
{
|
||||
if (sourceInstance != InstanceHandle.Empty)
|
||||
{
|
||||
// first check our target instance for the attribute. this MAY be empty
|
||||
value = GetAttributeValue<decimal>(sourceInstance, workDataInstance);
|
||||
}
|
||||
else
|
||||
{
|
||||
value = context.GetWorkData<decimal>(workDataInstance);
|
||||
}
|
||||
}
|
||||
else if (IsInstanceOf(workDataInstance, GetInstance(KnownInstanceGuids.Classes.DateAttribute)))
|
||||
{
|
||||
if (sourceInstance != InstanceHandle.Empty)
|
||||
{
|
||||
// first check our target instance for the attribute. this MAY be empty
|
||||
value = GetAttributeValue<DateTime>(sourceInstance, workDataInstance);
|
||||
}
|
||||
else
|
||||
{
|
||||
value = context.GetWorkData<DateTime>(workDataInstance);
|
||||
context.SetWorkData(GetInstance(KnownInstanceGuids.WorkSets.TaskRelatedInstance), context.InitiatingInstance);
|
||||
|
||||
InstanceHandle workData = Execute(context, workDataInstance);
|
||||
object? val = context.GetWorkData(workData);
|
||||
value = val?.ToString();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
context.SetWorkData(GetInstance(KnownInstanceGuids.WorkSets.TaskRelatedInstance), context.InitiatingInstance);
|
||||
|
||||
InstanceHandle workData = Execute(context, workDataInstance);
|
||||
object? val = context.GetWorkData(workData);
|
||||
value = val?.ToString();
|
||||
value = workDataObject;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
@ -2680,4 +2709,21 @@ public abstract class Oms
|
||||
}
|
||||
return ih;
|
||||
}
|
||||
|
||||
public InstanceHandle GetMethodParameter(Method method, string name)
|
||||
{
|
||||
IEnumerable<InstanceHandle> optionalParms = GetRelatedInstances(method, GetInstance(KnownRelationshipGuids.Method_with_Static_and_Parms__uses_parm__Work_Data));
|
||||
IEnumerable<InstanceHandle> requiredParms = GetRelatedInstances(method, GetInstance(KnownRelationshipGuids.Method_with_Static_and_Parms__uses_required_parm__Work_Data));
|
||||
IEnumerable<InstanceHandle> parms = optionalParms.Union(requiredParms);
|
||||
|
||||
foreach (InstanceHandle parm in parms)
|
||||
{
|
||||
string l_name = GetAttributeValue<string>(parm, GetInstance(KnownAttributeGuids.Text.Name));
|
||||
if (name.Equals(l_name))
|
||||
{
|
||||
return parm;
|
||||
}
|
||||
}
|
||||
return InstanceHandle.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,4 +35,11 @@ public class OmsInstanceOpBuilder
|
||||
Oms.AssignRelationship(iop, Oms.GetInstance(KnownRelationshipGuids.Filter_By_Type_Op__uses__Class), usesClass.GetHandle());
|
||||
return new FilterByTypeOp(iop);
|
||||
}
|
||||
|
||||
public CombineSetsOp CreateCombineSetsOp(IInstanceReference setFunction)
|
||||
{
|
||||
InstanceHandle iop = Oms.CreateInstanceOf(Oms.GetInstance(KnownInstanceGuids.InstanceOpClasses.CombineSetsOp));
|
||||
Oms.AssignRelationship(iop, Oms.GetInstance(KnownRelationshipGuids.Combine_Sets_Op__uses__Set_Function), setFunction.GetHandle());
|
||||
return new CombineSetsOp(iop);
|
||||
}
|
||||
}
|
||||
@ -132,6 +132,25 @@ public class OmsMethodBuilder
|
||||
return new BuildAttributeMethod(method);
|
||||
}
|
||||
|
||||
public BuildAttributeMethod CreateBuildAttributeMethod(InstanceHandle forClassInstance, string verb, string name, AccessModifier accessModifier, bool isStatic, InstanceHandle returnsAttribute, object? initialValue = null)
|
||||
{
|
||||
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);
|
||||
if (initialValue is string strval)
|
||||
{
|
||||
Oms.SetAttributeValue(method, Oms.GetInstance(KnownAttributeGuids.Text.Value), strval);
|
||||
}
|
||||
else if (initialValue is decimal numval)
|
||||
{
|
||||
Oms.SetAttributeValue(method, Oms.GetInstance(KnownAttributeGuids.Numeric.Value), numval);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
return new BuildAttributeMethod(method);
|
||||
}
|
||||
|
||||
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);
|
||||
@ -348,8 +367,20 @@ public class OmsMethodBuilder
|
||||
return new CalculateDateMethod(method);
|
||||
}
|
||||
|
||||
public BuildUIResponseMethod CreateBuildUIResponseMethod(InstanceHandle forClassInstance, string verb, string name, AccessModifier accessModifier, bool isStatic, InstanceHandle usesExecutableReturningElement)
|
||||
{
|
||||
public BuildElementMethod CreateBuildElementMethod(InstanceHandle forClassInstance, string verb, string name, AccessModifier accessModifier, bool isStatic, InstanceHandle hasBemProcess, InstanceHandle returnsElement)
|
||||
{
|
||||
InstanceHandle method = CreateMethodBase(Oms.GetInstance(KnownInstanceGuids.MethodClasses.BuildElementMethod), forClassInstance, verb, name, accessModifier, isStatic);
|
||||
Oms.AssignRelationship(method, Oms.GetInstance(KnownRelationshipGuids.Build_Element_Method__has__BEM_Process), hasBemProcess);
|
||||
Oms.AssignRelationship(method, Oms.GetInstance(KnownRelationshipGuids.Build_Element_Method__returns__Element), returnsElement);
|
||||
return new BuildElementMethod(method);
|
||||
}
|
||||
|
||||
public BuildUIResponseMethod CreateBuildUIResponseMethod(InstanceHandle forClassInstance, string verb, string name, AccessModifier accessModifier, bool isStatic, IExecutableReturningElement usesExecutableReturningElement)
|
||||
{
|
||||
return CreateBuildUIResponseMethod(forClassInstance, verb, name, accessModifier, isStatic, usesExecutableReturningElement.GetHandle());
|
||||
}
|
||||
public BuildUIResponseMethod CreateBuildUIResponseMethod(InstanceHandle forClassInstance, string verb, string name, AccessModifier accessModifier, bool isStatic, InstanceHandle usesExecutableReturningElement)
|
||||
{
|
||||
InstanceHandle method = CreateMethodBase(Oms.GetInstance(KnownInstanceGuids.MethodClasses.BuildUIResponseMethod), forClassInstance, verb, name, accessModifier, isStatic);
|
||||
InstanceHandle r_Build_UI_Response_Method__uses__Executable_returning_Element = Oms.GetInstance(KnownRelationshipGuids.Build_UI_Response_Method__uses__Executable_returning_Element);
|
||||
if (usesExecutableReturningElement != InstanceHandle.Empty)
|
||||
@ -361,7 +392,7 @@ public class OmsMethodBuilder
|
||||
//? should we throw an exception here?
|
||||
}
|
||||
return new BuildUIResponseMethod(method);
|
||||
}
|
||||
}
|
||||
|
||||
public ControlTransactionMethod CreateControlTransactionMethod(InstanceHandle forClassInstance, string verb, string name, AccessModifier accessModifier, bool isStatic, InstanceHandle processesElement, BuildResponseMethodBinding usesBuildResponseMethodBinding)
|
||||
{
|
||||
|
||||
8
mocha-dotnet/src/lib/Mocha.Core/Oop/ElementContent.cs
Normal file
8
mocha-dotnet/src/lib/Mocha.Core/Oop/ElementContent.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace Mocha.Core.Oop;
|
||||
|
||||
public class ElementContent : ConcreteInstanceWrapper
|
||||
{
|
||||
public ElementContent(InstanceHandle handle) : base(handle)
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,8 @@
|
||||
namespace Mocha.Core.Oop.InstanceOps;
|
||||
|
||||
public class CombineSetsOp : InstanceOp
|
||||
{
|
||||
|
||||
public CombineSetsOp(InstanceHandle handle) : base(handle) { }
|
||||
|
||||
}
|
||||
@ -20,6 +20,13 @@ namespace Mocha.Core.Oop;
|
||||
|
||||
public class LogicalOperator : BooleanOperator
|
||||
{
|
||||
public override Guid ClassId => KnownInstanceGuids.Classes.LogicalOperator;
|
||||
public override Guid ClassId => KnownInstanceGuids.Classes.LogicalOperator;
|
||||
internal LogicalOperator(InstanceHandle handle) : base(handle) { }
|
||||
|
||||
public static LogicalOperator EqualTo { get; internal set; } = null;
|
||||
public static LogicalOperator NotEqualTo { get; internal set; } = null;
|
||||
public static LogicalOperator GreaterThan { get; internal set; } = null;
|
||||
public static LogicalOperator LessThan { get; internal set; } = null;
|
||||
public static LogicalOperator GreaterThanOrEqualTo { get; internal set; } = null;
|
||||
public static LogicalOperator LessThanOrEqualTo { get; internal set; } = null;
|
||||
}
|
||||
@ -0,0 +1,6 @@
|
||||
namespace Mocha.Core.Oop.Methods;
|
||||
|
||||
public class BuildElementMethod : MethodReturningElement
|
||||
{
|
||||
public BuildElementMethod(InstanceHandle handle) : base(handle) { }
|
||||
}
|
||||
@ -7,4 +7,5 @@ public interface IZqMethod
|
||||
string Name { get; set; }
|
||||
ZqDataType ReturnDataType { get; set; }
|
||||
ZqMethodCall? Executable { get; }
|
||||
ZqParameter.ZqParameterCollection Parameters { get; }
|
||||
}
|
||||
|
||||
@ -44,23 +44,32 @@ public struct ZqDataType
|
||||
return new ZqDataType(name, isArray);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
public override string ToString()
|
||||
{
|
||||
string str = Name;
|
||||
if (IsArray)
|
||||
{
|
||||
str += "*";
|
||||
}
|
||||
return str;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
public override bool Equals([NotNullWhen(true)] object? obj)
|
||||
{
|
||||
public override bool Equals([NotNullWhen(true)] object? obj)
|
||||
{
|
||||
if (obj is ZqDataType zqd)
|
||||
{
|
||||
return this.Name.Equals(zqd.Name) && this.IsArray == zqd.IsArray;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool operator ==(ZqDataType left, ZqDataType right)
|
||||
{
|
||||
return left.Equals(right);
|
||||
}
|
||||
public static bool operator !=(ZqDataType left, ZqDataType right)
|
||||
{
|
||||
return !left.Equals(right);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -8,6 +8,7 @@ public class ZqMethodReference : ZqExpression, IZqMethod
|
||||
public string Name { get; set; }
|
||||
public ZqDataType ReturnDataType { get; set; }
|
||||
public ZqMethodCall? Executable { get { return null; }}
|
||||
public ZqParameter.ZqParameterCollection Parameters { get; } = new ZqParameter.ZqParameterCollection();
|
||||
|
||||
public ZqMethodReference(string className, string methodName)
|
||||
{
|
||||
|
||||
168
mocha-dotnet/src/lib/Mocha.Zq/ZqOmsExtensions.cs
Normal file
168
mocha-dotnet/src/lib/Mocha.Zq/ZqOmsExtensions.cs
Normal file
@ -0,0 +1,168 @@
|
||||
using Mocha.Core;
|
||||
using Mocha.Core.Oop;
|
||||
using Mocha.Core.Oop.Methods;
|
||||
using Mocha.Zq.Methods;
|
||||
|
||||
namespace Mocha.Zq;
|
||||
|
||||
public static class ZqOmsExtensions
|
||||
{
|
||||
public static object? LoadZq(this Oms oms, ZqObject obj)
|
||||
{
|
||||
if (obj is ZqClass clasz)
|
||||
{
|
||||
InstanceHandle ih = oms.CreateInstanceOf(oms.GetInstance(KnownInstanceGuids.Classes.Class));
|
||||
oms.SetAttributeValue(ih, oms.GetInstance(KnownAttributeGuids.Text.Name), clasz.Name);
|
||||
ApplyAccessModifier(oms, clasz, ih);
|
||||
|
||||
foreach (ZqMethod method in clasz.Functions)
|
||||
{
|
||||
Dictionary<ZqParameter, InstanceHandle> createdParms = new Dictionary<ZqParameter, InstanceHandle>();
|
||||
InstanceHandle ihMethod = InstanceHandle.Empty;
|
||||
if (method is ZqConditionalSelectAttributeMethod)
|
||||
{
|
||||
ihMethod = oms.CreateInstanceOf(oms.GetInstance(KnownInstanceGuids.MethodClasses.ConditionalSelectAttributeMethod));
|
||||
}
|
||||
|
||||
if (ihMethod != InstanceHandle.Empty)
|
||||
{
|
||||
oms.SetAttributeValue(ihMethod, oms.GetInstance(KnownAttributeGuids.Text.Name), method.Name);
|
||||
oms.AssignRelationship(ih, oms.GetInstance(KnownRelationshipGuids.Class__has__Method), ihMethod);
|
||||
|
||||
foreach (ZqParameter parm in method.Parameters)
|
||||
{
|
||||
if (parm.DataType == ZqDataType.Text)
|
||||
{
|
||||
InstanceHandle parmInst = oms.CreateInstanceOf(oms.GetInstance(KnownInstanceGuids.Classes.TextAttribute));
|
||||
oms.SetAttributeValue(parmInst, oms.GetInstance(KnownAttributeGuids.Text.Name), parm.Name);
|
||||
oms.AssignRelationship(ihMethod, oms.GetInstance(KnownRelationshipGuids.Method_with_Static_and_Parms__uses_parm__Work_Data), parmInst);
|
||||
createdParms[parm] = parmInst;
|
||||
}
|
||||
else if (parm.DataType == ZqDataType.Integer)
|
||||
{
|
||||
InstanceHandle parmInst = oms.CreateInstanceOf(oms.GetInstance(KnownInstanceGuids.Classes.NumericAttribute));
|
||||
oms.SetAttributeValue(parmInst, oms.GetInstance(KnownAttributeGuids.Text.Name), parm.Name);
|
||||
oms.AssignRelationship(ihMethod, oms.GetInstance(KnownRelationshipGuids.Method_with_Static_and_Parms__uses_parm__Work_Data), parmInst);
|
||||
createdParms[parm] = parmInst;
|
||||
}
|
||||
}
|
||||
|
||||
if (method is ZqConditionalSelectAttributeMethod sac)
|
||||
{
|
||||
foreach (ZqConditionalSelectAttributeCase _case in sac.Cases)
|
||||
{
|
||||
InstanceHandle ihCase = oms.CreateInstanceOf(oms.GetInstance(KnownInstanceGuids.Classes.ConditionalSelectAttributeCase));
|
||||
|
||||
foreach (ZqCondition condition in _case.TrueConditions)
|
||||
{
|
||||
if (method.Parameters.Contains(condition.Variable))
|
||||
{
|
||||
Core.Oop.BooleanOperator? booleanOp = null;
|
||||
InstanceHandle attr = createdParms[method.Parameters[condition.Variable]];
|
||||
if (condition.Operator == "==")
|
||||
{
|
||||
booleanOp = Core.Oop.LogicalOperator.EqualTo;
|
||||
}
|
||||
else if (condition.Operator == "!=")
|
||||
{
|
||||
booleanOp = Core.Oop.LogicalOperator.NotEqualTo;
|
||||
}
|
||||
else if (condition.Operator == ">")
|
||||
{
|
||||
booleanOp = Core.Oop.LogicalOperator.GreaterThan;
|
||||
}
|
||||
else if (condition.Operator == "<")
|
||||
{
|
||||
booleanOp = Core.Oop.LogicalOperator.LessThan;
|
||||
}
|
||||
else if (condition.Operator == ">=")
|
||||
{
|
||||
booleanOp = Core.Oop.LogicalOperator.GreaterThanOrEqualTo;
|
||||
}
|
||||
else if (condition.Operator == "<=")
|
||||
{
|
||||
booleanOp = Core.Oop.LogicalOperator.LessThanOrEqualTo;
|
||||
}
|
||||
|
||||
BuildAttributeMethod ba = oms.MethodBuilder.CreateBuildAttributeMethod(ih, "__compiled", String.Format("trueCondition{0}value2", _case.TrueConditions.IndexOf(condition)), Core.Oop.AccessModifier.Private, true, oms.GetInstance(KnownAttributeGuids.Numeric.PrimaryOperandValue), Decimal.Parse(condition.Value));
|
||||
ReturnAttributeMethodBinding ramb = ba.CreateMethodBinding(oms);
|
||||
|
||||
EvaluateBooleanExpressionMethod trueCondition = oms.MethodBuilder.CreateEvaluateBooleanExpressionMethod(ih, "__compiled", String.Format("trueCondition{0}", _case.TrueConditions.IndexOf(condition)), Core.Oop.AccessModifier.Private, true, oms.GetInstance(KnownAttributeGuids.Boolean.EvaluateWorkSet), attr, booleanOp, ramb);
|
||||
oms.AssignRelationship(ihCase, oms.GetInstance(KnownRelationshipGuids.Condition_Group__has_true_condition__Executable_returning_Work_Data), trueCondition.CreateMethodBinding(oms));
|
||||
}
|
||||
}
|
||||
foreach (ZqCondition condition in _case.FalseConditions)
|
||||
{
|
||||
if (method.Parameters.Contains(condition.Variable))
|
||||
{
|
||||
Core.Oop.BooleanOperator? booleanOp = null;
|
||||
InstanceHandle attr = createdParms[method.Parameters[condition.Variable]];
|
||||
if (condition.Operator == "==")
|
||||
{
|
||||
booleanOp = Core.Oop.LogicalOperator.EqualTo;
|
||||
}
|
||||
else if (condition.Operator == "!=")
|
||||
{
|
||||
booleanOp = Core.Oop.LogicalOperator.NotEqualTo;
|
||||
}
|
||||
else if (condition.Operator == ">")
|
||||
{
|
||||
booleanOp = Core.Oop.LogicalOperator.GreaterThan;
|
||||
}
|
||||
else if (condition.Operator == "<")
|
||||
{
|
||||
booleanOp = Core.Oop.LogicalOperator.LessThan;
|
||||
}
|
||||
else if (condition.Operator == ">=")
|
||||
{
|
||||
booleanOp = Core.Oop.LogicalOperator.GreaterThanOrEqualTo;
|
||||
}
|
||||
else if (condition.Operator == "<=")
|
||||
{
|
||||
booleanOp = Core.Oop.LogicalOperator.LessThanOrEqualTo;
|
||||
}
|
||||
|
||||
BuildAttributeMethod ba = oms.MethodBuilder.CreateBuildAttributeMethod(ih, "__compiled", String.Format("falseCondition{0}value2", _case.FalseConditions.IndexOf(condition)), Core.Oop.AccessModifier.Private, true, oms.GetInstance(KnownAttributeGuids.Numeric.PrimaryOperandValue), Decimal.Parse(condition.Value));
|
||||
ReturnAttributeMethodBinding ramb = ba.CreateMethodBinding(oms);
|
||||
|
||||
EvaluateBooleanExpressionMethod trueCondition = oms.MethodBuilder.CreateEvaluateBooleanExpressionMethod(ih, "__compiled", String.Format("falseCondition{0}", _case.FalseConditions.IndexOf(condition)), Core.Oop.AccessModifier.Private, true, oms.GetInstance(KnownAttributeGuids.Boolean.EvaluateWorkSet), attr, booleanOp, ramb);
|
||||
oms.AssignRelationship(ihCase, oms.GetInstance(KnownRelationshipGuids.Condition_Group__has_false_condition__Executable_returning_Work_Data), trueCondition.CreateMethodBinding(oms));
|
||||
}
|
||||
}
|
||||
oms.AssignRelationship(ihMethod, oms.GetInstance(KnownRelationshipGuids.Conditional_Select_Attribute_Method__has__Conditional_Select_Attribute_Case), ihCase);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return new Mocha.Core.Oop.Class(ih);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void ApplyAccessModifier(Oms oms, ZqClass clasz, InstanceHandle ih)
|
||||
{
|
||||
switch (clasz.AccessModifier)
|
||||
{
|
||||
case ZqAccessModifier.Public:
|
||||
{
|
||||
oms.AssignRelationship(ih, oms.GetInstance(KnownRelationshipGuids.Metadata_With_Access_Modifier__has__Access_Modifier), oms.GetInstance(KnownInstanceGuids.AccessModifiers.Public));
|
||||
break;
|
||||
}
|
||||
case ZqAccessModifier.Private:
|
||||
{
|
||||
oms.AssignRelationship(ih, oms.GetInstance(KnownRelationshipGuids.Metadata_With_Access_Modifier__has__Access_Modifier), oms.GetInstance(KnownInstanceGuids.AccessModifiers.Private));
|
||||
break;
|
||||
}
|
||||
case ZqAccessModifier.Protected:
|
||||
{
|
||||
oms.AssignRelationship(ih, oms.GetInstance(KnownRelationshipGuids.Metadata_With_Access_Modifier__has__Access_Modifier), oms.GetInstance(KnownInstanceGuids.AccessModifiers.Protected));
|
||||
break;
|
||||
}
|
||||
// default:
|
||||
// {
|
||||
// oms.AssignRelationship(ih, oms.GetInstance(KnownRelationshipGuids.Metadata_With_Access_Modifier__has__Access_Modifier), oms.GetInstance(KnownInstanceGuids.AccessModifiers.RootA2));
|
||||
// break;
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -7,11 +7,38 @@ public class ZqParameter
|
||||
public class ZqParameterCollection
|
||||
: System.Collections.ObjectModel.Collection<ZqParameter>
|
||||
{
|
||||
private Dictionary<string, ZqParameter> _itemsByName = new Dictionary<string, ZqParameter>();
|
||||
public bool Contains(string name)
|
||||
{
|
||||
return _itemsByName.ContainsKey(name);
|
||||
}
|
||||
|
||||
public ZqParameter this[string name]
|
||||
{
|
||||
get
|
||||
{
|
||||
return _itemsByName[name];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
protected override void ClearItems()
|
||||
{
|
||||
base.ClearItems();
|
||||
_itemsByName.Clear();
|
||||
}
|
||||
protected override void InsertItem(int index, ZqParameter item)
|
||||
{
|
||||
base.InsertItem(index, item);
|
||||
_itemsByName[item.Name] = item;
|
||||
}
|
||||
protected override void RemoveItem(int index)
|
||||
{
|
||||
_itemsByName.Remove(this[index].Name);
|
||||
base.RemoveItem(index);
|
||||
}
|
||||
}
|
||||
|
||||
public string Name { get; set; }
|
||||
public string Name { get; set; }
|
||||
public ZqDataType DataType { get; set; }
|
||||
|
||||
public ZqParameter(string name, ZqDataType dataType)
|
||||
|
||||
@ -449,6 +449,7 @@ public class ZqParser
|
||||
|
||||
private ZqMethod? ParseFunction2(string pp, ref int j, ref ZqDefParms defparms)
|
||||
{
|
||||
ZqMethod? retval = null;
|
||||
string functionName = ReadUntil(pp, ref j, '(', false).Trim();
|
||||
List<ZqParameter> parmListList = new List<ZqParameter>();
|
||||
string parmlist = ReadUntil(pp, ref j, ')', false);
|
||||
@ -524,7 +525,7 @@ public class ZqParser
|
||||
object val = ParseValue(value);
|
||||
ZqMethod func = new ZqSimpleReturnMethod(functionName, val);
|
||||
func.ReturnDataType = ZqDataType.Parse(returnDataType);
|
||||
return func;
|
||||
retval = func;
|
||||
}
|
||||
else if (!funcBody.Contains("\n"))
|
||||
{
|
||||
@ -536,13 +537,13 @@ public class ZqParser
|
||||
object? val = ParseValue(value);
|
||||
if (val is string)
|
||||
{
|
||||
return new ZqBuildAttributeMethod(functionName, val);
|
||||
retval = new ZqBuildAttributeMethod(functionName, val);
|
||||
}
|
||||
else if (val is ZqObject)
|
||||
{
|
||||
ZqMethod func = new ZqSimpleReturnMethod(functionName, (ZqObject)val);
|
||||
func.ReturnDataType = ZqDataType.Parse(returnDataType);
|
||||
return func;
|
||||
retval = func;
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -565,7 +566,7 @@ public class ZqParser
|
||||
{
|
||||
((IZqMethod)expr).Name = functionName;
|
||||
((IZqMethod)expr).ReturnDataType = ZqDataType.Parse(returnDataType);
|
||||
return (ZqMethod)expr;
|
||||
retval = (ZqMethod)expr;
|
||||
}
|
||||
else if (expr == null)
|
||||
{
|
||||
@ -610,7 +611,7 @@ public class ZqParser
|
||||
object rv = null;
|
||||
if (context.Variables.ContainsKey(varr.Name))
|
||||
{
|
||||
return new ZqBuildAttributeMethod(functionName, context.Variables[varr.Name]);
|
||||
retval = new ZqBuildAttributeMethod(functionName, context.Variables[varr.Name]);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -630,7 +631,15 @@ public class ZqParser
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
if (retval != null)
|
||||
{
|
||||
foreach (ZqParameter parm in parmListList)
|
||||
{
|
||||
retval.Parameters.Add(parm);
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
private object? ParseValue(string value)
|
||||
|
||||
@ -0,0 +1,113 @@
|
||||
// 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.Text.Json.Nodes;
|
||||
using Mocha.Core.Oop;
|
||||
using Mocha.Core.Oop.Methods;
|
||||
|
||||
namespace Mocha.Core.Tests.MethodTests;
|
||||
|
||||
public class BuildUIResponseMethodTests : MethodTestsBase
|
||||
{
|
||||
|
||||
[Test]
|
||||
public void Test1()
|
||||
{
|
||||
InstanceHandle irTestClass = Oms.GetInstance(TEST_CLASS_GUID);
|
||||
Assert.That(irTestClass, Is.Not.EqualTo(InstanceHandle.Empty));
|
||||
|
||||
InstanceHandle a_Name = Oms.GetInstance(KnownAttributeGuids.Text.Name);
|
||||
InstanceHandle a_Index = Oms.GetInstance(KnownAttributeGuids.Numeric.Index);
|
||||
InstanceHandle a_Static = Oms.GetInstance(KnownAttributeGuids.Boolean.Static);
|
||||
Oms.AddAttribute(irTestClass, a_Name);
|
||||
Oms.AddAttribute(irTestClass, a_Index);
|
||||
Oms.AddAttribute(irTestClass, a_Static);
|
||||
|
||||
InstanceHandle i_TestClass1 = Oms.CreateInstanceOf(irTestClass);
|
||||
InstanceHandle i_TestClass2 = Oms.CreateInstanceOf(irTestClass);
|
||||
|
||||
OmsMethodBuilder methodBuilder = new OmsMethodBuilder(Oms);
|
||||
WorkSet ws = Oms.CreateWorkSet("test");
|
||||
|
||||
Oms.SetAttributeValue(i_TestClass1, a_Name, "Test Class Instance 1");
|
||||
Oms.SetAttributeValue(i_TestClass2, a_Name, "Another Test Instance");
|
||||
|
||||
Oms.SetAttributeValue(i_TestClass1, a_Index, 42M);
|
||||
Oms.SetAttributeValue(i_TestClass2, a_Index, 36M);
|
||||
|
||||
Oms.SetAttributeValue(i_TestClass1, a_Static, true);
|
||||
Oms.SetAttributeValue(i_TestClass2, a_Static, false);
|
||||
|
||||
Method gsi = methodBuilder.CreateGetSpecifiedInstancesMethod(irTestClass, "get", "Test Class Instances", ws, new InstanceHandle[]
|
||||
{
|
||||
i_TestClass1,
|
||||
i_TestClass2
|
||||
});
|
||||
|
||||
MethodReturningAttribute gaOrder = methodBuilder.CreateGetAttributeMethod(irTestClass, "get", "Order", Oms.GetInstance(KnownAttributeGuids.Text.Order));
|
||||
ReturnAttributeMethodBinding rambOrder = gaOrder.CreateMethodBinding(Oms);
|
||||
|
||||
InstanceHandle bemProcess = Oms.CreateInstanceOf(Oms.GetInstance(KnownInstanceGuids.Classes.BEMProcess));
|
||||
|
||||
// loop on the GSI defined above
|
||||
Oms.AssignRelationship(bemProcess, Oms.GetInstance(KnownRelationshipGuids.BEM_Process__uses_loop__Executable_returning_Instance_Set), gsi.GetHandle());
|
||||
|
||||
// Oms.AssignRelationship(bemProcess, Oms.GetInstance(KnownRelationshipGuids.BEM_Process__uses_build__Executable_returning_Work_Data), huh);
|
||||
Oms.AssignRelationship(bemProcess, Oms.GetInstance(KnownRelationshipGuids.BEM_Process__uses_order__Executable_returning_Attribute), rambOrder);
|
||||
|
||||
InstanceHandle elem = Oms.CreateInstanceOf(Oms.GetInstance(KnownInstanceGuids.Classes.Element));
|
||||
InstanceHandle layout = Oms.CreateInstanceOf(Oms.GetInstance(KnownInstanceGuids.Classes.GroupLayout));
|
||||
Oms.AssignRelationship(elem, Oms.GetInstance(KnownRelationshipGuids.Element__has__Layout), layout);
|
||||
|
||||
InstanceHandle ecName = Oms.CreateInstanceOf(Oms.GetInstance(KnownInstanceGuids.Classes.ElementContent));
|
||||
Oms.AssignRelationship(ecName, Oms.GetInstance(KnownRelationshipGuids.Element_Content__has__Instance), a_Name);
|
||||
|
||||
InstanceHandle ecIndex = Oms.CreateInstanceOf(Oms.GetInstance(KnownInstanceGuids.Classes.ElementContent));
|
||||
Oms.AssignRelationship(ecIndex, Oms.GetInstance(KnownRelationshipGuids.Element_Content__has__Instance), a_Index);
|
||||
|
||||
InstanceHandle ecEditable = Oms.CreateInstanceOf(Oms.GetInstance(KnownInstanceGuids.Classes.ElementContent));
|
||||
Oms.AssignRelationship(ecEditable, Oms.GetInstance(KnownRelationshipGuids.Element_Content__has__Instance), a_Static);
|
||||
|
||||
Oms.AssignRelationship(elem, Oms.GetInstance(KnownRelationshipGuids.Element__has__Element_Content), new InstanceHandle[]
|
||||
{
|
||||
ecName,
|
||||
ecIndex,
|
||||
ecEditable
|
||||
});
|
||||
|
||||
MethodReturningElement bem = methodBuilder.CreateBuildElementMethod(irTestClass, "build", "element", AccessModifier.Public, true, bemProcess, elem);
|
||||
ReturnElementMethodBinding remb = bem.CreateMethodBinding(Oms);
|
||||
|
||||
Method buir = methodBuilder.CreateBuildUIResponseMethod(irTestClass, "build", "response", AccessModifier.Public, true, remb);
|
||||
|
||||
OmsContext context = Oms.CreateContext();
|
||||
|
||||
InstanceHandle wsH = Oms.Execute(context, buir);
|
||||
object? workData = context.GetWorkData(wsH);
|
||||
|
||||
Assert.That(workData, Is.InstanceOf<JsonObject>());
|
||||
|
||||
JsonObject o = (JsonObject)workData;
|
||||
|
||||
string s = o.ToJsonString();
|
||||
Assert.That(o["widget"]?.GetValue<string>(), Is.EqualTo("root"));
|
||||
Assert.That(o["body"]["rows"][0]["cellsMap"].AsObject().Count, Is.EqualTo(3));
|
||||
Assert.That(o["body"]["rows"][0]["cellsMap"]["46.1"]["label"].GetValue<string>(), Is.EqualTo("Name"));
|
||||
Assert.That(o["body"]["rows"][0]["cellsMap"]["46.1"]["value"].GetValue<string>(), Is.EqualTo("Test Class Instance 1"));
|
||||
}
|
||||
|
||||
}
|
||||
@ -111,6 +111,242 @@ namespace Mocha.Core.Tests.MethodTests
|
||||
Assert.That(data.Count(), Is.EqualTo(2));
|
||||
Assert.That(data.Contains(ihDate1) && data.Contains(ihDate2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CombineSetsOp_Intersection()
|
||||
{
|
||||
InstanceHandle ihSetA = Oms.GetInstance(KnownInstanceGuids.WorkSets.SetA);
|
||||
InstanceHandle ihSetB = Oms.GetInstance(KnownInstanceGuids.WorkSets.SetB);
|
||||
|
||||
InstanceHandle c_TestClass = Oms.GetInstance(TEST_CLASS_GUID);
|
||||
InstanceHandle iA1 = Oms.CreateInstanceOf(c_TestClass);
|
||||
InstanceHandle iA2 = Oms.CreateInstanceOf(c_TestClass);
|
||||
InstanceHandle iA3 = Oms.CreateInstanceOf(c_TestClass);
|
||||
InstanceHandle iA4 = Oms.CreateInstanceOf(c_TestClass);
|
||||
|
||||
InstanceHandle iB1 = Oms.CreateInstanceOf(c_TestClass);
|
||||
InstanceHandle iB2 = Oms.CreateInstanceOf(c_TestClass);
|
||||
InstanceHandle iB3 = Oms.CreateInstanceOf(c_TestClass);
|
||||
InstanceHandle iB4 = Oms.CreateInstanceOf(c_TestClass);
|
||||
|
||||
InstanceHandle[] irSetA = new InstanceHandle[]
|
||||
{
|
||||
iA1,
|
||||
iA2,
|
||||
iA3,
|
||||
iA4,
|
||||
iB4
|
||||
};
|
||||
InstanceHandle[] irSetB = new InstanceHandle[]
|
||||
{
|
||||
iA2,
|
||||
iB1,
|
||||
iB2,
|
||||
iB3,
|
||||
iB4
|
||||
};
|
||||
|
||||
OmsContext context = Oms.CreateContext();
|
||||
context.SetWorkData(Oms.GetInstance(KnownInstanceGuids.WorkSets.SetA), irSetA);
|
||||
context.SetWorkData(Oms.GetInstance(KnownInstanceGuids.WorkSets.SetB), irSetB);
|
||||
|
||||
WorkSet workSet = Oms.CreateWorkSet("Test Work Set for Combine Sets");
|
||||
|
||||
InstanceOp combineSetsOp = ((new OmsInstanceOpBuilder(Oms)).CreateCombineSetsOp(Oms.GetInstance(KnownInstanceGuids.SetFunctions.Intersection)));
|
||||
InstanceOpMethod iop = Oms.MethodBuilder.CreateInstanceOpMethod(c_TestClass, "combine", "Set A and Set B", AccessModifier.Public, true, workSet, combineSetsOp);
|
||||
|
||||
InstanceHandle workSet2 = Oms.Execute(context, iop);
|
||||
IEnumerable<InstanceHandle> irSetC = context.GetWorkData<IEnumerable<InstanceHandle>>(workSet);
|
||||
|
||||
Assert.That(irSetC.Count(), Is.EqualTo(2));
|
||||
Assert.That(irSetC.Contains(iA2) && irSetC.Contains(iB4));
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void CombineSetsOp_Union()
|
||||
{
|
||||
InstanceHandle ihSetA = Oms.GetInstance(KnownInstanceGuids.WorkSets.SetA);
|
||||
InstanceHandle ihSetB = Oms.GetInstance(KnownInstanceGuids.WorkSets.SetB);
|
||||
|
||||
InstanceHandle c_TestClass = Oms.GetInstance(TEST_CLASS_GUID);
|
||||
InstanceHandle iA1 = Oms.CreateInstanceOf(c_TestClass);
|
||||
InstanceHandle iA2 = Oms.CreateInstanceOf(c_TestClass);
|
||||
InstanceHandle iA3 = Oms.CreateInstanceOf(c_TestClass);
|
||||
InstanceHandle iA4 = Oms.CreateInstanceOf(c_TestClass);
|
||||
|
||||
InstanceHandle iB1 = Oms.CreateInstanceOf(c_TestClass);
|
||||
InstanceHandle iB2 = Oms.CreateInstanceOf(c_TestClass);
|
||||
InstanceHandle iB3 = Oms.CreateInstanceOf(c_TestClass);
|
||||
InstanceHandle iB4 = Oms.CreateInstanceOf(c_TestClass);
|
||||
|
||||
InstanceHandle[] irSetA = new InstanceHandle[]
|
||||
{
|
||||
iA1,
|
||||
iA2,
|
||||
iA3,
|
||||
iA4,
|
||||
iB4
|
||||
};
|
||||
InstanceHandle[] irSetB = new InstanceHandle[]
|
||||
{
|
||||
iA2,
|
||||
iB1,
|
||||
iB2,
|
||||
iB3,
|
||||
iB4
|
||||
};
|
||||
|
||||
OmsContext context = Oms.CreateContext();
|
||||
context.SetWorkData(Oms.GetInstance(KnownInstanceGuids.WorkSets.SetA), irSetA);
|
||||
context.SetWorkData(Oms.GetInstance(KnownInstanceGuids.WorkSets.SetB), irSetB);
|
||||
|
||||
WorkSet workSet = Oms.CreateWorkSet("Test Work Set for Combine Sets");
|
||||
|
||||
InstanceOp combineSetsOp = ((new OmsInstanceOpBuilder(Oms)).CreateCombineSetsOp(Oms.GetInstance(KnownInstanceGuids.SetFunctions.Union)));
|
||||
InstanceOpMethod iop = Oms.MethodBuilder.CreateInstanceOpMethod(c_TestClass, "combine", "Set A and Set B", AccessModifier.Public, true, workSet, combineSetsOp);
|
||||
|
||||
InstanceHandle workSet2 = Oms.Execute(context, iop);
|
||||
IEnumerable<InstanceHandle> irSetC = context.GetWorkData<IEnumerable<InstanceHandle>>(workSet);
|
||||
|
||||
Assert.That(irSetC.Count(), Is.EqualTo(8));
|
||||
Assert.That(irSetC.Contains(iA2) && irSetC.Contains(iB4));
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void CombineSetsOp_Difference()
|
||||
{
|
||||
InstanceHandle ihSetA = Oms.GetInstance(KnownInstanceGuids.WorkSets.SetA);
|
||||
InstanceHandle ihSetB = Oms.GetInstance(KnownInstanceGuids.WorkSets.SetB);
|
||||
|
||||
InstanceHandle c_TestClass = Oms.GetInstance(TEST_CLASS_GUID);
|
||||
InstanceHandle iA1 = Oms.CreateInstanceOf(c_TestClass);
|
||||
InstanceHandle iA2 = Oms.CreateInstanceOf(c_TestClass);
|
||||
InstanceHandle iA3 = Oms.CreateInstanceOf(c_TestClass);
|
||||
InstanceHandle iA4 = Oms.CreateInstanceOf(c_TestClass);
|
||||
|
||||
InstanceHandle iB1 = Oms.CreateInstanceOf(c_TestClass);
|
||||
InstanceHandle iB2 = Oms.CreateInstanceOf(c_TestClass);
|
||||
InstanceHandle iB3 = Oms.CreateInstanceOf(c_TestClass);
|
||||
InstanceHandle iB4 = Oms.CreateInstanceOf(c_TestClass);
|
||||
|
||||
InstanceHandle[] irSetA = new InstanceHandle[]
|
||||
{
|
||||
iA1,
|
||||
iA2,
|
||||
iA3,
|
||||
iA4,
|
||||
iB4
|
||||
};
|
||||
InstanceHandle[] irSetB = new InstanceHandle[]
|
||||
{
|
||||
iA2,
|
||||
iB1,
|
||||
iB2,
|
||||
iB3,
|
||||
iB4
|
||||
};
|
||||
|
||||
OmsContext context = Oms.CreateContext();
|
||||
context.SetWorkData(Oms.GetInstance(KnownInstanceGuids.WorkSets.SetA), irSetA);
|
||||
context.SetWorkData(Oms.GetInstance(KnownInstanceGuids.WorkSets.SetB), irSetB);
|
||||
|
||||
WorkSet workSet = Oms.CreateWorkSet("Test Work Set for Combine Sets");
|
||||
|
||||
InstanceOp combineSetsOp = ((new OmsInstanceOpBuilder(Oms)).CreateCombineSetsOp(Oms.GetInstance(KnownInstanceGuids.SetFunctions.Difference)));
|
||||
InstanceOpMethod iop = Oms.MethodBuilder.CreateInstanceOpMethod(c_TestClass, "combine", "Set A and Set B", AccessModifier.Public, true, workSet, combineSetsOp);
|
||||
|
||||
InstanceHandle workSet2 = Oms.Execute(context, iop);
|
||||
IEnumerable<InstanceHandle> irSetC = context.GetWorkData<IEnumerable<InstanceHandle>>(workSet);
|
||||
|
||||
Assert.That(irSetC.Count(), Is.EqualTo(3));
|
||||
Assert.That(irSetC.Contains(iA1) && irSetC.Contains(iA3) && irSetC.Contains(iA4));
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void CombineSetsOp_Union_using_Executables()
|
||||
{
|
||||
InstanceHandle ihSetA = Oms.GetInstance(KnownInstanceGuids.WorkSets.SetA);
|
||||
InstanceHandle ihSetB = Oms.GetInstance(KnownInstanceGuids.WorkSets.SetB);
|
||||
|
||||
InstanceHandle c_TestClass = Oms.GetInstance(TEST_CLASS_GUID);
|
||||
|
||||
InstanceHandle i_TestClass1 = Oms.CreateInstanceOf(c_TestClass);
|
||||
InstanceHandle i_TestClass2 = Oms.CreateInstanceOf(c_TestClass);
|
||||
|
||||
InstanceHandle i_TestClass3 = Oms.CreateInstanceOf(c_TestClass);
|
||||
InstanceHandle i_TestClass4 = Oms.CreateInstanceOf(c_TestClass);
|
||||
|
||||
WorkSet wsTmp = Oms.CreateWorkSet("Temporary Work Set");
|
||||
GetSpecifiedInstancesMethod m1 = Oms.MethodBuilder.CreateGetSpecifiedInstancesMethod(c_TestClass, "get", "Set A Instances", wsTmp, new InstanceHandle[] { i_TestClass1, i_TestClass2 });
|
||||
ReturnInstanceSetMethodBinding rsmb1 = m1.CreateMethodBinding(Oms);
|
||||
|
||||
GetSpecifiedInstancesMethod m2 = Oms.MethodBuilder.CreateGetSpecifiedInstancesMethod(c_TestClass, "get", "Set B Instances", wsTmp, new InstanceHandle[] { i_TestClass3, i_TestClass4 });
|
||||
ReturnInstanceSetMethodBinding rsmb2 = m2.CreateMethodBinding(Oms);
|
||||
|
||||
OmsContext context = Oms.CreateContext();
|
||||
|
||||
WorkSet workSet = Oms.CreateWorkSet("Test Work Set for Combine Sets");
|
||||
|
||||
InstanceOp combineSetsOp = ((new OmsInstanceOpBuilder(Oms)).CreateCombineSetsOp(Oms.GetInstance(KnownInstanceGuids.SetFunctions.Union)));
|
||||
InstanceOpMethod iop = Oms.MethodBuilder.CreateInstanceOpMethod(c_TestClass, "combine", "Set A and Set B", AccessModifier.Public, true, workSet, combineSetsOp);
|
||||
MethodBinding mb = iop.CreateMethodBinding(Oms, new KeyValuePair<InstanceHandle, object?>[]
|
||||
{
|
||||
new KeyValuePair<InstanceHandle, object?>(ihSetA, rsmb1),
|
||||
new KeyValuePair<InstanceHandle, object?>(ihSetB, rsmb2)
|
||||
});
|
||||
|
||||
InstanceHandle workSet2 = Oms.Execute(context, mb);
|
||||
IEnumerable<InstanceHandle> irSetC = context.GetWorkData<IEnumerable<InstanceHandle>>(workSet);
|
||||
|
||||
Assert.That(irSetC.Count(), Is.EqualTo(4));
|
||||
Assert.That(irSetC.Contains(i_TestClass1) && irSetC.Contains(i_TestClass2) && irSetC.Contains(i_TestClass3) && irSetC.Contains(i_TestClass4));
|
||||
}
|
||||
|
||||
|
||||
|
||||
[Test]
|
||||
public void CombineSetsOp_Difference_using_Executables()
|
||||
{
|
||||
InstanceHandle ihSetA = Oms.GetInstance(KnownInstanceGuids.WorkSets.SetA);
|
||||
InstanceHandle ihSetB = Oms.GetInstance(KnownInstanceGuids.WorkSets.SetB);
|
||||
|
||||
InstanceHandle c_TestClass = Oms.GetInstance(TEST_CLASS_GUID);
|
||||
|
||||
InstanceHandle i_TestClass1 = Oms.CreateInstanceOf(c_TestClass);
|
||||
InstanceHandle i_TestClass2 = Oms.CreateInstanceOf(c_TestClass);
|
||||
InstanceHandle i_TestClass3 = Oms.CreateInstanceOf(c_TestClass);
|
||||
InstanceHandle i_TestClass4 = Oms.CreateInstanceOf(c_TestClass);
|
||||
|
||||
WorkSet wsTmp = Oms.CreateWorkSet("Temporary Work Set");
|
||||
GetSpecifiedInstancesMethod m1 = Oms.MethodBuilder.CreateGetSpecifiedInstancesMethod(c_TestClass, "get", "Set A Instances", wsTmp, new InstanceHandle[] { i_TestClass1, i_TestClass2, i_TestClass3 });
|
||||
ReturnInstanceSetMethodBinding rsmb1 = m1.CreateMethodBinding(Oms);
|
||||
|
||||
GetSpecifiedInstancesMethod m2 = Oms.MethodBuilder.CreateGetSpecifiedInstancesMethod(c_TestClass, "get", "Set B Instances", wsTmp, new InstanceHandle[] { i_TestClass3 });
|
||||
ReturnInstanceSetMethodBinding rsmb2 = m2.CreateMethodBinding(Oms);
|
||||
|
||||
OmsContext context = Oms.CreateContext();
|
||||
|
||||
WorkSet workSet = Oms.CreateWorkSet("Test Work Set for Combine Sets");
|
||||
|
||||
InstanceOp combineSetsOp = ((new OmsInstanceOpBuilder(Oms)).CreateCombineSetsOp(Oms.GetInstance(KnownInstanceGuids.SetFunctions.Difference)));
|
||||
InstanceOpMethod iop = Oms.MethodBuilder.CreateInstanceOpMethod(c_TestClass, "combine", "Set A and Set B", AccessModifier.Public, true, workSet, combineSetsOp);
|
||||
MethodBinding mb = iop.CreateMethodBinding(Oms, new KeyValuePair<InstanceHandle, object?>[]
|
||||
{
|
||||
new KeyValuePair<InstanceHandle, object?>(ihSetA, rsmb1),
|
||||
new KeyValuePair<InstanceHandle, object?>(ihSetB, rsmb2)
|
||||
});
|
||||
|
||||
InstanceHandle workSet2 = Oms.Execute(context, mb);
|
||||
IEnumerable<InstanceHandle> irSetC = context.GetWorkData<IEnumerable<InstanceHandle>>(workSet);
|
||||
|
||||
Assert.That(irSetC.Count(), Is.EqualTo(2));
|
||||
Assert.That(irSetC.Contains(i_TestClass1) && irSetC.Contains(i_TestClass2));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using Mocha.Core;
|
||||
using Mocha.Core.Oop;
|
||||
using Mocha.Zq.Methods;
|
||||
|
||||
namespace Mocha.Zq.Tests;
|
||||
@ -33,15 +35,40 @@ public class MathTests
|
||||
Assert.That(zql.Functions.Count, Is.EqualTo(1));
|
||||
Assert.That(zql.Functions[0].Name, Is.EqualTo("gcd"));
|
||||
Assert.That(zql.Functions[0], Is.TypeOf<ZqConditionalSelectAttributeMethod>());
|
||||
Assert.That(zql.Functions[0].Parameters.Count, Is.EqualTo(2));
|
||||
|
||||
/*
|
||||
Oms oms = new Mocha.Testing.EmbeddedMiniOms();
|
||||
oms.Initialize();
|
||||
|
||||
InstanceHandle c_GCD = Oms.GetInstanceByName(Oms.GetInstance(KnownInstanceGuids.Classes.Class), "GreatestCommonDivisor");
|
||||
Assert.That(c_GCD, Is.Not.EqualTo(InstanceHandle.Empty));
|
||||
Mocha.Core.Oop.Class? clasz = oms.LoadZq(zql) as Mocha.Core.Oop.Class;
|
||||
Assert.That(clasz, Is.Not.Null);
|
||||
|
||||
InstanceHandle i_GcdMethod = zq.GetMethod("GreatestCommonDivisor.gcd");
|
||||
Assert.That(i_GcdMethod, Is.Not.EqualTo(InstanceHandle.Empty));
|
||||
*/
|
||||
if (clasz != null)
|
||||
{
|
||||
Assert.That(oms.GetAttributeValue<string>(clasz, oms.GetInstance(KnownAttributeGuids.Text.Name)), Is.EqualTo("GreatestCommonDivisor"));
|
||||
|
||||
InstanceHandle c_GCD = oms.GetInstanceByName(oms.GetInstance(KnownInstanceGuids.Classes.Class), "GreatestCommonDivisor");
|
||||
Assert.That(c_GCD, Is.Not.EqualTo(InstanceHandle.Empty));
|
||||
|
||||
Core.Oop.Methods.ConditionalSelectAttributeMethod? i_GcdMethod = oms.GetMethod(c_GCD, null, "gcd") as Core.Oop.Methods.ConditionalSelectAttributeMethod;
|
||||
Assert.That(i_GcdMethod, Is.Not.Null);
|
||||
|
||||
InstanceHandle parmA = oms.GetMethodParameter(i_GcdMethod, "p");
|
||||
InstanceHandle parmB = oms.GetMethodParameter(i_GcdMethod, "q");
|
||||
|
||||
ReturnAttributeMethodBinding ramb = i_GcdMethod.CreateMethodBinding(oms, new KeyValuePair<InstanceHandle, object?>[]
|
||||
{
|
||||
new KeyValuePair<InstanceHandle, object?>(parmA, 4),
|
||||
new KeyValuePair<InstanceHandle, object?>(parmB, 16)
|
||||
});
|
||||
|
||||
OmsContext context = oms.CreateContext();
|
||||
|
||||
InstanceHandle workSet = oms.Execute(context, ramb);
|
||||
object? retval = context.GetWorkData(workSet);
|
||||
|
||||
Assert.That(retval, Is.EqualTo(4));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user