IfcDoc.DocumentationISO.FormatExchange C# (CSharp) Method

FormatExchange() private static method

Formats table for single exchange
private static FormatExchange ( DocProject docProject, DocModelView docView, DocExchangeDefinition def, DocObject>.Dictionary mapEntity, string>.Dictionary mapSchema, DocPublication docPublication ) : string
docProject DocProject
docView DocModelView
def DocExchangeDefinition
mapEntity DocObject>.Dictionary
mapSchema string>.Dictionary
docPublication DocPublication
return string
        private static string FormatExchange(DocProject docProject, DocModelView docView, DocExchangeDefinition def, Dictionary<string, DocObject> mapEntity, Dictionary<string, string> mapSchema, DocPublication docPublication)
        {
            // format content
            StringBuilder sbMain = new StringBuilder();

            if(!String.IsNullOrEmpty(def.ExchangeClass))
            {
                sbMain.AppendLine("<table class=\"gridtable\">");
                sbMain.AppendLine("<tr><th>Process</th><th>Sender</th><th>Receiver</th></tr>");
                sbMain.AppendLine("<tr><td>" + def.ExchangeClass + "</td><td>" + def.SenderClass + "</td><td>" + def.ReceiverClass + "</td></tr>");
                sbMain.AppendLine("</table>");
            }

            // 1. manual content
            sbMain.Append(def.Documentation);

            // 2. map of entities and templates -- Identity | Template | Import | Export
            sbMain.AppendLine("<p></p>");//This exchange involves the following entities:</p>");

            SortedList<string, DocConceptRoot> sortlist = new SortedList<string, DocConceptRoot>();

            foreach (DocConceptRoot docRoot in docView.ConceptRoots)
            {
                foreach (DocTemplateUsage docUsage in docRoot.Concepts)
                {
                    foreach (DocExchangeItem docReq in docUsage.Exchanges)
                    {
                        //if (docReq.Exchange == def && docReq.Requirement != DocExchangeRequirementEnum.NotRelevant && docReq.Requirement != DocExchangeRequirementEnum.Excluded && !sortlist.ContainsKey(docRoot.ApplicableEntity.Name))
                        if (docReq.Exchange == def && docReq.Requirement != DocExchangeRequirementEnum.NotRelevant && !sortlist.ContainsKey(docRoot.ApplicableEntity.Name))
                        {
                            sortlist.Add(docRoot.ApplicableEntity.Name, docRoot);
                        }
                    }
                }
            }

            bool externaldataconstraints = false;

            // new style - table
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("<table class=\"exchange\">");
            sb.AppendLine("<tr><th colspan=\"5\"><img src=\"../../../img/mvd-" + MakeLinkName(def) + ".png\" />&nbsp; " + def.Name + "</th></tr>");
            sb.AppendLine("<tr><th>Entity/Concept</th><th>Attributes</th><th>Constraints</th><th>I</th><th>E</th></tr>");
            foreach (string ent in sortlist.Keys)
            {
                DocConceptRoot docRoot = sortlist[ent];

                sb.Append("<tr><td colspan=\"5\"><b><i>");
                sb.Append(docRoot.ApplicableEntity.Name);
                sb.AppendLine("</i></b></td></tr>");

                // determine schema
                string schema = mapSchema[ent];

                foreach (DocTemplateUsage docConcept in docRoot.Concepts)
                {
                    if (docConcept.Definition != null)
                    {
                        DocExchangeRequirementEnum reqImport = DocExchangeRequirementEnum.NotRelevant;
                        DocExchangeRequirementEnum reqExport = DocExchangeRequirementEnum.NotRelevant;
                        foreach (DocExchangeItem docReq in docConcept.Exchanges)
                        {
                            if (docReq.Exchange == def)
                            {
                                if (docReq.Applicability == DocExchangeApplicabilityEnum.Export)
                                {
                                    reqExport = docReq.Requirement;
                                }
                                else if (docReq.Applicability == DocExchangeApplicabilityEnum.Import)
                                {
                                    reqImport = docReq.Requirement;
                                }
                            }
                        }

                        if (reqImport != DocExchangeRequirementEnum.NotRelevant || reqExport != DocExchangeRequirementEnum.NotRelevant)
                        {
                            if (docConcept.Definition.Name.Equals("External Data Constraints"))
                            {
                                if(!externaldataconstraints)
                                {
                                    // show heading for first time
                                    sbMain.Append("<h4>Data Requirements for tabular formats</h4>");
                                    externaldataconstraints = true;
                                }

                                // new for GSA: cross-tab report to show mappings between exchanges and applications and vice-versa
                                List<DocModelView> listViewCross = new List<DocModelView>();
                                if (true)//docPublication.Comparison)
                                {
                                    foreach (DocModelView docEachView in docPublication.Views)
                                    {
                                        if (docEachView != docView )
                                        {
                                            listViewCross.Add(docEachView);
                                        }
                                    }
                                }

                                // table and description
                                sbMain.Append("<h5>" + docConcept.Name + "</h5>");
                                sbMain.Append(docConcept.Documentation);

                                sbMain.AppendLine("<table class=\"gridtable\">");
                                sbMain.Append("<tr><th>Column</th><th>Mapping</th><th>Definition</th><th>Notes</th>");
                                foreach(DocModelView docViewCross in listViewCross)
                                {
                                    foreach (DocExchangeDefinition docExchangeCross in docViewCross.Exchanges)
                                    {
                                        sbMain.Append("<th><a href=\"../../views/");
                                        sbMain.Append(MakeLinkName(docViewCross));
                                        sbMain.Append("/");
                                        sbMain.Append(MakeLinkName(docExchangeCross));
                                        sbMain.Append(".htm\"><img width=\"16\" src=\"../../../img/mvd-");
                                        sbMain.Append(MakeLinkName(docExchangeCross));
                                        sbMain.Append(".png\" title=\"");
                                        sbMain.Append(docExchangeCross.Name);
                                        sbMain.Append("\"/></a></th>");
                                    }
                                }
                                sbMain.AppendLine("</tr>");
                                foreach(DocTemplateItem docItem in docConcept.Items)
                                {
                                    string name = docItem.GetParameterValue("Name");
                                    string refv = docItem.GetParameterValue("Reference");
                                    string mapp = FormatReference(docProject, refv);

                                    string desc = null;
                                    CvtValuePath valpath = CvtValuePath.Parse(refv, mapEntity);

                                    if (valpath != null &&
                                        valpath.Property != null &&
                                        valpath.Property.Name.Equals("IsDefinedBy") &&
                                        valpath.InnerPath != null && valpath.InnerPath.Type.Name.Equals("IfcRelDefinesByProperties"))
                                    {
                                        DocObject docPset = null;
                                        mapEntity.TryGetValue(valpath.Identifier, out docPset);

                                        if (docPset is DocPropertySet)
                                        {
                                            DocProperty docProp = ((DocPropertySet)docPset).GetProperty(valpath.InnerPath.InnerPath.Identifier);
                                            if (docProp != null)
                                            {
                                                desc = docProp.Documentation;// localize??
                                            }
                                        }
                                        else if (docPset is DocQuantitySet)
                                        {
                                            DocQuantity docProp = ((DocQuantitySet)docPset).GetQuantity(valpath.InnerPath.InnerPath.Identifier);
                                            if (docProp != null)
                                            {
                                                desc = docProp.Documentation;// localize??
                                            }
                                        }
                                    }
                                    else if (valpath != null &&
                                        valpath.Property != null &&
                                        valpath.Property.Name.Equals("HasPropertySets") &&
                                        valpath.InnerPath != null && valpath.InnerPath.Type.Name.Equals("IfcPropertySet"))
                                    {
                                        DocObject docPset = null;
                                        mapEntity.TryGetValue(valpath.Identifier, out docPset);

                                        if (docPset is DocPropertySet)
                                        {
                                            DocProperty docProp = ((DocPropertySet)docPset).GetProperty(valpath.InnerPath.Identifier);
                                            if (docProp != null)
                                            {
                                                desc = docProp.Documentation;// localize??
                                            }
                                        }
                                    }

                                    if (desc == null)
                                    {
                                        while (valpath != null && valpath.InnerPath != null && valpath.InnerPath.Property != null)
                                        {
                                            valpath = valpath.InnerPath;
                                        }
                                        if (valpath != null && valpath.Property != null)
                                        {
                                            desc = valpath.Property.Documentation;
                                        }
                                        else if(valpath != null)
                                        {
                                            desc = "The IFC class identifier indicating the subtype of object.";
                                        }
                                    }

                                    sbMain.Append("<tr><td>" + name + "</td><td>" + mapp + "</td><td>" + desc + "</td><td>" + docItem.Documentation + "</td>");
                                    foreach (DocModelView docViewCross in listViewCross)
                                    {
                                        foreach (DocExchangeDefinition docExchangeCross in docViewCross.Exchanges)
                                        {
                                            // find any table in that exchange containing a matching mapping
                                            sbMain.Append("<td>");

                                            foreach (DocConceptRoot docRootCross in docViewCross.ConceptRoots)
                                            {
                                                foreach (DocTemplateUsage docConceptCross in docRootCross.Concepts)
                                                {
                                                    if (docConceptCross.Definition != null && docConceptCross.Definition.Name.Equals("External Data Constraints"))
                                                    {
                                                        DocExchangeRequirementEnum reqImportCross = DocExchangeRequirementEnum.NotRelevant;
                                                        DocExchangeRequirementEnum reqExportCross = DocExchangeRequirementEnum.NotRelevant;
                                                        foreach (DocExchangeItem docReq in docConceptCross.Exchanges)
                                                        {
                                                            if (docReq.Exchange == docExchangeCross)
                                                            {
                                                                if (docReq.Applicability == DocExchangeApplicabilityEnum.Export)
                                                                {
                                                                    reqExportCross = docReq.Requirement;
                                                                }
                                                                else if (docReq.Applicability == DocExchangeApplicabilityEnum.Import)
                                                                {
                                                                    reqImportCross = docReq.Requirement;
                                                                }

                                                            }
                                                        }

                                                        // found it, now look for any matching data mappings
                                                        if (reqImportCross != DocExchangeRequirementEnum.NotRelevant || reqExportCross != DocExchangeRequirementEnum.NotRelevant)
                                                        {
                                                            foreach (DocTemplateItem docItemCross in docConceptCross.Items)
                                                            {
                                                                string crossrefv = docItemCross.GetParameterValue("Reference");
                                                                if (crossrefv != null && crossrefv.Equals(refv))
                                                                {
                                                                    string crosstabl = docItemCross.GetParameterValue("Table");
                                                                    string crossname = docItemCross.GetParameterValue("Name");

                                                                    sbMain.Append("<a href=\"../../views/");
                                                                    sbMain.Append(MakeLinkName(docViewCross));
                                                                    sbMain.Append("/");
                                                                    sbMain.Append(MakeLinkName(docExchangeCross));
                                                                    sbMain.Append(".htm\"><img width=\"16\" src=\"../../../img/attr-mandatory");
                                                                    sbMain.Append(".png\" title=\"");
                                                                    sbMain.Append(docExchangeCross.Name + ": " + crosstabl + "." + crossname);
                                                                    sbMain.Append("\"/></a>");

                                                                    //sbMain.Append(crosstabl + "." + crossname); //... use icon to show import or export, with tooltip showing name...
                                                                    break;
                                                                }
                                                            }
                                                        }

                                                    }
                                                }
                                            }
                                            sbMain.Append("</td>");
                                        }
                                    }
                                    sbMain.AppendLine("</tr>");
                                }
                                sbMain.AppendLine("</table>");

                                // bring out separately
                                //string table = FormatConceptTable(docProject, docView, docRoot.ApplicableEntity, docRoot, docConcept, mapEntity, mapSchema);
                                //sbMain.Append(table);
                            }
                            else
                            {
                                sb.Append("<tr><td>&nbsp;&nbsp;<a href=\"../../templates/");
                                sb.Append(MakeLinkName(docConcept.Definition));
                                sb.Append(".htm\">");
                                sb.Append(docConcept.Definition.Name);
                                sb.Append("</a></td><td>");

                                bool first = true;
                                if (docConcept.Definition.Rules != null)
                                {
                                    foreach (DocModelRule docRule in docConcept.Definition.Rules)
                                    {
                                        if (!first)
                                        {
                                            sb.Append("<br/>");
                                        }
                                        sb.Append(docRule.Name);
                                        first = false;
                                    }
                                }
                                sb.Append("</td><td>");

                                string table = FormatConceptTable(docProject, docView, docRoot.ApplicableEntity, docRoot, docConcept, mapEntity, mapSchema);
                                sb.Append(table);

                                sb.Append("</td><td>");
                                AppendRequirement(sb, reqImport, 3);
                                sb.Append("</td><td>");
                                AppendRequirement(sb, reqExport, 3);
                                sb.AppendLine("</td></tr>");
                            }
                        }
                    }
                }

            }
            sb.AppendLine("</table>");

            // then general table for IFC
            sbMain.AppendLine("<h4>Data Requirements for IFC formats</h4>");
            sbMain.Append(sb.ToString());

            return sbMain.ToString();
        }