private static string FormatEntityConcepts(
DocProject docProject,
DocEntity entity,
Dictionary<string, DocObject> mapEntity,
Dictionary<string, string> mapSchema,
Dictionary<DocObject, bool> included,
List<ContentRef> listFigures,
List<ContentRef> listTables,
string path,
DocPublication docPublication)
{
StringBuilder sb = new StringBuilder();
// find concepts for entity
foreach (DocModelView docView in docProject.ModelViews)
{
if (included == null || included.ContainsKey(docView))
{
// check if there are any applicable concepts
bool hasConceptsAtEntity = false;
foreach (DocConceptRoot docRoot in docView.ConceptRoots)
{
if (docRoot.ApplicableEntity == entity)
{
hasConceptsAtEntity = true;
}
}
// inherited use definitions
// build list of inherited views
DocModelView[] listViews = docProject.GetViewInheritance(docView);
List<string> listLines = new List<string>();
Dictionary<DocTemplateDefinition, DocTemplateUsage> mapSuper = new Dictionary<DocTemplateDefinition, DocTemplateUsage>();
List<DocTemplateDefinition> listSuppress = new List<DocTemplateDefinition>();
List<DocTemplateDefinition> listOverride = new List<DocTemplateDefinition>();
DocEntity docSuper = entity;
while (docSuper != null)
{
StringBuilder sbSuper = new StringBuilder();
// find parent concept roots
bool renderclass = false;
foreach (DocModelView docViewBase in listViews)
{
foreach (DocConceptRoot docSuperRoot in docViewBase.ConceptRoots)
{
if (docSuperRoot.ApplicableEntity == docSuper)
{
string schema = mapSchema[docSuper.Name].ToLower();
foreach (DocTemplateUsage docSuperUsage in docSuperRoot.Concepts)
{
bool flag = false;
if (docSuperUsage.Suppress)
{
if (!listSuppress.Contains(docSuperUsage.Definition))
{
listSuppress.Add(docSuperUsage.Definition);
flag = true;
}
}
else if (docSuperUsage.Override)
{
if (!listOverride.Contains(docSuperUsage.Definition))
{
listOverride.Add(docSuperUsage.Definition);
flag = true;
}
}
if (docSuperUsage.Definition != null && !mapSuper.ContainsKey(docSuperUsage.Definition) && !docSuperUsage.Suppress)
{
if (!renderclass)
{
renderclass = true;
sbSuper.Append("<tr><td colspan=\"3\">");
sbSuper.Append("<a href=\"../../" + schema + "/lexical/" + MakeLinkName(docSuper) + ".htm\">");
if (docSuper.IsAbstract())
{
sbSuper.Append("<i>");
sbSuper.Append(docSuper.Name);
sbSuper.Append("</i>");
}
else
{
sbSuper.Append(docSuper.Name);
}
sbSuper.Append("</a></td></tr>");
}
bool suppress = listSuppress.Contains(docSuperUsage.Definition);
bool overiden = listOverride.Contains(docSuperUsage.Definition);
foreach(DocTemplateDefinition dtd in listSuppress)
{
if (docSuperUsage.Definition == dtd || docSuperUsage.Definition.Templates.Contains(dtd))
{
suppress = true;
break;
}
}
foreach (DocTemplateDefinition dtd in listOverride)
{
if (docSuperUsage.Definition == dtd || docSuperUsage.Definition.Templates.Contains(dtd))
{
overiden = true;
break;
}
}
if(flag)
{
suppress = false;
overiden = false;
}
sbSuper.Append("<tr><td> </td><td>");
mapSuper.Add(docSuperUsage.Definition, docSuperUsage);
string templateid = MakeLinkName(docSuperUsage.Definition);
sbSuper.Append("<a href=\"../../");
sbSuper.Append(schema);
sbSuper.Append("/lexical/" + MakeLinkName(docSuper) + ".htm#" + templateid + "\">");
if (suppress || overiden)
{
sbSuper.Append("<del>");
}
if (!String.IsNullOrEmpty(docSuperUsage.Name))
{
sbSuper.Append(docSuperUsage.Name);
}
else
{
sbSuper.Append(docSuperUsage.Definition.Name);
}
if (suppress || overiden)
{
sbSuper.Append("</del>");
}
sbSuper.Append("</a>");
if(overiden)
{
sbSuper.Append(" (overridden)");
}
else if(suppress)
{
sbSuper.Append(" (suppressed)");
}
sbSuper.Append("</td><td>");
sbSuper.Append("<a href=\"../../templates/" + MakeLinkName(docSuperUsage.Definition) + ".htm\">" + docSuperUsage.Definition + "</a>");
sbSuper.Append("</td><td>");
sbSuper.Append(docViewBase.Name);
sbSuper.Append("</td></tr>");
sbSuper.AppendLine();
}
}
}
}
}
if (sbSuper.Length > 0)
{
listLines.Add(sbSuper.ToString());
}
// go to base type
docSuper = docProject.GetDefinition(docSuper.BaseDefinition) as DocEntity;
}
if (hasConceptsAtEntity || listLines.Count > 0)
{
sb.AppendLine("<section>");
sb.AppendLine("<h5 class=\"num\">Definitions applying to " + docView.Name + "</h5>");
// link to instance diagram
if (hasConceptsAtEntity)
{
string linkdiagram = MakeLinkName(docView) + "/" + MakeLinkName(entity) + ".htm";
sb.Append("<p><a href=\"../../../annex/annex-d/" + linkdiagram + "\"><img style=\"border: 0px\" src=\"../../../img/diagram.png\" /> Instance diagram</a></p>");
}
sb.AppendLine("<hr />");
foreach (DocConceptRoot docRoot in docView.ConceptRoots)
{
if (docRoot.ApplicableEntity == entity)
{
sb.Append("<h5>" + docRoot.Name + "</h5>");
if (docRoot.ApplicableTemplate != null)
{
string applicabletemplatetable = FormatConceptTable(docProject, docView, entity, docRoot, null, mapEntity, mapSchema);
sb.Append(applicabletemplatetable);
}
sb.Append(docRoot.Documentation);
if (docRoot.Concepts.Count > 0)
{
sb.AppendLine("<details open=\"open\">");
sb.AppendLine("<summary>Concept usage</summary>");
foreach (DocTemplateUsage eachusage in docRoot.Concepts)
{
FormatEntityUsage(docProject, entity, docRoot, eachusage, mapEntity, mapSchema, listFigures, listTables, included, sb, path, docPublication);
}
sb.AppendLine("</details>");
//... mvdXML for entire root
ConceptRoot mvdConceptRoot = new ConceptRoot();
Program.ExportMvdConceptRoot(mvdConceptRoot, docRoot, false);
XmlSerializer ser = new XmlSerializer(typeof(ConceptRoot));
StringBuilder mvdOutput = new StringBuilder();
using (System.IO.Stream streamMVD = new System.IO.MemoryStream())
{
ser.Serialize(streamMVD, mvdConceptRoot, null);
streamMVD.Position = 0;
using (System.IO.StreamReader reader = new System.IO.StreamReader(streamMVD))
{
while (!reader.EndOfStream)
{
string mvdLine = reader.ReadLine();
int pos = 0;
while (pos < mvdLine.Length && mvdLine[pos] == ' ')
{
mvdOutput.Append("\t");
pos++;
}
// replace any leading spaces with tabs for proper formatting
string mvdMark = mvdLine.Substring(pos, mvdLine.Length - pos);
mvdOutput.AppendLine(mvdMark);
}
}
}
string html = System.Web.HttpUtility.HtmlEncode(mvdOutput.ToString());
html = html.Replace("\r\n", "<br/>\r\n");
html = html.Replace("\t", " ");
//sb.AppendLine("<section>");
sb.AppendLine("<details><summary>mvdXML Specification</summary>");
sb.AppendLine("<div class=\"xsd\"><code class=\"xsd\">");
sb.AppendLine(html); //... need to use tabs...
//sb.AppendLine(mvdOutput.ToString());
sb.AppendLine("</code></div></details>");
//sb.AppendLine("</section>");
}
}
}
}
// now format inherited use definitions
if (listLines.Count > 0)
{
sb.AppendLine("<section>");
sb.AppendLine("<details>");
sb.AppendLine("<summary>Concept inheritance</summary>");
sb.AppendLine("<p><table class=\"attributes\">");
sb.AppendLine("<tr><th><b>#</b></th><th><b>Concept</b></th><th><b>Template</b></th><th><b>Model View</b></th></tr>");
for (int iLine = listLines.Count - 1; iLine >= 0; iLine--)
{
// reverse order
sb.AppendLine(listLines[iLine]);
}
sb.AppendLine("</table>");
sb.AppendLine("</details>");
sb.AppendLine("</section>");
}
sb.AppendLine("</section>");
}
}
sb = sb.Replace("<EPM-HTML>", "");
sb = sb.Replace("</EPM-HTML>", "");
return sb.ToString();
}