Beispiel #1
0
        private void SaveNode(TreeNode tn)
        {
            ChangeInfo info = (ChangeInfo)tn.Tag;

            if (tn.Checked)
            {
                if (info.Original == null)
                {
                    // add new item
                    if (info.Change is DocLocalization)
                    {
                        DocLocalization localChange = (DocLocalization)info.Change;

                        ChangeInfo parentinfo = (ChangeInfo)tn.Parent.Tag;
                        DocObject  docObj     = (DocObject)parentinfo.Original;
                        docObj.RegisterLocalization(localChange.Locale, localChange.Name, localChange.Documentation);
                    }
                    else if (info.Change is DocAttribute)
                    {
                        DocAttribute localAttr = (DocAttribute)info.Change;

                        ChangeInfo parentinfo = (ChangeInfo)tn.Parent.Tag;
                        DocEntity  docEntity  = (DocEntity)parentinfo.Original;

                        DocAttribute docAttr = (DocAttribute)localAttr.Clone();
                        docEntity.Attributes.Add(docAttr);
                    }
                    else if (info.Change is DocWhereRule)
                    {
                        DocWhereRule localAttr = (DocWhereRule)info.Change;

                        ChangeInfo parentinfo = (ChangeInfo)tn.Parent.Tag;
                        DocEntity  docEntity  = (DocEntity)parentinfo.Original;

                        DocWhereRule docAttr = (DocWhereRule)localAttr.Clone();
                        docEntity.WhereRules.Add(docAttr);
                    }
                    else if (info.Change is DocFunction)
                    {
                        DocFunction localAttr = (DocFunction)info.Change;

                        ChangeInfo parentinfo = (ChangeInfo)tn.Parent.Tag;
                        DocSchema  docSchema  = (DocSchema)parentinfo.Original;

                        DocFunction docAttr = (DocFunction)localAttr.Clone();
                        docSchema.Functions.Add(docAttr);
                    }
                    else if (info.Change is DocConstant)
                    {
                        this.ToString();
                    }
                    else if (info.Change is DocProperty)
                    {
                        this.ToString();

                        DocProperty localProp = (DocProperty)info.Change;

                        ChangeInfo     parentinfo = (ChangeInfo)tn.Parent.Tag;
                        DocPropertySet docPset    = (DocPropertySet)parentinfo.Original;

                        DocProperty docProperty = (DocProperty)localProp.Clone();
                        docPset.Properties.Add(docProperty);
                    }
                    else if (info.Change is DocPropertyConstant)
                    {
                        this.ToString();

                        DocPropertyConstant localProp = (DocPropertyConstant)info.Change;

                        ChangeInfo             parentinfo = (ChangeInfo)tn.Parent.Tag;
                        DocPropertyEnumeration docPset    = (DocPropertyEnumeration)parentinfo.Original;

                        DocPropertyEnumeration docEnumChange = (DocPropertyEnumeration)parentinfo.Change;
                        int index = docEnumChange.Constants.IndexOf(localProp);

                        DocPropertyConstant docProperty = (DocPropertyConstant)localProp.Clone();
                        docPset.Constants.Insert(index, docProperty);
                    }
                    else
                    {
                        this.ToString();
                    }
                }
                else if (info.Change == null)
                {
                    // removal of definition
                    if (info.Original is DocAttribute)
                    {
                        DocAttribute docAttr    = (DocAttribute)info.Original;
                        ChangeInfo   parentinfo = (ChangeInfo)tn.Parent.Tag;
                        DocEntity    docEntity  = (DocEntity)parentinfo.Original;

                        docEntity.Attributes.Remove(docAttr);
                        docAttr.Delete();
                    }
                    else
                    {
                        this.ToString();
                    }
                }
                else
                {
                    // change of documentation
                    info.Original.Name          = info.Change.Name;
                    info.Original.Documentation = info.Change.Documentation;

                    if (info.Original is DocWhereRule)
                    {
                        DocWhereRule whereOriginal = (DocWhereRule)info.Original;
                        DocWhereRule whereChange   = (DocWhereRule)info.Change;
                        whereOriginal.Expression = whereChange.Expression;
                    }
                    else if (info.Original is DocFunction)
                    {
                        DocFunction whereOriginal = (DocFunction)info.Original;
                        DocFunction whereChange   = (DocFunction)info.Change;
                        whereOriginal.Expression = whereChange.Expression;
                    }
                }
            }

            foreach (TreeNode tnSub in tn.Nodes)
            {
                SaveNode(tnSub);
            }
        }
Beispiel #2
0
        public FormMerge(Dictionary <Guid, DocObject> mapOriginal, DocProject docChange) : this()
        {
            this.m_mapOriginal = mapOriginal;

            // add nodes for everything, then delete ones that haven't changed or don't have any children

            // iterate and find changes in documentation
            foreach (DocPropertyEnumeration docChangePset in docChange.PropertyEnumerations)
            {
                DocObject docOriginalPset = null;
                if (mapOriginal.TryGetValue(docChangePset.Uuid, out docOriginalPset))
                {
                    TreeNode tnPset = null;
                    if (!String.Equals(docOriginalPset.Documentation, docChangePset.Documentation))
                    {
                        tnPset = this.AddNode(null, new ChangeInfo(docOriginalPset.Name, docOriginalPset, docChangePset));
                    }

                    foreach (DocPropertyConstant docChangeProp in docChangePset.Constants)
                    {
                        DocObject docOriginalProp = ((DocPropertyEnumeration)docOriginalPset).GetConstant(docChangeProp.Name);
                        if (docOriginalProp != null)
                        {
                            TreeNode tnProperty = null;
                            if (!String.Equals(docOriginalProp.Documentation, docChangeProp.Documentation))
                            {
                                if (tnPset == null)
                                {
                                    tnPset = this.AddNode(null, new ChangeInfo(docOriginalPset.Name, docOriginalPset, docChangePset));
                                }

                                tnProperty = this.AddNode(tnPset, new ChangeInfo(docOriginalPset.Name + "." + docOriginalProp.Name, docOriginalProp, docChangeProp));
                            }

                            // localization
                            foreach (DocLocalization docChangeLocal in docChangeProp.Localization)
                            {
                                DocLocalization docOriginalLocal = docOriginalProp.GetLocalization(docChangeLocal.Locale);
                                if (docOriginalLocal != null)
                                {
                                    if (!String.Equals(docOriginalLocal.Documentation, docChangeLocal.Documentation))
                                    {
                                        if (tnPset == null)
                                        {
                                            tnPset = this.AddNode(null, new ChangeInfo(docOriginalPset.Name, docOriginalPset, docChangePset));
                                        }

                                        if (tnProperty == null)
                                        {
                                            tnProperty = this.AddNode(tnPset, new ChangeInfo(docOriginalPset.Name + "." + docOriginalProp.Name, docOriginalProp, docChangeProp));
                                        }

                                        this.AddNode(tnProperty, new ChangeInfo(docChangeLocal.Locale, docOriginalLocal, docChangeLocal));
                                    }
                                }
                                else
                                {
                                    if (tnPset == null)
                                    {
                                        tnPset = this.AddNode(null, new ChangeInfo(docOriginalPset.Name, docOriginalPset, docChangePset));
                                    }

                                    if (tnProperty == null)
                                    {
                                        tnProperty = this.AddNode(tnPset, new ChangeInfo(docOriginalPset.Name + "." + docOriginalProp.Name, docOriginalProp, docChangeProp));
                                    }

                                    // new localization
                                    this.AddNode(tnProperty, new ChangeInfo(docChangeLocal.Locale, docOriginalLocal, docChangeLocal));
                                }
                            }
                        }
                        else
                        {
                            if (tnPset == null)
                            {
                                tnPset = this.AddNode(null, new ChangeInfo(docOriginalPset.Name, docOriginalPset, docChangePset));
                            }

                            // NEW:
                            this.AddNode(tnPset, new ChangeInfo(docChangePset.Name + "." + docChangeProp.Name, null, docChangeProp));
                        }
                    }
                }
                else
                {
                    // NEW:
                    this.AddNode(null, new ChangeInfo(docChangePset.Name, null, docChangePset));
                }
            }

            foreach (DocSection docChangeSection in docChange.Sections)
            {
                DocObject docOriginalSection = null;
                if (mapOriginal.TryGetValue(docChangeSection.Uuid, out docOriginalSection))
                {
                    foreach (DocSchema docChangeSchema in docChangeSection.Schemas)
                    {
                        DocObject docOriginalSchema;
                        if (mapOriginal.TryGetValue(docChangeSchema.Uuid, out docOriginalSchema))
                        {
                            // compare schemas

                            TreeNode tnSchema = this.AddNode(null, new ChangeInfo(docOriginalSchema.Name, docOriginalSchema, docChangeSchema));

                            foreach (DocType docChangeType in docChangeSchema.Types)
                            {
                                DocObject docOriginalType = null;
                                if (mapOriginal.TryGetValue(docChangeType.Uuid, out docOriginalType))
                                {
                                    TreeNode tnType = null;

                                    if (!String.Equals(docOriginalType.Documentation, docChangeType.Documentation))
                                    {
                                        tnType = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalType.Name, docOriginalType, docChangeType));
                                    }

                                    if (docChangeType is DocEnumeration)
                                    {
                                        DocEnumeration docChangeEnum = (DocEnumeration)docChangeType;
                                        foreach (DocConstant docChangeConst in docChangeEnum.Constants)
                                        {
                                            DocObject docOriginalConst = null;
                                            if (mapOriginal.TryGetValue(docChangeConst.Uuid, out docOriginalConst))
                                            {
                                                if (!String.Equals(docOriginalConst.Documentation, docChangeConst.Documentation))
                                                {
                                                    if (tnType == null)
                                                    {
                                                        tnType = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalType.Name, docOriginalType, docChangeType));
                                                    }
                                                    this.AddNode(tnType, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalType.Name + "." + docOriginalConst.Name, docOriginalConst, docChangeConst));
                                                }
                                            }
                                            else
                                            {
                                                if (tnType == null)
                                                {
                                                    tnType = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalType.Name, docOriginalType, docChangeType));
                                                }

                                                // NEW:
                                                this.AddNode(tnType, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalType.Name + "." + docOriginalConst.Name, null, docChangeConst));
                                            }
                                        }
                                    }
                                }
                            }

                            foreach (DocEntity docChangeEntity in docChangeSchema.Entities)
                            {
                                DocObject docOriginalObj = null;
                                if (mapOriginal.TryGetValue(docChangeEntity.Uuid, out docOriginalObj))
                                {
                                    DocEntity docOriginalEntity = (DocEntity)docOriginalObj;
                                    TreeNode  tnEntity          = null;

                                    if (!String.Equals(docOriginalEntity.Documentation, docChangeEntity.Documentation))
                                    {
                                        tnEntity = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalEntity.Name, docOriginalEntity, docChangeEntity));
                                    }

                                    // add attributes
                                    foreach (DocAttribute docChangeAttr in docChangeEntity.Attributes)
                                    {
                                        DocObject docOriginalAttr = null;
                                        if (mapOriginal.TryGetValue(docChangeAttr.Uuid, out docOriginalAttr))
                                        {
                                            if (!String.Equals(docOriginalAttr.Name, docChangeAttr.Name) ||
                                                !String.Equals(docOriginalAttr.Documentation, docChangeAttr.Documentation))
                                            {
                                                if (tnEntity == null)
                                                {
                                                    tnEntity = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalEntity.Name, docOriginalEntity, docChangeEntity));
                                                }
                                                this.AddNode(tnEntity, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalEntity.Name + "." + docOriginalAttr.Name, docOriginalAttr, docChangeAttr));
                                            }
                                        }
                                        else
                                        {
                                            if (tnEntity == null)
                                            {
                                                tnEntity = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalEntity.Name, docOriginalEntity, docChangeEntity));
                                            }

                                            // new attribute
                                            this.AddNode(tnEntity, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalEntity.Name + "." + docChangeAttr.Name, null, docChangeAttr));
                                        }
                                    }

                                    // remove attributes
                                    foreach (DocAttribute docOriginalAttr in docOriginalEntity.Attributes)
                                    {
                                        bool bFound = false;
                                        foreach (DocAttribute docChangeAttr in docChangeEntity.Attributes)
                                        {
                                            if (docOriginalAttr.Uuid.Equals(docChangeAttr.Uuid))
                                            {
                                                bFound = true;
                                                break;
                                            }
                                        }

                                        if (!bFound)
                                        {
                                            if (tnEntity == null)
                                            {
                                                tnEntity = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalEntity.Name, docOriginalEntity, docChangeEntity));
                                            }

                                            // delete attribute
                                            this.AddNode(tnEntity, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalEntity.Name + "." + docOriginalAttr.Name, docOriginalAttr, null));
                                        }
                                    }

                                    foreach (DocWhereRule docChangeWhere in docChangeEntity.WhereRules)
                                    {
                                        DocObject docOriginalWhere = null;
                                        if (mapOriginal.TryGetValue(docChangeWhere.Uuid, out docOriginalWhere))
                                        {
                                            DocWhereRule docOriginalWhereRule = (DocWhereRule)docOriginalWhere;
                                            if (!String.Equals(docOriginalWhere.Name, docChangeWhere.Name) ||
                                                !String.Equals(docOriginalWhere.Documentation, docChangeWhere.Documentation) ||
                                                !String.Equals(docOriginalWhereRule.Expression, docChangeWhere.Expression))
                                            {
                                                if (tnEntity == null)
                                                {
                                                    tnEntity = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalEntity.Name, docOriginalEntity, docChangeEntity));
                                                }

                                                this.AddNode(tnEntity, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalEntity.Name + "." + docOriginalWhere.Name, docOriginalWhere, docChangeWhere));
                                            }
                                        }
                                        else
                                        {
                                            if (tnEntity == null)
                                            {
                                                tnEntity = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalEntity.Name, docOriginalEntity, docChangeEntity));
                                            }

                                            // new where rule
                                            this.AddNode(tnEntity, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalEntity.Name + "." + docChangeWhere.Name, null, docChangeWhere));
                                        }
                                    }

                                    foreach (DocUniqueRule docChangeAttr in docChangeEntity.UniqueRules)
                                    {
                                        DocObject docOriginalAttr = null;
                                        if (mapOriginal.TryGetValue(docChangeAttr.Uuid, out docOriginalAttr))
                                        {
                                            if (!String.Equals(docOriginalAttr.Documentation, docChangeAttr.Documentation))
                                            {
                                                if (tnEntity == null)
                                                {
                                                    tnEntity = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalEntity.Name, docOriginalEntity, docChangeEntity));
                                                }

                                                this.AddNode(tnEntity, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalEntity.Name + "." + docOriginalAttr.Name, docOriginalAttr, docChangeAttr));
                                            }
                                        }
                                    }
                                }
                            }

                            foreach (DocFunction docChangeFunction in docChangeSchema.Functions)
                            {
                                DocObject docOriginalFunc = null;
                                if (mapOriginal.TryGetValue(docChangeFunction.Uuid, out docOriginalFunc))
                                {
                                    TreeNode tnType = null;

                                    DocFunction docOriginalFunction = (DocFunction)docOriginalFunc;

                                    if (!String.Equals(docOriginalFunction.Name, docChangeFunction.Name) ||
                                        !String.Equals(docOriginalFunction.Documentation, docChangeFunction.Documentation) ||
                                        !String.Equals(docOriginalFunction.Expression, docChangeFunction.Expression))
                                    {
                                        tnType = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalFunction.Name, docOriginalFunction, docChangeFunction));
                                    }
                                }
                                else
                                {
                                    // new attribute
                                    this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docChangeFunction.Name, null, docChangeFunction));
                                }
                            }

                            foreach (DocPropertySet docChangePset in docChangeSchema.PropertySets)
                            {
                                DocObject docOriginalPset = null;
                                if (mapOriginal.TryGetValue(docChangePset.Uuid, out docOriginalPset))
                                {
                                    TreeNode tnPset = null;
                                    if (!String.Equals(docOriginalPset.Documentation, docChangePset.Documentation))
                                    {
                                        tnPset = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalPset.Name, docOriginalPset, docChangePset));
                                    }

                                    foreach (DocProperty docChangeProp in docChangePset.Properties)
                                    {
                                        DocObject docOriginalProp = ((DocPropertySet)docOriginalPset).GetProperty(docChangeProp.Name);
                                        if (docOriginalProp != null)
                                        {
                                            TreeNode tnProperty = null;
                                            if (!String.Equals(docOriginalProp.Documentation, docChangeProp.Documentation))
                                            {
                                                if (tnPset == null)
                                                {
                                                    tnPset = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalPset.Name, docOriginalPset, docChangePset));
                                                }

                                                tnProperty = this.AddNode(tnPset, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalPset.Name + "." + docOriginalProp.Name, docOriginalProp, docChangeProp));
                                            }

                                            // localization
                                            foreach (DocLocalization docChangeLocal in docChangeProp.Localization)
                                            {
                                                DocLocalization docOriginalLocal = docOriginalProp.GetLocalization(docChangeLocal.Locale);
                                                if (docOriginalLocal != null)
                                                {
                                                    if (!String.Equals(docOriginalLocal.Documentation, docChangeLocal.Documentation))
                                                    {
                                                        if (tnPset == null)
                                                        {
                                                            tnPset = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalPset.Name, docOriginalPset, docChangePset));
                                                        }

                                                        if (tnProperty == null)
                                                        {
                                                            tnProperty = this.AddNode(tnPset, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalPset.Name + "." + docOriginalProp.Name, docOriginalProp, docChangeProp));
                                                        }

                                                        this.AddNode(tnProperty, new ChangeInfo(docChangeLocal.Locale, docOriginalLocal, docChangeLocal));
                                                    }
                                                }
                                                else
                                                {
                                                    if (tnPset == null)
                                                    {
                                                        tnPset = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalPset.Name, docOriginalPset, docChangePset));
                                                    }

                                                    if (tnProperty == null)
                                                    {
                                                        tnProperty = this.AddNode(tnPset, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalPset.Name + "." + docOriginalProp.Name, docOriginalProp, docChangeProp));
                                                    }

                                                    // new localization
                                                    this.AddNode(tnProperty, new ChangeInfo(docChangeLocal.Locale, docOriginalLocal, docChangeLocal));
                                                }
                                            }
                                        }
                                        else
                                        {
                                            if (tnPset == null)
                                            {
                                                tnPset = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalPset.Name, docOriginalPset, docChangePset));
                                            }

                                            // NEW:
                                            this.AddNode(tnPset, new ChangeInfo(docChangeSchema.Name + "." + docChangePset.Name + "." + docChangeProp.Name, null, docChangeProp));
                                        }
                                    }
                                }
                                else
                                {
                                    // NEW:
                                    this.AddNode(tnSchema, new ChangeInfo(docChangeSchema.Name + "." + docChangePset.Name, null, docChangePset));
                                }
                            }

                            foreach (DocQuantitySet docChangePset in docChangeSchema.QuantitySets)
                            {
                                DocObject docOriginalPset = null;
                                if (mapOriginal.TryGetValue(docChangePset.Uuid, out docOriginalPset))
                                {
                                    TreeNode tnQset = null;
                                    if (!String.Equals(docOriginalPset.Documentation, docChangePset.Documentation))
                                    {
                                        tnQset = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalPset.Name, docOriginalPset, docChangePset));
                                    }

                                    foreach (DocQuantity docChangeProp in docChangePset.Quantities)
                                    {
                                        DocObject docOriginalProp = ((DocQuantitySet)docOriginalPset).GetQuantity(docChangeProp.Name);
                                        if (docOriginalProp != null)
                                        {
                                            if (!String.Equals(docOriginalProp.Documentation, docChangeProp.Documentation))
                                            {
                                                if (tnQset == null)
                                                {
                                                    tnQset = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalPset.Name, docOriginalPset, docChangePset));
                                                }
                                                this.AddNode(tnQset, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalPset.Name + "." + docOriginalProp.Name, docOriginalProp, docChangeProp));
                                            }
                                        }
                                        else
                                        {
                                            if (tnQset == null)
                                            {
                                                tnQset = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalPset.Name, docOriginalPset, docChangePset));
                                            }

                                            // NEW:
                                            this.AddNode(tnQset, new ChangeInfo(docChangeSchema.Name + "." + docChangePset.Name + "." + docChangeProp.Name, null, docChangeProp));
                                        }
                                    }
                                }
                                else
                                {
                                    // NEW:
                                    this.AddNode(tnSchema, new ChangeInfo(docChangeSchema.Name + "." + docChangePset.Name, null, docChangePset));
                                }
                            }
                        }
                    }
                }
            }

            if (this.treeView.Nodes.Count > 0)
            {
                this.treeView.SelectedNode = this.treeView.Nodes[0];
            }
        }
Beispiel #3
0
        /// <summary>
        /// Loads all content from a folder hierarchy (overlaying anything already existing)
        /// </summary>
        /// <param name="project"></param>
        /// <param name="path"></param>
        public static void LoadFolder(DocProject project, string path)
        {
            // get all files within folder hierarchy
            string pathSchema         = path + @"\schemas";
            IEnumerable <string> en   = System.IO.Directory.EnumerateFiles(pathSchema, "*.cs", System.IO.SearchOption.AllDirectories);
            List <string>        list = new List <string>();

            foreach (string s in en)
            {
                list.Add(s);
            }
            string[] files = list.ToArray();

            Dictionary <string, string> options = new Dictionary <string, string> {
                { "CompilerVersion", "v4.0" }
            };

            Microsoft.CSharp.CSharpCodeProvider        prov  = new Microsoft.CSharp.CSharpCodeProvider(options);
            System.CodeDom.Compiler.CompilerParameters parms = new System.CodeDom.Compiler.CompilerParameters();
            parms.GenerateInMemory   = true;
            parms.GenerateExecutable = false;
            parms.ReferencedAssemblies.Add("System.dll");
            parms.ReferencedAssemblies.Add("System.Core.dll");
            parms.ReferencedAssemblies.Add("System.ComponentModel.dll");
            parms.ReferencedAssemblies.Add("System.ComponentModel.DataAnnotations.dll");
            parms.ReferencedAssemblies.Add("System.Data.dll");
            parms.ReferencedAssemblies.Add("System.Runtime.Serialization.dll");
            parms.ReferencedAssemblies.Add("System.Xml.dll");

            System.CodeDom.Compiler.CompilerResults results = prov.CompileAssemblyFromFile(parms, files);
            System.Reflection.Assembly assem = results.CompiledAssembly;

            LoadAssembly(project, assem);

            // EXPRESS rules (eventually in C#, though .exp file snippets for now)
            en = System.IO.Directory.EnumerateFiles(pathSchema, "*.exp", System.IO.SearchOption.AllDirectories);
            foreach (string file in en)
            {
                string name = Path.GetFileNameWithoutExtension(file);
                string expr = null;
                using (StreamReader readExpr = new StreamReader(file, Encoding.UTF8))
                {
                    if (name.Contains('-'))
                    {
                        // where rule
                        expr = readExpr.ReadToEnd();
                    }
                    else
                    {
                        // function: skip first and last lines
                        readExpr.ReadLine();

                        StringBuilder sbExpr = new StringBuilder();
                        while (!readExpr.EndOfStream)
                        {
                            string line = readExpr.ReadLine();
                            if (!readExpr.EndOfStream)
                            {
                                sbExpr.AppendLine(line);
                            }
                        }

                        expr = sbExpr.ToString();
                    }
                }

                if (name.Contains('-'))
                {
                    // where rule
                    string[] parts = name.Split('-');
                    if (parts.Length == 2)
                    {
                        DocWhereRule docWhere = new DocWhereRule();
                        docWhere.Name       = parts[1];
                        docWhere.Expression = expr;

                        DocDefinition docDef = project.GetDefinition(parts[0]);
                        if (docDef is DocEntity)
                        {
                            DocEntity docEnt = (DocEntity)docDef;
                            docEnt.WhereRules.Add(docWhere);
                        }
                        else if (docDef is DocDefined)
                        {
                            DocDefined docEnt = (DocDefined)docDef;
                            docEnt.WhereRules.Add(docWhere);
                        }
                        else if (docDef == null)
                        {
                            //... global rule...
                        }
                    }
                }
                else
                {
                    // function
                    string schema = Path.GetDirectoryName(file);
                    schema = Path.GetDirectoryName(schema);
                    schema = Path.GetFileName(schema);
                    DocSchema docSchema = project.GetSchema(schema);
                    if (docSchema != null)
                    {
                        DocFunction docFunction = new DocFunction();
                        docSchema.Functions.Add(docFunction);
                        docFunction.Name       = name;
                        docFunction.Expression = expr;
                    }
                }
            }

            // now, hook up html documentation
            en = System.IO.Directory.EnumerateFiles(pathSchema, "*.htm", System.IO.SearchOption.AllDirectories);
            foreach (string file in en)
            {
                string    name   = Path.GetFileNameWithoutExtension(file);
                DocObject docObj = null;
                if (name == "schema")
                {
                    string schema = Path.GetDirectoryName(file);
                    schema = Path.GetFileName(schema);
                    docObj = project.GetSchema(schema);
                }
                else if (name.Contains('-'))
                {
                    // where rule
                    string[] parts = name.Split('-');
                    if (parts.Length == 2)
                    {
                        DocDefinition docDef = project.GetDefinition(parts[0]);
                        if (docDef is DocEntity)
                        {
                            DocEntity docEnt = (DocEntity)docDef;
                            foreach (DocWhereRule docWhereRule in docEnt.WhereRules)
                            {
                                if (docWhereRule.Name.Equals(parts[1]))
                                {
                                    docObj = docWhereRule;
                                    break;
                                }
                            }
                        }
                        else if (docDef is DocDefined)
                        {
                            DocDefined docEnt = (DocDefined)docDef;
                            foreach (DocWhereRule docWhereRule in docEnt.WhereRules)
                            {
                                if (docWhereRule.Name.Equals(parts[1]))
                                {
                                    docObj = docWhereRule;
                                    break;
                                }
                            }
                        }
                    }
                }
                else
                {
                    docObj = project.GetDefinition(name);

                    if (docObj == null)
                    {
                        docObj = project.GetFunction(name);
                    }
                }

                if (docObj != null)
                {
                    using (StreamReader readHtml = new StreamReader(file, Encoding.UTF8))
                    {
                        docObj.Documentation = readHtml.ReadToEnd();
                    }
                }
            }

            // load schema diagrams
            en = System.IO.Directory.EnumerateFiles(pathSchema, "*.svg", System.IO.SearchOption.AllDirectories);
            foreach (string file in en)
            {
                string schema = Path.GetDirectoryName(file);
                schema = Path.GetFileName(schema);

                DocSchema docSchema = project.GetSchema(schema);
                if (docSchema != null)
                {
                    using (IfcDoc.Schema.SVG.SchemaSVG schemaSVG = new IfcDoc.Schema.SVG.SchemaSVG(file, docSchema, project, DiagramFormat.UML))
                    {
                        schemaSVG.Load();
                    }
                }
            }

            // psets, qsets
            //...

            // exchanges
            en = System.IO.Directory.EnumerateFiles(path, "*.mvdxml", System.IO.SearchOption.AllDirectories);
            foreach (string file in en)
            {
                IfcDoc.Schema.MVD.SchemaMVD.Load(project, file);
            }

            // examples
            string pathExamples = path + @"\examples";

            if (Directory.Exists(pathExamples))
            {
                en = System.IO.Directory.EnumerateFiles(pathExamples, "*.htm", SearchOption.TopDirectoryOnly);
                foreach (string file in en)
                {
                    DocExample docExample = new DocExample();
                    docExample.Name = Path.GetFileNameWithoutExtension(file);
                    project.Examples.Add(docExample);

                    using (StreamReader reader = new StreamReader(file))
                    {
                        docExample.Documentation = reader.ReadToEnd();
                    }

                    string dirpath = file.Substring(0, file.Length - 4);
                    if (Directory.Exists(dirpath))
                    {
                        IEnumerable <string> suben = System.IO.Directory.EnumerateFiles(dirpath, "*.ifc", SearchOption.TopDirectoryOnly);
                        foreach (string ex in suben)
                        {
                            DocExample docEx = new DocExample();
                            docEx.Name = Path.GetFileNameWithoutExtension(ex);
                            docExample.Examples.Add(docEx);

                            // read the content of the file
                            using (FileStream fs = new FileStream(ex, FileMode.Open, FileAccess.Read))
                            {
                                docEx.File = new byte[fs.Length];
                                fs.Read(docEx.File, 0, docEx.File.Length);
                            }

                            // read documentation
                            string exdoc = ex.Substring(0, ex.Length - 4) + ".htm";
                            if (File.Exists(exdoc))
                            {
                                using (StreamReader reader = new StreamReader(exdoc))
                                {
                                    docEx.Documentation = reader.ReadToEnd();
                                }
                            }
                        }
                    }
                }
            }

            // localization
            en = System.IO.Directory.EnumerateFiles(path, "*.txt", System.IO.SearchOption.AllDirectories);
            foreach (string file in en)
            {
                using (FormatCSV format = new FormatCSV(file))
                {
                    try
                    {
                        format.Instance = project;
                        format.Load();
                    }
                    catch
                    {
                    }
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// Creates a documentation schema from a VEX schema
        /// </summary>
        /// <param name="schemata">The VEX schema to import</param>
        /// <param name="project">The documentation project where the imported schema is to be created</param>
        /// <returns>The imported documentation schema</returns>
        internal static DocSchema ImportVex(SCHEMATA schemata, DocProject docProject, bool updateDescriptions)
        {
            DocSchema docSchema = docProject.RegisterSchema(schemata.name);
            if (updateDescriptions && schemata.comment != null && schemata.comment.text != null)
            {
                docSchema.Documentation = schemata.comment.text.text;
            }
            docSchema.DiagramPagesHorz = schemata.settings.page.nhorizontalpages;
            docSchema.DiagramPagesVert = schemata.settings.page.nverticalpages;

            // remember current types for deletion if they no longer exist
            List<DocObject> existing = new List<DocObject>();
            foreach (DocType doctype in docSchema.Types)
            {
                existing.Add(doctype);
            }
            foreach (DocEntity docentity in docSchema.Entities)
            {
                existing.Add(docentity);
            }
            foreach (DocFunction docfunction in docSchema.Functions)
            {
                existing.Add(docfunction);
            }
            foreach (DocGlobalRule docrule in docSchema.GlobalRules)
            {
                existing.Add(docrule);
            }

            docSchema.PageTargets.Clear();
            docSchema.SchemaRefs.Clear();
            docSchema.Comments.Clear();

            // remember references for fixing up attributes afterwords
            Dictionary<object, DocDefinition> mapRefs = new Dictionary<object, DocDefinition>();
            Dictionary<ATTRIBUTE_DEF, DocAttribute> mapAtts = new Dictionary<ATTRIBUTE_DEF, DocAttribute>();
            //Dictionary<SELECT_DEF, DocSelectItem> mapSels = new Dictionary<SELECT_DEF, DocSelectItem>();
            Dictionary<SELECT_DEF, DocLine> mapSL = new Dictionary<SELECT_DEF, DocLine>();
            Dictionary<SUBTYPE_DEF, DocLine> mapSubs = new Dictionary<SUBTYPE_DEF, DocLine>();
            Dictionary<PAGE_REF, DocPageTarget> mapPage = new Dictionary<PAGE_REF, DocPageTarget>();

            // entities and types
            foreach (object obj in schemata.objects)
            {
                if (obj is ENTITIES)
                {
                    ENTITIES ent = (ENTITIES)obj; // filter out orphaned entities having upper flags set
                    if ((ent.flag & 0xFFFF0000) == 0 && (ent.interfaceto == null || ent.interfaceto.theschema == null))
                    {
                        // create if doesn't exist
                        string name = ent.name.text;

                        string super = null;
                        if (ent.supertypes.Count > 0 && ent.supertypes[0].the_supertype is ENTITIES)
                        {
                            ENTITIES superent = (ENTITIES)ent.supertypes[0].the_supertype;
                            super = superent.name.text;
                        }

                        DocEntity docEntity = docSchema.RegisterEntity(name);
                        if (existing.Contains(docEntity))
                        {
                            existing.Remove(docEntity);
                        }
                        mapRefs.Add(obj, docEntity);

                        // clear out existing if merging
                        docEntity.BaseDefinition = null;

                        foreach(DocSubtype docSub in docEntity.Subtypes)
                        {
                            docSub.Delete();
                        }
                        docEntity.Subtypes.Clear();

                        foreach(DocUniqueRule docUniq in docEntity.UniqueRules)
                        {
                            docUniq.Delete();
                        }
                        docEntity.UniqueRules.Clear();

                        foreach(DocLine docLine in docEntity.Tree)
                        {
                            docLine.Delete();
                        }
                        docEntity.Tree.Clear();

                        if (updateDescriptions && ent.comment != null && ent.comment.text != null)
                        {
                            docEntity.Documentation = ent.comment.text.text;
                        }
                        if (ent.supertypes.Count > 0 && ent.supertypes[0].the_supertype is ENTITIES)
                        {
                            docEntity.BaseDefinition = ((ENTITIES)ent.supertypes[0].the_supertype).name.text;
                        }

                        docEntity.EntityFlags = ent.flag;
                        if (ent.subtypes != null)
                        {
                            foreach (SUBTYPE_DEF sd in ent.subtypes)
                            {
                                // new (3.8): intermediate subtypes for diagrams
                                DocLine docLine = new DocLine();
                                ImportVexLine(sd.layout, null, docLine.DiagramLine, null);
                                docEntity.Tree.Add(docLine);

                                OBJECT od = (OBJECT)sd.the_subtype;

                                // tunnel through page ref
                                if (od is PAGE_REF_TO)
                                {
                                    od = ((PAGE_REF_TO)od).pageref;
                                }

                                if (od is TREE)
                                {
                                    TREE tree = (TREE)od;
                                    foreach (OBJECT o in tree.list)
                                    {
                                        OBJECT os = o;
                                        OBJECT_LINE_LAYOUT linelayout = null;

                                        if (o is SUBTYPE_DEF)
                                        {
                                            SUBTYPE_DEF osd = (SUBTYPE_DEF)o;
                                            linelayout = osd.layout;

                                            os = ((SUBTYPE_DEF)o).the_subtype;
                                        }

                                        if (os is PAGE_REF_TO)
                                        {
                                            os = ((PAGE_REF_TO)os).pageref;
                                        }

                                        if (os is ENTITIES)
                                        {
                                            DocSubtype docSub = new DocSubtype();
                                            docSub.DefinedType = ((ENTITIES)os).name.text;
                                            docEntity.Subtypes.Add(docSub);

                                            DocLine docSubline = new DocLine();
                                            docLine.Tree.Add(docSubline);

                                            if (o is SUBTYPE_DEF)
                                            {
                                                mapSubs.Add((SUBTYPE_DEF)o, docSubline);
                                            }

                                            ImportVexLine(linelayout, null, docSubline.DiagramLine, null);
                                        }
                                        else
                                        {
                                            Debug.Assert(false);
                                        }
                                    }
                                }
                                else if (od is ENTITIES)
                                {
                                    DocSubtype docInt = new DocSubtype();
                                    docEntity.Subtypes.Add(docInt);

                                    docInt.DefinedType = ((ENTITIES)od).name.text;
                                }
                                else
                                {
                                    Debug.Assert(false);
                                }
                            }
                        }

                        // determine EXPRESS-G page based on placement (required for generating hyperlinks)
                        if (ent.layout != null)
                        {
                            ImportVexRectangle(docEntity, ent.layout.rectangle, schemata);
                        }

                        if (ent.attributes != null)
                        {
                            List<DocAttribute> existingattr = new List<DocAttribute>();
                            foreach (DocAttribute docAttr in docEntity.Attributes)
                            {
                                existingattr.Add(docAttr);
                            }

                            // attributes are replaced, not merged (template don't apply here)
                            foreach (ATTRIBUTE_DEF attr in ent.attributes)
                            {
                                if (attr.name != null)
                                {
                                    DocAttribute docAttr = docEntity.RegisterAttribute(attr.name.text);
                                    mapAtts.Add(attr, docAttr);

                                    if (existingattr.Contains(docAttr))
                                    {
                                        existingattr.Remove(docAttr);
                                    }

                                    if (updateDescriptions && attr.comment != null && attr.comment.text != null)
                                    {
                                        docAttr.Documentation = attr.comment.text.text;
                                    }

                                    if (docAttr.DiagramLabel != null)
                                    {
                                        docAttr.DiagramLabel.Delete();
                                        docAttr.DiagramLabel = null;
                                    }

                                    foreach(DocPoint docPoint in docAttr.DiagramLine)
                                    {
                                        docPoint.Delete();
                                    }
                                    docAttr.DiagramLine.Clear();

                                    if (attr.layout != null)
                                    {
                                        if (attr.layout.pline != null)
                                        {
                                            // intermediate lines
                                            if (attr.layout.pline.rpoint != null)
                                            {
                                                docAttr.DiagramLabel = new DocRectangle();
                                                ImportVexLine(attr.layout, attr.name.layout, docAttr.DiagramLine, docAttr.DiagramLabel);
                                            }
                                        }
                                    }

                                    OBJECT def = attr.the_attribute;
                                    if (attr.the_attribute is PAGE_REF_TO)
                                    {
                                        PAGE_REF_TO pr = (PAGE_REF_TO)attr.the_attribute;
                                        def = pr.pageref;
                                    }

                                    if (def is DEFINED_TYPE)
                                    {
                                        DEFINED_TYPE dt = (DEFINED_TYPE)def;
                                        docAttr.DefinedType = dt.name.text;
                                    }
                                    else if (def is ENTITIES)
                                    {
                                        ENTITIES en = (ENTITIES)def;
                                        docAttr.DefinedType = en.name.text;
                                    }
                                    else if (def is ENUMERATIONS)
                                    {
                                        ENUMERATIONS en = (ENUMERATIONS)def;
                                        docAttr.DefinedType = en.name.text;
                                    }
                                    else if (def is SELECTS)
                                    {
                                        SELECTS en = (SELECTS)def;
                                        docAttr.DefinedType = en.name.text;
                                    }
                                    else if (def is PRIMITIVE_TYPE)
                                    {
                                        PRIMITIVE_TYPE en = (PRIMITIVE_TYPE)def;

                                        string length = "";
                                        if (en.constraints > 0)
                                        {
                                            length = " (" + en.constraints.ToString() + ")";
                                        }
                                        else if (en.constraints < 0)
                                        {
                                            int len = -en.constraints;
                                            length = " (" + len.ToString() + ") FIXED";
                                        }

                                        docAttr.DefinedType = en.name.text + length;
                                    }
                                    else if (def is SCHEMA_REF)
                                    {
                                        SCHEMA_REF en = (SCHEMA_REF)def;
                                        docAttr.DefinedType = en.name.text;
                                    }
                                    else
                                    {
                                        Debug.Assert(false);
                                    }

                                    docAttr.AttributeFlags = attr.attributeflag;

                                    AGGREGATES vexAggregates = attr.aggregates;
                                    DocAttribute docAggregate = docAttr;
                                    while (vexAggregates != null)
                                    {
                                        // traverse nested aggregation (e.g. IfcStructuralLoadConfiguration)
                                        docAggregate.AggregationType = vexAggregates.aggrtype + 1;
                                        docAggregate.AggregationLower = vexAggregates.lower;
                                        docAggregate.AggregationUpper = vexAggregates.upper;
                                        docAggregate.AggregationFlag = vexAggregates.flag;

                                        vexAggregates = vexAggregates.next;
                                        if (vexAggregates != null)
                                        {
                                            // inner array (e.g. IfcStructuralLoadConfiguration)
                                            docAggregate.AggregationAttribute = new DocAttribute();
                                            docAggregate = docAggregate.AggregationAttribute;
                                        }
                                    }

                                    docAttr.Derived = attr.is_derived;

                                    if (attr.user_redeclaration != null)
                                    {
                                        docAttr.Inverse = attr.user_redeclaration;
                                    }
                                    else if (attr.is_inverse is ATTRIBUTE_DEF)
                                    {
                                        ATTRIBUTE_DEF adef = (ATTRIBUTE_DEF)attr.is_inverse;
                                        docAttr.Inverse = adef.name.text;
                                    }
                                    else if (attr.is_inverse != null)
                                    {
                                        Debug.Assert(false);
                                    }
                                }
                            }

                            foreach(DocAttribute docAttr in existingattr)
                            {
                                docEntity.Attributes.Remove(docAttr);
                                docAttr.Delete();
                            }
                        }

                        // unique rules
                        if (ent.uniquenes != null)
                        {
                            // rules are replaced, not merged (template don't apply here)
                            //docEntity.UniqueRules = new List<DocUniqueRule>();
                            foreach (UNIQUE_RULE rule in ent.uniquenes)
                            {
                                DocUniqueRule docRule = new DocUniqueRule();
                                docEntity.UniqueRules.Add(docRule);
                                docRule.Name = rule.name;

                                docRule.Items = new List<DocUniqueRuleItem>();
                                foreach (ATTRIBUTE_DEF ruleitem in rule.for_attribute)
                                {
                                    DocUniqueRuleItem item = new DocUniqueRuleItem();
                                    item.Name = ruleitem.name.text;
                                    docRule.Items.Add(item);
                                }
                            }
                        }

                        // where rules
                        if (ent.wheres != null)
                        {
                            List<DocWhereRule> existingattr = new List<DocWhereRule>();
                            foreach (DocWhereRule docWhere in docEntity.WhereRules)
                            {
                                existingattr.Add(docWhere);
                            }

                            foreach (WHERE_RULE where in ent.wheres)
                            {
                                DocWhereRule docWhere = docEntity.RegisterWhereRule(where.name);
                                docWhere.Expression = where.rule_context;

                                if(existingattr.Contains(docWhere))
                                {
                                    existingattr.Remove(docWhere);
                                }

                                if (updateDescriptions && where.comment != null && where.comment.text != null)
                                {
                                    docWhere.Documentation = where.comment.text.text;
                                }
                            }

                            foreach(DocWhereRule exist in existingattr)
                            {
                                exist.Delete();
                                docEntity.WhereRules.Remove(exist);
                            }
                        }
                    }
                }
                else if (obj is ENUMERATIONS)
                {
                    ENUMERATIONS ent = (ENUMERATIONS)obj;
                    if (ent.interfaceto == null || ent.interfaceto.theschema == null)
                    {
                        if (schemata.name.Equals("IfcConstructionMgmtDomain", StringComparison.OrdinalIgnoreCase) && ent.name.text.Equals("IfcNullStyle", StringComparison.OrdinalIgnoreCase))
                        {
                            // hack to workaround vex bug
                            Debug.Assert(true);
                        }
                        else
                        {

                            DocEnumeration docEnumeration = docSchema.RegisterType<DocEnumeration>(ent.name.text);
                            if (existing.Contains(docEnumeration))
                            {
                                existing.Remove(docEnumeration);
                            }
                            mapRefs.Add(obj, docEnumeration);

                            if (updateDescriptions && ent.comment != null && ent.comment.text != null)
                            {
                                docEnumeration.Documentation = ent.comment.text.text;
                            }

                            // determine EXPRESS-G page based on placement (required for generating hyperlinks)
                            if (ent.typelayout != null && schemata.settings != null && schemata.settings.page != null)
                            {
                                ImportVexRectangle(docEnumeration, ent.typelayout.rectangle, schemata);
                            }

                            // enumeration values are replaced, not merged (template don't apply here)
                            docEnumeration.Constants.Clear();
                            foreach (string s in ent.enums)
                            {
                                DocConstant docConstant = new DocConstant();
                                docEnumeration.Constants.Add(docConstant);
                                docConstant.Name = s;
                            }
                        }
                    }
                }
                else if (obj is DEFINED_TYPE)
                {
                    DEFINED_TYPE ent = (DEFINED_TYPE)obj;

                    if (ent.interfaceto == null || ent.interfaceto.theschema == null)
                    {
                        DocDefined docDefined = docSchema.RegisterType<DocDefined>(ent.name.text);
                        if (existing.Contains(docDefined))
                        {
                            existing.Remove(docDefined);
                        }

                        mapRefs.Add(obj, docDefined);

                        if (updateDescriptions && ent.comment != null && ent.comment.text != null)
                        {
                            docDefined.Documentation = ent.comment.text.text;
                        }

                        if (ent.layout != null)
                        {
                            ImportVexRectangle(docDefined, ent.layout.rectangle, schemata);
                        }

                        if(ent.defined.object_line_layout != null)
                        {
                            foreach(DocPoint docPoint in docDefined.DiagramLine)
                            {
                                docPoint.Delete();
                            }
                            docDefined.DiagramLine.Clear();
                            ImportVexLine(ent.defined.object_line_layout, null, docDefined.DiagramLine, null);
                        }

                        OBJECT os = (OBJECT)ent.defined.defined;
                        if (os is PAGE_REF_TO)
                        {
                            os = ((PAGE_REF_TO)os).pageref;
                        }

                        if (os is PRIMITIVE_TYPE)
                        {
                            PRIMITIVE_TYPE pt = (PRIMITIVE_TYPE)os;
                            docDefined.DefinedType = pt.name.text;

                            if (pt.constraints != 0)
                            {
                                docDefined.Length = pt.constraints;
                            }
                        }
                        else if (os is DEFINED_TYPE)
                        {
                            DEFINED_TYPE dt = (DEFINED_TYPE)os;
                            docDefined.DefinedType = dt.name.text;
                        }
                        else if (os is ENTITIES)
                        {
                            ENTITIES et = (ENTITIES)os;
                            docDefined.DefinedType = et.name.text;
                        }
                        else
                        {
                            Debug.Assert(false);
                        }

                        // aggregation
                        AGGREGATES vexAggregates = ent.defined.aggregates;
                        if (vexAggregates != null)
                        {
                            DocAttribute docAggregate = new DocAttribute();
                            docDefined.Aggregation = docAggregate;

                            docAggregate.AggregationType = vexAggregates.aggrtype + 1;
                            docAggregate.AggregationLower = vexAggregates.lower;
                            docAggregate.AggregationUpper = vexAggregates.upper;
                            docAggregate.AggregationFlag = vexAggregates.flag;
                        }

                        // where rules
                        if (ent.whererules != null)
                        {
                            // rules are replaced, not merged (template don't apply here)
                            foreach(DocWhereRule docWhere in docDefined.WhereRules)
                            {
                                docWhere.Delete();
                            }
                            docDefined.WhereRules.Clear();
                            foreach (WHERE_RULE where in ent.whererules)
                            {
                                DocWhereRule docWhere = new DocWhereRule();
                                docDefined.WhereRules.Add(docWhere);
                                docWhere.Name = where.name;
                                docWhere.Expression = where.rule_context;

                                if (where.comment != null && where.comment.text != null)
                                {
                                    docWhere.Documentation = where.comment.text.text;
                                }
                            }
                        }

                    }
                }
                else if (obj is SELECTS)
                {
                    SELECTS ent = (SELECTS)obj;
                    if (ent.interfaceto == null || ent.interfaceto.theschema == null)
                    {
                        DocSelect docSelect = docSchema.RegisterType<DocSelect>(ent.name.text);
                        if (existing.Contains(docSelect))
                        {
                            existing.Remove(docSelect);
                        }
                        mapRefs.Add(obj, docSelect);

                        if (updateDescriptions && ent.comment != null && ent.comment.text != null)
                        {
                            docSelect.Documentation = ent.comment.text.text;
                        }

                        // determine EXPRESS-G page based on placement (required for generating hyperlinks)
                        if (ent.typelayout != null)
                        {
                            ImportVexRectangle(docSelect, ent.typelayout.rectangle, schemata);
                        }

                        docSelect.Selects.Clear();
                        docSelect.Tree.Clear();
                        foreach (SELECT_DEF sdef in ent.selects)
                        {
                            DocLine docLine = new DocLine();
                            docSelect.Tree.Add(docLine);
                            ImportVexLine(sdef.layout, null, docLine.DiagramLine, null);

                            mapSL.Add(sdef, docLine);

                            if (sdef.def is TREE)
                            {
                                TREE tree = (TREE)sdef.def;

                                foreach (OBJECT o in tree.list)
                                {
                                    DocSelectItem dsi = new DocSelectItem();
                                    docSelect.Selects.Add(dsi);

                                    OBJECT os = o;
                                    if (o is SELECT_DEF)
                                    {
                                        SELECT_DEF selectdef = (SELECT_DEF)o;

                                        DocLine docLineSub = new DocLine();
                                        docLine.Tree.Add(docLineSub);
                                        ImportVexLine(selectdef.layout, null, docLineSub.DiagramLine, null);

                                        mapSL.Add(selectdef, docLineSub);

                                        os = ((SELECT_DEF)o).def;
                                    }
                                    else
                                    {
                                        Debug.Assert(false);
                                    }

                                    if (os is PAGE_REF_TO)
                                    {
                                        PAGE_REF_TO pr = (PAGE_REF_TO)os;
                                        os = pr.pageref;
                                    }

                                    if (os is DEFINITION)
                                    {
                                        dsi.Name = ((DEFINITION)os).name.text;
                                    }
                                }
                            }
                            else
                            {
                                OBJECT os = (OBJECT)sdef.def;

                                if (os is PAGE_REF_TO)
                                {
                                    PAGE_REF_TO pr = (PAGE_REF_TO)os;
                                    os = pr.pageref;
                                }

                                DocSelectItem dsi = new DocSelectItem();
                                docSelect.Selects.Add(dsi);
                                if (os is DEFINITION)
                                {
                                    dsi.Name = ((DEFINITION)os).name.text;
                                }
                            }
                        }
                    }
                }
                else if (obj is GLOBAL_RULE)
                {
                    GLOBAL_RULE func = (GLOBAL_RULE)obj;

                    DocGlobalRule docFunction = docSchema.RegisterRule(func.name);
                    if (existing.Contains(docFunction))
                    {
                        existing.Remove(docFunction);
                    }

                    // clear out existing if merging
                    docFunction.WhereRules.Clear();

                    if (updateDescriptions && func.comment != null && func.comment.text != null)
                    {
                        docFunction.Documentation = func.comment.text.text;
                    }
                    docFunction.Expression = func.rule_context;

                    foreach (WHERE_RULE wr in func.where_rule)
                    {
                        DocWhereRule docW = new DocWhereRule();
                        docW.Name = wr.name;
                        docW.Expression = wr.rule_context;
                        if (wr.comment != null)
                        {
                            docW.Documentation = wr.comment.text.text;
                        }
                        docFunction.WhereRules.Add(docW);
                    }

                    if (func.for_entities.Count == 1)
                    {
                        docFunction.ApplicableEntity = func.for_entities[0].ToString();
                    }
                }
                else if (obj is USER_FUNCTION)
                {
                    USER_FUNCTION func = (USER_FUNCTION)obj;

                    DocFunction docFunction = docSchema.RegisterFunction(func.name);
                    if (existing.Contains(docFunction))
                    {
                        existing.Remove(docFunction);
                    }

                    if (updateDescriptions && func.comment != null && func.comment.text != null)
                    {
                        docFunction.Documentation = func.comment.text.text;
                    }
                    docFunction.Expression = func.rule_context;

                    // NOTE: While the VEX schema can represent parameters and return values, Visual Express does not implement it!
                    // Rather, parameter info is also included in the 'rule_context'
                    if (func.return_value != null)
                    {
                        docFunction.ReturnValue = func.return_value.ToString();
                    }
                    else
                    {
                        docFunction.ReturnValue = null;
                    }
                    docFunction.Parameters.Clear();
                    if (func.parameter_list != null)
                    {
                        foreach (PARAMETER par in func.parameter_list)
                        {
                            DocParameter docParameter = new DocParameter();
                            docParameter.Name = par.name;
                            docParameter.DefinedType = par.parameter_type.ToString();
                            docFunction.Parameters.Add(docParameter);
                        }
                    }
                }
                else if (obj is PRIMITIVE_TYPE)
                {
                    PRIMITIVE_TYPE prim = (PRIMITIVE_TYPE)obj;

                    DocPrimitive docPrimitive = new DocPrimitive();
                    docPrimitive.Name = prim.name.text;
                    if (prim.layout != null)
                    {
                        ImportVexRectangle(docPrimitive, prim.layout.rectangle, schemata);
                    }

                    docSchema.Primitives.Add(docPrimitive);
                    mapRefs.Add(obj, docPrimitive);
                }
                else if (obj is COMMENT)
                {
                    COMMENT comment = (COMMENT)obj;

                    // only deal with comments that are part of EXPRESS-G layout -- ignore those referenced by definitions and old cruft left behind due to older versions of VisualE that were buggy
                    if (comment.layout != null)
                    {
                        DocComment docComment = new DocComment();
                        docComment.Documentation = comment.text.text;
                        ImportVexRectangle(docComment, comment.layout.rectangle, schemata);

                        docSchema.Comments.Add(docComment);
                    }
                }
                else if (obj is INTERFACE_SCHEMA)
                {
                    INTERFACE_SCHEMA iface = (INTERFACE_SCHEMA)obj;

                    DocSchemaRef docSchemaRef = new DocSchemaRef();
                    docSchema.SchemaRefs.Add(docSchemaRef);

                    docSchemaRef.Name = iface.schema_name;

                    foreach (object o in iface.item)
                    {
                        if (o is DEFINITION)
                        {
                            DocDefinitionRef docDefRef = new DocDefinitionRef();
                            docSchemaRef.Definitions.Add(docDefRef);
                            mapRefs.Add(o, docDefRef);

                            docDefRef.Name = ((DEFINITION)o).name.text;

                            if (o is DEFINED_TYPE)
                            {
                                DEFINED_TYPE dt = (DEFINED_TYPE)o;
                                if (dt.layout != null)
                                {
                                    ImportVexRectangle(docDefRef, dt.layout.rectangle, schemata);
                                }
                            }
                            else if (o is ENTITIES)
                            {
                                ENTITIES ents = (ENTITIES)o;
                                if (ents.layout != null) // null for IfcPolyline reference in IfcGeometricModelResource
                                {
                                    ImportVexRectangle(docDefRef, ents.layout.rectangle, schemata);
                                }

                                if (ents.subtypes != null)
                                {
                                    foreach (SUBTYPE_DEF subdef in ents.subtypes)
                                    {
                                        OBJECT_LINE_LAYOUT linelayout = subdef.layout;

                                        DocLine docSub = new DocLine();
                                        ImportVexLine(subdef.layout, null, docSub.DiagramLine, null);
                                        docDefRef.Tree.Add(docSub);

                                        if(subdef.the_subtype is TREE)
                                        {
                                            TREE tree = (TREE)subdef.the_subtype;
                                            foreach(object oo in tree.list)
                                            {
                                                if(oo is SUBTYPE_DEF)
                                                {
                                                    SUBTYPE_DEF subsubdef = (SUBTYPE_DEF)oo;
                                                    DocLine docSubSub = new DocLine();
                                                    docSub.Tree.Add(docSubSub);

                                                    ImportVexLine(subsubdef.layout, null, docSubSub.DiagramLine, null);

                                                    mapSubs.Add(subsubdef, docSubSub);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            else if (o is ENUMERATIONS)
                            {
                                ENUMERATIONS enums = (ENUMERATIONS)o;
                                if (enums.typelayout != null)
                                {
                                    ImportVexRectangle(docDefRef, enums.typelayout.rectangle, schemata);
                                }
                            }
                            else if (o is SELECTS)
                            {
                                SELECTS sels = (SELECTS)o;
                                if (sels.typelayout != null)
                                {
                                    ImportVexRectangle(docDefRef, sels.typelayout.rectangle, schemata);
                                }
                            }
                            else if(o is SCHEMA_REF)
                            {
                                SCHEMA_REF sref = (SCHEMA_REF)o;
                                if(sref.layout != null)
                                {
                                    ImportVexRectangle(docDefRef, sref.layout.rectangle, schemata);
                                }
                            }
                        }
                        else if (o is USER_FUNCTION)
                        {
                            DocDefinitionRef docDefRef = new DocDefinitionRef();
                            docSchemaRef.Definitions.Add(docDefRef);

                            USER_FUNCTION uf = (USER_FUNCTION)o;
                            docDefRef.Name = uf.name;
                        }
                    }
                }
                else if (obj is PAGE_REF)
                {
                    PAGE_REF pageref = (PAGE_REF)obj;

                    DocPageTarget docPageTarget = new DocPageTarget();
                    docSchema.PageTargets.Add(docPageTarget);
                    docPageTarget.Name = pageref.text.text;
                    docPageTarget.DiagramNumber = pageref.pagenr;
                    ImportVexLine(pageref.pageline.layout, null, docPageTarget.DiagramLine, null);
                    ImportVexRectangle(docPageTarget, pageref.layout.rectangle, schemata);

                    foreach (PAGE_REF_TO pagerefto in pageref.pagerefto)
                    {
                        DocPageSource docPageSource = new DocPageSource();
                        docPageTarget.Sources.Add(docPageSource);

                        docPageSource.DiagramNumber = pagerefto.pagenr;
                        docPageSource.Name = pagerefto.text.text;
                        ImportVexRectangle(docPageSource, pagerefto.layout.rectangle, schemata);

                        mapRefs.Add(pagerefto, docPageSource);
                    }

                    mapPage.Add(pageref, docPageTarget);
                }
            }

            foreach (DocObject docobj in existing)
            {
                if (docobj is DocEntity)
                {
                    docSchema.Entities.Remove((DocEntity)docobj);
                }
                else if (docobj is DocType)
                {
                    docSchema.Types.Remove((DocType)docobj);
                }
                else if (docobj is DocFunction)
                {
                    docSchema.Functions.Remove((DocFunction)docobj);
                }
                else if (docobj is DocGlobalRule)
                {
                    docSchema.GlobalRules.Remove((DocGlobalRule)docobj);
                }

                docobj.Delete();
            }

            // now fix up attributes
            foreach (ATTRIBUTE_DEF docAtt in mapAtts.Keys)
            {
                DocAttribute docAttr = mapAtts[docAtt];
                docAttr.Definition = mapRefs[docAtt.the_attribute];
            }

            foreach (PAGE_REF page in mapPage.Keys)
            {
                DocPageTarget docPage = mapPage[page];
                docPage.Definition = mapRefs[page.pageline.pageref];
            }

            foreach (SELECT_DEF sd in mapSL.Keys)
            {
                DocLine docLine = mapSL[sd];
                if (mapRefs.ContainsKey(sd.def))
                {
                    docLine.Definition = mapRefs[sd.def];
                }
            }

            foreach (SUBTYPE_DEF sd in mapSubs.Keys)
            {
                DocLine docLine = mapSubs[sd];
                if (mapRefs.ContainsKey(sd.the_subtype))
                {
                    docLine.Definition = mapRefs[sd.the_subtype];
                }
            }

            foreach(object o in mapRefs.Keys)
            {
                if (o is DEFINED_TYPE)
                {
                    DEFINED_TYPE def = (DEFINED_TYPE)o;
                    if (def.interfaceto == null || def.interfaceto.theschema == null)
                    {
                        // declared within
                        DocDefined docDef = (DocDefined)mapRefs[o];
                        docDef.Definition = mapRefs[def.defined.defined];
                    }
                }
            }

            return docSchema;
        }
Beispiel #5
0
        private void toolStripMenuItemInsertWhere_Click(object sender, EventArgs e)
        {
            DocWhereRule docAttr = new DocWhereRule();

            int offset = -1;
            TreeNode tnParent = this.treeView.SelectedNode;
            if (tnParent.Tag is DocEntity)
            {
                DocEntity docEntity = (DocEntity)tnParent.Tag;
                docEntity.WhereRules.Add(docAttr);

                offset = docEntity.Attributes.Count + docEntity.WhereRules.Count - 1;
            }
            else if(tnParent.Tag is DocDefined)
            {
                DocDefined docDefined = (DocDefined)tnParent.Tag;
                docDefined.WhereRules.Add(docAttr);
            }

            this.treeView.SelectedNode = this.LoadNode(tnParent, docAttr, docAttr.ToString(), false, offset);
            toolStripMenuItemEditRename_Click(this, e);
        }
Beispiel #6
0
        /// <summary>
        /// Loads all content from a folder hierarchy (overlaying anything already existing)
        /// </summary>
        /// <param name="project"></param>
        /// <param name="path"></param>
        public static void Load(DocProject project, string path)
        {
            // get all files within folder hierarchy
            string pathSchema         = path + @"\schemas";
            IEnumerable <string> en   = System.IO.Directory.EnumerateFiles(pathSchema, "*.cs", System.IO.SearchOption.AllDirectories);
            List <string>        list = new List <string>();

            foreach (string s in en)
            {
                list.Add(s);
            }
            string[] files = list.ToArray();

            Dictionary <string, string> options = new Dictionary <string, string> {
                { "CompilerVersion", "v4.0" }
            };

            Microsoft.CSharp.CSharpCodeProvider        prov  = new Microsoft.CSharp.CSharpCodeProvider(options);
            System.CodeDom.Compiler.CompilerParameters parms = new System.CodeDom.Compiler.CompilerParameters();
            parms.GenerateInMemory   = true;
            parms.GenerateExecutable = false;
            parms.ReferencedAssemblies.Add("System.dll");
            parms.ReferencedAssemblies.Add("System.Core.dll");
            parms.ReferencedAssemblies.Add("System.ComponentModel.dll");
            parms.ReferencedAssemblies.Add("System.ComponentModel.DataAnnotations.dll");
            parms.ReferencedAssemblies.Add("System.Data.dll");
            parms.ReferencedAssemblies.Add("System.Runtime.Serialization.dll");
            parms.ReferencedAssemblies.Add("System.Xml.dll");

            System.CodeDom.Compiler.CompilerResults results = prov.CompileAssemblyFromFile(parms, files);
            System.Reflection.Assembly assem = results.CompiledAssembly;

            // look through classes of assembly
            foreach (Type t in assem.GetTypes())
            {
                string[]   namespaceparts = t.Namespace.Split('.');
                string     schema         = namespaceparts[namespaceparts.Length - 1];
                DocSection docSection     = null;
                if (t.Namespace.EndsWith("Resource"))
                {
                    docSection = project.Sections[7];
                }
                else if (t.Namespace.EndsWith("Domain"))
                {
                    docSection = project.Sections[6];
                }
                else if (t.Namespace.Contains("Shared"))
                {
                    docSection = project.Sections[5];
                }
                else
                {
                    docSection = project.Sections[4]; // kernel, extensions
                }

                // find schema
                DocSchema docSchema = null;
                foreach (DocSchema docEachSchema in docSection.Schemas)
                {
                    if (docEachSchema.Name.Equals(schema))
                    {
                        docSchema = docEachSchema;
                        break;
                    }
                }

                if (docSchema == null)
                {
                    docSchema      = new DocSchema();
                    docSchema.Name = schema;
                    docSection.Schemas.Add(docSchema);
                    docSection.SortSchemas();
                }

                DocDefinition docDef = null;
                if (t.IsEnum)
                {
                    DocEnumeration docEnum = new DocEnumeration();
                    docSchema.Types.Add(docEnum);
                    docDef = docEnum;

                    System.Reflection.FieldInfo[] fields = t.GetFields(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
                    foreach (System.Reflection.FieldInfo field in fields)
                    {
                        DocConstant docConst = new DocConstant();
                        docEnum.Constants.Add(docConst);
                        docConst.Name = field.Name;

                        DescriptionAttribute[] attrs = (DescriptionAttribute[])field.GetCustomAttributes(typeof(DescriptionAttribute), false);
                        if (attrs.Length == 1)
                        {
                            docConst.Documentation = attrs[0].Description;
                        }
                    }
                }
                else if (t.IsValueType)
                {
                    DocDefined docDefined = new DocDefined();
                    docSchema.Types.Add(docDefined);
                    docDef = docDefined;

                    PropertyInfo[] fields = t.GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);
                    docDefined.DefinedType = fields[0].PropertyType.Name;
                }
                else if (t.IsInterface)
                {
                    DocSelect docSelect = new DocSelect();
                    docSchema.Types.Add(docSelect);
                    docDef = docSelect;
                }
                else if (t.IsClass)
                {
                    DocEntity docEntity = new DocEntity();
                    docSchema.Entities.Add(docEntity);
                    docDef = docEntity;

                    if (t.BaseType != typeof(object))
                    {
                        docEntity.BaseDefinition = t.BaseType.Name;
                    }

                    if (!t.IsAbstract)
                    {
                        docEntity.EntityFlags = 0x20;
                    }

                    Dictionary <int, DocAttribute> attrsDirect  = new Dictionary <int, DocAttribute>();
                    List <DocAttribute>            attrsInverse = new List <DocAttribute>();
                    PropertyInfo[] fields = t.GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | BindingFlags.DeclaredOnly);
                    foreach (PropertyInfo field in fields)
                    {
                        DocAttribute docAttr = new DocAttribute();
                        docAttr.Name = field.Name.Substring(1);

                        Type typeField = field.PropertyType;
                        if (typeField.IsGenericType)
                        {
                            Type typeGeneric = typeField.GetGenericTypeDefinition();
                            typeField = typeField.GetGenericArguments()[0];
                            if (typeGeneric == typeof(Nullable <>))
                            {
                                docAttr.IsOptional = true;
                            }
                            else if (typeGeneric == typeof(ISet <>))
                            {
                                docAttr.AggregationType = (int)DocAggregationEnum.SET;
                            }
                            else if (typeGeneric == typeof(IList <>))
                            {
                                docAttr.AggregationType = (int)DocAggregationEnum.LIST;
                            }
                        }

                        docAttr.DefinedType = typeField.Name;


                        MinLengthAttribute mla = (MinLengthAttribute)field.GetCustomAttribute(typeof(MinLengthAttribute));
                        if (mla != null)
                        {
                            docAttr.AggregationLower = mla.Length.ToString();
                        }

                        MaxLengthAttribute mxa = (MaxLengthAttribute)field.GetCustomAttribute(typeof(MaxLengthAttribute));
                        if (mxa != null)
                        {
                            docAttr.AggregationUpper = mxa.Length.ToString();
                        }

                        PropertyInfo propinfo = t.GetProperty(docAttr.Name);
                        if (propinfo != null)
                        {
                            DescriptionAttribute da = (DescriptionAttribute)propinfo.GetCustomAttribute(typeof(DescriptionAttribute));
                            if (da != null)
                            {
                                docAttr.Documentation = da.Description;
                            }
                        }

                        DataMemberAttribute dma = (DataMemberAttribute)field.GetCustomAttribute(typeof(DataMemberAttribute));
                        if (dma != null)
                        {
                            attrsDirect.Add(dma.Order, docAttr);

                            RequiredAttribute rqa = (RequiredAttribute)field.GetCustomAttribute(typeof(RequiredAttribute));
                            if (rqa == null)
                            {
                                docAttr.IsOptional = true;
                            }

                            CustomValidationAttribute cva = (CustomValidationAttribute)field.GetCustomAttribute(typeof(CustomValidationAttribute));
                            if (cva != null)
                            {
                                docAttr.IsUnique = true;
                            }
                        }
                        else
                        {
                            InversePropertyAttribute ipa = (InversePropertyAttribute)field.GetCustomAttribute(typeof(InversePropertyAttribute));
                            if (ipa != null)
                            {
                                docAttr.Inverse = ipa.Property;
                                attrsInverse.Add(docAttr);
                            }
                        }

                        // xml
                        XmlIgnoreAttribute xia = (XmlIgnoreAttribute)field.GetCustomAttribute(typeof(XmlIgnoreAttribute));
                        if (xia != null)
                        {
                            docAttr.XsdFormat = DocXsdFormatEnum.Hidden;
                        }
                        else
                        {
                            XmlElementAttribute xea = (XmlElementAttribute)field.GetCustomAttribute(typeof(XmlElementAttribute));
                            if (xea != null)
                            {
                                if (!String.IsNullOrEmpty(xea.ElementName))
                                {
                                    docAttr.XsdFormat = DocXsdFormatEnum.Element;
                                }
                                else
                                {
                                    docAttr.XsdFormat = DocXsdFormatEnum.Attribute;
                                }
                            }
                        }
                    }

                    foreach (DocAttribute docAttr in attrsDirect.Values)
                    {
                        docEntity.Attributes.Add(docAttr);
                    }

                    foreach (DocAttribute docAttr in attrsInverse)
                    {
                        docEntity.Attributes.Add(docAttr);
                    }

                    // get derived attributes based on properties
                    PropertyInfo[] props = t.GetProperties(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public);
                    foreach (PropertyInfo prop in props)
                    {
                        // if no backing field, then derived
                        FieldInfo field = t.GetField("_" + prop.Name, BindingFlags.NonPublic | BindingFlags.Instance);
                        if (field == null)
                        {
                            DocAttribute docDerived = new DocAttribute();
                            docDerived.Name = prop.Name;
                            docEntity.Attributes.Add(docDerived);
                        }
                    }
                }

                if (docDef != null)
                {
                    docDef.Name = t.Name;
                    docDef.Uuid = t.GUID;
                }

                docSchema.SortTypes();
                docSchema.SortEntities();
            }

            // pass 2: hook up selects
            foreach (Type t in assem.GetTypes())
            {
                Type[] typeInterfaces = t.GetInterfaces();
                if (typeInterfaces.Length > 0)
                {
                    foreach (Type typeI in typeInterfaces)
                    {
                        DocSelect docSelect = project.GetDefinition(typeI.Name) as DocSelect;
                        if (docSelect != null)
                        {
                            DocSelectItem docItem = new DocSelectItem();
                            docItem.Name = t.Name;
                            docSelect.Selects.Add(docItem);
                        }
                    }
                }
            }

            // EXPRESS rules (eventually in C#, though .exp file snippets for now)
            en = System.IO.Directory.EnumerateFiles(pathSchema, "*.exp", System.IO.SearchOption.AllDirectories);
            foreach (string file in en)
            {
                string name = Path.GetFileNameWithoutExtension(file);
                string expr = null;
                using (StreamReader readExpr = new StreamReader(file, Encoding.UTF8))
                {
                    expr = readExpr.ReadToEnd();
                }

                if (name.Contains('-'))
                {
                    // where rule
                    string[] parts = name.Split('-');
                    if (parts.Length == 2)
                    {
                        DocWhereRule docWhere = new DocWhereRule();
                        docWhere.Name       = parts[1];
                        docWhere.Expression = expr;

                        DocDefinition docDef = project.GetDefinition(parts[0]);
                        if (docDef is DocEntity)
                        {
                            DocEntity docEnt = (DocEntity)docDef;
                            docEnt.WhereRules.Add(docWhere);
                        }
                        else if (docDef is DocDefined)
                        {
                            DocDefined docEnt = (DocDefined)docDef;
                            docEnt.WhereRules.Add(docWhere);
                        }
                        else if (docDef == null)
                        {
                            //... global rule...
                        }
                    }
                }
                else
                {
                    // function
                    string schema = Path.GetDirectoryName(file);
                    schema = Path.GetDirectoryName(schema);
                    schema = Path.GetFileName(schema);
                    DocSchema docSchema = project.GetSchema(schema);
                    if (docSchema != null)
                    {
                        DocFunction docFunction = new DocFunction();
                        docSchema.Functions.Add(docFunction);
                        docFunction.Name       = name;
                        docFunction.Expression = expr;
                    }
                }
            }

            // now, hook up html documentation
            en = System.IO.Directory.EnumerateFiles(pathSchema, "*.htm", System.IO.SearchOption.AllDirectories);
            foreach (string file in en)
            {
                string    name   = Path.GetFileNameWithoutExtension(file);
                DocObject docObj = null;
                if (name == "schema")
                {
                    string schema = Path.GetDirectoryName(file);
                    schema = Path.GetFileName(schema);
                    docObj = project.GetSchema(schema);
                }
                else if (name.Contains('-'))
                {
                    // where rule
                    string[] parts = name.Split('-');
                    if (parts.Length == 2)
                    {
                        DocDefinition docDef = project.GetDefinition(parts[0]);
                        if (docDef is DocEntity)
                        {
                            DocEntity docEnt = (DocEntity)docDef;
                            foreach (DocWhereRule docWhereRule in docEnt.WhereRules)
                            {
                                if (docWhereRule.Name.Equals(parts[1]))
                                {
                                    docObj = docWhereRule;
                                    break;
                                }
                            }
                        }
                        else if (docDef is DocDefined)
                        {
                            DocDefined docEnt = (DocDefined)docDef;
                            foreach (DocWhereRule docWhereRule in docEnt.WhereRules)
                            {
                                if (docWhereRule.Name.Equals(parts[1]))
                                {
                                    docObj = docWhereRule;
                                    break;
                                }
                            }
                        }
                    }
                }
                else
                {
                    docObj = project.GetDefinition(name);

                    if (docObj == null)
                    {
                        docObj = project.GetFunction(name);
                    }
                }

                if (docObj != null)
                {
                    using (StreamReader readHtml = new StreamReader(file, Encoding.UTF8))
                    {
                        docObj.Documentation = readHtml.ReadToEnd();
                    }
                }
            }

            // load schema diagrams
            en = System.IO.Directory.EnumerateFiles(pathSchema, "*.svg", System.IO.SearchOption.AllDirectories);
            foreach (string file in en)
            {
                string schema = Path.GetDirectoryName(file);
                schema = Path.GetFileName(schema);

                DocSchema docSchema = project.GetSchema(schema);
                if (docSchema != null)
                {
                    using (IfcDoc.Schema.SVG.SchemaSVG schemaSVG = new IfcDoc.Schema.SVG.SchemaSVG(file, docSchema, project))
                    {
                        schemaSVG.Load();
                    }
                }
            }

            // psets, qsets
            //...

            // exchanges
            en = System.IO.Directory.EnumerateFiles(path, "*.mvdxml", System.IO.SearchOption.AllDirectories);
            foreach (string file in en)
            {
                IfcDoc.Schema.MVD.SchemaMVD.Load(project, file);
            }

            // examples
            string pathExamples = path + @"\examples";

            if (Directory.Exists(pathExamples))
            {
                en = System.IO.Directory.EnumerateFiles(pathExamples, "*.htm", SearchOption.TopDirectoryOnly);
                foreach (string file in en)
                {
                    DocExample docExample = new DocExample();
                    docExample.Name = Path.GetFileNameWithoutExtension(file);
                    project.Examples.Add(docExample);

                    using (StreamReader reader = new StreamReader(file))
                    {
                        docExample.Documentation = reader.ReadToEnd();
                    }

                    string dirpath = file.Substring(0, file.Length - 4);
                    if (Directory.Exists(dirpath))
                    {
                        IEnumerable <string> suben = System.IO.Directory.EnumerateFiles(dirpath, "*.ifc", SearchOption.TopDirectoryOnly);
                        foreach (string ex in suben)
                        {
                            DocExample docEx = new DocExample();
                            docEx.Name = Path.GetFileNameWithoutExtension(ex);
                            docExample.Examples.Add(docEx);

                            // read the content of the file
                            using (FileStream fs = new FileStream(ex, FileMode.Open, FileAccess.Read))
                            {
                                docEx.File = new byte[fs.Length];
                                fs.Read(docEx.File, 0, docEx.File.Length);
                            }

                            // read documentation
                            string exdoc = ex.Substring(0, ex.Length - 4) + ".htm";
                            if (File.Exists(exdoc))
                            {
                                using (StreamReader reader = new StreamReader(exdoc))
                                {
                                    docEx.Documentation = reader.ReadToEnd();
                                }
                            }
                        }
                    }
                }
            }

            // localization
            en = System.IO.Directory.EnumerateFiles(path, "*.txt", System.IO.SearchOption.AllDirectories);
            foreach (string file in en)
            {
                using (FormatCSV format = new FormatCSV(file))
                {
                    try
                    {
                        format.Instance = project;
                        format.Load();
                    }
                    catch
                    {
                    }
                }
            }
        }