");
sw.WriteLine("
");
}
else if (instParentClass.GlobalIdentifier == KnownInstanceGuids.Classes.ElementPageComponent)
{
Instance element = oms.GetRelatedInstance(inst, KnownRelationshipGuids.Element_Page_Component__has__Element);
Instance[] elementDisplayOptions = oms.GetRelatedInstances(inst, KnownRelationshipGuids.Element_Page_Component__has__Element_Content_Display_Option);
Instance ecDoSingular = oms.GetInstance(KnownInstanceGuids.ElementContentDisplayOptions.Singular);
bool singular = (oms.InstanceSetContains(elementDisplayOptions, ecDoSingular));
if (singular)
{
sw.WriteFixedLengthString(String.Format("
");
if (element != null)
{
Instance[] elementContents = oms.GetRelatedInstances(element, KnownRelationshipGuids.Element__has__Element_Content);
foreach (Instance elementContent in elementContents)
{
Instance elementContentInstance = oms.GetRelatedInstance(elementContent, KnownRelationshipGuids.Element_Content__has__Instance);
InstanceKey ecid = oms.GetInstanceKey(elementContentInstance);
sw.WriteLine(String.Format("
");
}
}
}
else
{
sw.WriteFixedLengthString(String.Format("
");
sw.WriteLine("Test PageBuilder 1 item ");
sw.WriteLine("");
sw.WriteLine("
");
sw.WriteLine("
");
sw.WriteLine("
");
sw.WriteLine("
");
sw.WriteLine("
");
sw.WriteLine("
");
if (element != null)
{
Instance[] elementContents = oms.GetRelatedInstances(element, KnownRelationshipGuids.Element__has__Element_Content);
sw.WriteLine("");
sw.WriteLine("");
foreach (Instance elementContent in elementContents)
{
Instance elementContentInstance = oms.GetRelatedInstance(elementContent, KnownRelationshipGuids.Element_Content__has__Instance);
InstanceKey ecid = oms.GetInstanceKey(elementContentInstance);
sw.WriteLine(String.Format("", oms.GetInstanceKey(elementContentInstance)));
sw.WriteLine(String.Format("{0} ", oms.GetInstanceText(elementContentInstance)));
sw.WriteLine(" ");
}
sw.WriteLine(" ");
sw.WriteLine("");
sw.WriteLine("");
foreach (Instance elementContent in elementContents)
{
sw.WriteLine("");
Instance elementContentInstance = oms.GetRelatedInstance(elementContent, KnownRelationshipGuids.Element_Content__has__Instance);
InstanceKey ecid = oms.GetInstanceKey(elementContentInstance);
Instance elementContentInstanceParentClass = oms.GetParentClass(elementContentInstance);
if (elementContentInstanceParentClass.GlobalIdentifier == KnownInstanceGuids.Classes.TextAttribute)
{
Instance[] instDisplayOptions = oms.GetRelatedInstances(elementContent, KnownRelationshipGuids.Element_Content__has__Element_Content_Display_Option);
Instance instDO_ObscuredText = oms.GetInstance(KnownInstanceGuids.ElementContentDisplayOptions.ObscuredText);
if (oms.InstanceSetContains(instDisplayOptions, instDO_ObscuredText))
{
sw.WriteLine(String.Format(" ", String.Format("ec__{0}", ecid.ToString().Replace("$", "_"))));
}
else
{
sw.WriteLine(String.Format(" ", String.Format("ec__{0}", ecid.ToString().Replace("$", "_"))));
}
}
else
{
sw.WriteLine(String.Format("(EC not implemented for class '{0}')", elementContentInstanceParentClass.GlobalIdentifier));
}
sw.WriteLine(" ");
}
sw.WriteLine(" ");
sw.WriteLine(" ");
}
}
}
else if (instParentClass.GlobalIdentifier == KnownInstanceGuids.Classes.ParagraphPageComponent)
{
sw.WriteFixedLengthString(String.Format("", instId));
Instance instMethod = oms.GetRelatedInstance(inst, KnownRelationshipGuids.Content_Page_Component__gets_content_from__Method);
OmsContext ctx = new OmsContext();
object methodResult = oms.ExecuteMethod(instMethod, ctx);
if (methodResult is string)
{
sw.Write((string)methodResult);
}
else if (methodResult is Instance[])
{
sw.Write(oms.GetInstanceText(((Instance[])methodResult)[0]));
}
}
else if (instParentClass.GlobalIdentifier == KnownInstanceGuids.Classes.TabContainerPageComponent)
{
}
else if (instParentClass.GlobalIdentifier == KnownInstanceGuids.Classes.SequentialContainerPageComponent)
{
sw.WriteFixedLengthString(String.Format("
");
}
}
private void WriteClassAttribute(StreamWriter sw, Instance inst, string requiredClasses = null)
{
System.Text.StringBuilder sbClassName = new System.Text.StringBuilder();
if (requiredClasses != null)
{
sbClassName.Append(requiredClasses);
if (!requiredClasses.EndsWith(" ", StringComparison.OrdinalIgnoreCase))
{
sbClassName.Append(' ');
}
}
Instance instStyle = oms.GetRelatedInstance(inst, KnownRelationshipGuids.Page_Component__has__Style);
if (instStyle != null)
{
Instance[] instStyleClasses = oms.GetRelatedInstances(instStyle, KnownRelationshipGuids.Style__has__Style_Class);
for (int i = 0; i < instStyleClasses.Length; i++)
{
string value = oms.GetAttributeValue(instStyleClasses[i], KnownAttributeGuids.Text.Value);
sbClassName.Append(value);
if (i < instStyleClasses.Length - 1)
{
sbClassName.Append(' ');
}
}
}
if (sbClassName.Length > 0)
{
sw.WriteFixedLengthString(String.Format(" class=\"{0}\"", sbClassName.ToString()));
}
}
private void RenderEndTag(Instance inst, StreamWriter sw)
{
Instance instParentClass = oms.GetParentClass(inst);
if (instParentClass.GlobalIdentifier == KnownInstanceGuids.Classes.ImagePageComponent)
{
}
else if (instParentClass.GlobalIdentifier == KnownInstanceGuids.Classes.PanelPageComponent)
{
sw.WriteLine("
");
}
else if (instParentClass.GlobalIdentifier == KnownInstanceGuids.Classes.ButtonPageComponent)
{
sw.WriteLine("");
}
else if (instParentClass.GlobalIdentifier == KnownInstanceGuids.Classes.DetailPageComponent)
{
}
else if (instParentClass.GlobalIdentifier == KnownInstanceGuids.Classes.HeadingPageComponent)
{
decimal level = oms.GetAttributeValue(inst, KnownAttributeGuids.Numeric.Level);
sw.WriteFixedLengthString(String.Format("", level));
}
else if (instParentClass.GlobalIdentifier == KnownInstanceGuids.Classes.SummaryPageComponent)
{
sw.WriteLine("");
}
else if (instParentClass.GlobalIdentifier == KnownInstanceGuids.Classes.ElementPageComponent)
{
Instance[] elementDisplayOptions = oms.GetRelatedInstances(inst, KnownRelationshipGuids.Element_Page_Component__has__Element_Content_Display_Option);
Instance ecDoSingular = oms.GetInstance(KnownInstanceGuids.ElementContentDisplayOptions.Singular);
bool singular = (oms.InstanceSetContains(elementDisplayOptions, ecDoSingular));
if (singular)
{
sw.WriteLine("");
}
else
{
sw.WriteLine("
");
}
}
else if (instParentClass.GlobalIdentifier == KnownInstanceGuids.Classes.ParagraphPageComponent)
{
sw.WriteLine("");
}
else if (instParentClass.GlobalIdentifier == KnownInstanceGuids.Classes.TabContainerPageComponent)
{
}
else if (instParentClass.GlobalIdentifier == KnownInstanceGuids.Classes.SequentialContainerPageComponent)
{
sw.WriteLine("
");
sw.WriteLine();
}
}
public void RenderPageComponent(Instance inst, StreamWriter sw)
{
Instance instParentClass = oms.GetParentClass(inst);
RenderBeginTag(inst, sw);
sw.WriteLine();
if (oms.IsClassSubclassOf(instParentClass, KnownInstanceGuids.Classes.ContainerPageComponent))
{
Instance[] instChildren = oms.GetRelatedInstances(inst, KnownRelationshipGuids.Container_Page_Component__has__Page_Component);
foreach (Instance inst2 in instChildren)
{
RenderPageComponent(inst2, sw);
}
sw.WriteLine();
}
RenderEndTag(inst, sw);
}
public void RenderPage(Instance instPage, StreamWriter sw)
{
Instance instMasterPage = oms.GetRelatedInstance(instPage, KnownRelationshipGuids.Page__has_master__Page);
sw.WriteLine("");
sw.WriteLine("");
sw.Write("
");
sw.WriteLine(GetPageTitle(instPage));
sw.WriteLine(" ");
Instance instTenant = oms.GetTenantInstance();
Instance instShortcutIcon = oms.GetRelatedInstance(instTenant, KnownRelationshipGuids.Tenant__has_icon_image__File);
sw.WriteLine(String.Format("
", sess.GetAttachmentUrl(instShortcutIcon, sess.GetOmsAttachmentEntropy())));
sw.WriteLine("
");
sw.WriteLine("");
sw.WriteLine("");
sw.WriteLine("");
sw.WriteLine("
");
sw.WriteLine("");
sw.WriteLine("");
}
private string GetPageTitle(Instance instPage)
{
string title = oms.GetInstanceText(instPage);
if (title == null)
{
Instance instMasterPage = oms.GetRelatedInstance(instPage, KnownRelationshipGuids.Page__has_master__Page);
title = oms.GetInstanceText(instMasterPage);
}
return title;
}
private void WritePageStyles(StreamWriter sw, Instance instPage)
{
Instance[] instStyles = oms.GetRelatedInstances(instPage, KnownRelationshipGuids.Page__has__Style);
sw.Write("body { ");
foreach (Instance instStyle in instStyles)
{
RenderStyleSheet(sw, instStyle);
}
sw.Write(" }");
Instance[] instComponents = oms.GetRelatedInstances(instPage, KnownRelationshipGuids.Page__has__Page_Component);
foreach (Instance instComponent in instComponents)
{
ApplyComponentStyle(sw, instComponent);
}
}
private void ApplyComponentStyle(StreamWriter sw, Instance instComponent)
{
sw.WriteFixedLengthString(String.Format("[data-instance-id=\"{0}\"] {{", oms.GetInstanceKey(instComponent)));
Instance[] instComponentStyles = oms.GetRelatedInstances(instComponent, KnownRelationshipGuids.Page_Component__has__Style);
foreach (Instance instComponentStyle in instComponentStyles)
{
RenderStyleSheet(sw, instComponentStyle);
}
sw.Write(" } ");
Instance instComponentClass = oms.GetParentClass(instComponent);
if (oms.IsClassSubclassOf(instComponentClass, KnownInstanceGuids.Classes.ContainerPageComponent))
{
Instance[] instSubComponents = oms.GetRelatedInstances(instComponent, KnownRelationshipGuids.Container_Page_Component__has__Page_Component);
foreach (Instance instSubComponent in instSubComponents)
{
ApplyComponentStyle(sw, instSubComponent);
}
}
if (instComponentClass.GlobalIdentifier == KnownInstanceGuids.Classes.PanelPageComponent)
{
Instance[] instHeaderComponents = oms.GetRelatedInstances(instComponent, KnownRelationshipGuids.Panel_Page_Component__has_header__Page_Component);
foreach (Instance inst2 in instHeaderComponents)
{
ApplyComponentStyle(sw, inst2);
}
Instance[] instContentComponents = oms.GetRelatedInstances(instComponent, KnownRelationshipGuids.Panel_Page_Component__has_content__Page_Component);
foreach (Instance inst2 in instContentComponents)
{
ApplyComponentStyle(sw, inst2);
}
Instance[] instFooterComponents = oms.GetRelatedInstances(instComponent, KnownRelationshipGuids.Panel_Page_Component__has_footer__Page_Component);
foreach (Instance inst2 in instFooterComponents)
{
ApplyComponentStyle(sw, inst2);
}
}
}
private void RenderStyleSheet(StreamWriter sw, Instance instStyle)
{
Instance[] instStylesImplemented = oms.GetRelatedInstances(instStyle, KnownRelationshipGuids.Style__implements__Style);
foreach (Instance inst in instStylesImplemented)
{
RenderStyleSheet(sw, inst);
}
Instance instBackgroundImage = oms.GetRelatedInstance(instStyle, KnownRelationshipGuids.Style__gets_background_image_File_from__Return_Instance_Set_Method_Binding);
if (instBackgroundImage != null)
{
OmsContext ctx = new OmsContext();
object instFileRet = oms.ExecuteMethod(instBackgroundImage, ctx);
if (instFileRet is Instance[])
{
Instance instFile = ((Instance[])instFileRet)[0];
sw.WriteFixedLengthString(String.Format("background-image: url('{0}');", sess.GetAttachmentUrl(instFile, sess.GetOmsAttachmentEntropy())));
}
}
Instance[] instStyleRules = oms.GetRelatedInstances(instStyle, KnownRelationshipGuids.Style__has__Style_Rule);
foreach (Instance instStyleRule in instStyleRules)
{
Instance instStyleProperty = oms.GetRelatedInstance(instStyleRule, KnownRelationshipGuids.Style_Rule__has__Style_Property);
string cssName = oms.GetAttributeValue
(instStyleProperty, KnownAttributeGuids.Text.CSSValue);
string value = oms.GetAttributeValue(instStyleRule, KnownAttributeGuids.Text.Value);
sw.WriteFixedLengthString(String.Format("{0}: {1};", cssName, value));
}
}
}
}