Exemplo n.º 1
0
        public CellValue GetCell(int row, int col)
        {
            DocConceptRoot        docRoot     = this.m_view.ConceptRoots[row];
            DocExchangeDefinition docExchange = this.m_view.Exchanges[col];

            foreach (DocTemplateUsage docUsage in docRoot.Concepts)
            {
                if (docUsage.Definition == this.m_template)
                {
                    foreach (DocExchangeItem docEx in docUsage.Exchanges)
                    {
                        if (docEx.Exchange == docExchange && docEx.Applicability == DocExchangeApplicabilityEnum.Export)
                        {
                            switch (docEx.Requirement)
                            {
                            case DocExchangeRequirementEnum.Mandatory:
                                return(CellValue.Required);

                            case DocExchangeRequirementEnum.Optional:
                                return(CellValue.Optional);
                            }
                        }
                    }

                    return(CellValue.None);
                }
            }

            return(CellValue.None);
        }
Exemplo n.º 2
0
        public object GetObject(int row, int col)
        {
            if (row < 0 || row >= this.m_listTemplate.Count)
            {
                return(null);
            }

            if (col < 0 || col >= this.m_view.Exchanges.Count)
            {
                return(null);
            }

            DocTemplateDefinition docTemplate = this.m_listTemplate[row];
            DocExchangeDefinition docExchange = this.m_view.Exchanges[col];

            foreach (DocTemplateUsage docUsage in this.m_root.Concepts)
            {
                if (docUsage.Definition == docTemplate)
                {
                    foreach (DocExchangeItem docItem in docUsage.Exchanges)
                    {
                        if (docItem.Exchange == docExchange && docItem.Applicability == DocExchangeApplicabilityEnum.Export)
                        {
                            return(docItem);
                        }
                    }
                }
            }

            return(CellValue.None);
        }
Exemplo n.º 3
0
        public CheckGridExchange(DocExchangeDefinition docExchange, DocModelView docView, DocProject docProject)
        {
            this.m_project      = docProject;
            this.m_view         = docView;
            this.m_exchange     = docExchange;
            this.m_listTemplate = docProject.GetTemplateList();

            // filter out template list to only those that are currently used
            for (int i = this.m_listTemplate.Count - 1; i >= 0; i--)
            {
                bool used = false;
                foreach (DocConceptRoot docRoot in this.m_view.ConceptRoots)
                {
                    foreach (DocTemplateUsage docUsage in docRoot.Concepts)
                    {
                        if (docUsage.Definition == this.m_listTemplate[i])
                        {
                            used = true;
                            break;
                        }
                    }
                }

                if (!used)
                {
                    this.m_listTemplate.RemoveAt(i);
                }
            }
        }
Exemplo n.º 4
0
        public string FormatData(DocPublication docPublication, DocExchangeDefinition docExchange, Dictionary<string, DocObject> map, Dictionary<long, SEntity> instances, SEntity root, bool markup)
        {
            this.m_stream = new System.IO.MemoryStream();
            this.Instance = root;
            this.Markup = markup;
            this.Save();

            this.m_stream.Position = 0;
            StreamReader reader = new StreamReader(this.m_stream);
            string content = reader.ReadToEnd();
            return content;
        }
Exemplo n.º 5
0
        public CellValue GetCell(int row, int col)
        {
            if (row < 0 || row >= this.m_listTemplate.Count)
            {
                return(CellValue.Unavailable);
            }

            if (col < 0 || col >= this.m_view.Exchanges.Count)
            {
                return(CellValue.Unavailable);
            }

            DocTemplateDefinition docTemplate = this.m_listTemplate[row];
            DocExchangeDefinition docExchange = this.m_view.Exchanges[col];

            foreach (DocTemplateUsage docUsage in this.m_root.Concepts)
            {
                if (docUsage.Definition == docTemplate)
                {
                    foreach (DocExchangeItem docItem in docUsage.Exchanges)
                    {
                        if (docItem.Exchange == docExchange && docItem.Applicability == DocExchangeApplicabilityEnum.Export)
                        {
                            switch (docItem.Requirement)
                            {
                            case DocExchangeRequirementEnum.Mandatory:
                                return(CellValue.Mandatory);

                            case DocExchangeRequirementEnum.Optional:
                                return(CellValue.Recommended);

                            default:
                                return(CellValue.None);
                            }
                        }
                    }
                }
            }

            return(CellValue.None);
        }
Exemplo n.º 6
0
        public FormValidate(DocProject project, DocModelView docView, DocExchangeDefinition docExchange) : this()
        {
            this.textBoxPath.Text       = Properties.Settings.Default.ValidateFile;
            this.checkBoxReport.Checked = Properties.Settings.Default.ValidateReport;

            foreach (DocModelView docEachView in project.ModelViews)
            {
                this.comboBoxView.Items.Add(docEachView);
            }

            if (docView == null && project.ModelViews.Count > 0)
            {
                docView = project.ModelViews[0];
            }
            this.comboBoxView.SelectedItem = docView;

            if (docExchange == null && docView != null && docView.Exchanges.Count > 0)
            {
                docExchange = docView.Exchanges[0];
            }
            this.comboBoxExchange.SelectedItem = docExchange;
        }
Exemplo n.º 7
0
        public FormValidate(DocProject project, DocModelView docView, DocExchangeDefinition docExchange) : this()
        {
            this.textBoxPath.Text = Properties.Settings.Default.ValidateFile;
            this.checkBoxReport.Checked = Properties.Settings.Default.ValidateReport;

            foreach (DocModelView docEachView in project.ModelViews)
            {
                this.comboBoxView.Items.Add(docEachView);
            }

            if (docView == null && project.ModelViews.Count > 0)
            {
                docView = project.ModelViews[0];
            }
            this.comboBoxView.SelectedItem = docView;

            if (docExchange == null && docView != null && docView.Exchanges.Count > 0)
            {
                docExchange = docView.Exchanges[0];
            }
            this.comboBoxExchange.SelectedItem = docExchange;
        }
Exemplo n.º 8
0
        public string FormatData(DocPublication docPublication, DocExchangeDefinition docExchange, Dictionary <string, DocObject> map, Dictionary <long, SEntity> instances)
        {
            System.IO.MemoryStream stream = new System.IO.MemoryStream();
            if (instances.Count > 0)
            {
                SEntity rootproject = null;
                foreach (SEntity ent in instances.Values)
                {
                    if (ent.GetType().Name.Equals("IfcProject"))
                    {
                        rootproject = ent;
                        break;
                    }
                }

                if (rootproject != null)
                {
                    Type type = rootproject.GetType();

                    DataContractJsonSerializer contract = new DataContractJsonSerializer(type);

                    try
                    {
                        contract.WriteObject(stream, rootproject);
                    }
                    catch (Exception xx)
                    {
                        //...
                        xx.ToString();
                    }
                }
            }

            stream.Position = 0;
            System.IO.TextReader reader = new System.IO.StreamReader(stream);
            string content = reader.ReadToEnd();

            return(content);
        }
Exemplo n.º 9
0
        public object GetObject(int row, int col)
        {
            DocConceptRoot        docRoot     = this.m_view.ConceptRoots[row];
            DocExchangeDefinition docExchange = this.m_view.Exchanges[col];

            foreach (DocTemplateUsage docUsage in docRoot.Concepts)
            {
                if (docUsage.Definition == this.m_template)
                {
                    foreach (DocExchangeItem docEx in docUsage.Exchanges)
                    {
                        if (docEx.Exchange == docExchange && docEx.Applicability == DocExchangeApplicabilityEnum.Export)
                        {
                            return(docEx);
                        }
                    }

                    return(null);
                }
            }

            return(null);
        }
Exemplo n.º 10
0
        public void SetCell(int row, int col, CellValue val)
        {
            DocTemplateDefinition docTemplate = this.m_listTemplate[row];
            DocExchangeDefinition docExchange = this.m_view.Exchanges[col];

            DocTemplateUsage docUsage = null;

            foreach (DocTemplateUsage eachUsage in this.m_root.Concepts)
            {
                if (eachUsage.Definition == docTemplate)
                {
                    docUsage = eachUsage;
                    break;
                }
            }

            if (docUsage == null)
            {
                docUsage = new DocTemplateUsage();
                this.m_root.Concepts.Add(docUsage);
                docUsage.Definition = docTemplate;
            }

            DocExchangeRequirementEnum req = DocExchangeRequirementEnum.NotRelevant;

            switch (val)
            {
            case CellValue.Mandatory:
                req = DocExchangeRequirementEnum.Mandatory;
                break;

            case CellValue.Recommended:
                req = DocExchangeRequirementEnum.Optional;
                break;
            }
            docUsage.RegisterExchange(docExchange, req);
        }
Exemplo n.º 11
0
        public Compiler(DocProject project, DocModelView[] views, DocExchangeDefinition exchange)
        {
            this.m_project  = project;
            this.m_views    = views;
            this.m_exchange = exchange;

            string schemaid = project.GetSchemaIdentifier();

            this.m_assembly    = AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName(schemaid), AssemblyBuilderAccess.RunAndSave);
            this.m_module      = this.m_assembly.DefineDynamicModule("IFC4.dll", "IFC4.dll");
            this.m_definitions = new Dictionary <string, DocObject>();
            this.m_types       = new Dictionary <string, Type>();
            this.m_fields      = new Dictionary <Type, Dictionary <string, FieldInfo> >();
            this.m_templates   = new Dictionary <DocTemplateDefinition, MethodInfo>();
            this.m_namespaces  = new Dictionary <string, string>();

            Dictionary <DocObject, bool> included = null;

            if (this.m_views != null)
            {
                included = new Dictionary <DocObject, bool>();
                foreach (DocModelView docView in this.m_views)
                {
                    this.m_project.RegisterObjectsInScope(docView, included);
                }
            }

            foreach (DocSection docSection in project.Sections)
            {
                foreach (DocSchema docSchema in docSection.Schemas)
                {
                    foreach (DocEntity docEntity in docSchema.Entities)
                    {
                        if (included == null || included.ContainsKey(docEntity))
                        {
                            if (!this.m_definitions.ContainsKey(docEntity.Name))
                            {
                                this.m_definitions.Add(docEntity.Name, docEntity);
                                this.m_namespaces.Add(docEntity.Name, docSchema.Name);
                            }
                        }
                    }

                    foreach (DocType docType in docSchema.Types)
                    {
                        if (included == null || included.ContainsKey(docType))
                        {
                            if (!this.m_definitions.ContainsKey(docType.Name))
                            {
                                this.m_definitions.Add(docType.Name, docType);
                                this.m_namespaces.Add(docType.Name, docSchema.Name);
                            }
                        }
                    }
                }
            }

            // first register types and fields
            foreach (string key in this.m_definitions.Keys)
            {
                RegisterType(key);
            }

            // now register template functions (may depend on fields existing)

            // find associated ConceptRoot for model view, define validation function
            if (this.m_views != null)
            {
                foreach (DocModelView view in this.m_views)
                {
                    string viewname = view.Code;
                    foreach (DocConceptRoot root in view.ConceptRoots)
                    {
                        Type tOpen = null;

                        if (this.m_types.TryGetValue(root.ApplicableEntity.Name, out tOpen) && tOpen is TypeBuilder)
                        {
                            TypeBuilder tb = (TypeBuilder)tOpen;
                            foreach (DocTemplateUsage concept in root.Concepts)
                            {
                                CompileConcept(concept, view, tb);
                            }
                        }
                    }
                }
            }



            // seal types once all are built
            List <TypeBuilder> listBase = new List <TypeBuilder>();

            foreach (string key in this.m_definitions.Keys)
            {
                Type tOpen = this.m_types[key];
                while (tOpen is TypeBuilder)
                {
                    listBase.Add((TypeBuilder)tOpen);
                    tOpen = tOpen.BaseType;
                }

                // seal in base class order
                for (int i = listBase.Count - 1; i >= 0; i--)
                {
                    Type tClosed = listBase[i].CreateType();
                    this.m_types[tClosed.Name] = tClosed;
                }
                listBase.Clear();


                // record bindings
                DocDefinition docDef = this.m_definitions[key] as DocDefinition;
                if (docDef != null)
                {
                    docDef.RuntimeType = this.m_types[key];

                    if (docDef is DocEntity)
                    {
                        DocEntity docEnt = (DocEntity)docDef;
                        foreach (DocAttribute docAttr in docEnt.Attributes)
                        {
                            docAttr.RuntimeField = docDef.RuntimeType.GetField(docAttr.Name);
                        }
                    }
                }
            }
        }
Exemplo n.º 12
0
        public string FormatData(DocProject docProject, DocPublication docPublication, DocExchangeDefinition docExchange, Dictionary <string, DocObject> map, Dictionary <long, SEntity> instances, SEntity root, bool markup)
        {
            //Guid guidMapping = Guid.Parse("");//...

            StringBuilder sb = new StringBuilder();

            foreach (DocModelView docView in docPublication.Views)
            {
                foreach (DocConceptRoot docRoot in docView.ConceptRoots)
                {
                    // look for specific concept root dealing with mappings
                    foreach (DocTemplateUsage docConcept in docRoot.Concepts)
                    {
                        if (docConcept.Definition != null && docConcept.Definition.Name.Equals("External Data Constraints") && docConcept.Items.Count > 0)//...
                        {
                            bool included = true;

                            if (docExchange != null)
                            {
                                included = false;
                                // if exhcnage specified, check for inclusion
                                foreach (DocExchangeItem docExchangeItem in docConcept.Exchanges)
                                {
                                    if (docExchangeItem.Exchange == docExchange && docExchangeItem.Requirement == DocExchangeRequirementEnum.Mandatory)
                                    {
                                        included = true;
                                        break;
                                    }
                                }
                            }

                            // check if there are any instances to populate table
                            if (included)
                            {
                                included = false;
                                foreach (SEntity e in instances.Values)
                                {
                                    string eachname = e.GetType().Name;
                                    if (docRoot.ApplicableEntity.IsInstanceOfType(e))
                                    {
                                        included = true;
                                        break;
                                    }
                                }
                            }

                            if (included)
                            {
                                string table = docConcept.Items[0].GetParameterValue("Table");
                                string query = docConcept.Items[0].GetParameterValue("Reference");

                                sb.AppendLine("<h4>" + docConcept.Name + "</h4>");
                                sb.AppendLine("<table class=\"gridtable\">");

                                List <string>       colstyles = new List <string>();
                                List <string>       colformat = new List <string>();
                                List <CvtValuePath> colmaps   = new List <CvtValuePath>();

                                // generate header row
                                sb.AppendLine("<tr>");
                                foreach (DocTemplateItem docItem in docConcept.Items)
                                {
                                    string name = docItem.GetParameterValue("Name");
                                    string disp = "#" + docItem.GetColor().ToArgb().ToString("X8"); //docItem.GetParameterValue("Color");docItem.GetParameterValue("Color");
                                    string expr = docItem.GetParameterValue("Reference");
                                    string form = docItem.GetParameterValue("Format");

                                    string style = "";
                                    if (!String.IsNullOrEmpty(disp))
                                    {
                                        style = " style=\"background-color:" + disp + ";\"";
                                    }
                                    colstyles.Add(style);

                                    string format = "";
                                    if (!String.IsNullOrEmpty(form))
                                    {
                                        format = form;
                                    }
                                    colformat.Add(format);

                                    string       desc    = "";
                                    CvtValuePath valpath = CvtValuePath.Parse(expr, map); //todo: move out of loop
                                    colmaps.Add(valpath);
                                    if (valpath != null)
                                    {
                                        desc = /*valpath.GetDescription(map) + "&#10;&#10;" + */ valpath.ToString().Replace("\\", "&#10;");
                                    }

                                    sb.Append("<th><a href=\"../../schema/views/" + DocumentationISO.MakeLinkName(docView) + "/" + DocumentationISO.MakeLinkName(docExchange) + ".htm#" + DocumentationISO.MakeLinkName(docConcept) + "\" title=\"" + desc + "\">");
                                    sb.Append(name);
                                    sb.Append("</a></th>");
                                }
                                ;
                                sb.AppendLine("</tr>");

                                // generate data rows
                                foreach (SEntity e in instances.Values)
                                {
                                    string eachname = e.GetType().Name;
                                    if (docRoot.ApplicableEntity.IsInstanceOfType(e))
                                    {
                                        bool          includerow = true;
                                        StringBuilder sbRow      = new StringBuilder();

                                        sbRow.Append("<tr>");
                                        int iCol = 0;
                                        foreach (DocTemplateItem docItem in docConcept.Items)
                                        {
                                            sbRow.Append("<td" + colstyles[iCol]);
                                            CvtValuePath valpath = colmaps[iCol];
                                            string       format  = colformat[iCol];

                                            iCol++;

                                            if (valpath != null)
                                            {
                                                string nn = docItem.GetParameterValue("Name");

                                                object value = valpath.GetValue(e, null);

                                                if (value == e)
                                                {
                                                    value = e.GetType().Name;
                                                }
                                                else if (value is SEntity)
                                                {
                                                    // use name
                                                    FieldInfo fieldValue = value.GetType().GetField("Name");
                                                    if (fieldValue != null)
                                                    {
                                                        value = fieldValue.GetValue(value);
                                                    }
                                                }
                                                else if (value is System.Collections.IList)
                                                {
                                                    System.Collections.IList list   = (System.Collections.IList)value;
                                                    StringBuilder            sbList = new StringBuilder();
                                                    foreach (object elem in list)
                                                    {
                                                        FieldInfo fieldName = elem.GetType().GetField("Name");
                                                        if (fieldName != null)
                                                        {
                                                            object elemname = fieldName.GetValue(elem);
                                                            if (elemname != null)
                                                            {
                                                                FieldInfo fieldValue = elemname.GetType().GetField("Value");
                                                                if (fieldValue != null)
                                                                {
                                                                    object elemval = fieldValue.GetValue(elemname);
                                                                    sbList.Append(elemval.ToString());
                                                                }
                                                            }
                                                        }
                                                        sbList.Append("; <br/>");
                                                    }
                                                    value = sbList.ToString();
                                                }
                                                else if (value is Type)
                                                {
                                                    value = ((Type)value).Name;
                                                }

                                                if (!String.IsNullOrEmpty(format))
                                                {
                                                    if (format.Equals("Required") && value == null)
                                                    {
                                                        includerow = false;
                                                    }
                                                }

                                                if (value != null)
                                                {
                                                    FieldInfo fieldValue = value.GetType().GetField("Value");
                                                    if (fieldValue != null)
                                                    {
                                                        value = fieldValue.GetValue(value);
                                                    }

                                                    if (format != null && format.Equals("True") && (value == null || !value.ToString().Equals("True")))
                                                    {
                                                        includerow = false;
                                                    }

                                                    if (value is Double)
                                                    {
                                                        sbRow.Append(" align=\"right\">");

                                                        sbRow.Append(((Double)value).ToString("N3"));
                                                    }
                                                    else if (value is List <Int64> )
                                                    {
                                                        sbRow.Append(">");

                                                        // latitude or longitude
                                                        List <Int64> intlist = (List <Int64>)value;
                                                        if (intlist.Count >= 3)
                                                        {
                                                            sbRow.Append(intlist[0] + "° " + intlist[1] + "' " + intlist[2] + "\"");
                                                        }
                                                    }
                                                    else if (value != null)
                                                    {
                                                        sbRow.Append(">");
                                                        sbRow.Append(value.ToString()); // todo: html-encode
                                                    }
                                                }
                                                else
                                                {
                                                    sbRow.Append(">");
                                                    sbRow.Append("&nbsp;");
                                                }
                                            }
                                            else
                                            {
                                                sbRow.Append(">");
                                            }

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

                                        if (includerow)
                                        {
                                            sb.Append(sbRow.ToString());
                                        }
                                    }
                                }

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

            return(sb.ToString());
        }
Exemplo n.º 13
0
        public Compiler(DocProject project, DocModelView[] views, DocExchangeDefinition exchange)
        {
            this.m_project = project;
            this.m_views = views;
            this.m_exchange = exchange;

            this.m_assembly = AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName("IFC4"), AssemblyBuilderAccess.RunAndSave);
            this.m_module = this.m_assembly.DefineDynamicModule("IFC4.dll", "IFC4.dll");
            this.m_definitions = new Dictionary<string, DocObject>();
            this.m_types = new Dictionary<string, Type>();
            this.m_fields = new Dictionary<Type, Dictionary<string, FieldInfo>>();
            this.m_templates = new Dictionary<DocTemplateDefinition, MethodInfo>();
            this.m_namespaces = new Dictionary<string, string>();

            Dictionary<DocObject, bool> included = null;
            if (this.m_views != null)
            {
                included = new Dictionary<DocObject, bool>();
                foreach (DocModelView docView in this.m_views)
                {
                    this.m_project.RegisterObjectsInScope(docView, included);
                }
            }

            foreach (DocSection docSection in project.Sections)
            {
                foreach (DocSchema docSchema in docSection.Schemas)
                {
                    foreach (DocEntity docEntity in docSchema.Entities)
                    {
                        if (included == null || included.ContainsKey(docEntity))
                        {
                            if (!this.m_definitions.ContainsKey(docEntity.Name))
                            {
                                this.m_definitions.Add(docEntity.Name, docEntity);
                                this.m_namespaces.Add(docEntity.Name, docSchema.Name);
                            }
                        }
                    }

                    foreach (DocType docType in docSchema.Types)
                    {
                        if (included == null || included.ContainsKey(docType))
                        {
                            if (!this.m_definitions.ContainsKey(docType.Name))
                            {
                                this.m_definitions.Add(docType.Name, docType);
                                this.m_namespaces.Add(docType.Name, docSchema.Name);
                            }
                        }
                    }
                }
            }

            // first register types and fields
            foreach (string key in this.m_definitions.Keys)
            {
                RegisterType(key);
            }

            // now register template functions (may depend on fields existing)

            // find associated ConceptRoot for model view, define validation function
            if (this.m_views != null)
            {
                foreach (DocModelView view in this.m_views)
                {
                    string viewname = view.Code;
                    foreach (DocConceptRoot root in view.ConceptRoots)
                    {
                        Type tOpen= null;
                        
                        if (this.m_types.TryGetValue(root.ApplicableEntity.Name, out tOpen) && tOpen is TypeBuilder)
                        {
                            TypeBuilder tb = (TypeBuilder)tOpen;
                            foreach (DocTemplateUsage concept in root.Concepts)
                            {
                                CompileConcept(concept, view, tb);
                            }
                        }
                    }
                }
            }



            // seal types once all are built
            List<TypeBuilder> listBase = new List<TypeBuilder>();
            foreach (string key in this.m_definitions.Keys)
            {
                Type tOpen = this.m_types[key];
                while (tOpen is TypeBuilder)
                {
                    listBase.Add((TypeBuilder)tOpen);
                    tOpen = tOpen.BaseType;
                }

                // seal in base class order
                for (int i = listBase.Count - 1; i >= 0; i--)
                {
                    Type tClosed = listBase[i].CreateType();
                    this.m_types[tClosed.Name] = tClosed;
                }
                listBase.Clear();
            }
        }
Exemplo n.º 14
0
 //UNUSED!!!! => Use FormatTTL_Stream.FormatData() instead
 public string FormatData(DocPublication docPublication, DocExchangeDefinition docExchange, Dictionary<string, DocObject> map, Dictionary<long, SEntity> instances, SEntity root, bool markup)
 {
     //UNUSED!!!! => Use FormatTTL_Stream.FormatData() instead
     return null;
 }
Exemplo n.º 15
0
        public string FormatData(DocPublication docPublication, DocExchangeDefinition docExchange, Dictionary<string, DocObject> map, Dictionary<long, SEntity> instances)
        {
            System.IO.MemoryStream stream = new System.IO.MemoryStream();
            if (instances.Count > 0)
            {
                SEntity rootproject = null;
                foreach (SEntity ent in instances.Values)
                {
                    if (ent.GetType().Name.Equals("IfcProject"))
                    {
                        rootproject = ent;
                        break;
                    }
                }

                if (rootproject != null)
                {
                    Type type = rootproject.GetType();

                    DataContractJsonSerializer contract = new DataContractJsonSerializer(type);

                    try
                    {
                        contract.WriteObject(stream, rootproject);
                    }
                    catch(Exception xx)
                    {
                        //...
                        xx.ToString();
                    }
                }
            }

            stream.Position = 0;
            System.IO.TextReader reader = new System.IO.StreamReader(stream);
            string content = reader.ReadToEnd();
            return content;
        }
Exemplo n.º 16
0
        public static DocProject LoadFile(string filePath)
        {
            List <object> instances = new List <object>();
            string        ext       = System.IO.Path.GetExtension(filePath).ToLower();
            string        schema    = "";
            DocProject    project   = null;

            switch (ext)
            {
            case ".ifcdoc":
                using (FileStream streamDoc = new FileStream(filePath, FileMode.Open, FileAccess.Read))
                {
                    Dictionary <long, object> dictionaryInstances = null;
                    StepSerializer            formatDoc           = new StepSerializer(typeof(DocProject), SchemaDOC.Types);
                    project = (DocProject)formatDoc.ReadObject(streamDoc, out dictionaryInstances);
                    instances.AddRange(dictionaryInstances.Values);
                    schema = formatDoc.Schema;
                }
                break;

            case ".ifcdocxml":
                using (FileStream streamDoc = new FileStream(filePath, FileMode.Open, FileAccess.Read))
                {
                    Dictionary <string, object> dictionaryInstances = null;
                    XmlSerializer formatDoc = new XmlSerializer(typeof(DocProject));
                    project = (DocProject)formatDoc.ReadObject(streamDoc, out dictionaryInstances);
                    instances.AddRange(dictionaryInstances.Values);
                }
                break;

            default:
                MessageBox.Show("Unsupported file type " + ext, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                break;

#if MDB
            case ".mdb":
                using (FormatMDB format = new FormatMDB(this.m_file, SchemaDOC.Types, this.m_instances))
                {
                    format.Load();
                }
                break;
#endif
            }
            if (project == null)
            {
                return(null);
            }

            double schemaVersion = 0;
            if (!string.IsNullOrEmpty(schema))
            {
                string[] fields = schema.Split("_".ToCharArray());
                int      i      = 0;
                if (fields.Length > 1)
                {
                    if (int.TryParse(fields[1], out i))
                    {
                        schemaVersion = i;
                    }
                    if (fields.Length > 2 && int.TryParse(fields[2], out i))
                    {
                        schemaVersion += i / 10.0;
                    }
                }
            }
            List <SEntity> listDelete = new List <SEntity>();
            List <DocTemplateDefinition> listTemplate = new List <DocTemplateDefinition>();

            foreach (object o in instances)
            {
                if (o is DocSchema)
                {
                    DocSchema docSchema = (DocSchema)o;

                    // renumber page references
                    foreach (DocPageTarget docTarget in docSchema.PageTargets)
                    {
                        if (docTarget.Definition != null)                         // fix it up -- NULL bug from older .ifcdoc files
                        {
                            int page = docSchema.GetDefinitionPageNumber(docTarget);
                            int item = docSchema.GetPageTargetItemNumber(docTarget);
                            docTarget.Name = page + "," + item + " " + docTarget.Definition.Name;

                            foreach (DocPageSource docSource in docTarget.Sources)
                            {
                                docSource.Name = docTarget.Name;
                            }
                        }
                    }
                }
                else if (o is DocExchangeDefinition)
                {
                    // files before V4.9 had Description field; no longer needed so use regular Documentation field again.
                    DocExchangeDefinition docexchange = (DocExchangeDefinition)o;
                    if (docexchange._Description != null)
                    {
                        docexchange.Documentation = docexchange._Description;
                        docexchange._Description  = null;
                    }
                }
                else if (o is DocTemplateDefinition)
                {
                    // files before V5.0 had Description field; no longer needed so use regular Documentation field again.
                    DocTemplateDefinition doctemplate = (DocTemplateDefinition)o;
                    if (doctemplate._Description != null)
                    {
                        doctemplate.Documentation = doctemplate._Description;
                        doctemplate._Description  = null;
                    }

                    listTemplate.Add((DocTemplateDefinition)o);
                }
                else if (o is DocConceptRoot)
                {
                    // V12.0: ensure template is defined
                    DocConceptRoot docConcRoot = (DocConceptRoot)o;
                    if (docConcRoot.ApplicableTemplate == null && docConcRoot.ApplicableEntity != null)
                    {
                        docConcRoot.ApplicableTemplate      = new DocTemplateDefinition();
                        docConcRoot.ApplicableTemplate.Type = docConcRoot.ApplicableEntity.Name;
                    }
                }
                else if (o is DocTemplateUsage)
                {
                    // V12.0: ensure template is defined
                    DocTemplateUsage docUsage = (DocTemplateUsage)o;
                    if (docUsage.Definition == null)
                    {
                        docUsage.Definition = new DocTemplateDefinition();
                    }
                }
                else if (o is DocLocalization)
                {
                    DocLocalization localization = o as DocLocalization;
                    if (!string.IsNullOrEmpty(localization.Name))
                    {
                        localization.Name = localization.Name.Trim();
                    }
                }
                // ensure all objects have valid guid
                DocObject docObject = o as DocObject;
                if (docObject != null)
                {
                    if (docObject.Uuid == Guid.Empty)
                    {
                        docObject.Uuid = Guid.NewGuid();
                    }
                    if (!string.IsNullOrEmpty(docObject.Documentation))
                    {
                        docObject.Documentation = docObject.Documentation.Trim();
                    }

                    if (schemaVersion < 12.1)
                    {
                        DocChangeSet docChangeSet = docObject as DocChangeSet;
                        if (docChangeSet != null)
                        {
                            docChangeSet.ChangesEntities.RemoveAll(x => !isUnchanged(x));
                        }
                        else
                        {
                            if (schemaVersion < 12)
                            {
                                DocEntity entity = docObject as DocEntity;
                                if (entity != null)
                                {
                                    entity.ClearDefaultMember();
                                }
                            }
                        }
                    }
                }
            }

            if (project == null)
            {
                return(null);
            }

            if (schemaVersion > 0 && schemaVersion < 12.1)
            {
                Dictionary <string, DocPropertyEnumeration> encounteredPropertyEnumerations = new Dictionary <string, DocPropertyEnumeration>();
                foreach (DocSchema docSchema in project.Sections.SelectMany(x => x.Schemas))
                {
                    extractListingsV12_1(project, docSchema, encounteredPropertyEnumerations);
                }
            }
            foreach (DocModelView docModelView in project.ModelViews)
            {
                // sort alphabetically (V11.3+)
                docModelView.SortConceptRoots();
            }

            // upgrade to Publications (V9.6)
            if (project.Annotations.Count == 4)
            {
                project.Publications.Clear();

                DocAnnotation docCover    = project.Annotations[0];
                DocAnnotation docContents = project.Annotations[1];
                DocAnnotation docForeword = project.Annotations[2];
                DocAnnotation docIntro    = project.Annotations[3];

                DocPublication docPub = new DocPublication();
                docPub.Name          = "Default";
                docPub.Documentation = docCover.Documentation;
                docPub.Owner         = docCover.Owner;
                docPub.Author        = docCover.Author;
                docPub.Code          = docCover.Code;
                docPub.Copyright     = docCover.Copyright;
                docPub.Status        = docCover.Status;
                docPub.Version       = docCover.Version;

                docPub.Annotations.Add(docForeword);
                docPub.Annotations.Add(docIntro);

                project.Publications.Add(docPub);

                docCover.Delete();
                docContents.Delete();
                project.Annotations.Clear();
            }
            project.SortProject();
            return(project);
        }
Exemplo n.º 17
0
        private void toolStripMenuItemToolsValidate_Click(object sender, EventArgs e)
        {
            DocModelView docView = null;
            if (this.m_filterviews != null && this.m_filterviews.Length > 0)
            {
                docView = this.m_filterviews[0];
            }

            using (FormValidate form = new FormValidate(this.m_project, docView, this.m_filterexchange))
            {
                DialogResult res = form.ShowDialog();
                if (res != DialogResult.OK || String.IsNullOrEmpty(Properties.Settings.Default.ValidateFile))
                    return;

                this.m_filterviews = new DocModelView[] {form.SelectedView};
                this.m_filterexchange = form.SelectedExchange;

                using (this.m_formProgress = new FormProgress())
                {
                    this.m_formProgress.Text = "Validating File";
                    this.m_formProgress.Description = "Validating file...";

                    this.backgroundWorkerValidate.RunWorkerAsync();

                    res = this.m_formProgress.ShowDialog();
                    if (res != DialogResult.OK)
                    {
                        this.backgroundWorkerValidate.CancelAsync();
                    }
                }

                if (this.m_exception != null)
                {
                    MessageBox.Show(this, this.m_exception.Message, "Error");
                    this.m_exception = null;
                    return;
                }

                // show window
                this.splitContainerEdit.Panel2Collapsed = false;
                this.InitInstanceList();

            }

            #if false
            DialogResult res = this.openFileDialogValidate.ShowDialog();
            if (res != DialogResult.OK)
                return;

            using(FormSelectView form = new FormSelectView(this.m_project, "Select the model view for validating the file."))
            {
                if(form.ShowDialog(this) == System.Windows.Forms.DialogResult.OK && form.Selection != null)
                {
                    this.m_filterviews = form.Selection;
                    using (FormSelectExchange formExchange = new FormSelectExchange(this.m_filterviews[0]))
                    {
                        if (formExchange.ShowDialog(this) == System.Windows.Forms.DialogResult.OK && formExchange.Selection != null)
                        {
                            this.m_filterexchange = formExchange.Selection;

                            using (this.m_formProgress = new FormProgress())
                            {
                                this.m_formProgress.Text = "Validating File";
                                this.m_formProgress.Description = "Validating file...";

                                this.backgroundWorkerValidate.RunWorkerAsync();

                                res = this.m_formProgress.ShowDialog();
                                if (res != DialogResult.OK)
                                {
                                    this.backgroundWorkerValidate.CancelAsync();
                                }
                            }
                        }
                    }

                    if (this.m_exception != null)
                    {
                        MessageBox.Show(this, this.m_exception.Message, "Error");
                        this.m_exception = null;
                        return;
                    }

                    // show window
                    this.splitContainerEdit.Panel2Collapsed = false;
                    this.InitInstanceList();
                }
            }
            #endif
        }
Exemplo n.º 18
0
        public CheckGridExchange(DocExchangeDefinition docExchange, DocModelView docView, DocProject docProject)
        {
            this.m_project = docProject;
            this.m_view = docView;
            this.m_exchange = docExchange;
            this.m_listTemplate = docProject.GetTemplateList();

            // filter out template list to only those that are currently used
            for (int i = this.m_listTemplate.Count - 1; i >= 0; i--)
            {
                bool used = false;
                foreach (DocConceptRoot docRoot in this.m_view.ConceptRoots)
                {
                    foreach (DocTemplateUsage docUsage in docRoot.Concepts)
                    {
                        if (docUsage.Definition == this.m_listTemplate[i])
                        {
                            used = true;
                            break;
                        }
                    }
                }

                if (!used)
                {
                    this.m_listTemplate.RemoveAt(i);
                }
            }
        }
Exemplo n.º 19
0
        public string FormatData(DocProject docProject, DocPublication docPublication, DocExchangeDefinition docExchange, Dictionary<string, DocObject> map, Dictionary<long, SEntity> instances, SEntity root, bool markup)
        {
            // load properties
            this.m_fullpropertynames.Clear();
            foreach(DocSection docSection in docProject.Sections)
            {
                foreach(DocSchema docSchema in docSection.Schemas)
                {
                    foreach(DocEntity docEntity in docSchema.Entities)
                    {
                        if(!docEntity.IsAbstract())
                        {
                            DocEntity docClass = docEntity;
                            while(docClass != null)
                            {
                                foreach(DocAttribute docAttr in docClass.Attributes)
                                {
                                    if (String.IsNullOrEmpty(docAttr.Derived) &&
                                        String.IsNullOrEmpty(docAttr.Inverse))
                                    {
                                        string row0 = docEntity.Name;
                                        string row1 = docAttr.Name;
                                        string row2 = docAttr.Name + "_" + docClass.Name;
                                        string row3 = "ENTITY";

                                        DocAggregationEnum docAggr = docAttr.GetAggregation();
                                        if(docAggr == DocAggregationEnum.SET)
                                        {
                                            row3 = "SET";
                                        }
                                        else if(docAggr == DocAggregationEnum.LIST)
                                        {
                                            row3 = "LIST";
                                        }

                                        this.m_fullpropertynames.Add(row1 + "_" + row0, new ObjectProperty(row0, row1, row2, row3));
                                    }
                                }

                                docClass = docProject.GetDefinition(docClass.BaseDefinition) as DocEntity;
                            }
                        }
                    }
                }
            }

            this.m_stream = new System.IO.MemoryStream();
            this.Instances = instances;
            this.Markup = markup;
            this.Save();

            this.m_stream.Position = 0;
            StreamReader reader = new StreamReader(this.m_stream);
            string content = reader.ReadToEnd();
            return content;
        }
Exemplo n.º 20
0
        public string FormatData(DocPublication docPublication, DocExchangeDefinition docExchange, Dictionary<string, DocObject> map, Dictionary<long, SEntity> instances, SEntity root, bool markup)
        {
            //Guid guidMapping = Guid.Parse("");//...

            StringBuilder sb = new StringBuilder();

            foreach (DocModelView docView in docPublication.Views)
            {
                foreach (DocConceptRoot docRoot in docView.ConceptRoots)
                {
                    // look for specific concept root dealing with mappings
                    foreach (DocTemplateUsage docConcept in docRoot.Concepts)
                    {
                        if (docConcept.Definition != null && docConcept.Definition.Name.Equals("External Data Constraints") && docConcept.Items.Count > 0)//...
                        {
                            bool included = true;

                            if (docExchange != null)
                            {
                                included = false;
                                // if exhcnage specified, check for inclusion
                                foreach (DocExchangeItem docExchangeItem in docConcept.Exchanges)
                                {
                                    if (docExchangeItem.Exchange == docExchange && docExchangeItem.Requirement == DocExchangeRequirementEnum.Mandatory)
                                    {
                                        included = true;
                                        break;
                                    }
                                }
                            }

                            if (included)
                            {
                                string table = docConcept.Items[0].GetParameterValue("Table");
                                string query = docConcept.Items[0].GetParameterValue("Reference");

                                //if (query == null)
                                //{
                                //    query = String.Empty;
                                //}

                                //int cap = query.IndexOf('.');
                                //string typename = query.Substring(0, cap);

                                // find corresponding type?
                                //instance.GetType().Assembly.GetType(typename);

                                // query all data of given type
                                //...

                                sb.AppendLine("<h4>" + docConcept.Name + "</h4>");
                                sb.AppendLine("<table class=\"gridtable\">");

                                // generate header row
                                sb.AppendLine("<tr>");
                                foreach (DocTemplateItem docItem in docConcept.Items)
                                {
                                    string name = docItem.GetParameterValue("Name");
                                    string color = docItem.GetParameterValue("Color");
                                    //... use color...

                                    sb.Append("<th>");
                                    sb.Append(name);
                                    sb.Append("</th>");
                                };
                                sb.AppendLine("</tr>");

                                // generate data rows
                                foreach (SEntity e in instances.Values)
                                {
                                    string eachname = e.GetType().Name;
                                    if (docRoot.ApplicableEntity.IsInstanceOfType(e))
                                    {
                                        sb.Append("<tr>");
                                        foreach (DocTemplateItem docItem in docConcept.Items)
                                        {
                                            sb.Append("<td>");

                                            string expr = docItem.GetParameterValue("Reference");
                                            CvtValuePath valpath = CvtValuePath.Parse(expr, map); //todo: move out of loop
                                            if (valpath != null)
                                            {
                                                object value = valpath.GetValue(e, null);

                                                if (value == e)
                                                {
                                                    value = e.GetType().Name;
                                                }
                                                else if (value is SEntity)
                                                {
                                                    // use name
                                                    FieldInfo fieldValue = value.GetType().GetField("Name");
                                                    if (fieldValue != null)
                                                    {
                                                        value = fieldValue.GetValue(value);
                                                    }
                                                }
                                                else if (value is System.Collections.IList)
                                                {
                                                    System.Collections.IList list = (System.Collections.IList)value;
                                                    StringBuilder sbList = new StringBuilder();
                                                    foreach(object elem in list)
                                                    {
                                                        FieldInfo fieldName = elem.GetType().GetField("Name");
                                                        if(fieldName != null)
                                                        {
                                                            object elemname = fieldName.GetValue(elem);
                                                            if(elemname != null)
                                                            {
                                                                FieldInfo fieldValue = elemname.GetType().GetField("Value");
                                                                if (fieldValue != null)
                                                                {
                                                                    object elemval = fieldValue.GetValue(elemname);
                                                                    sbList.Append(elemval.ToString());
                                                                }
                                                            }
                                                        }
                                                        sbList.Append("; <br/>");
                                                    }
                                                    value = sbList.ToString();
                                                }
                                                else if (value is Type)
                                                {
                                                    value = ((Type)value).Name;
                                                }

                                                if (value != null)
                                                {
                                                    FieldInfo fieldValue = value.GetType().GetField("Value");
                                                    if (fieldValue != null)
                                                    {
                                                        value = fieldValue.GetValue(value);
                                                    }

                                                    if (value != null)
                                                    {
                                                        sb.Append(value.ToString()); // todo: html-encode
                                                    }
                                                }
                                                else
                                                {
                                                    sb.Append("&nbsp;");
                                                }
                                            }

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

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

            return sb.ToString();
        }
Exemplo n.º 21
0
        internal static void ImportMvd(mvdXML mvd, DocProject docProject, string filepath)
        {
            if (mvd.Templates != null)
            {
                Dictionary<EntityRule, DocModelRuleEntity> fixups = new Dictionary<EntityRule, DocModelRuleEntity>();
                foreach (ConceptTemplate mvdTemplate in mvd.Templates)
                {
                    DocTemplateDefinition docDef = docProject.GetTemplate(mvdTemplate.Uuid);
                    if (docDef == null)
                    {
                        docDef = new DocTemplateDefinition();
                        docProject.Templates.Add(docDef);
                    }

                    ImportMvdTemplate(mvdTemplate, docDef, fixups);
                }

                foreach(EntityRule er in fixups.Keys)
                {
                    DocModelRuleEntity docEntityRule = fixups[er];
                    if(er.References != null)
                    {
                        foreach(TemplateRef tr in er.References)
                        {
                            DocTemplateDefinition dtd = docProject.GetTemplate(tr.Ref);
                            if(dtd != null)
                            {
                                docEntityRule.References.Add(dtd);
                            }
                        }
                    }
                }
            }

            if (mvd.Views != null)
            {
                foreach (ModelView mvdView in mvd.Views)
                {
                    DocModelView docView = docProject.GetView(mvdView.Uuid);
                    if (docView == null)
                    {
                        docView = new DocModelView();
                        docProject.ModelViews.Add(docView);
                    }

                    ImportMvdObject(mvdView, docView);

                    docView.BaseView = mvdView.BaseView;
                    docView.Exchanges.Clear();
                    Dictionary<Guid, ExchangeRequirement> mapExchange = new Dictionary<Guid, ExchangeRequirement>();
                    foreach (ExchangeRequirement mvdExchange in mvdView.ExchangeRequirements)
                    {
                        mapExchange.Add(mvdExchange.Uuid, mvdExchange);

                        DocExchangeDefinition docExchange = new DocExchangeDefinition();
                        ImportMvdObject(mvdExchange, docExchange);
                        docView.Exchanges.Add(docExchange);

                        docExchange.Applicability = (DocExchangeApplicabilityEnum)mvdExchange.Applicability;

                        // attempt to find icons if exists -- remove extention
                        try
                        {
                            string iconpath = filepath.Substring(0, filepath.Length - 7) + @"\mvd-" + docExchange.Name.ToLower().Replace(' ', '-') + ".png";
                            if (System.IO.File.Exists(iconpath))
                            {
                                docExchange.Icon = System.IO.File.ReadAllBytes(iconpath);
                            }
                        }
                        catch
                        {

                        }
                    }

                    foreach (ConceptRoot mvdRoot in mvdView.Roots)
                    {
                        // find the entity
                        DocEntity docEntity = LookupEntity(docProject, mvdRoot.ApplicableRootEntity);
                        if (docEntity != null)
                        {
                            DocConceptRoot docConceptRoot = docView.GetConceptRoot(mvdRoot.Uuid);
                            if (docConceptRoot == null)
                            {
                                docConceptRoot = new DocConceptRoot();
                                if (docView.ConceptRoots == null)
                                {
                                    docView.ConceptRoots = new List<DocConceptRoot>();
                                }
                                docView.ConceptRoots.Add(docConceptRoot);
                            }

                            ImportMvdObject(mvdRoot, docConceptRoot);
                            docConceptRoot.ApplicableEntity = docEntity;

                            if (mvdRoot.Applicability != null)
                            {
                                docConceptRoot.ApplicableTemplate = docProject.GetTemplate(mvdRoot.Applicability.Template.Ref);
                                if(mvdRoot.Applicability.TemplateRules != null)
                                {
                                    docConceptRoot.ApplicableOperator = (DocTemplateOperator)Enum.Parse(typeof(TemplateOperator), mvdRoot.Applicability.TemplateRules.Operator.ToString());
                                    foreach (TemplateRule r in mvdRoot.Applicability.TemplateRules.TemplateRule)
                                    {
                                        DocTemplateItem docItem = ImportMvdItem(r, docProject, mapExchange);
                                        docConceptRoot.ApplicableItems.Add(docItem);
                                    }
                                }
                            }

                            docConceptRoot.Concepts.Clear();
                            foreach (Concept mvdNode in mvdRoot.Concepts)
                            {
                                DocTemplateUsage docUse = new DocTemplateUsage();
                                docConceptRoot.Concepts.Add(docUse);
                                ImportMvdConcept(mvdNode, docUse, docProject, mapExchange);
                            }
                        }
                        else
                        {
                            //TODO: log error
                        }
                    }
                }
            }
        }
Exemplo n.º 22
0
        private void toolStripMenuItemEditPaste_Click(object sender, EventArgs e)
        {
            if (this.treeView.Focused)
            {
                DocObject docSelect = this.treeView.SelectedNode.Tag as DocObject;
                if (docSelect is DocSection && this.m_clipboard is DocSchema && this.m_clipboardNode.Parent.Tag is DocSection)
                {
                    DocSchema docSchema = (DocSchema)this.m_clipboard;
                    DocSection docSectionNew = (DocSection)docSelect;
                    DocSection docSectionOld = (DocSection)this.m_clipboardNode.Parent.Tag;

                    docSectionOld.Schemas.Remove(docSchema);
                    docSectionNew.Schemas.Add(docSchema);

                    this.m_clipboardNode.Remove();
                    TreeNode tnSchema = this.LoadNode(this.treeView.SelectedNode, docSchema, docSchema.Name, true);
                    this.treeView.SelectedNode = tnSchema;
                    LoadNodeSchema(tnSchema, docSchema);
                }
                else if (docSelect is DocSchema && this.m_clipboard is DocPropertySet)
                {
                    DocSchema schemaNew = (DocSchema)docSelect;
                    DocPropertySet psetOld = (DocPropertySet)this.m_clipboard;
                    if (this.m_clipboardCut)
                    {
                        if (this.m_clipboardNode.Parent.Parent.Tag is DocSchema)
                        {
                            DocSchema schemaOld = (DocSchema)this.m_clipboardNode.Parent.Parent.Tag;
                            schemaOld.PropertySets.Remove(psetOld);
                            schemaNew.PropertySets.Add(psetOld);

                            this.m_clipboardNode.Remove();
                            this.m_clipboardNode = null;
                            this.m_clipboard = null;
                            this.m_clipboardCut = false;

                            this.treeView.SelectedNode = this.LoadNode(this.treeView.SelectedNode.Nodes[4], psetOld, psetOld.Name, false);
                        }
                    }
                    else
                    {
                        // TODO...
                    }
                }
                else if (docSelect is DocPropertySet && this.m_clipboard is DocProperty)
                {
                    DocPropertySet psetNew = (DocPropertySet)docSelect;
                    DocProperty propOld = (DocProperty)this.m_clipboard;
                    if (this.m_clipboardCut)
                    {
                        if (this.m_clipboardNode.Parent.Tag is DocPropertySet)
                        {
                            DocPropertySet psetOld = (DocPropertySet)this.m_clipboardNode.Parent.Tag;
                            psetOld.Properties.Remove(propOld);
                            psetNew.Properties.Add(propOld);

                            this.m_clipboardNode.Remove();
                            this.m_clipboardNode = null;
                            this.m_clipboard = null;
                            this.m_clipboardCut = false;

                            this.treeView.SelectedNode = this.LoadNode(this.treeView.SelectedNode, propOld, propOld.Name, false);
                        }
                    }
                    else
                    {
                        DocProperty propNew = new DocProperty();
                        propNew.Name = propOld.Name;
                        propNew.Documentation = propOld.Documentation;
                        propNew.PropertyType = propOld.PropertyType;
                        propNew.PrimaryDataType = propOld.PrimaryDataType;
                        propNew.SecondaryDataType = propOld.SecondaryDataType;
                        foreach(DocLocalization localOld in propOld.Localization)
                        {
                            DocLocalization localNew = new DocLocalization();
                            localNew.Name = localOld.Name;
                            localNew.Documentation = localOld.Documentation;
                            localNew.Category = localOld.Category;
                            localNew.Locale = localOld.Locale;
                            localNew.URL = localOld.URL;
                            propNew.Localization.Add(localNew);
                        }

                        this.treeView.SelectedNode = this.LoadNode(this.treeView.SelectedNode, propNew, propNew.Name, false);
                    }
                }
                else if (docSelect is DocConceptRoot && this.m_clipboard is DocTemplateUsage)
                {
                    DocConceptRoot docRoot = (DocConceptRoot)docSelect;

                    DocTemplateUsage docSource = (DocTemplateUsage)this.m_clipboard;
                    DocTemplateUsage docTarget = new DocTemplateUsage();
                    docRoot.Concepts.Add(docTarget);

                    CopyTemplateUsage(docSource, docTarget);

                    this.treeView.SelectedNode = LoadNode(this.treeView.SelectedNode, docTarget, docTarget.Name, false);
                }
                else if (docSelect is DocModelView && this.m_clipboard is DocExchangeDefinition)
                {
                    DocModelView docView = (DocModelView)docSelect;
                    DocExchangeDefinition docSource = (DocExchangeDefinition)this.m_clipboard;
                    DocExchangeDefinition docTarget = new DocExchangeDefinition();

                    docView.Exchanges.Add(docTarget);
                    docTarget.Name = docSource.Name;
                    docTarget.Documentation = docSource.Documentation;
                    docTarget.Author = docSource.Author;
                    docTarget.Copyright = docSource.Copyright;
                    docTarget.Owner = docSource.Owner;
                    docTarget.Icon = docSource.Icon;

                    // copy entity requirements if in same view
                    if (docView.Exchanges.Contains(docSource))
                    {
                        foreach (DocConceptRoot docRoot in docView.ConceptRoots)
                        {
                            foreach (DocTemplateUsage docConcept in docRoot.Concepts)
                            {
                                List<DocExchangeItem> listNew = new List<DocExchangeItem>();

                                foreach (DocExchangeItem docSourceER in docConcept.Exchanges)
                                {
                                    if (docSourceER.Exchange == docSource)
                                    {
                                        DocExchangeItem docTargetER = new DocExchangeItem();
                                        docTargetER.Exchange = docTarget;
                                        docTargetER.Applicability = docSourceER.Applicability;
                                        docTargetER.Requirement = docSourceER.Requirement;

                                        listNew.Add(docTargetER);
                                    }
                                }

                                foreach (DocExchangeItem docTargetER in listNew)
                                {
                                    docConcept.Exchanges.Add(docTargetER);
                                }
                            }
                        }
                    }

                    this.treeView.SelectedNode = LoadNode(this.treeView.SelectedNode, docTarget, docTarget.Name, false);
                }
            }
            else
            {
                this.textBoxHTML.Paste();
            }
        }
Exemplo n.º 23
0
        /// <summary>
        /// Formats table for single exchange
        /// </summary>
        /// <param name="def"></param>
        /// <returns></returns>
        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();
        }
Exemplo n.º 24
0
        public Compiler(DocProject project, DocModelView[] views, DocExchangeDefinition exchange, bool psets)
        {
            this.m_project  = project;
            this.m_views    = views;
            this.m_exchange = exchange;
            this.m_psets    = psets;

            // version needs to be included for extracting XML namespace (Major.Minor.Addendum.Corrigendum)
            string                 version            = project.GetSchemaVersion();
            ConstructorInfo        conContract        = (typeof(AssemblyVersionAttribute).GetConstructor(new Type[] { typeof(string) }));
            CustomAttributeBuilder cabAssemblyVersion = new CustomAttributeBuilder(conContract, new object[] { version });

            string schemaid = project.GetSchemaIdentifier();
            string assembly = "buildingSmart." + schemaid;
            string module   = assembly + ".dll";

            this.m_rootnamespace = assembly + ".";

            this.m_assembly    = AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName(assembly), AssemblyBuilderAccess.RunAndSave, new CustomAttributeBuilder[] { cabAssemblyVersion });
            this.m_module      = this.m_assembly.DefineDynamicModule(module, module);
            this.m_definitions = new Dictionary <string, DocObject>();
            this.m_types       = new Dictionary <string, Type>();
            this.m_fields      = new Dictionary <Type, Dictionary <string, FieldInfo> >();
            this.m_templates   = new Dictionary <DocTemplateDefinition, MethodInfo>();
            this.m_namespaces  = new Dictionary <string, string>();

            Dictionary <DocObject, bool> included = null;

            if (this.m_views != null)
            {
                included = new Dictionary <DocObject, bool>();
                foreach (DocModelView docView in this.m_views)
                {
                    this.m_project.RegisterObjectsInScope(docView, included);
                }
            }
            if (psets)
            {
                foreach (DocPropertyEnumeration docPropEnum in project.PropertyEnumerations)
                {
                    DocEnumeration docType = docPropEnum.ToEnumeration();
                    if (!this.m_definitions.ContainsKey(docType.Name))
                    {
                        this.m_definitions.Add(docType.Name, docType);
                    }
                }
            }

            foreach (DocSection docSection in project.Sections)
            {
                foreach (DocSchema docSchema in docSection.Schemas)
                {
                    foreach (DocEntity docEntity in docSchema.Entities)
                    {
                        if (included == null || included.ContainsKey(docEntity))
                        {
                            if (!this.m_definitions.ContainsKey(docEntity.Name))
                            {
                                this.m_definitions.Add(docEntity.Name, docEntity);
                                this.m_namespaces.Add(docEntity.Name, docSchema.Name);
                            }
                        }
                    }

                    foreach (DocType docType in docSchema.Types)
                    {
                        if (included == null || included.ContainsKey(docType))
                        {
                            if (!this.m_definitions.ContainsKey(docType.Name))
                            {
                                this.m_definitions.Add(docType.Name, docType);
                                this.m_namespaces.Add(docType.Name, docSchema.Name);
                            }
                        }
                    }
                }
            }

            // second pass:
            if (psets)
            {
                foreach (DocSection docSection in project.Sections)
                {
                    foreach (DocSchema docSchema in docSection.Schemas)
                    {
                        foreach (DocPropertySet docPset in docSchema.PropertySets)
                        {
                            DocEntity docType = docPset.ToEntity(this.m_definitions);
                            if (!this.m_definitions.ContainsKey(docType.Name))
                            {
                                this.m_definitions.Add(docType.Name, docType);
                                this.m_namespaces.Add(docType.Name, docSchema.Name);
                            }
                        }

                        foreach (DocQuantitySet docQset in docSchema.QuantitySets)
                        {
                            DocEntity docType = docQset.ToEntity(this.m_definitions);
                            if (!this.m_definitions.ContainsKey(docType.Name))
                            {
                                this.m_definitions.Add(docType.Name, docType);
                                this.m_namespaces.Add(docType.Name, docSchema.Name);
                            }
                        }
                    }
                }
            }

            // first register types and fields
            foreach (string key in this.m_definitions.Keys)
            {
                Type typereg = RegisterType(key);

                // localization -- use custom attributes for now -- ideal way would be to use assembly resources, though has bugs in .net 4.0
                if (typereg is TypeBuilder)
                {
                    TypeBuilder tb = (TypeBuilder)typereg;

                    DocObject docObj = this.m_definitions[key];
                    foreach (DocLocalization docLocal in docObj.Localization)
                    {
                        CustomAttributeBuilder cab = docLocal.ToCustomAttributeBuilder();
                        if (cab != null)
                        {
                            tb.SetCustomAttribute(cab);
                        }
                    }
                }
            }

            // now register template functions (may depend on fields existing)

            // find associated ConceptRoot for model view, define validation function
            if (this.m_views != null)
            {
                foreach (DocModelView view in this.m_views)
                {
                    string viewname = view.Code;
                    foreach (DocConceptRoot root in view.ConceptRoots)
                    {
                        Type tOpen = null;

                        if (this.m_types.TryGetValue(root.ApplicableEntity.Name, out tOpen) && tOpen is TypeBuilder)
                        {
                            TypeBuilder tb = (TypeBuilder)tOpen;


                            // new: generate type for concept root
                            //if (view.Name != null && root.Name != null)
                            {
                                /*
                                 * string typename = this.m_rootnamespace + "." + view.Name.Replace(" ", "_") + "." + root.Name.Replace(" ", "_");
                                 * //Type tbConceptRoot = RegisterType(typename);
                                 * TypeBuilder tbRoot = this.m_module.DefineType(typename, attr, typebase);
                                 */

                                // add typebuilder to map temporarily in case referenced by an attribute within same class or base class
                                //this.m_types.Add(typename, tb);

                                foreach (DocTemplateUsage concept in root.Concepts)
                                {
                                    CompileConcept(concept, view, tb);
                                }
                            }
                        }
                    }
                }
            }

            //Dictionary<string, Stream> mapResStreams = new Dictionary<string, Stream>();
            //Dictionary<string, ResXResourceWriter> mapResources = new Dictionary<string, ResXResourceWriter>();

            // seal types once all are built
            List <TypeBuilder> listBase = new List <TypeBuilder>();

            foreach (string key in this.m_definitions.Keys)
            {
                Type tOpen = this.m_types[key];
                while (tOpen is TypeBuilder)
                {
                    listBase.Add((TypeBuilder)tOpen);
                    tOpen = tOpen.BaseType;
                }

                // seal in base class order
                for (int i = listBase.Count - 1; i >= 0; i--)
                {
                    Type tClosed = listBase[i].CreateType();
                    this.m_types[tClosed.Name] = tClosed;
                }
                listBase.Clear();


                // record bindings
                DocDefinition docDef = this.m_definitions[key] as DocDefinition;
                if (docDef != null)
                {
                    docDef.RuntimeType = this.m_types[key];

                    if (docDef is DocEntity)
                    {
                        DocEntity docEnt = (DocEntity)docDef;
                        foreach (DocAttribute docAttr in docEnt.Attributes)
                        {
                            docAttr.RuntimeField = docDef.RuntimeType.GetProperty(docAttr.Name);
                        }
                    }

#if false // bug in .net framework 4.0+ -- can't read resources dynamically defined
                    // capture localization
                    foreach (DocLocalization docLocal in docDef.Localization)
                    {
                        if (!String.IsNullOrEmpty(docLocal.Locale))
                        {
                            string major = docLocal.Locale.Substring(0, 2).ToLower();

                            ResXResourceWriter reswriter = null;
                            if (!mapResources.TryGetValue(major, out reswriter))
                            {
                                MemoryStream stream = new MemoryStream();
                                mapResStreams.Add(major, stream);

                                reswriter = new ResXResourceWriter(stream);
                                mapResources.Add(major, reswriter);
                            }

                            ResXDataNode node = new ResXDataNode(docDef.Name, docLocal.Name);
                            node.Comment = docLocal.Documentation;
                            reswriter.AddResource(node);
                        }
                    }
#endif
                }
            }

#if false
            foreach (string locale in mapResStreams.Keys)
            {
                ResXResourceWriter writer = mapResources[locale];
                writer.Generate();
                Stream stream = mapResStreams[locale];
                stream.Seek(0, SeekOrigin.Begin);
                m_module.DefineManifestResource("Resources." + locale + ".resx", stream, ResourceAttributes.Public);
            }
#endif
        }
Exemplo n.º 25
0
        public string FormatData(DocProject docProject, DocPublication docPublication, DocExchangeDefinition docExchange, Dictionary <string, DocObject> map, Dictionary <long, SEntity> instances, SEntity root, bool markup)
        {
            this.m_stream = new System.IO.MemoryStream();
            this.Instance = root;
            this.Markup   = markup;
            this.Save();

            this.m_stream.Position = 0;
            StreamReader reader  = new StreamReader(this.m_stream);
            string       content = reader.ReadToEnd();

            return(content);
        }
Exemplo n.º 26
0
        public void FormatData(Stream stream, DocProject docProject, DocPublication docPublication, DocExchangeDefinition docExchange, Dictionary <string, DocObject> map, Dictionary <string, Type> typemap, Dictionary <long, SEntity> instances, SEntity root, bool markup)
        {
            StringBuilder sb = new StringBuilder();

            foreach (DocModelView docView in docPublication.Views)
            {
                foreach (DocConceptRoot docRoot in docView.ConceptRoots)
                {
                    // look for specific concept root dealing with mappings
                    foreach (DocTemplateUsage docConcept in docRoot.Concepts)
                    {
                        if (docConcept.Definition != null && docConcept.Definition.Uuid.Equals(DocTemplateDefinition.guidTemplateMapping) && docConcept.Items.Count > 0)                        //...
                        {
                            bool included = true;

                            if (docExchange != null)
                            {
                                included = false;
                                // if exhcnage specified, check for inclusion
                                foreach (DocExchangeItem docExchangeItem in docConcept.Exchanges)
                                {
                                    if (docExchangeItem.Exchange == docExchange && docExchangeItem.Requirement == DocExchangeRequirementEnum.Mandatory)
                                    {
                                        included = true;
                                        break;
                                    }
                                }
                            }

                            // check if there are any instances to populate table
                            if (included)
                            {
                                included = false;
                                foreach (SEntity e in instances.Values)
                                {
                                    string eachname = e.GetType().Name;
                                    if (docRoot.ApplicableEntity.IsInstanceOfType(e))
                                    {
                                        included = true;
                                        break;
                                    }
                                }
                            }

                            if (included)
                            {
                                string dataconcept = FormatDataConcept(docProject, docPublication, docExchange, map, typemap, instances, root, markup, docView, docRoot, docConcept);
                                sb.Append(dataconcept);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 27
0
        private void toolStripMenuItemInsertExchange_Click(object sender, EventArgs e)
        {
            DocModelView docView = this.treeView.SelectedNode.Tag as DocModelView;
            DocExchangeDefinition docExchange = new DocExchangeDefinition();
            docView.Exchanges.Add(docExchange);

            TreeNode tnParent = this.treeView.SelectedNode;
            this.treeView.SelectedNode = this.LoadNode(tnParent, docExchange, docExchange.ToString(), false);

            toolStripMenuItemEditRename_Click(this, e);
        }
Exemplo n.º 28
0
        /// <summary>
        /// Formats table for single exchange
        /// </summary>
        /// <param name="def"></param>
        /// <returns></returns>
        private static string FormatExchange(DocProject docProject, DocModelView docView, DocExchangeDefinition def, Dictionary<string, DocObject> mapEntity, Dictionary<string, string> mapSchema)
        {
            // format content
            StringBuilder sb = new StringBuilder();

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

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

            // 2. map of entities and templates -- Identity | Template | Import | Export
            sb.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);
                        }
                    }
                }
            }

            // new style - table
            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 false
                            sb.Append("<tr><td>&nbsp;&nbsp;<a href=\"../../");
                            sb.Append(schema.ToLower());
                            sb.Append("/lexical/");
                            sb.Append(ent.ToLower());
                            sb.Append(".htm#");
                            sb.Append(MakeLinkName(docConcept.Definition));
                            sb.Append("\">");
                            sb.Append(docConcept.Definition.Name);
                            sb.Append("</a></td><td>");
#endif
                            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>");

            return sb.ToString();
        }
Exemplo n.º 29
0
 public string FormatData(DocPublication docPublication, DocExchangeDefinition docExchange, Dictionary <string, DocObject> map, Dictionary <long, SEntity> instances)
 {
     //...???
     return(null);
 }
Exemplo n.º 30
0
        public string FormatDataConcept(DocProject docProject, DocPublication docPublication, DocExchangeDefinition docExchange, Dictionary <string, DocObject> map, Dictionary <string, Type> typemap, Dictionary <long, SEntity> instances, SEntity root, bool markup, DocModelView docView, DocConceptRoot docRoot, DocTemplateUsage docConcept)
        {
            StringBuilder sb = new StringBuilder();

            string table = docConcept.Items[0].GetParameterValue("Table");
            string query = docConcept.Items[0].GetParameterValue("Reference");

            sb.AppendLine("<h4>" + docConcept.Name + "</h4>");
            sb.AppendLine("<table class=\"gridtable\">");

            List <string>       colstyles = new List <string>();
            List <string>       colformat = new List <string>();
            List <CvtValuePath> colmaps   = new List <CvtValuePath>();

            // generate header row
            sb.AppendLine("<tr>");
            foreach (DocTemplateItem docItem in docConcept.Items)
            {
                string name = docItem.GetParameterValue("Name");
                string disp = "#" + docItem.GetColor().ToArgb().ToString("X8");                 //docItem.GetParameterValue("Color");docItem.GetParameterValue("Color");
                string expr = docItem.GetParameterValue("Reference");
                string form = docItem.GetParameterValue("Format");

                string style = "";
                if (!String.IsNullOrEmpty(disp))
                {
                    style = " style=\"background-color:" + disp + ";\"";
                }
                colstyles.Add(style);

                string format = "";
                if (!String.IsNullOrEmpty(form))
                {
                    format = form;
                }
                colformat.Add(format);

                string       desc    = "";
                CvtValuePath valpath = CvtValuePath.Parse(expr, map);
                colmaps.Add(valpath);
                if (valpath != null)
                {
                    desc = /*valpath.GetDescription(map) + "&#10;&#10;" + */ valpath.ToString().Replace("\\", "&#10;");
                }

                sb.Append("<th><a href=\"../../schema/views/" + DocumentationISO.MakeLinkName(docView) + "/" + DocumentationISO.MakeLinkName(docExchange) + ".htm#" + DocumentationISO.MakeLinkName(docConcept) + "\" title=\"" + desc + "\">");
                sb.Append(name);
                sb.Append("</a></th>");
            }
            ;
            sb.AppendLine("</tr>");

            // generate data rows
            List <DocModelRule> trace = new List <DocModelRule>();

            foreach (SEntity e in instances.Values)
            {
                string eachname = e.GetType().Name;
                if (docRoot.ApplicableEntity.IsInstanceOfType(e))
                {
                    bool includerow = true;

                    // if root has more complex rules, check them
                    if (docRoot.ApplicableTemplate != null && docRoot.ApplicableItems.Count > 0)
                    {
                        includerow = false;

                        // must check1
                        foreach (DocTemplateItem docItem in docRoot.ApplicableItems)
                        {
                            foreach (DocModelRule rule in docRoot.ApplicableTemplate.Rules)
                            {
                                try
                                {
                                    trace.Clear();
                                    bool?result = rule.Validate(e, docItem, typemap, trace, e, null, null);
                                    if (result == true && docRoot.ApplicableOperator == DocTemplateOperator.Or)
                                    {
                                        includerow = true;
                                        break;
                                    }
                                }
                                catch
                                {
                                    docRoot.ToString();
                                }
                            }

                            // don't yet support AND or other operators

                            if (includerow)
                            {
                                break;
                            }
                        }
                    }


                    if (includerow)
                    {
                        StringBuilder sbRow = new StringBuilder();

                        sbRow.Append("<tr>");
                        int iCol = 0;
                        foreach (DocTemplateItem docItem in docConcept.Items)
                        {
                            sbRow.Append("<td" + colstyles[iCol]);
                            CvtValuePath valpath = colmaps[iCol];
                            string       format  = colformat[iCol];

                            iCol++;

                            if (valpath != null)
                            {
                                string nn = docItem.GetParameterValue("Name");

                                object value = valpath.GetValue(e, null);

                                if (value == e)
                                {
                                    value = e.GetType().Name;
                                }
                                else if (value is SEntity)
                                {
                                    // use name
                                    FieldInfo fieldValue = value.GetType().GetField("Name");
                                    if (fieldValue != null)
                                    {
                                        value = fieldValue.GetValue(value);
                                    }
                                }
                                else if (value is System.Collections.IList)
                                {
                                    System.Collections.IList list   = (System.Collections.IList)value;
                                    StringBuilder            sbList = new StringBuilder();
                                    foreach (object elem in list)
                                    {
                                        FieldInfo fieldName = elem.GetType().GetField("Name");
                                        if (fieldName != null)
                                        {
                                            object elemname = fieldName.GetValue(elem);
                                            if (elemname != null)
                                            {
                                                FieldInfo fieldValue = elemname.GetType().GetField("Value");
                                                if (fieldValue != null)
                                                {
                                                    object elemval = fieldValue.GetValue(elemname);
                                                    sbList.Append(elemval.ToString());
                                                }
                                            }
                                        }
                                        sbList.Append("; <br/>");
                                    }
                                    value = sbList.ToString();
                                }
                                else if (value is Type)
                                {
                                    value = ((Type)value).Name;
                                }

                                if (!String.IsNullOrEmpty(format))
                                {
                                    if (format.Equals("Required") && value == null)
                                    {
                                        includerow = false;
                                    }
                                }

                                if (value != null)
                                {
                                    FieldInfo fieldValue = value.GetType().GetField("Value");
                                    if (fieldValue != null)
                                    {
                                        value = fieldValue.GetValue(value);
                                    }

                                    if (format != null && format.Equals("True") && (value == null || !value.ToString().Equals("True")))
                                    {
                                        includerow = false;
                                    }

                                    if (value is Double)
                                    {
                                        sbRow.Append(" align=\"right\">");

                                        sbRow.Append(((Double)value).ToString("N3"));
                                    }
                                    else if (value is List <Int64> )
                                    {
                                        sbRow.Append(">");

                                        // latitude or longitude
                                        List <Int64> intlist = (List <Int64>)value;
                                        if (intlist.Count >= 3)
                                        {
                                            sbRow.Append(intlist[0] + "° " + intlist[1] + "' " + intlist[2] + "\"");
                                        }
                                    }
                                    else if (value != null)
                                    {
                                        sbRow.Append(">");
                                        sbRow.Append(value.ToString());                                         // todo: html-encode
                                    }
                                }
                                else
                                {
                                    sbRow.Append(">");
                                    sbRow.Append("&nbsp;");
                                }
                            }
                            else
                            {
                                sbRow.Append(">");
                            }

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

                        if (includerow)
                        {
                            sb.Append(sbRow.ToString());
                        }
                    }
                }
            }

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

            return(sb.ToString());
        }
Exemplo n.º 31
0
 public void FormatData(Stream stream, DocProject docProject, DocPublication docPublication, DocExchangeDefinition docExchange, Dictionary <string, DocObject> map, Dictionary <string, Type> typemap, Dictionary <long, SEntity> instances, SEntity root, bool markup)
 {
     this.m_stream = stream;
     this.Instance = root;
     this.Markup   = markup;
     this.Save();
 }