diff --git a/mocha-dotnet/src/lib/Mocha.Core.UI.Server/Commands/ElementCommand.cs b/mocha-dotnet/src/lib/Mocha.Core.UI.Server/Commands/ElementCommand.cs index b48e047..d5f2d58 100644 --- a/mocha-dotnet/src/lib/Mocha.Core.UI.Server/Commands/ElementCommand.cs +++ b/mocha-dotnet/src/lib/Mocha.Core.UI.Server/Commands/ElementCommand.cs @@ -30,40 +30,37 @@ public class ElementCommand : InstanceCommand protected override void ProcessInternal(WebServerProcessRequestEventArgs e, Core.Oms oms, Core.OmsContext ctx, StreamWriter sw) { - if (e.Context.Request.Method == "POST") + if (e.Context.Request.Method == "POST" && oms.IsInstanceOf(ProcessingInstance, oms.GetInstance(KnownInstanceGuids.Classes.Element))) { - if (oms.IsInstanceOf(ProcessingInstance, oms.GetInstance(KnownInstanceGuids.Classes.Element))) + ctx.SetWorkData(oms.GetInstance(KnownInstanceGuids.Classes.Instance), ProcessingInstance); + + // what we should do, is build a transaction with all updated ECs and fields and values + // if any update fails, the entire transaction should be rolled back + Response resp = oms.ProcessElement(ctx, ProcessingInstance, e.Context.Request.Form); + if (resp != null) { - ctx.SetWorkData(oms.GetInstance(KnownInstanceGuids.Classes.Instance), ProcessingInstance); - - // what we should do, is build a transaction with all updated ECs and fields and values - // if any update fails, the entire transaction should be rolled back - Response resp = oms.ProcessElement(ctx, ProcessingInstance, e.Context.Request.Form); - if (resp != null) - { - JsonObject obj2 = resp.GetResponse(oms, ctx); - RespondWithJson(oms, sw, e.Context, 200, "OK", obj2); - return; - } - else - { - JsonObject obj2 = new JsonObject(); - obj2.Add("result", "failure"); - obj2.Add("message", "no CT associated with element"); - RespondWithJson(oms, sw, e.Context, 400, "Bad Request", obj2); - return; - } - - foreach (KeyValuePair kvp in e.Context.Request.Form) - { - Console.Error.WriteLine("---> {0} = {1}", kvp.Key, kvp.Value); - } - - JsonObject obj = new JsonObject(); - obj.Add("result", "failure"); - obj.Add("message", "not implemented"); - RespondWithJson(oms, sw, e.Context, 500, "Internal Server Error", obj); + JsonObject obj2 = resp.GetResponse(oms, ctx); + RespondWithJson(oms, sw, e.Context, 200, "OK", obj2); + return; } + else + { + JsonObject obj2 = new JsonObject(); + obj2.Add("result", "failure"); + obj2.Add("message", "no CT associated with element"); + RespondWithJson(oms, sw, e.Context, 400, "Bad Request", obj2); + return; + } + + foreach (KeyValuePair kvp in e.Context.Request.Form) + { + Console.Error.WriteLine("---> {0} = {1}", kvp.Key, kvp.Value); + } + + JsonObject obj = new JsonObject(); + obj.Add("result", "failure"); + obj.Add("message", "not implemented"); + RespondWithJson(oms, sw, e.Context, 500, "Internal Server Error", obj); } else { @@ -100,6 +97,27 @@ public class ElementCommand : InstanceCommand } else if (oms.IsInstanceOf(ProcessingInstance, oms.GetInstance(KnownInstanceGuids.Classes.Task))) { + foreach (KeyValuePair kvp in e.Context.Request.Form) + { + if (kvp.Key == "relatedInstance") + { + object? v = oms.ParseValue(kvp.Value); + + InstanceHandle relatedWorkSet = oms.GetRelatedInstance(ProcessingInstance, oms.GetInstance(KnownRelationshipGuids.Task__has_related__Work_Set)); + if (relatedWorkSet != InstanceHandle.Empty) + { + ctx.SetWorkData(relatedWorkSet, v); + } + } + else + { + if (oms.TryParseInstanceRef(kvp.Key, out InstanceHandle h)) + { + ctx.SetWorkData(h, oms.ParseValue(kvp.Value)); + } + } + } + RespndWithTask(oms, sw, e.Context, ctx, ProcessingInstance); } else diff --git a/mocha-dotnet/src/lib/Mocha.Core/KnownAttributeGuids.cs b/mocha-dotnet/src/lib/Mocha.Core/KnownAttributeGuids.cs index 1cfc499..8444fb9 100755 --- a/mocha-dotnet/src/lib/Mocha.Core/KnownAttributeGuids.cs +++ b/mocha-dotnet/src/lib/Mocha.Core/KnownAttributeGuids.cs @@ -49,6 +49,7 @@ namespace Mocha.Core } public static class Boolean { + public static Guid EvaluateWorkSet { get; } = new Guid("{62c28f9e-5ce8-4ce5-8a56-1e80f1af7f6a}"); public static Guid MethodIsOfTypeSpecified { get; } = new Guid("{6e9df667-0f95-4320-a4be-5cdb00f1d4ee}"); public static Guid DisplayVersionInBadge { get; } = new Guid("{BE5966A4-C4CA-49A6-B504-B6E8759F392D}"); public static Guid Editable { get; } = new Guid("{957fd8b3-fdc4-4f35-87d6-db1c0682f53c}"); diff --git a/mocha-dotnet/src/lib/Mocha.Core/KnownInstanceGuids.cs b/mocha-dotnet/src/lib/Mocha.Core/KnownInstanceGuids.cs index 15a61da..daef50e 100755 --- a/mocha-dotnet/src/lib/Mocha.Core/KnownInstanceGuids.cs +++ b/mocha-dotnet/src/lib/Mocha.Core/KnownInstanceGuids.cs @@ -292,6 +292,7 @@ namespace Mocha.Core public static Guid GetInstanceText { get; } = new Guid("{b024abd6-1f2b-495a-9da3-c9ce29fb0c2f}"); public static Guid GetRandomNumber { get; } = new Guid("{8f7945da-4cad-49cb-9838-85f3524a5adb}"); public static Guid GetIPAddress { get; } = new Guid("{45411e57-ef6e-44f5-8801-603e567d73d4}"); + public static Guid GetGlobalIdentifier { get; } = new Guid("{1a7ebec3-dc02-4c9b-a5df-0c72646453c9}"); } public static class SystemInstanceSetRoutines { diff --git a/mocha-dotnet/src/lib/Mocha.Core/KnownRelationshipGuids.cs b/mocha-dotnet/src/lib/Mocha.Core/KnownRelationshipGuids.cs index cd7810c..964aff1 100755 --- a/mocha-dotnet/src/lib/Mocha.Core/KnownRelationshipGuids.cs +++ b/mocha-dotnet/src/lib/Mocha.Core/KnownRelationshipGuids.cs @@ -101,6 +101,7 @@ namespace Mocha.Core public static Guid Task__has__Task_Category { get; } = new Guid("{84048159-430d-4f6c-9361-115c8629c517}"); public static Guid Task__executes__Method_Call { get; } = new Guid("{D8C0D4D4-F8C6-4B92-A2C1-8BF16B16203D}"); public static Guid Task__has_preview_action_title__Translation { get; } = new Guid("{3f65ce02-11dd-4829-a46b-b9ea1b43e56a}"); + public static Guid Task__has_related__Work_Set { get; } = new Guid("{2eb391b4-7da2-4eca-8460-dcda7757c47a}"); public static Guid Prompt__has__Report_Field { get; } = new Guid("{922CCB05-61EA-441D-96E0-63D58231D202}"); // 3de784b9-4561-42f0-946f-b1e90d80029e public static Guid Report_Field__for__Prompt { get; } = new Guid("{5DED3DB4-6864-45A9-A5FF-8E5A35AD6E6F}"); // b5f59216-a1f1-4979-8642-a4845e59daa8 diff --git a/mocha-dotnet/src/lib/Mocha.Core/Oms.cs b/mocha-dotnet/src/lib/Mocha.Core/Oms.cs index 8668733..31c469e 100644 --- a/mocha-dotnet/src/lib/Mocha.Core/Oms.cs +++ b/mocha-dotnet/src/lib/Mocha.Core/Oms.cs @@ -62,6 +62,27 @@ public abstract class Oms UpdateSyntacticSugar(); + RegisterSystemAttributeRoutine(KnownInstanceGuids.SystemAttributeRoutines.GetGlobalIdentifier, delegate (Oms oms, OmsContext context) + { + object? wd = context.GetWorkData(oms.GetInstance(KnownInstanceGuids.Classes.Instance)); + if (wd is InstanceHandle wdi) + { + if (oms.IsInstanceOf(wdi, oms.GetInstance(KnownInstanceGuids.Classes.WorkSet))) + { + bool evaluateWorkSet = oms.GetAttributeValue(wdi, oms.GetInstance(KnownAttributeGuids.Boolean.EvaluateWorkSet)); + if (evaluateWorkSet) + { + wd = context.GetWorkData(wdi); + if (wd is InstanceHandle wdi2) + { + wdi = wdi2; + } + } + } + return oms.GetGlobalIdentifier(wdi).ToString("b"); + } + return null; + }); RegisterSystemInstanceSetRoutine(KnownInstanceGuids.SystemInstanceSetRoutines.GetCurrentUser, delegate (Oms oms, OmsContext context) { Console.Error.WriteLine("oms: executing system instance set routine {0}", KnownInstanceGuids.SystemUpdateRoutines.LoginUser); @@ -1167,7 +1188,7 @@ public abstract class Oms bool is_static = GetAttributeValue(methodOrMethodBinding, GetInstance(KnownAttributeGuids.Boolean.Static)); if (!is_static && targetInstance == null) { - throw new NullReferenceException(String.Format("Attempt to call instance method `{0}` without an instance", methodOrMethodBinding)); + //sthrow new NullReferenceException(String.Format("Attempt to call instance method `{0}` without an instance", methodOrMethodBinding)); } if (targetInstance == null) @@ -2231,4 +2252,94 @@ public abstract class Oms { return _tenantStack.Pop(); } + + public object? ParseValue(string value) + { + if (value.Contains(',') && (value.Contains('$') || (value.Contains('{') && value.Contains('}') && value.Length > 38))) + { + List list = new List(); + string[] values = value.Split(new char[] { ',' }); + foreach (string value2 in values) + { + if (TryParseInstanceRef(value2, out InstanceHandle h2)) + { + list.Add(h2); + } + } + return list; + } + else if (value.Contains('$') || (value.StartsWith('{') && value.EndsWith('}') && value.Length == 38)) + { + if (TryParseInstanceRef(value, out InstanceHandle h2)) + { + return h2; + } + } + else if (Boolean.TryParse(value, out bool b)) + { + return b; + } + else if (Decimal.TryParse(value, out decimal d)) + { + return d; + } + else if (DateTime.TryParse(value, out DateTime dt)) + { + return dt; + } + return value; + } + + private object? ParseValueForWorkData__TypeSafeFirst(InstanceHandle h, string value) + { + if (IsInstanceOf(h, GetInstance(KnownInstanceGuids.Classes.WorkSet)) || IsInstanceOf(h, GetInstance(KnownInstanceGuids.Classes.Class))) + { + if (value.Contains(",")) + { + List list = new List(); + string[] values = value.Split(new char[] { ',' }); + foreach (string value2 in values) + { + if (TryParseInstanceRef(value2, out InstanceHandle h2)) + { + list.Add(h2); + } + } + return list; + } + else + { + if (TryParseInstanceRef(value, out InstanceHandle h2)) + { + return h2; + } + } + } + else if (IsInstanceOf(h, GetInstance(KnownInstanceGuids.Classes.TextAttribute))) + { + return value; + } + else if (IsInstanceOf(h, GetInstance(KnownInstanceGuids.Classes.BooleanAttribute))) + { + if (Boolean.TryParse(value, out bool d)) + { + return d; + } + } + else if (IsInstanceOf(h, GetInstance(KnownInstanceGuids.Classes.NumericAttribute))) + { + if (Decimal.TryParse(value, out decimal d)) + { + return d; + } + } + else if (IsInstanceOf(h, GetInstance(KnownInstanceGuids.Classes.DateAttribute))) + { + if (DateTime.TryParse(value, out DateTime d)) + { + return d; + } + } + throw new FormatException(); + } } diff --git a/mocha-dotnet/src/lib/Mocha.Core/UI/Renderer.cs b/mocha-dotnet/src/lib/Mocha.Core/UI/Renderer.cs index 420cea5..7a0c040 100644 --- a/mocha-dotnet/src/lib/Mocha.Core/UI/Renderer.cs +++ b/mocha-dotnet/src/lib/Mocha.Core/UI/Renderer.cs @@ -128,6 +128,20 @@ public class Renderer } } } + else + { + InstanceHandle ecinst = OMS.GetRelatedInstance(parentElementContent, OMS.GetInstance(KnownRelationshipGuids.Element_Content__has__Instance)); + object? wdv = context.GetWorkData(ecinst); + if (wdv == null) + { + wdv = context.GetWorkData(parentElementContent); + } + + if (wdv is InstanceHandle) + { + value = ((InstanceHandle)wdv); + } + } } if (useWidget is MonikerList) diff --git a/mocha-dotnet/src/lib/Mocha.Core/UI/Widgets/MonikerList.cs b/mocha-dotnet/src/lib/Mocha.Core/UI/Widgets/MonikerList.cs index c938dee..112c2db 100644 --- a/mocha-dotnet/src/lib/Mocha.Core/UI/Widgets/MonikerList.cs +++ b/mocha-dotnet/src/lib/Mocha.Core/UI/Widgets/MonikerList.cs @@ -47,7 +47,11 @@ public class MonikerList : Widget obj.Add("relatedTasksUriTemplate", String.Format("/{0}/inst/{1}/rel-tasks", OMS.GetTenantName(OMS.CurrentTenant), OMS.GetInstanceKey(SelectedInstances.First()).ToString())); } obj.Add("text", OMS.GetInstanceText(ParentInstance)); - obj.Add("singular", true); + + if (OMS.GetAttributeValue(ParentInstance, OMS.GetInstance(KnownAttributeGuids.Boolean.Singular))) + { + obj.Add("singular", true); + } } protected override bool ShouldBeEnabled()