diff --git a/mocha-common b/mocha-common index 985bc77..285fffd 160000 --- a/mocha-common +++ b/mocha-common @@ -1 +1 @@ -Subproject commit 985bc77a65e8a404132f33f3bcb45494ecd8d380 +Subproject commit 285fffd97bf38b0f74fd3e2a5f6e4370856188f9 diff --git a/mocha-dotnet/src/lib/Mocha.Core.UI.Server/Commands/GlobalsCommand.cs b/mocha-dotnet/src/lib/Mocha.Core.UI.Server/Commands/GlobalsCommand.cs new file mode 100644 index 0000000..140080f --- /dev/null +++ b/mocha-dotnet/src/lib/Mocha.Core.UI.Server/Commands/GlobalsCommand.cs @@ -0,0 +1,64 @@ +// Copyright (C) 2024 Michael Becker +// +// 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 . + + +using System.Text.Json.Nodes; +using MBS.Web; + +namespace Mocha.Core.UI.Server.Commands; + +public class GlobalsCommand : OmsServerCommand +{ + public override IEnumerable UriPatterns => new string[] { "/globals/{iid}" }; + + protected override void ProcessInternal(WebServerProcessRequestEventArgs e, Oms oms, OmsContext ctx, StreamWriter sw) + { + if (oms.TryParseInstanceRef(Variables["iid"], out InstanceHandle h)) + { + if (e.Context.Request.Method == "POST") + { + string value = e.Context.Request.Form["value"]; + ctx.SetGlobal(h, value); + + e.Context.Response.ResponseCode = 200; + e.Context.Response.ResponseText = "OK"; + e.Context.Response.ContentType = "application/json"; + + JsonObject json = new JsonObject(); + json.Add("result", "success"); + sw.Write(json.ToJsonString()); + + Console.Error.WriteLine("uis: globals: setting '{0}' = '{1}'", oms.GetGlobalIdentifier(h), value); + } + else + { + string value = ctx.GetGlobal(h); + + e.Context.Response.ResponseCode = 200; + e.Context.Response.ResponseText = "OK"; + e.Context.Response.ContentType = "application/json"; + + JsonObject json = new JsonObject(); + json.Add("result", "success"); + json.Add("value", value); + sw.Write(json.ToJsonString()); + + Console.Error.WriteLine("uis: globals: getting '{0}' = '{1}'", oms.GetGlobalIdentifier(h), value); + } + } + } +} \ No newline at end of file diff --git a/mocha-dotnet/src/lib/Mocha.Core/KnownRelationshipGuids.cs b/mocha-dotnet/src/lib/Mocha.Core/KnownRelationshipGuids.cs index 25137b4..19c8738 100755 --- a/mocha-dotnet/src/lib/Mocha.Core/KnownRelationshipGuids.cs +++ b/mocha-dotnet/src/lib/Mocha.Core/KnownRelationshipGuids.cs @@ -415,6 +415,8 @@ namespace Mocha.Core public static Guid Build_UI_Response_Method__uses__Executable_returning_Element { get; } = new Guid("{6f066ec6-b978-4627-81da-78fee1bed5e5}"); public static Guid Executable_returning_Element__used_by__Build_UI_Response_Method { get; } = new Guid("{0e662556-ca79-43fe-9a50-57ad22df65de}"); + public static Guid Build_UI_Response_Method__gets_target_url_from__Executable_returning_Attribute { get; } = new Guid("{6c09db3b-6fc9-4bf6-ab16-a49bc7d4101b}"); + public static Guid Control_Transaction_Method__processes__Element { get; } = new Guid("{24bc1dc0-d6cc-44ff-86ba-1360ebd59f3a}"); public static Guid Element__processed_by__Control_Transaction_Method { get; } = new Guid("{0f182291-6784-47b3-a8d3-d2f6ebf3950c}"); public static Guid Control_Transaction_Method__uses__Build_Response_Method_Binding { get; } = new Guid("{d8f2f0cc-54a2-4004-a383-8c1321495531}"); diff --git a/mocha-dotnet/src/lib/Mocha.Core/MethodImplementations/EvaluateBooleanExpressionMethodImplementation.cs b/mocha-dotnet/src/lib/Mocha.Core/MethodImplementations/EvaluateBooleanExpressionMethodImplementation.cs index c082d3e..8cdd756 100644 --- a/mocha-dotnet/src/lib/Mocha.Core/MethodImplementations/EvaluateBooleanExpressionMethodImplementation.cs +++ b/mocha-dotnet/src/lib/Mocha.Core/MethodImplementations/EvaluateBooleanExpressionMethodImplementation.cs @@ -46,7 +46,7 @@ public class EvaluateBooleanExpressionMethodImplementation : MethodImplementatio InstanceHandle source = oms.GetRelatedInstance(method, oms.GetInstance(KnownRelationshipGuids.Evaluate_Boolean_Expression_Method__has_source__Executable_returning_Work_Data)); InstanceHandle comparison = oms.GetRelatedInstance(method, oms.GetInstance(KnownRelationshipGuids.Evaluate_Boolean_Expression_Method__uses__Boolean_Operator)); - Console.Error.WriteLine("EBE - source {0}", oms.GetGlobalIdentifier(source)); + // Console.Error.WriteLine("EBE - source {0}", oms.GetGlobalIdentifier(source)); InstanceHandle rsource = oms.Execute(context, source); object? rsource_valueraw = context.GetWorkData(rsource); diff --git a/mocha-dotnet/src/lib/Mocha.Core/Oms.cs b/mocha-dotnet/src/lib/Mocha.Core/Oms.cs index a69542a..3f8f26e 100644 --- a/mocha-dotnet/src/lib/Mocha.Core/Oms.cs +++ b/mocha-dotnet/src/lib/Mocha.Core/Oms.cs @@ -1347,7 +1347,7 @@ public abstract class Oms } private string _GetInstanceTextHack(InstanceHandle inst) { - Console.Error.WriteLine("!!! HACK !!! GetInstanceTextHack !!! HACK !!!"); + // Console.Error.WriteLine("!!! HACK !!! GetInstanceTextHack !!! HACK !!!"); StringBuilder sb = new StringBuilder(); if (IsInstanceOf(inst, GetInstance(KnownInstanceGuids.Classes.Relationship))) { @@ -2042,7 +2042,29 @@ public abstract class Oms Console.Error.WriteLine("----> ok, executing method {0}", executesMethod.GlobalIdentifier); // execute BRMB - string targetURL = GetAttributeValue(executesMethod, GetInstance(KnownAttributeGuids.Text.TargetURL)); + string targetURLAttr = GetAttributeValue(executesMethod, GetInstance(KnownAttributeGuids.Text.TargetURL)); + string targetURL = targetURLAttr; + + InstanceHandle usesTargetURLFromExecutableReturningAttribute = GetRelatedInstance(executesMethod, GetInstance(KnownRelationshipGuids.Build_UI_Response_Method__gets_target_url_from__Executable_returning_Attribute)); + if (usesTargetURLFromExecutableReturningAttribute != InstanceHandle.Empty) + { + if (IsInstanceOf(usesTargetURLFromExecutableReturningAttribute, GetInstance(KnownInstanceGuids.Classes.TextAttribute))) + { + targetURL = ctx.GetGlobal(usesTargetURLFromExecutableReturningAttribute); + } + else + { + InstanceHandle h = Execute(ctx, usesTargetURLFromExecutableReturningAttribute); + if (h != InstanceHandle.Empty) + { + targetURL = ctx.GetWorkData(h); + if (targetURL == null) + { + targetURL = targetURLAttr; + } + } + } + } if (targetURL != null) { return new RedirectResponse(targetURL); diff --git a/mocha-dotnet/src/lib/Mocha.Core/OmsContext.cs b/mocha-dotnet/src/lib/Mocha.Core/OmsContext.cs index fa6b840..ff0a548 100644 --- a/mocha-dotnet/src/lib/Mocha.Core/OmsContext.cs +++ b/mocha-dotnet/src/lib/Mocha.Core/OmsContext.cs @@ -211,6 +211,10 @@ public class OmsContext { return (T)(_GlobalData[parm]); } + else if (typeof(T) == typeof(string)) + { + return (T)((object)_GlobalData[parm].ToString()); + } } return defaultValue; }