diff --git a/mocha-dotnet/src/app/Mocha.ServerApplication/MochaWebApplication.cs b/mocha-dotnet/src/app/Mocha.ServerApplication/MochaWebApplication.cs index 673c3a3..4c515ed 100644 --- a/mocha-dotnet/src/app/Mocha.ServerApplication/MochaWebApplication.cs +++ b/mocha-dotnet/src/app/Mocha.ServerApplication/MochaWebApplication.cs @@ -120,7 +120,22 @@ public abstract class MochaWebApplication : WebApplication } if (parts.Length == 2) { - e.Context.Response.Redirect("~/" + parts[1] + "/d/home.htmld"); + Oms.SelectTenant(Oms.GetTenantByName(parts[1])); + InstanceHandle c_Tenant = Oms.GetInstance(KnownInstanceGuids.Classes.Tenant); + InstanceHandle i_Tenant = Oms.GetInstancesOf(c_Tenant).First(); + + InstanceHandle r_Tenant__has_initiating__Route = Oms.GetInstance(KnownRelationshipGuids.Tenant__has_initiating__Route); + + InstanceHandle i_Route = Oms.GetRelatedInstance(i_Tenant, r_Tenant__has_initiating__Route); + if (i_Route != InstanceHandle.Empty) + { + string targetUrl = Oms.GetAttributeValue(i_Route, Oms.GetInstance(KnownAttributeGuids.Text.TargetURL)); + e.Context.Response.Redirect(targetUrl.Replace("{tenant}", parts[1])); + } + else + { + e.Context.Response.Redirect("~/" + parts[1] + "/d/home.htmld"); + } e.Handled = true; } } diff --git a/mocha-dotnet/src/app/Mocha.ServerApplication/Program.cs b/mocha-dotnet/src/app/Mocha.ServerApplication/Program.cs index 9804884..b0167ec 100644 --- a/mocha-dotnet/src/app/Mocha.ServerApplication/Program.cs +++ b/mocha-dotnet/src/app/Mocha.ServerApplication/Program.cs @@ -146,6 +146,9 @@ public class Program : MochaWebApplication oms.SetAttributeValue(route, a_TargetURL, "/{tenant}/d/welcome.htmld"); oms.AssignRelationship(route, r_Route__processed_by__Control_Transaction_Method, ct.Handle); + + InstanceHandle r_Tenant__has_initiating__Route = oms.GetInstance(KnownRelationshipGuids.Tenant__has_initiating__Route); + oms.AssignRelationship(i_Tenant, r_Tenant__has_initiating__Route, route); } return oms; } diff --git a/mocha-dotnet/src/lib/Mocha.Core/KnownRelationshipGuids.cs b/mocha-dotnet/src/lib/Mocha.Core/KnownRelationshipGuids.cs index cb96276..03c1146 100755 --- a/mocha-dotnet/src/lib/Mocha.Core/KnownRelationshipGuids.cs +++ b/mocha-dotnet/src/lib/Mocha.Core/KnownRelationshipGuids.cs @@ -379,5 +379,7 @@ namespace Mocha.Core public static Guid Route__processed_by__Control_Transaction_Method { get; } = new Guid("{6b9ad17e-69a2-42bf-8197-5ab266c76cd1}"); public static Guid Control_Transaction_Method__processes__Route { get; } = new Guid("{d1c3aa8a-0928-4c46-9aba-9a368b3dea5a}"); + public static Guid Tenant__has_initiating__Route { get; } = new Guid("{41dc15a8-c748-4d90-ae4e-104e45d15f2b}"); + public static Guid Route__initiates_for__Tenant { get; } = new Guid("{6682949b-f8d7-49a8-b7c3-a66a304a7fdb}"); } } diff --git a/mocha-dotnet/src/lib/Mocha.Core/OmsImplementations/Mini/Modules/WebModule.cs b/mocha-dotnet/src/lib/Mocha.Core/OmsImplementations/Mini/Modules/WebModule.cs index e4d8ca9..48282e0 100644 --- a/mocha-dotnet/src/lib/Mocha.Core/OmsImplementations/Mini/Modules/WebModule.cs +++ b/mocha-dotnet/src/lib/Mocha.Core/OmsImplementations/Mini/Modules/WebModule.cs @@ -12,17 +12,20 @@ public class WebModule : MiniOmsModule return rt; } + private InstanceHandle c_Tenant; + protected override void BuildInternal(Oms oms) { a_TargetURL = oms.CreateInstanceOf(c_Attribute, KnownAttributeGuids.Text.TargetURL); c_Route = oms.CreateClass("Route", KnownInstanceGuids.Classes.Route); + c_Tenant = oms.GetInstance(KnownInstanceGuids.Classes.Tenant); oms.AddAttribute(c_Route, a_TargetURL); c_ControlTransactionMethod = oms.GetInstance(KnownInstanceGuids.MethodClasses.ControlTransactionMethod); oms.CreateRelationship(c_Route, "processed by", c_ControlTransactionMethod, KnownRelationshipGuids.Route__processed_by__Control_Transaction_Method, true, "processes", KnownRelationshipGuids.Control_Transaction_Method__processes__Route); - + oms.CreateRelationship(c_Tenant, "has initiating", c_Route, KnownRelationshipGuids.Tenant__has_initiating__Route, true, "initiates for", KnownRelationshipGuids.Route__initiates_for__Tenant); // Route.processed by CT - Control Transaction Method // CT - Control Transaction Method.uses Build Response Method Binding // Build Response Method Binding.executes Method -- Build UI Response Method diff --git a/mocha-dotnet/tests/Mocha.Core.Tests/MethodTests/ControlTransactionMethodTests.cs b/mocha-dotnet/tests/Mocha.Core.Tests/MethodTests/ControlTransactionMethodTests.cs new file mode 100644 index 0000000..e023579 --- /dev/null +++ b/mocha-dotnet/tests/Mocha.Core.Tests/MethodTests/ControlTransactionMethodTests.cs @@ -0,0 +1,55 @@ +// 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 Mocha.Core.Oop; +using Mocha.Core.Oop.Methods; + +namespace Mocha.Core.Tests.MethodTests; + +public class ControlTransactionMethodTests : MethodTestsBase +{ + + [Test] + public void AssignAttributeMethodTest() + { + InstanceHandle irTestClass = Oms.GetInstance(TEST_CLASS_GUID); + InstanceHandle irTestClassInstance = Oms.CreateInstanceOf(irTestClass); + + InstanceHandle a_Name = Oms.GetInstance(KnownAttributeGuids.Text.Name); + Oms.AddAttribute(irTestClass, a_Name); + + string test_value = "Jackdaws love my big sphinx of quartz."; + + string value = Oms.GetAttributeValue(irTestClassInstance, a_Name); + Assert.That(value, Is.Not.EqualTo(test_value)); + + OmsMethodBuilder builder = new OmsMethodBuilder(Oms); + + BuildAttributeMethod ih_BA = builder.CreateBuildAttributeMethod(irTestClass, "build", "Test Attribute", AccessModifier.Public, true, a_Name, test_value); + ReturnAttributeMethodBinding ramb1 = builder.CreateReturnAttributeMethodBinding(ih_BA); + + AssignAttributeMethod ih_AA = builder.CreateAssignAttributeMethod(irTestClass, "set", "Test Attribute Value to `Jackdaws...`", AccessModifier.Public, true, ramb1, a_Name); + + OmsContext context = Oms.CreateContext(); + Oms.Execute(context, ih_AA, irTestClassInstance); + + value = Oms.GetAttributeValue(irTestClassInstance, a_Name); + Assert.That(value, Is.EqualTo(test_value)); + } + +} \ No newline at end of file