start working on rendering pages
This commit is contained in:
parent
41d7fb1959
commit
f7cdcbb33a
@ -1,11 +1,7 @@
|
||||
using System.Xml;
|
||||
using MBS.Core;
|
||||
using MBS.Web;
|
||||
using MBS.Web.UI;
|
||||
using MBS.Web.UI.HtmlControls;
|
||||
using MBS.Web.UI.WebControls;
|
||||
using Mocha.Core;
|
||||
using Mocha.ServerApplication.Controls;
|
||||
|
||||
namespace Mocha.ServerApplication.HardcodedPages;
|
||||
|
||||
@ -17,10 +13,23 @@ public class TenantedRoutingPage : BaseWebPage
|
||||
this.ProcessedByCT = processedByCT;
|
||||
}
|
||||
|
||||
protected override void RenderContents(XmlWriter writer)
|
||||
protected override void CreateChildControls()
|
||||
{
|
||||
base.RenderContents(writer);
|
||||
writer.WriteRaw(String.Format("<h1>Processed by CT: {0}</h1>", ((MochaWebApplication)Application.Instance).Oms.GetInstanceText(ProcessedByCT)));
|
||||
base.CreateChildControls();
|
||||
|
||||
Oms oms = ((MochaWebApplication)Application.Instance).Oms;
|
||||
InstanceHandle usesBuildResponseMethodBinding = oms.GetRelatedInstance(ProcessedByCT, oms.GetInstance(KnownRelationshipGuids.Control_Transaction_Method__uses__Build_Response_Method_Binding));
|
||||
|
||||
OmsContext context = oms.CreateContext();
|
||||
PageRenderer renderer = new PageRenderer(context);
|
||||
|
||||
InstanceHandle element = oms.Execute(context, usesBuildResponseMethodBinding);
|
||||
|
||||
// writer.WriteRaw(String.Format("<h1>Processed by CT: {0}</h1>", oms.GetInstanceText(ProcessedByCT)));
|
||||
// writer.WriteRaw(String.Format("<h1>Responds with Element: {0}</h1>", oms.GetInstanceText(element)));
|
||||
|
||||
Container ct = renderer.RenderElement(element);
|
||||
Controls.Add(ct);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
59
mocha-dotnet/src/app/Mocha.ServerApplication/PageRenderer.cs
Normal file
59
mocha-dotnet/src/app/Mocha.ServerApplication/PageRenderer.cs
Normal file
@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using MBS.Web;
|
||||
using MBS.Web.UI.WebControls;
|
||||
using Mocha.Core;
|
||||
|
||||
namespace Mocha.ServerApplication;
|
||||
|
||||
public class PageRenderer
|
||||
{
|
||||
public OmsContext Context { get; }
|
||||
public PageRenderer(OmsContext context)
|
||||
{
|
||||
Context = context;
|
||||
}
|
||||
|
||||
public Container RenderElement(InstanceHandle element)
|
||||
{
|
||||
Oms oms = Context.Oms;
|
||||
|
||||
Container ct = new Container();
|
||||
|
||||
InstanceHandle r_Element__has__Element_Content = oms.GetInstance(KnownRelationshipGuids.Element__has__Element_Content);
|
||||
|
||||
IEnumerable<InstanceHandle> elementContents = oms.GetRelatedInstances(element, r_Element__has__Element_Content);
|
||||
foreach (InstanceHandle elementContent in elementContents)
|
||||
{
|
||||
Control ctl = RenderElementContent(elementContent);
|
||||
ct.Controls.Add(ctl);
|
||||
}
|
||||
return ct;
|
||||
}
|
||||
|
||||
private Control RenderElementContent(InstanceHandle elementContent)
|
||||
{
|
||||
Oms oms = Context.Oms;
|
||||
|
||||
InstanceHandle c_TextAttribute = oms.GetInstance(KnownInstanceGuids.Classes.TextAttribute);
|
||||
InstanceHandle c_BooleanAttribute = oms.GetInstance(KnownInstanceGuids.Classes.BooleanAttribute);
|
||||
InstanceHandle c_NumericAttribute = oms.GetInstance(KnownInstanceGuids.Classes.NumericAttribute);
|
||||
InstanceHandle c_DateAttribute = oms.GetInstance(KnownInstanceGuids.Classes.DateAttribute);
|
||||
|
||||
InstanceHandle r_Element_Content__has__Element_Content_Display_Option = oms.GetInstance(KnownRelationshipGuids.Element_Content__has__Element_Content_Display_Option);
|
||||
InstanceHandle r_Element_Content__has__Instance = oms.GetInstance(KnownRelationshipGuids.Element_Content__has__Instance);
|
||||
|
||||
IEnumerable<InstanceHandle> displayOptions = oms.GetRelatedInstances(elementContent, r_Element_Content__has__Element_Content_Display_Option);
|
||||
InstanceHandle ecInstance = oms.GetRelatedInstance(elementContent, r_Element_Content__has__Instance);
|
||||
|
||||
if (oms.IsInstanceOf(ecInstance, c_TextAttribute))
|
||||
{
|
||||
InstanceHandle a_Value = oms.GetInstance(KnownAttributeGuids.Text.Value);
|
||||
|
||||
TextBox ctl = new TextBox();
|
||||
ctl.Value = oms.GetAttributeValue<string>(ecInstance, a_Value);
|
||||
return ctl;
|
||||
}
|
||||
|
||||
return new Label(String.Format("No implementaton for EC instance type {0}", oms.GetGlobalIdentifier(oms.GetParentClass(ecInstance))));
|
||||
}
|
||||
}
|
||||
@ -106,6 +106,8 @@ public class Program : MochaWebApplication
|
||||
oms.SetTranslationValue(i_Tenant, r_Tenant__has_login_header__Translation, i_English, "Alerynn: Infinite Universe");
|
||||
oms.SetTranslationValue(i_Tenant, r_Tenant__has_login_footer__Translation, i_English, "Welcome to the Nest!");
|
||||
|
||||
InstanceHandle a_Name = oms.GetInstance(KnownAttributeGuids.Text.Name);
|
||||
|
||||
InstanceHandle c_User = oms.GetInstance(KnownInstanceGuids.Classes.User);
|
||||
InstanceHandle a_UserName = oms.GetInstance(KnownAttributeGuids.Text.UserName);
|
||||
|
||||
@ -125,6 +127,8 @@ public class Program : MochaWebApplication
|
||||
InstanceHandle r_Element_Content__has__Instance = oms.GetInstance(KnownRelationshipGuids.Element_Content__has__Instance);
|
||||
|
||||
InstanceHandle el_AlerynnWelcome1 = oms.CreateInstanceOf(c_Element);
|
||||
oms.SetAttributeValue(el_AlerynnWelcome1, a_Name, "alerynn welcome page");
|
||||
|
||||
InstanceHandle ec_AlerynnWelcome1 = oms.CreateInstanceOf(c_ElementContent);
|
||||
oms.AssignRelationship(ec_AlerynnWelcome1, r_Element_Content__has__Instance, a_AlerynnWelcome1);
|
||||
oms.AssignRelationship(el_AlerynnWelcome1, r_Element__has__Element_Content, ec_AlerynnWelcome1);
|
||||
|
||||
@ -23,10 +23,10 @@ namespace Mocha.Core;
|
||||
|
||||
public class OmsContext
|
||||
{
|
||||
private Oms oms;
|
||||
public Oms Oms { get; }
|
||||
internal OmsContext(Oms oms)
|
||||
{
|
||||
this.oms = oms;
|
||||
Oms = oms;
|
||||
}
|
||||
|
||||
private Dictionary<InstanceHandle, object?> _WorkData = new Dictionary<InstanceHandle, object?>();
|
||||
@ -39,7 +39,7 @@ public class OmsContext
|
||||
if (_WorkData.ContainsKey(parm))
|
||||
return _WorkData[parm];
|
||||
|
||||
Console.Error.WriteLine("work data not found for parm {0}", oms.GetGlobalIdentifier(parm));
|
||||
Console.Error.WriteLine("work data not found for parm {0}", Oms.GetGlobalIdentifier(parm));
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -63,21 +63,21 @@ public class OmsContext
|
||||
}
|
||||
public void SetWorkData(InstanceHandle parm, object? value)
|
||||
{
|
||||
if (oms.IsInstanceOf(parm, oms.GetInstance(KnownInstanceGuids.Classes.WorkSet)))
|
||||
if (Oms.IsInstanceOf(parm, Oms.GetInstance(KnownInstanceGuids.Classes.WorkSet)))
|
||||
{
|
||||
bool singular = false;
|
||||
if (!oms.TryGetAttributeValue<bool>(parm, oms.GetInstance(KnownAttributeGuids.Boolean.Singular), out singular))
|
||||
if (!Oms.TryGetAttributeValue<bool>(parm, Oms.GetInstance(KnownAttributeGuids.Boolean.Singular), out singular))
|
||||
{
|
||||
singular = false;
|
||||
}
|
||||
|
||||
if (value is InstanceHandle)
|
||||
{
|
||||
IReadOnlyCollection<InstanceHandle> irs = oms.GetRelatedInstances(parm, oms.GetInstance(KnownRelationshipGuids.Work_Set__has_valid__Class));
|
||||
IReadOnlyCollection<InstanceHandle> irs = Oms.GetRelatedInstances(parm, Oms.GetInstance(KnownRelationshipGuids.Work_Set__has_valid__Class));
|
||||
if (irs.Count > 0)
|
||||
{
|
||||
InstanceHandle ir = (InstanceHandle)value;
|
||||
InstanceHandle parentClass = oms.GetParentClass(ir);
|
||||
InstanceHandle parentClass = Oms.GetParentClass(ir);
|
||||
if (!irs.Contains(parentClass))
|
||||
{
|
||||
throw new ArgumentException("instance reference must be an instance of appropriate class");
|
||||
@ -91,12 +91,12 @@ public class OmsContext
|
||||
{
|
||||
throw new InvalidOperationException("Singular Work Set must only contain a single InstanceReference or be an array of InstanceReference that contains exactly zero or one item.");
|
||||
}
|
||||
IEnumerable<InstanceHandle> irs = oms.GetRelatedInstances(parm, oms.GetInstance(KnownRelationshipGuids.Work_Set__has_valid__Class));
|
||||
IEnumerable<InstanceHandle> irs = Oms.GetRelatedInstances(parm, Oms.GetInstance(KnownRelationshipGuids.Work_Set__has_valid__Class));
|
||||
if (irs != null)
|
||||
{
|
||||
foreach (InstanceHandle ir in insts)
|
||||
{
|
||||
InstanceHandle parentClass = oms.GetParentClass(ir);
|
||||
InstanceHandle parentClass = Oms.GetParentClass(ir);
|
||||
if (!irs.Contains(parentClass))
|
||||
{
|
||||
throw new ArgumentException("instance reference must be an instance of appropriate class");
|
||||
@ -111,7 +111,7 @@ public class OmsContext
|
||||
{
|
||||
throw new InvalidOperationException("Singular Work Set must only contain a single InstanceReference or be an array of InstanceReference that contains exactly zero or one item.");
|
||||
}
|
||||
IEnumerable<InstanceHandle> irs = oms.GetRelatedInstances(parm, oms.GetInstance(KnownRelationshipGuids.Work_Set__has_valid__Class));
|
||||
IEnumerable<InstanceHandle> irs = Oms.GetRelatedInstances(parm, Oms.GetInstance(KnownRelationshipGuids.Work_Set__has_valid__Class));
|
||||
if (irs != null)
|
||||
{
|
||||
if (irs.Count() > 0)
|
||||
@ -119,7 +119,7 @@ public class OmsContext
|
||||
foreach (InstanceWrapper iw in insts)
|
||||
{
|
||||
InstanceHandle ir = iw.Handle;
|
||||
InstanceHandle parentClass = oms.GetParentClass(ir);
|
||||
InstanceHandle parentClass = Oms.GetParentClass(ir);
|
||||
if (!irs.Contains(parentClass))
|
||||
{
|
||||
throw new ArgumentException("instance reference must be an instance of appropriate class");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user