From 6e99d815ebfc51e1ddabd3fe2f5ba7192e595728 Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Tue, 21 Oct 2025 08:43:07 -0400 Subject: [PATCH] move attribute conversion and handling code into separate AttributeImplementation class for ease of adding new attribute types --- .../lib/Mocha.Core/AttributeImplementation.cs | 55 +++++++++++++ .../BooleanAttributeImplementation.cs | 57 +++++++++++++ .../DateAttributeImplementation.cs | 64 +++++++++++++++ .../NumericAttributeImplementation.cs | 58 ++++++++++++++ .../TextAttributeImplementation.cs | 80 +++++++++++++++++++ .../src/lib/Mocha.Core/AttributeValue.cs | 2 +- .../src/lib/Mocha.Core/ClassImplementation.cs | 24 ++++++ .../src/lib/Mocha.Core/InstanceKey.cs | 6 +- .../src/lib/Mocha.Core/KnownAttributeGuids.cs | 1 + .../BuildAttributeMethodImplementation.cs | 55 +------------ .../BuildElementMethodImplementation.cs | 43 ++-------- mocha-dotnet/src/lib/Mocha.Core/Oms.cs | 25 ++++++ 12 files changed, 379 insertions(+), 91 deletions(-) create mode 100644 mocha-dotnet/src/lib/Mocha.Core/AttributeImplementation.cs create mode 100644 mocha-dotnet/src/lib/Mocha.Core/AttributeImplementations/BooleanAttributeImplementation.cs create mode 100644 mocha-dotnet/src/lib/Mocha.Core/AttributeImplementations/DateAttributeImplementation.cs create mode 100644 mocha-dotnet/src/lib/Mocha.Core/AttributeImplementations/NumericAttributeImplementation.cs create mode 100644 mocha-dotnet/src/lib/Mocha.Core/AttributeImplementations/TextAttributeImplementation.cs create mode 100644 mocha-dotnet/src/lib/Mocha.Core/ClassImplementation.cs diff --git a/mocha-dotnet/src/lib/Mocha.Core/AttributeImplementation.cs b/mocha-dotnet/src/lib/Mocha.Core/AttributeImplementation.cs new file mode 100644 index 0000000..03ff9b2 --- /dev/null +++ b/mocha-dotnet/src/lib/Mocha.Core/AttributeImplementation.cs @@ -0,0 +1,55 @@ +// Copyright (C) 2025 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; + +namespace Mocha.Core; + +public abstract class AttributeImplementation : AttributeImplementation +{ + public T ConvertFrom(Oms oms, object? value, T defaultValue = default(T)) + { + object? converted = ConvertFromInternal(oms, value); + if (converted is T) + { + return (T)converted; + } + return defaultValue; + } +} + +public abstract class AttributeImplementation : ClassImplementation +{ + protected abstract object? ConvertFromInternal(Oms oms, object? value); + + public object? ReadDerivedData(BinaryReader br) + { + return ReadDerivedDataInternal(br); + } + protected abstract object? ReadDerivedDataInternal(BinaryReader br); + protected abstract object? ExecuteBuildAttributeMethodInternal(Oms oms, OmsContext context, InstanceHandle method); + public object? ExecuteBuildAttributeMethod(Oms oms, OmsContext context, InstanceHandle method) + { + return ExecuteBuildAttributeMethodInternal(oms, context, method); + } + + protected abstract void ExecuteBuildElementInternal(Oms oms, InstanceHandle targetInstance, InstanceHandle elementContent, InstanceHandle elementContentInstance, JsonObject objCell); + public void ExecuteBuildElement(Oms oms, InstanceHandle targetInstance, InstanceHandle elementContent, InstanceHandle elementContentInstance, JsonObject objCell) + { + ExecuteBuildElementInternal(oms, targetInstance, elementContent, elementContentInstance, objCell); + } +} diff --git a/mocha-dotnet/src/lib/Mocha.Core/AttributeImplementations/BooleanAttributeImplementation.cs b/mocha-dotnet/src/lib/Mocha.Core/AttributeImplementations/BooleanAttributeImplementation.cs new file mode 100644 index 0000000..8e6c83d --- /dev/null +++ b/mocha-dotnet/src/lib/Mocha.Core/AttributeImplementations/BooleanAttributeImplementation.cs @@ -0,0 +1,57 @@ +// Copyright (C) 2025 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; + +namespace Mocha.Core.AttributeImplementations; + +public class BooleanAttributeImplementation : AttributeImplementation +{ + public override Guid ClassGuid => KnownInstanceGuids.Classes.BooleanAttribute; + + protected override object? ConvertFromInternal(Oms oms, object? value) + { + if (value is string) + { + return Boolean.Parse((string)value); + } + return value; + } + protected override object? ReadDerivedDataInternal(BinaryReader br) + { + throw new NotImplementedException(); + } + protected override object? ExecuteBuildAttributeMethodInternal(Oms oms, OmsContext context, InstanceHandle method) + { + object? value = oms.UnsafeGetAttributeValue(method, oms.GetInstance(KnownAttributeGuids.Text.Value)); // initial value + + if (value is string) + { + bool val = Boolean.Parse((string)value); + return val; + } + return null; + } + protected override void ExecuteBuildElementInternal(Oms oms, InstanceHandle targetInstance, InstanceHandle elementContent, InstanceHandle elementContentInstance, JsonObject objCell) + { + objCell.Add("widget", "checkBox"); + objCell.Add("value", oms.GetAttributeValue(targetInstance, elementContentInstance)); + objCell.Add("text", oms.GetAttributeValue(targetInstance, elementContentInstance) ? "Yes" : "No"); + } +} \ No newline at end of file diff --git a/mocha-dotnet/src/lib/Mocha.Core/AttributeImplementations/DateAttributeImplementation.cs b/mocha-dotnet/src/lib/Mocha.Core/AttributeImplementations/DateAttributeImplementation.cs new file mode 100644 index 0000000..a78ac87 --- /dev/null +++ b/mocha-dotnet/src/lib/Mocha.Core/AttributeImplementations/DateAttributeImplementation.cs @@ -0,0 +1,64 @@ +// Copyright (C) 2025 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; + +namespace Mocha.Core.AttributeImplementations; + +public class DateAttributeImplementation : AttributeImplementation +{ + public override Guid ClassGuid => KnownInstanceGuids.Classes.DateAttribute; + + protected override object? ConvertFromInternal(Oms oms, object? value) + { + if (value is string) + { + return Boolean.Parse((string)value); + } + return value; + } + protected override object? ReadDerivedDataInternal(BinaryReader br) + { + throw new NotImplementedException(); + } + protected override object? ExecuteBuildAttributeMethodInternal(Oms oms, OmsContext context, InstanceHandle method) + { + object? value = oms.UnsafeGetAttributeValue(method, oms.GetInstance(KnownAttributeGuids.Text.Value)); // initial value + + if (value is string) + { + DateTime val = DateTime.Parse((string)value); + return val; + } + return null; + } + protected override void ExecuteBuildElementInternal(Oms oms, InstanceHandle targetInstance, InstanceHandle elementContent, InstanceHandle elementContentInstance, JsonObject objCell) + { + objCell.Add("widget", "date"); + + DateTime dt = oms.GetAttributeValue(targetInstance, elementContentInstance); + 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"); + } +} \ No newline at end of file diff --git a/mocha-dotnet/src/lib/Mocha.Core/AttributeImplementations/NumericAttributeImplementation.cs b/mocha-dotnet/src/lib/Mocha.Core/AttributeImplementations/NumericAttributeImplementation.cs new file mode 100644 index 0000000..7bc13e1 --- /dev/null +++ b/mocha-dotnet/src/lib/Mocha.Core/AttributeImplementations/NumericAttributeImplementation.cs @@ -0,0 +1,58 @@ +// Copyright (C) 2025 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; + +namespace Mocha.Core.AttributeImplementations; + +public class NumericAttributeImplementation : AttributeImplementation +{ + public override Guid ClassGuid => KnownInstanceGuids.Classes.NumericAttribute; + + protected override object? ConvertFromInternal(Oms oms, object? value) + { + if (value is string) + { + return Boolean.Parse((string)value); + } + return value; + } + protected override object? ReadDerivedDataInternal(BinaryReader br) + { + throw new NotImplementedException(); + } + protected override object? ExecuteBuildAttributeMethodInternal(Oms oms, OmsContext context, InstanceHandle method) + { + object? value = oms.UnsafeGetAttributeValue(method, oms.GetInstance(KnownAttributeGuids.Numeric.Value)); // initial value + + if (value is decimal) + { + return value; + } + return null; + } + protected override void ExecuteBuildElementInternal(Oms oms, InstanceHandle targetInstance, InstanceHandle elementContent, InstanceHandle elementContentInstance, JsonObject objCell) + { + objCell.Add("widget", "number"); + objCell.Add("value", oms.GetAttributeValue(targetInstance, elementContentInstance)); + objCell.Add("text", oms.GetAttributeValue(targetInstance, elementContentInstance).ToString()); + objCell.Add("precision", 6); + objCell.Add("format", "#0.######"); + } +} \ No newline at end of file diff --git a/mocha-dotnet/src/lib/Mocha.Core/AttributeImplementations/TextAttributeImplementation.cs b/mocha-dotnet/src/lib/Mocha.Core/AttributeImplementations/TextAttributeImplementation.cs new file mode 100644 index 0000000..c8324b5 --- /dev/null +++ b/mocha-dotnet/src/lib/Mocha.Core/AttributeImplementations/TextAttributeImplementation.cs @@ -0,0 +1,80 @@ +// Copyright (C) 2025 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; + +namespace Mocha.Core.AttributeImplementations; + +public class TextAttributeImplementation : AttributeImplementation +{ + public override Guid ClassGuid => KnownInstanceGuids.Classes.TextAttribute; + protected override object? ConvertFromInternal(Oms oms, object? value) + { + return (string)value; //! ??? + } + protected override object? ReadDerivedDataInternal(BinaryReader br) + { + int length = br.ReadInt32(); + string value = br.ReadString(); + return value; + } + protected override object? ExecuteBuildAttributeMethodInternal(Oms oms, OmsContext context, InstanceHandle method) + { + object? value = oms.UnsafeGetAttributeValue(method, oms.GetInstance(KnownAttributeGuids.Text.Value)); // initial value + + if (value is string) + { + IEnumerable 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 (val is string) + { + value = ((string)value) + (string)val; + } + } + return value; + } + return null; + } + protected override void ExecuteBuildElementInternal(Oms oms, InstanceHandle targetInstance, InstanceHandle elementContent, InstanceHandle elementContentInstance, JsonObject objCell) + { + objCell.Add("widget", "text"); + if (targetInstance == InstanceHandle.Empty) + { + objCell.Add("value", oms.GetAttributeValue(elementContentInstance, oms.GetInstance(KnownAttributeGuids.Text.Value))); + } + else + { + objCell.Add("value", oms.GetAttributeValue(targetInstance, elementContentInstance)); + } + } +} \ No newline at end of file diff --git a/mocha-dotnet/src/lib/Mocha.Core/AttributeValue.cs b/mocha-dotnet/src/lib/Mocha.Core/AttributeValue.cs index 953920d..571f74e 100644 --- a/mocha-dotnet/src/lib/Mocha.Core/AttributeValue.cs +++ b/mocha-dotnet/src/lib/Mocha.Core/AttributeValue.cs @@ -15,7 +15,7 @@ // You should have received a copy of the GNU General Public License // along with Mocha.NET. If not, see . -namespace Mocha.Core; +namespace Mocha.Core; public struct AttributeValue { diff --git a/mocha-dotnet/src/lib/Mocha.Core/ClassImplementation.cs b/mocha-dotnet/src/lib/Mocha.Core/ClassImplementation.cs new file mode 100644 index 0000000..c2f8d2b --- /dev/null +++ b/mocha-dotnet/src/lib/Mocha.Core/ClassImplementation.cs @@ -0,0 +1,24 @@ +// Copyright (C) 2025 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 . + +namespace Mocha.Core; + +public abstract class ClassImplementation +{ + public abstract Guid ClassGuid { get; } + +} \ No newline at end of file diff --git a/mocha-dotnet/src/lib/Mocha.Core/InstanceKey.cs b/mocha-dotnet/src/lib/Mocha.Core/InstanceKey.cs index 8810a30..96d41d0 100755 --- a/mocha-dotnet/src/lib/Mocha.Core/InstanceKey.cs +++ b/mocha-dotnet/src/lib/Mocha.Core/InstanceKey.cs @@ -203,15 +203,15 @@ namespace Mocha.Core IEnumerable attributes = oms.GetRelatedInstances(_parentClassInstance, oms.GetInstance(KnownRelationshipGuids.Class__has__Attribute)); foreach (InstanceHandle att in attributes) { - if (oms.IsInstanceOf(att, oms.GetInstance(KnownInstanceGuids.Classes.TextAttribute))) + AttributeImplementation? impl = oms.GetAttributeImplementation(att); + if (impl != null) { if (br.BaseStream.EndOfStream()) { break; } - int length = br.ReadInt32(); - string value = br.ReadString(); + object? value = impl.ReadDerivedData(br); derivedData[att] = value; } } diff --git a/mocha-dotnet/src/lib/Mocha.Core/KnownAttributeGuids.cs b/mocha-dotnet/src/lib/Mocha.Core/KnownAttributeGuids.cs index 38513df..c4ea2ce 100755 --- a/mocha-dotnet/src/lib/Mocha.Core/KnownAttributeGuids.cs +++ b/mocha-dotnet/src/lib/Mocha.Core/KnownAttributeGuids.cs @@ -28,6 +28,7 @@ namespace Mocha.Core public static Guid CSSValue { get; } = new Guid("{C0DD4A42-F503-4EB3-8034-7C428B1B8803}"); public static Guid RelationshipType { get; } = new Guid("{71106B12-1934-4834-B0F6-D894637BAEED}"); public static Guid Order { get; } = new Guid("{49423f66-8837-430d-8cac-7892ebdcb1fe}"); + public static Guid HelpText { get; } = new Guid("{edfe6493-0adf-4d49-9f19-babbe9a99acf}"); public static Guid TargetURL { get; } = new Guid("{970F79A0-9EFE-4E7D-9286-9908C6F06A67}"); public static Guid ReferralURL { get; } = new Guid("{6daaa721-db70-43ad-b373-6a8038e69d2e}"); diff --git a/mocha-dotnet/src/lib/Mocha.Core/MethodImplementations/BuildAttributeMethodImplementation.cs b/mocha-dotnet/src/lib/Mocha.Core/MethodImplementations/BuildAttributeMethodImplementation.cs index 5617de6..97a762a 100644 --- a/mocha-dotnet/src/lib/Mocha.Core/MethodImplementations/BuildAttributeMethodImplementation.cs +++ b/mocha-dotnet/src/lib/Mocha.Core/MethodImplementations/BuildAttributeMethodImplementation.cs @@ -32,60 +32,13 @@ public class BuildAttributeMethodImplementation : MethodImplementation // InstanceHandle forInstance = (InstanceHandle) context.GetWorkData(irForClass); - if (oms.IsInstanceOf(returnsAttribute, oms.GetInstance(KnownInstanceGuids.Classes.TextAttribute))) + AttributeImplementation impl = oms.GetAttributeImplementation(returnsAttribute); + object? value = impl.ExecuteBuildAttributeMethod(oms, context, method); + if (value != null) { - object? value = oms.UnsafeGetAttributeValue(method, oms.GetInstance(KnownAttributeGuids.Text.Value)); // initial value - - if (value is string) - { - IEnumerable 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 (val is string) - { - value = ((string)value) + (string)val; - } - } - } context.SetWorkData(returnsAttribute, value); } - else if (oms.IsInstanceOf(returnsAttribute, oms.GetInstance(KnownInstanceGuids.Classes.BooleanAttribute))) - { - object? value = oms.UnsafeGetAttributeValue(method, oms.GetInstance(KnownAttributeGuids.Text.Value)); // initial value - - if (value is string) - { - bool val = Boolean.Parse((string)value); - context.SetWorkData(returnsAttribute, val); - } - } - 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(); - } - + return returnsAttribute; } } \ No newline at end of file diff --git a/mocha-dotnet/src/lib/Mocha.Core/MethodImplementations/BuildElementMethodImplementation.cs b/mocha-dotnet/src/lib/Mocha.Core/MethodImplementations/BuildElementMethodImplementation.cs index e82e7a7..7e33c02 100644 --- a/mocha-dotnet/src/lib/Mocha.Core/MethodImplementations/BuildElementMethodImplementation.cs +++ b/mocha-dotnet/src/lib/Mocha.Core/MethodImplementations/BuildElementMethodImplementation.cs @@ -138,46 +138,17 @@ public class BuildElementMethodImplementation : MethodImplementation { objCell.Add("enabled", false); } - // objCell.Add("helpText", "blah blah"); - if (oms.IsInstanceOf(ecInst, oms.GetInstance(KnownInstanceGuids.Classes.TextAttribute))) + string? helpText = oms.GetAttributeValue(elementContent, oms.GetInstance(KnownAttributeGuids.Text.HelpText)); + if (helpText != null) { - objCell.Add("widget", "text"); - if (targetInstance == InstanceHandle.Empty) - { - objCell.Add("value", oms.GetAttributeValue(ecInst, oms.GetInstance(KnownAttributeGuids.Text.Value))); - } - else - { - objCell.Add("value", oms.GetAttributeValue(targetInstance, ecInst)); - } + objCell.Add("helpText", helpText); } - else if (oms.IsInstanceOf(ecInst, oms.GetInstance(KnownInstanceGuids.Classes.BooleanAttribute))) - { - objCell.Add("widget", "checkBox"); - objCell.Add("value", oms.GetAttributeValue(targetInstance, ecInst)); - objCell.Add("text", oms.GetAttributeValue(targetInstance, ecInst) ? "Yes" : "No"); - } - else if (oms.IsInstanceOf(ecInst, oms.GetInstance(KnownInstanceGuids.Classes.NumericAttribute))) - { - objCell.Add("widget", "number"); - objCell.Add("value", oms.GetAttributeValue(targetInstance, ecInst)); - objCell.Add("text", oms.GetAttributeValue(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(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"); + if (oms.IsInstanceOf(ecInst, oms.GetInstance(KnownInstanceGuids.Classes.Attribute))) + { + AttributeImplementation impl = oms.GetAttributeImplementation(ecInst); + impl.ExecuteBuildElement(oms, targetInstance, elementContent, ecInst, objCell); } else { diff --git a/mocha-dotnet/src/lib/Mocha.Core/Oms.cs b/mocha-dotnet/src/lib/Mocha.Core/Oms.cs index 1b6c4f5..ba038b9 100644 --- a/mocha-dotnet/src/lib/Mocha.Core/Oms.cs +++ b/mocha-dotnet/src/lib/Mocha.Core/Oms.cs @@ -57,6 +57,12 @@ public abstract class Oms { RegisterMethodImplementation(impl.MethodClassGuid, impl); } + + AttributeImplementation[] attributeImplementations = MBS.Core.Reflection.TypeLoader.GetAvailableTypes(new System.Reflection.Assembly[] { Assembly.GetExecutingAssembly() }); + foreach (AttributeImplementation impl in attributeImplementations) + { + RegisterAttributeImplementation(impl.ClassGuid, impl); + } } protected virtual void InitializeInternal() @@ -1219,6 +1225,12 @@ public abstract class Oms methodImplementations[methodClassId] = implementation; } + private Dictionary attributeImplementations = new Dictionary(); + private void RegisterAttributeImplementation(Guid attributeClassId, AttributeImplementation implementation) + { + attributeImplementations[attributeClassId] = implementation; + } + public InstanceHandle Execute(OmsContext context, MethodBinding methodBinding, IInstanceReference? targetInstance = null) { InstanceHandle? targetInstanceHandle = null; @@ -2768,4 +2780,17 @@ public abstract class Oms } return InstanceHandle.Empty; } + + public AttributeImplementation GetAttributeImplementation(InstanceHandle att) + { + InstanceHandle parentClass = GetParentClass(att); + Guid classGuid = GetGlobalIdentifier(parentClass); + + // find AttributeImplementation whose ClassGuid matches + if (attributeImplementations.ContainsKey(classGuid)) + { + return attributeImplementations[classGuid]; + } + throw new NotImplementedException(String.Format("implementation for attribute class {0} not found", classGuid)); + } }