Exemplo n.º 1
0
        public string FormatDefinitions(DocProject docProject, DocPublication docPublication, Dictionary <string, DocObject> map, Dictionary <DocObject, bool> included)
        {
            StringBuilder sb = new StringBuilder();

            foreach (DocSection docSection in docProject.Sections)
            {
                foreach (DocSchema docSchema in docSection.Schemas)
                {
                    foreach (DocType docType in docSchema.Types)
                    {
                        bool use = true;
                        if (included != null)
                        {
                            use = false;
                            included.TryGetValue(docType, out use);
                        }

                        if (use)
                        {
                            if (docType is DocDefined)
                            {
                                DocDefined docDefined = (DocDefined)docType;
                                string     text       = this.FormatDefined(docDefined, map, included);
                                sb.AppendLine(text);
                            }
                            else if (docType is DocSelect)
                            {
                                DocSelect docSelect = (DocSelect)docType;
                                string    text      = this.FormatSelect(docSelect, map, included);
                                sb.AppendLine(text);
                            }
                            else if (docType is DocEnumeration)
                            {
                                DocEnumeration docEnumeration = (DocEnumeration)docType;
                                string         text           = this.FormatEnumeration(docEnumeration, map, included);
                                sb.AppendLine(text);
                            }
                        }
                    }

                    foreach (DocEntity docEntity in docSchema.Entities)
                    {
                        bool use = true;
                        if (included != null)
                        {
                            use = false;
                            included.TryGetValue(docEntity, out use);
                        }

                        if (use)
                        {
                            string text = this.FormatEntity(docEntity, map, included);
                            sb.AppendLine(text);
                        }
                    }
                }
            }

            return(sb.ToString());
        }
Exemplo n.º 2
0
 public string FormatDefined(DocDefined docDefined)
 {
     return
         ("public struct " + docDefined.Name + "\r\n" +
          "{\r\n" +
          "\t" + docDefined.DefinedType + " Value;\r\n" +
          "}");
 }
Exemplo n.º 3
0
        public string FormatDefined(DocDefined docDefined, Dictionary <string, DocObject> map, Dictionary <DocObject, bool> included)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("public struct " + docDefined.Name);

            // implement any selects
            BuildSelectEntries(sb, docDefined, map, included, false);

            sb.AppendLine();
            sb.AppendLine("{");
            sb.AppendLine("\t" + FormatIdentifier(docDefined.DefinedType) + " Value;");
            sb.AppendLine("}");

            return(sb.ToString());
        }
Exemplo n.º 4
0
        private void LoadType(TreeNode tnParent, DocType type)
        {
            // add entity
            TreeNode tn = new TreeNode();

            tn.Tag  = type;
            tn.Text = type.Name;
            this.m_mapInherit.Add(type, tn);

            if (tnParent != null)
            {
                tnParent.Nodes.Add(tn);
            }
            else
            {
                this.treeViewInheritance.Nodes.Add(tn);
            }

            if (this.m_selection == type)
            {
                this.treeViewInheritance.SelectedNode = tn;
            }

            // special case if typed as aggregation to an entity, e.g. IfcPropertySetDefinitionSet
            if (type is DocDefined)
            {
                DocDefined docDef = (DocDefined)type;
                if (docDef.Aggregation != null)
                {
                    foreach (DocSection docSection in this.m_project.Sections)
                    {
                        foreach (DocSchema docSchema in docSection.Schemas)
                        {
                            foreach (DocEntity docEntity in docSchema.Entities)
                            {
                                if (docEntity.Name.Equals(docDef.DefinedType))
                                {
                                    LoadEntity(tn, docEntity);
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 5
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
                    {
                    }
                }
            }
        }
Exemplo n.º 6
0
 public string FormatDefined(DocDefined docDefined, Dictionary <string, DocObject> map, Dictionary <DocObject, bool> included)
 {
     return(null);            // nothing to define
 }
Exemplo n.º 7
0
        public static string FormatDefinedSimple(DocDefined docDefined)
        {
            string defined = ToXsdType(docDefined.DefinedType);

            StringBuilder sb = new StringBuilder();

            if (docDefined.Aggregation != null)
            {
                string aggtype = docDefined.Aggregation.GetAggregation().ToString().ToLower();

                if (docDefined.Aggregation.GetAggregation() == DocAggregationEnum.SET)
                {
                    sb.Append("\t<xs:complexType name=\"");
                    sb.Append(docDefined.Name);
                    sb.Append("\">");
                    sb.AppendLine();

                    sb.AppendLine("\t\t<xs:sequence>");
                    sb.Append("\t\t\t<xs:element ref=\"");
                    sb.Append(defined);
                    sb.AppendLine("\" maxOccurs=\"unbounded\"/>");
                    sb.AppendLine("\t\t</xs:sequence>");

                    sb.Append("\t\t<xs:attribute ref=\"ifc:itemType\" fixed=\"");
                    sb.Append(defined);
                    sb.AppendLine("\"/>");

                    sb.Append("\t\t<xs:attribute ref=\"ifc:cType\" fixed=\"");
                    sb.Append(aggtype);
                    sb.AppendLine("\"/>");

                    sb.Append("\t\t<xs:attribute ref=\"ifc:arraySize\" use=\"");
                    sb.Append("optional");
                    sb.AppendLine("\"/>");

                    sb.Append("\t</xs:complexType>");
                    sb.AppendLine();
                }
                else
                {
                    sb.Append("\t<xs:complexType name=\"");
                    sb.Append(docDefined.Name);
                    sb.Append("\">");
                    sb.AppendLine();

                    sb.AppendLine("\t\t<xs:simpleContent>");
                    sb.Append("\t\t\t<xs:extension base=\"ifc:List-");
                    sb.Append(docDefined.Name);
                    sb.AppendLine("\">");

                    sb.Append("\t\t\t\t<xs:attribute ref=\"ifc:itemType\" fixed=\"");
                    sb.Append(defined);
                    sb.AppendLine("\"/>");

                    sb.Append("\t\t\t\t<xs:attribute ref=\"ifc:cType\" fixed=\"");
                    sb.Append(aggtype);
                    sb.AppendLine("\"/>");

                    sb.Append("\t\t\t\t<xs:attribute ref=\"ifc:arraySize\" use=\"");
                    sb.Append("optional");
                    sb.AppendLine("\"/>");

                    sb.AppendLine("\t\t\t</xs:extension>");
                    sb.AppendLine("\t\t</xs:simpleContent>");

                    sb.Append("\t</xs:complexType>");
                    sb.AppendLine();

                    // simple type
                    sb.Append("\t<xs:simpleType name=\"List-");
                    sb.Append(docDefined.Name);
                    sb.Append("\">");
                    sb.AppendLine();

                    sb.AppendLine("\t\t<xs:restriction>");
                    sb.AppendLine("\t\t\t<xs:simpleType>");
                    sb.Append("\t\t\t\t<xs:list itemType=\"");
                    sb.Append(defined);
                    sb.AppendLine("\"/>");
                    sb.AppendLine("\t\t\t</xs:simpleType>");

                    if (docDefined.Aggregation.GetAggregation() == DocAggregationEnum.ARRAY)
                    {
                        sb.Append("\t\t\t<xs:minLength value=\"");
                        sb.Append(docDefined.Aggregation.GetAggregationNestingUpper());
                        sb.AppendLine("\"/>");
                    }
                    else if (docDefined.Aggregation.AggregationLower != null)
                    {
                        sb.Append("\t\t\t<xs:minLength value=\"");
                        sb.Append(docDefined.Aggregation.GetAggregationNestingLower());
                        sb.AppendLine("\"/>");
                    }

                    if (docDefined.Aggregation.AggregationUpper != null)
                    {
                        sb.Append("\t\t\t<xs:maxLength value=\"");
                        sb.Append(docDefined.Aggregation.GetAggregationNestingUpper());
                        sb.AppendLine("\"/>");
                    }

                    sb.AppendLine("\t\t</xs:restriction>");

                    sb.Append("\t</xs:simpleType>");
                    sb.AppendLine();
                }
            }
            else
            {
                sb.Append("\t<xs:simpleType name=\"");
                sb.Append(docDefined.Name);
                sb.Append("\">");
                sb.AppendLine();

                sb.Append("\t\t<xs:restriction base=\"");
                sb.Append(defined);

                if (docDefined.Length > 0)
                {
                    sb.Append("\">");
                    sb.AppendLine();

                    sb.Append("\t\t\t<xs:maxLength value=\"");
                    sb.Append(docDefined.Length);
                    sb.AppendLine("\"/>");

                    sb.AppendLine("\t\t</xs:restriction>");
                }
                else if (docDefined.Length < 0)
                {
                    // fixed
                    sb.Append("\">");
                    sb.AppendLine();

                    sb.Append("\t\t\t<xs:minLength value=\"");
                    sb.Append(-docDefined.Length);
                    sb.AppendLine("\"/>");

                    sb.Append("\t\t\t<xs:maxLength value=\"");
                    sb.Append(-docDefined.Length);
                    sb.AppendLine("\"/>");

                    sb.AppendLine("\t\t</xs:restriction>");
                }
                else if (docDefined.Aggregation != null)
                {
                    sb.Append("\">");
                    sb.AppendLine();

                    if (docDefined.Aggregation.AggregationLower != null)
                    {
                        sb.Append("\t\t\t<xs:minLength value=\"");
                        sb.Append(docDefined.Aggregation.GetAggregationNestingLower());
                        sb.AppendLine("\"/>");
                    }

                    if (docDefined.Aggregation.AggregationUpper != null)
                    {
                        sb.Append("\t\t\t<xs:maxLength value=\"");
                        sb.Append(docDefined.Aggregation.GetAggregationNestingUpper());
                        sb.AppendLine("\"/>");
                    }

                    sb.AppendLine("\t\t</xs:restriction>");
                }
                else
                {
                    sb.Append("\"/>");
                    sb.AppendLine();
                }

                sb.Append("\t</xs:simpleType>");
                sb.AppendLine();
            }

            return(sb.ToString());
        }
Exemplo n.º 8
0
        public static string FormatTypeWrapper(DocType docDefined, Dictionary <string, DocObject> map)
        {
            StringBuilder sb = new StringBuilder();

            // wrapper

            /*
             * <xs:element name="IfcPressureMeasure-wrapper" nillable="true">
             * <xs:complexType>
             * <xs:simpleContent>
             *  <xs:extension base="ifc:IfcPressureMeasure">
             *      <xs:attributeGroup ref="ifc:instanceAttributes"/>
             *  </xs:extension>
             * </xs:simpleContent>
             * </xs:complexType>
             * </xs:element>
             */

            bool complex = false;

            if (docDefined is DocDefined)
            {
                DocDefined docDef = (DocDefined)docDefined;
                DocObject  docobj = null;
                if (docDef.DefinedType != null && map.TryGetValue(docDef.DefinedType, out docobj) && docobj is DocEntity)
                {
                    complex = true;
                }
            }

            sb.Append("\t<xs:element name=\"");
            sb.Append(docDefined.Name);
            sb.Append("-wrapper\" nillable=\"true\">");
            sb.AppendLine();

            sb.AppendLine("\t\t<xs:complexType>");

            if (complex)
            {
                sb.AppendLine("\t\t\t<xs:complexContent>");
            }
            else
            {
                sb.AppendLine("\t\t\t<xs:simpleContent>");
            }

            sb.Append("\t\t\t\t<xs:extension base=\"");
            sb.Append(ToXsdType(docDefined.Name));
            sb.AppendLine("\">");

            sb.AppendLine("\t\t\t\t\t<xs:attributeGroup ref=\"ifc:instanceAttributes\"/>");

            sb.AppendLine("\t\t\t\t</xs:extension>");

            if (complex)
            {
                sb.AppendLine("\t\t\t</xs:complexContent>");
            }
            else
            {
                sb.AppendLine("\t\t\t</xs:simpleContent>");
            }
            sb.AppendLine("\t\t</xs:complexType>");

            sb.Append("\t</xs:element>");

            sb.AppendLine();

            return(sb.ToString());
        }
Exemplo n.º 9
0
        private void CompileConcept(DocTemplateUsage concept, DocModelView view, TypeBuilder tb)
        {
            bool includeconcept = true;

            if (this.m_exchange != null)
            {
                includeconcept = false;
                foreach (DocExchangeItem ei in concept.Exchanges)
                {
                    if (ei.Exchange == this.m_exchange && ei.Applicability == DocExchangeApplicabilityEnum.Export &&
                        (ei.Requirement == DocExchangeRequirementEnum.Mandatory || ei.Requirement == DocExchangeRequirementEnum.Optional))
                    {
                        includeconcept = true;
                    }
                }
            }

            // bool ConceptTemplateA([Parameter1, ...]);
            // {
            //    // for loading reference value:
            //    .ldfld [AttributeRule]
            //    .ldelem [Index] // for collection, get element by index
            //    .castclass [EntityRule] for entity, cast to expected type;
            //    // for object graphs, repeat the above instructions to load value
            //
            //    for loading constant:
            //    .ldstr 'value'
            //
            //    for comparison functions:
            //    .cge
            //
            //    for logical aggregations, repeat each item, pushing 2 elements on stack, then run comparison
            //    .or
            //
            //    return the boolean value on the stack
            //    .ret;
            // }

            // bool[] ConceptA()
            // {
            //    bool[] result = new bool[2];
            //
            //    if parameters are specified, call for each template rule; otherwise call just once
            //    result[0] = ConceptTemplateA([Parameter1, ...]); // TemplateRule#1
            //    result[1] = ConceptTemplateA([Parameter1, ...]); // TemplateRule#2
            //
            //    return result;
            // }

            // compile a method for the template definition, where parameters are passed to the template


#if true
            if (includeconcept && concept.Definition != null)
            {
                MethodInfo methodTemplate = this.RegisterTemplate(concept.Definition);

                // verify that definition is compatible with entity (user error)
                if (methodTemplate != null && methodTemplate.DeclaringType.IsAssignableFrom(tb))
                {
                    string methodname = DocumentationISO.MakeLinkName(view) + "_" + DocumentationISO.MakeLinkName(concept.Definition);



                    MethodBuilder method    = tb.DefineMethod(methodname, MethodAttributes.Public, CallingConventions.HasThis, typeof(bool[]), null);
                    ILGenerator   generator = method.GetILGenerator();

                    DocModelRule[] parameters = concept.Definition.GetParameterRules();

                    if (parameters != null && parameters.Length > 0)
                    {
                        // allocate array of booleans, store as local variable
                        generator.DeclareLocal(typeof(bool[]));
                        generator.Emit(OpCodes.Ldc_I4, concept.Items.Count);
                        generator.Emit(OpCodes.Newarr, typeof(bool));
                        generator.Emit(OpCodes.Stloc_0);

                        // call for each item with specific parameters
                        for (int row = 0; row < concept.Items.Count; row++)
                        {
                            DocTemplateItem docItem = concept.Items[row];

                            generator.Emit(OpCodes.Ldloc_0);                               // push the array object onto the stack, for storage later
                            generator.Emit(OpCodes.Ldc_I4, row);                           // push the array index onto the stack for storage later

                            generator.Emit(OpCodes.Ldarg_0);                               // push the *this* pointer for the IFC object instance

                            // push parameters onto stack
                            for (int col = 0; col < parameters.Length; col++)
                            {
                                DocModelRule docParam   = parameters[col];
                                string       paramvalue = docItem.GetParameterValue(docParam.Identification);
                                if (paramvalue != null)
                                {
                                    DocDefinition docParamType = concept.Definition.GetParameterType(docParam.Identification, this.m_definitions);
                                    if (docParamType is DocDefined)
                                    {
                                        DocDefined docDefined = (DocDefined)docParamType;
                                        switch (docDefined.DefinedType)
                                        {
                                        case "INTEGER":
                                        {
                                            Int64 ival = 0;
                                            Int64.TryParse(paramvalue, out ival);
                                            generator.Emit(OpCodes.Ldc_I8, ival);
                                            generator.Emit(OpCodes.Box);
                                        }
                                        break;

                                        case "REAL":
                                        {
                                            Double dval = 0.0;
                                            Double.TryParse(paramvalue, out dval);
                                            generator.Emit(OpCodes.Ldc_R8, dval);
                                            generator.Emit(OpCodes.Box);
                                        }
                                        break;

                                        case "STRING":
                                            generator.Emit(OpCodes.Ldstr, paramvalue);
                                            break;

                                        default:
                                            generator.Emit(OpCodes.Ldstr, paramvalue);
                                            break;
                                        }
                                    }
                                    else
                                    {
                                        // assume string
                                        generator.Emit(OpCodes.Ldstr, paramvalue);
                                    }
                                }
                                else
                                {
                                    generator.Emit(OpCodes.Ldnull);
                                }
                            }

                            generator.Emit(OpCodes.Call, methodTemplate);                  // call the validation function for the concept template
                            generator.Emit(OpCodes.Stelem_I1);                             // store the result (bool) into an array slot
                        }

                        // return the array of boolean results
                        generator.Emit(OpCodes.Ldloc_0);
                        generator.Emit(OpCodes.Ret);
                    }
                    else
                    {
                        // allocate array of booleans, store as local variable
                        generator.DeclareLocal(typeof(bool[]));
                        generator.Emit(OpCodes.Ldc_I4, 1);
                        generator.Emit(OpCodes.Newarr, typeof(bool));
                        generator.Emit(OpCodes.Stloc_0);

                        generator.Emit(OpCodes.Ldloc_0);                           // push the array object onto the stack, for storage later
                        generator.Emit(OpCodes.Ldc_I4, 0);                         // push the array index onto the stack for storage later

                        // call once
                        generator.Emit(OpCodes.Ldarg_0);                           // push the *this* pointer for the IFC object instance
                        generator.Emit(OpCodes.Call, methodTemplate);              // call the validation function for the concept template
                        generator.Emit(OpCodes.Stelem_I1);                         // store the result (bool) into an array slot

                        // return the array of boolean results
                        generator.Emit(OpCodes.Ldloc_0);
                        generator.Emit(OpCodes.Ret);
                    }
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine("Incompatible template: " + tb.Name + " - " + concept.Definition.Name);
                }
            }
#endif
            // recurse
            foreach (DocTemplateUsage docChild in concept.Concepts)
            {
                CompileConcept(docChild, view, tb);
            }
        }
Exemplo n.º 10
0
        private void BuildFields(StringBuilder sb, DocEntity docEntity, Dictionary <string, DocObject> map)
        {
#if true //... make configurable... -- for now all classes are mapped as separate tables, where lookup must join each
            // super
            DocObject docSuper = null;
            if (docEntity.BaseDefinition != null && map.TryGetValue(docEntity.BaseDefinition, out docSuper) && docSuper is DocEntity)
            {
                BuildFields(sb, (DocEntity)docSuper, map);
            }
#endif
            foreach (DocAttribute docAttr in docEntity.Attributes)
            {
                if (docAttr.GetAggregation() == DocAggregationEnum.NONE && docAttr.Inverse == null) // don't deal with lists -- separate tables
                {
                    sb.Append(", ");
                    sb.AppendLine();

                    sb.Append("\t");
                    sb.Append(docAttr.Name);
                    sb.Append(" ");

                    DocObject docRef = null;

                    if (docAttr.DefinedType == null || !map.TryGetValue(docAttr.DefinedType, out docRef) || docRef is DocDefined)
                    {
                        string deftype = docAttr.DefinedType;
                        if (docRef is DocDefined)
                        {
                            DocDefined docDef = (DocDefined)docRef;
                            deftype = docDef.DefinedType;
                        }
                        switch (deftype)
                        {
                        case "BOOLEAN":
                            sb.Append(" BIT");
                            break;

                        case "INTEGER":
                            sb.Append(" INTEGER");
                            break;

                        case "REAL":
                            sb.Append(" FLOAT");
                            break;

                        case "BINARY":
                            sb.Append(" TEXT");
                            break;

                        case "STRING":
                        default:
                            sb.Append(" TEXT");
                            break;
                        }
                    }
                    else if (docRef is DocEntity) //... docselect...
                    {
                        // if non-rooted, then embed as XML...

                        sb.Append(" INTEGER"); // oid
                    }
                    else if (docRef is DocSelect)
                    {
                        sb.Append(" INTEGER"); // oid... and type...
                    }
                    else if (docRef is DocEnumeration)
                    {
                        sb.Append(" VARCHAR");
                    }
                }
            }
        }
Exemplo n.º 11
0
 public string FormatDefined(DocDefined docDefined)
 {
     // nothing -- java does not support structures
     return("/* " + docDefined.Name + " : " + docDefined.DefinedType + " (Java does not support structures, so usage of defined types are inline for efficiency.) */\r\n");
 }
Exemplo n.º 12
0
 public string FormatDefined(DocDefined docDefined)
 {
     // nothing -- java does not support structures
     return "/* " + docDefined.Name + " : " + docDefined.DefinedType + " (Java does not support structures, so usage of defined types are inline for efficiency.) */\r\n";
 }
Exemplo n.º 13
0
 public string FormatDefined(DocDefined docDefined, Dictionary <string, DocObject> map, Dictionary <DocObject, bool> included)
 {
     return(FormatDefinedFull(docDefined, false));
 }
Exemplo n.º 14
0
        /// <summary>
        /// Updates any connected geometry to match definition
        /// </summary>
        /// <param name="docDef"></param>
        public void LayoutDefinition(DocDefinition selection)
        {
            // then traverse all dependencies on selection
            if (selection is DocEntity)
            {
                DocEntity docEntity = (DocEntity)selection;
                foreach (DocAttribute docAttr in docEntity.Attributes)
                {
                    LayoutLine(docEntity, docAttr.Definition, docAttr.DiagramLine);
                    if (docAttr.DiagramLabel != null)
                    {
                        docAttr.DiagramLabel.X = docAttr.DiagramLine[0].X;
                        docAttr.DiagramLabel.Y = docAttr.DiagramLine[2].Y - 20.0;
                    }
                }

                foreach (DocLine docLine in docEntity.Tree)
                {
                    LayoutTree(docEntity, docLine);
                }
            }
            else if (selection is DocDefinitionRef)
            {
                DocDefinitionRef docRef = (DocDefinitionRef)selection;
                foreach (DocLine docLine in docRef.Tree)
                {
                    LayoutTree(docRef, docLine);
                }
            }
            else if (selection is DocDefined)
            {
                DocDefined docDef = (DocDefined)selection;
                LayoutLine(docDef, docDef.Definition, docDef.DiagramLine);
            }
            else if (selection is DocSelect)
            {
                DocSelect docSelect = (DocSelect)selection;
                foreach (DocLine docLine in docSelect.Tree)
                {
                    LayoutTree(docSelect, docLine);
                }
            }
            else if (selection is DocPageTarget)
            {
                DocPageTarget docTarget = (DocPageTarget)selection;
                LayoutLine(docTarget.Definition, docTarget, docTarget.DiagramLine);
                docTarget.DiagramLine.Reverse();
            }

            foreach (DocPageTarget docPageTarget in this.m_schema.PageTargets)
            {
                if (docPageTarget.Definition == selection)
                {
                    LayoutLine(docPageTarget.Definition, docPageTarget, docPageTarget.DiagramLine);
                    docPageTarget.DiagramLine.Reverse();
                }
            }

            foreach (DocSchemaRef docSchemaRef in this.m_schema.SchemaRefs)
            {
                foreach (DocDefinitionRef docDefRef in docSchemaRef.Definitions)
                {
                    foreach (DocLine docLine in docDefRef.Tree)
                    {
                        if (docLine.Definition == selection)
                        {
                            LayoutLine(docDefRef, docLine.Definition, docLine.DiagramLine);
                        }
                        else
                        {
                            foreach (DocLine docSub in docLine.Tree)
                            {
                                if (docSub.Definition == selection)
                                {
                                    LayoutNode(docLine, docSub);
                                }
                            }
                        }
                    }
                }
            }

            foreach (DocEntity docEntity in this.m_schema.Entities)
            {
                // if there multile attributes refer to the same definition, then space evenly
                int count = 0;
                foreach (DocAttribute docAttr in docEntity.Attributes)
                {
                    if (docAttr.Definition == selection)
                    {
                        count++;
                    }
                }

                int each = 0;
                foreach (DocAttribute docAttr in docEntity.Attributes)
                {
                    if (docAttr.Definition == selection)
                    {
                        LayoutLine(docEntity, docAttr.Definition, docAttr.DiagramLine);
                        if (count > 1 && docAttr.DiagramLine.Count == 3)
                        {
                            each++;
                            docAttr.DiagramLine[0].Y = selection.DiagramRectangle.Y + (selection.DiagramRectangle.Height * (double)each / (double)(count + 1));
                            docAttr.DiagramLine[1].Y = selection.DiagramRectangle.Y + (selection.DiagramRectangle.Height * (double)each / (double)(count + 1));
                            docAttr.DiagramLine[2].Y = selection.DiagramRectangle.Y + (selection.DiagramRectangle.Height * (double)each / (double)(count + 1));
                        }

                        if (docAttr.DiagramLabel == null)
                        {
                            docAttr.DiagramLabel = new DocRectangle();
                        }
                        docAttr.DiagramLabel.X = docAttr.DiagramLine[0].X;
                        docAttr.DiagramLabel.Y = docAttr.DiagramLine[2].Y - 20.0;
                    }
                }

                foreach (DocLine docLine in docEntity.Tree)
                {
                    if (docLine.Definition == selection)
                    {
                        LayoutLine(docEntity, docLine.Definition, docLine.DiagramLine);
                    }
                    else
                    {
                        foreach (DocLine docSub in docLine.Tree)
                        {
                            if (docSub.Definition == selection)
                            {
                                LayoutNode(docLine, docSub);
                            }
                        }
                    }
                }
            }

            foreach (DocType docType in this.m_schema.Types)
            {
                if (docType is DocDefined)
                {
                    DocDefined docDef = (DocDefined)docType;
                    if (docDef.Definition == selection)
                    {
                        LayoutLine(docDef, docDef.Definition, docDef.DiagramLine);
                    }
                }
                else if (docType is DocSelect)
                {
                    DocSelect docSel = (DocSelect)docType;
                    foreach (DocLine docLine in docSel.Tree)
                    {
                        if (docLine.Definition == selection)
                        {
                            LayoutLine(docSel, selection, docLine.DiagramLine);
                        }

                        foreach (DocLine docSub in docLine.Tree)
                        {
                            if (docSub.Definition == selection)
                            {
                                LayoutNode(docLine, docSub);
                            }
                        }
                    }
                }
            }

            // recalculate page extents and resize/repaginate if necessary
            double cx = 0.0;
            double cy = 0.0;

            foreach (DocType docDef in this.m_schema.Types)
            {
                ExpandExtents(docDef.DiagramRectangle, ref cx, ref cy);
            }
            foreach (DocEntity docDef in this.m_schema.Entities)
            {
                ExpandExtents(docDef.DiagramRectangle, ref cx, ref cy);
            }
            foreach (DocPrimitive docDef in this.m_schema.Primitives)
            {
                ExpandExtents(docDef.DiagramRectangle, ref cx, ref cy);
            }
            foreach (DocPageTarget docDef in this.m_schema.PageTargets)
            {
                ExpandExtents(docDef.DiagramRectangle, ref cx, ref cy);
                foreach (DocPageSource docSource in docDef.Sources)
                {
                    ExpandExtents(docSource.DiagramRectangle, ref cx, ref cy);
                }
            }
            foreach (DocSchemaRef docRef in this.m_schema.SchemaRefs)
            {
                foreach (DocDefinitionRef docDef in docRef.Definitions)
                {
                    ExpandExtents(docDef.DiagramRectangle, ref cx, ref cy);
                }
            }
            foreach (DocComment docDef in this.m_schema.Comments)
            {
                ExpandExtents(docDef.DiagramRectangle, ref cx, ref cy);
            }
            this.m_schema.DiagramPagesHorz = 1 + (int)Math.Floor(cx * Factor / PageX);
            this.m_schema.DiagramPagesVert = 1 + (int)Math.Floor(cy * Factor / PageY);
        }
Exemplo n.º 15
0
        public void Save()
        {
            string dirpath = System.IO.Path.GetDirectoryName(this.m_filename);

            if (!System.IO.Directory.Exists(this.m_filename))
            {
                System.IO.Directory.CreateDirectory(dirpath);
            }

            using (System.IO.StreamWriter writer = new System.IO.StreamWriter(this.m_filename))
            {
                writer.WriteLine("// This file was automatically generated from IFCDOC at www.buildingsmart-tech.org.");
                writer.WriteLine("// IFC content is copyright (C) 1996-2013 BuildingSMART International Ltd.");
                writer.WriteLine();

                writer.WriteLine("using System;");
                writer.WriteLine();

                if (this.m_definition != null)
                {
                    writer.WriteLine("namespace BuildingSmart.IFC");
                    writer.WriteLine("{");

                    if (this.m_definition is DocDefined)
                    {
                        DocDefined docDefined = (DocDefined)this.m_definition;

                        writer.WriteLine("\tpublic struct " + this.m_definition.Name);
                        writer.WriteLine("\t{");
                        writer.WriteLine("\t\t" + docDefined.DefinedType + " Value;");
                        writer.WriteLine("\t}");
                    }
                    else if (this.m_definition is DocSelect)
                    {
                        writer.WriteLine("\tpublic interface " + this.m_definition.Name);
                        writer.WriteLine("\t{");
                        writer.WriteLine("\t}");
                    }
                    else if (this.m_definition is DocEnumeration)
                    {
                        DocEnumeration docEnumumeration = (DocEnumeration)this.m_definition;

                        writer.WriteLine("\tpublic enum " + this.m_definition.Name);
                        writer.WriteLine("\t{");
                        int counter = 0;
                        foreach (DocConstant docConstant in docEnumumeration.Constants)
                        {
                            counter++;
                            int val = counter;

                            if (docConstant.Name.Equals("NOTDEFINED"))
                            {
                                val = 0;
                            }
                            else if (docConstant.Name.Equals("USERDEFINED"))
                            {
                                val = -1;
                            }

                            writer.WriteLine("\t\t" + docConstant.Name + " = " + val + ",");
                        }
                        writer.WriteLine("\t}");
                    }
                    else if (this.m_definition is DocEntity)
                    {
                        DocEntity docEntity = (DocEntity)this.m_definition;

                        string basedef = docEntity.BaseDefinition;
                        if (String.IsNullOrEmpty(basedef))
                        {
                            basedef = "IfcBase";
                        }

                        writer.WriteLine("\tpublic partial class " + this.m_definition.Name + " : " + basedef);
                        writer.WriteLine("\t{");

                        // fields
                        foreach (DocAttribute docAttribute in docEntity.Attributes)
                        {
                            switch (docAttribute.GetAggregation())
                            {
                            case DocAggregationEnum.SET:
                                writer.WriteLine("\t\tprivate ICollection<" + docAttribute.DefinedType + "> _" + docAttribute.Name + ";");
                                break;

                            case DocAggregationEnum.LIST:
                                writer.WriteLine("\t\tprivate IList<" + docAttribute.DefinedType + "> _" + docAttribute.Name + ";");
                                break;

                            default:
                                writer.WriteLine("\t\tprivate " + docAttribute.DefinedType + " _" + docAttribute.Name + ";");
                                break;
                            }
                        }

                        // constructor
                        writer.WriteLine();
                        writer.WriteLine("\t\tpublic " + docEntity.Name + "()");
                        writer.WriteLine("\t\t{");
                        //... values...
                        writer.WriteLine("\t\t}");

                        // properties
                        foreach (DocAttribute docAttribute in docEntity.Attributes)
                        {
                            writer.WriteLine();

                            switch (docAttribute.GetAggregation())
                            {
                            case DocAggregationEnum.SET:
                                writer.WriteLine("\t\tpublic ICollection<" + docAttribute.DefinedType + "> " + docAttribute.Name);
                                break;

                            case DocAggregationEnum.LIST:
                                writer.WriteLine("\t\tpublic IList<" + docAttribute.DefinedType + "> " + docAttribute.Name);
                                break;

                            default:
                                writer.WriteLine("\t\tpublic " + docAttribute.DefinedType + " " + docAttribute.Name);
                                break;
                            }
                            writer.WriteLine("\t\t{");

                            writer.WriteLine("\t\t\tget");
                            writer.WriteLine("\t\t\t{");
                            writer.WriteLine("\t\t\t\treturn this._" + docAttribute.Name + ";");
                            writer.WriteLine("\t\t\t}");

                            if (docAttribute.GetAggregation() == DocAggregationEnum.NONE)
                            {
                                writer.WriteLine("\t\t\tset");
                                writer.WriteLine("\t\t\t{");

                                writer.WriteLine("\t\t\t\tthis.OnBeforePropertyChange(\"" + docAttribute.Name + "\");");
                                writer.WriteLine("\t\t\t\tthis._" + docAttribute.Name + " = value;");
                                writer.WriteLine("\t\t\t\tthis.OnAfterPropertyChange(\"" + docAttribute.Name + "\");");

                                writer.WriteLine("\t\t\t}");
                            }

                            writer.WriteLine("\t\t}");
                        }

                        // serialization
                        writer.WriteLine();
                        writer.WriteLine("\t\tprivate void GetObjectData(SerializationInfo info, StreamingContext context)");
                        writer.WriteLine("\t\t{");
                        foreach (DocAttribute docAttribute in docEntity.Attributes)
                        {
                            if (docAttribute.Inverse == null && docAttribute.Derived == null)
                            {
                                writer.WriteLine("\t\t\tinfo.AddValue(\"" + docAttribute.Name + "\", this._" + docAttribute.Name + ");");
                            }
                        }
                        writer.WriteLine("\t\t}");

                        writer.WriteLine();
                        writer.WriteLine("\t\tprivate void SetObjectData(SerializationInfo info, StreamingContext context)");
                        writer.WriteLine("\t\t{");
                        foreach (DocAttribute docAttribute in docEntity.Attributes)
                        {
                            if (docAttribute.Inverse == null && docAttribute.Derived == null)
                            {
                                string method = "GetValue";
                                writer.WriteLine("\t\t\tthis._" + docAttribute.Name + " = info." + method + "(\"" + docAttribute.Name + "\");");
                            }
                        }
                        writer.WriteLine("\t\t}");

                        writer.WriteLine("\t}");
                    }

                    writer.WriteLine("}");
                }
                else
                {
                    writer.WriteLine("namespace BuildingSmart.IFC.Properties");
                    writer.WriteLine("{");
                    writer.WriteLine();

                    Dictionary <string, string[]> mapEnums = new Dictionary <string, string[]>();

                    foreach (DocSection docSection in this.m_project.Sections)
                    {
                        foreach (DocSchema docSchema in docSection.Schemas)
                        {
                            foreach (DocPropertySet docPset in docSchema.PropertySets)
                            {
                                writer.WriteLine("    /// <summary>");
                                writer.WriteLine("    /// " + docPset.Documentation.Replace('\r', ' ').Replace('\n', ' '));
                                writer.WriteLine("    /// </summary>");

                                writer.WriteLine("    public class " + docPset.Name + " : Pset");
                                writer.WriteLine("    {");

                                foreach (DocProperty docProperty in docPset.Properties)
                                {
                                    writer.WriteLine("        /// <summary>");
                                    writer.WriteLine("        /// " + docProperty.Documentation.Replace('\r', ' ').Replace('\n', ' '));
                                    writer.WriteLine("        /// </summary>");

                                    switch (docProperty.PropertyType)
                                    {
                                    case DocPropertyTemplateTypeEnum.P_SINGLEVALUE:
                                        writer.WriteLine("        public " + docProperty.PrimaryDataType + " " + docProperty.Name + " { get { return this.GetValue<" + docProperty.PrimaryDataType + ">(\"" + docProperty.Name + "\"); } set { this.SetValue<" + docProperty.PrimaryDataType + ">(\"" + docProperty.Name + "\", value); } }");
                                        break;

                                    case DocPropertyTemplateTypeEnum.P_ENUMERATEDVALUE:
                                        // record enum for later
                                    {
                                        string[] parts = docProperty.SecondaryDataType.Split(':');
                                        if (parts.Length == 2)
                                        {
                                            string typename = parts[0];
                                            if (!mapEnums.ContainsKey(typename))
                                            {
                                                string[] enums = parts[1].Split(',');
                                                mapEnums.Add(typename, enums);

                                                writer.WriteLine("        public " + typename + " " + docProperty.Name + " { get { return this.GetValue<" + typename + ">(\"" + docProperty.Name + "\"); } set { this.SetValue<" + typename + ">(\"" + docProperty.Name + "\", value); } }");
                                            }
                                        }
                                    }
                                    break;

                                    case DocPropertyTemplateTypeEnum.P_BOUNDEDVALUE:
                                        writer.WriteLine("        public PBound<" + docProperty.PrimaryDataType + "> " + docProperty.Name + " { get { return this.GetBound<" + docProperty.PrimaryDataType + ">(\"" + docProperty.Name + "\"); } }");
                                        break;

                                    case DocPropertyTemplateTypeEnum.P_LISTVALUE:
                                        break;

                                    case DocPropertyTemplateTypeEnum.P_TABLEVALUE:
                                        writer.WriteLine("        public PTable<" + docProperty.PrimaryDataType + ", " + docProperty.SecondaryDataType + "> " + docProperty.Name + " { get { return this.GetTable<" + docProperty.PrimaryDataType + ", " + docProperty.SecondaryDataType + ">(\"" + docProperty.Name + "\"); } }");
                                        break;

                                    case DocPropertyTemplateTypeEnum.P_REFERENCEVALUE:
                                        if (docProperty.PrimaryDataType.Equals("IfcTimeSeries"))
                                        {
                                            string datatype = docProperty.SecondaryDataType;
                                            if (String.IsNullOrEmpty(datatype))
                                            {
                                                datatype = "IfcReal";
                                            }
                                            writer.WriteLine("        public PTimeSeries<" + datatype + "> " + docProperty.Name + " { get { return this.GetTimeSeries<" + datatype + ">(\"" + docProperty.Name + "\"); } }");
                                        }
                                        // ... TBD
                                        break;

                                    case DocPropertyTemplateTypeEnum.COMPLEX:
                                        //... TBD
                                        break;
                                    }
                                }

                                writer.WriteLine("    }");
                                writer.WriteLine();
                            }
                        }
                    }

                    // enums
                    foreach (string strEnum in mapEnums.Keys)
                    {
                        string[] enums = mapEnums[strEnum];

                        writer.WriteLine("    /// <summary>");
                        writer.WriteLine("    /// </summary>");
                        writer.WriteLine("    public enum " + strEnum);
                        writer.WriteLine("    {");

                        int counter = 0;
                        foreach (string val in enums)
                        {
                            int    num = 0;
                            string id  = val.ToUpper().Trim('.').Replace('-', '_');
                            switch (id)
                            {
                            case "OTHER":
                                num = -1;
                                break;

                            case "NOTKNOWN":
                                num = -2;
                                break;

                            case "UNSET":
                                num = 0;
                                break;

                            default:
                                counter++;
                                num = counter;
                                break;
                            }

                            if (id[0] >= '0' && id[0] <= '9')
                            {
                                id = "_" + id; // avoid numbers
                            }

                            writer.WriteLine("        /// <summary></summary>");
                            writer.WriteLine("        " + id + " = " + num + ",");
                        }

                        writer.WriteLine("    }");
                        writer.WriteLine();
                    }

                    writer.WriteLine("}");
                }
            }
        }
Exemplo n.º 16
0
 public string FormatDefined(DocDefined docDefined, Dictionary <string, DocObject> map, Dictionary <DocObject, bool> included)
 {
     // nothing -- java does not support structures
     return("/* " + docDefined.Name + " : " + docDefined.DefinedType + " (Java does not support structures, so usage of defined types are inline for efficiency.) */\r\n");
 }
Exemplo n.º 17
0
        public void Save()
        {
            string dirpath = System.IO.Path.GetDirectoryName(this.m_filename);

            if (!System.IO.Directory.Exists(this.m_filename))
            {
                System.IO.Directory.CreateDirectory(dirpath);
            }

            using (System.IO.StreamWriter writer = new System.IO.StreamWriter(this.m_filename))
            {
                writer.WriteLine("// This file was automatically generated from IFCDOC at www.buildingsmart-tech.org.");
                writer.WriteLine("// IFC content is copyright (C) 1996-2013 BuildingSMART International Ltd.");
                writer.WriteLine();

                writer.WriteLine("using System;");
                writer.WriteLine();

                if (this.m_definition != null)
                {
                    writer.WriteLine("namespace BuildingSmart.IFC");
                    writer.WriteLine("{");

                    if (this.m_definition is DocDefined)
                    {
                        DocDefined docDefined = (DocDefined)this.m_definition;
                        string     text       = this.Indent(this.FormatDefined(docDefined), 1);
                        writer.WriteLine(text);
                    }
                    else if (this.m_definition is DocSelect)
                    {
                        DocSelect docSelect = (DocSelect)this.m_definition;
                        string    text      = this.Indent(this.FormatSelect(docSelect, this.m_map, null), 1);
                        writer.WriteLine(text);
                    }
                    else if (this.m_definition is DocEnumeration)
                    {
                        DocEnumeration docEnumeration = (DocEnumeration)this.m_definition;
                        string         text           = this.Indent(this.FormatEnumeration(docEnumeration), 1);
                        writer.WriteLine(text);
                    }
                    else if (this.m_definition is DocEntity)
                    {
                        DocEntity docEntity = (DocEntity)this.m_definition;
                        string    text      = this.Indent(this.FormatEntity(docEntity, this.m_map, null), 1);
                        writer.WriteLine(docEntity);
                    }

                    writer.WriteLine("}");
                }
                else
                {
                    writer.WriteLine("namespace BuildingSmart.IFC.Properties");
                    writer.WriteLine("{");
                    writer.WriteLine();

                    Dictionary <string, string[]> mapEnums = new Dictionary <string, string[]>();

                    foreach (DocSection docSection in this.m_project.Sections)
                    {
                        foreach (DocSchema docSchema in docSection.Schemas)
                        {
                            foreach (DocPropertySet docPset in docSchema.PropertySets)
                            {
                                writer.WriteLine("    /// <summary>");
                                if (docPset.Documentation != null)
                                {
                                    writer.WriteLine("    /// " + docPset.Documentation.Replace('\r', ' ').Replace('\n', ' '));
                                }
                                writer.WriteLine("    /// </summary>");

                                writer.WriteLine("    public class " + docPset.Name + " : Pset");
                                writer.WriteLine("    {");

                                foreach (DocProperty docProperty in docPset.Properties)
                                {
                                    writer.WriteLine("        /// <summary>");
                                    if (docProperty.Documentation != null)
                                    {
                                        writer.WriteLine("        /// " + docProperty.Documentation.Replace('\r', ' ').Replace('\n', ' '));
                                    }
                                    writer.WriteLine("        /// </summary>");

                                    switch (docProperty.PropertyType)
                                    {
                                    case DocPropertyTemplateTypeEnum.P_SINGLEVALUE:
                                        writer.WriteLine("        public " + docProperty.PrimaryDataType + " " + docProperty.Name + " { get { return this.GetValue<" + docProperty.PrimaryDataType + ">(\"" + docProperty.Name + "\"); } set { this.SetValue<" + docProperty.PrimaryDataType + ">(\"" + docProperty.Name + "\", value); } }");
                                        break;

                                    case DocPropertyTemplateTypeEnum.P_ENUMERATEDVALUE:
                                    {
                                        string typename = docProperty.SecondaryDataType;
                                        if (typename == null)
                                        {
                                            typename = docProperty.PrimaryDataType;         // older version
                                        }
                                        int colon = typename.IndexOf(':');
                                        if (colon > 0)
                                        {
                                            // backwards compatibility
                                            typename = typename.Substring(0, colon);
                                        }
                                        writer.WriteLine("        public " + typename + " " + docProperty.Name + " { get { return this.GetValue<" + typename + ">(\"" + docProperty.Name + "\"); } set { this.SetValue<" + typename + ">(\"" + docProperty.Name + "\", value); } }");
                                    }
                                    break;

                                    case DocPropertyTemplateTypeEnum.P_BOUNDEDVALUE:
                                        writer.WriteLine("        public PBound<" + docProperty.PrimaryDataType + "> " + docProperty.Name + " { get { return this.GetBound<" + docProperty.PrimaryDataType + ">(\"" + docProperty.Name + "\"); } }");
                                        break;

                                    case DocPropertyTemplateTypeEnum.P_LISTVALUE:
                                        break;

                                    case DocPropertyTemplateTypeEnum.P_TABLEVALUE:
                                        writer.WriteLine("        public PTable<" + docProperty.PrimaryDataType + ", " + docProperty.SecondaryDataType + "> " + docProperty.Name + " { get { return this.GetTable<" + docProperty.PrimaryDataType + ", " + docProperty.SecondaryDataType + ">(\"" + docProperty.Name + "\"); } }");
                                        break;

                                    case DocPropertyTemplateTypeEnum.P_REFERENCEVALUE:
                                        if (docProperty.PrimaryDataType.Equals("IfcTimeSeries"))
                                        {
                                            string datatype = docProperty.SecondaryDataType;
                                            if (String.IsNullOrEmpty(datatype))
                                            {
                                                datatype = "IfcReal";
                                            }
                                            writer.WriteLine("        public PTimeSeries<" + datatype + "> " + docProperty.Name + " { get { return this.GetTimeSeries<" + datatype + ">(\"" + docProperty.Name + "\"); } }");
                                        }
                                        // ... TBD
                                        break;

                                    case DocPropertyTemplateTypeEnum.COMPLEX:
                                        //... TBD
                                        break;
                                    }
                                }

                                writer.WriteLine("    }");
                                writer.WriteLine();
                            }

                            foreach (DocPropertyEnumeration docEnum in docSchema.PropertyEnums)
                            {
                                writer.WriteLine("    /// <summary>");
                                writer.WriteLine("    /// </summary>");
                                writer.WriteLine("    public enum " + docEnum.Name);
                                writer.WriteLine("    {");

                                int counter = 0;
                                foreach (DocPropertyConstant docConst in docEnum.Constants)
                                {
                                    int    num = 0;
                                    string id  = docConst.Name.ToUpper().Trim('.').Replace('-', '_');
                                    switch (id)
                                    {
                                    case "OTHER":
                                        num = -1;
                                        break;

                                    case "NOTKNOWN":
                                        num = -2;
                                        break;

                                    case "UNSET":
                                        num = 0;
                                        break;

                                    default:
                                        counter++;
                                        num = counter;
                                        break;
                                    }

                                    if (id[0] >= '0' && id[0] <= '9')
                                    {
                                        id = "_" + id; // avoid numbers
                                    }

                                    writer.WriteLine("        /// <summary></summary>");
                                    writer.WriteLine("        " + docConst.Name + " = " + num + ",");
                                }

                                writer.WriteLine("    }");
                                writer.WriteLine();
                            }

                            //writer.WriteLine("}");



#if false
                            // enums
                            foreach (string strEnum in mapEnums.Keys)
                            {
                                string[] enums = mapEnums[strEnum];

                                writer.WriteLine("    /// <summary>");
                                writer.WriteLine("    /// </summary>");
                                writer.WriteLine("    public enum " + strEnum);
                                writer.WriteLine("    {");

                                int counter = 0;
                                foreach (string val in enums)
                                {
                                    int    num = 0;
                                    string id  = val.ToUpper().Trim('.').Replace('-', '_');
                                    switch (id)
                                    {
                                    case "OTHER":
                                        num = -1;
                                        break;

                                    case "NOTKNOWN":
                                        num = -2;
                                        break;

                                    case "UNSET":
                                        num = 0;
                                        break;

                                    default:
                                        counter++;
                                        num = counter;
                                        break;
                                    }

                                    if (id[0] >= '0' && id[0] <= '9')
                                    {
                                        id = "_" + id; // avoid numbers
                                    }

                                    writer.WriteLine("        /// <summary></summary>");
                                    writer.WriteLine("        " + id + " = " + num + ",");
                                }

                                writer.WriteLine("    }");
                                writer.WriteLine();
                            }

                            writer.WriteLine("}");
#endif
                        }
                    }
                }
            }
        }
Exemplo n.º 18
0
        public string FormatDefinedFull(DocDefined docDefined, bool fullListing)
        {
            StringBuilder sb = new StringBuilder();

            string defined = ToOwlClass(docDefined.DefinedType);

            if (docDefined.Aggregation != null)
            {
                string aggtype = docDefined.Aggregation.GetAggregation().ToString().ToLower();

                if (docDefined.Aggregation.GetAggregation() == DocAggregationEnum.SET)
                {
                    //IfcPropertySetDefinitionSet

                    sb.AppendLine("ifc:" + docDefined.Name);
                    sb.AppendLine("\trdf:type owl:Class ;");

                    //TODO:: Add (SELECT) parent classes

                    sb.AppendLine("\trdfs:subClassOf ");
                    sb.AppendLine("\t\t[ ");
                    sb.AppendLine("\t\t\trdf:type owl:Restriction ;");
                    sb.AppendLine("\t\t\towl:allValuesFrom " + defined + " ;");
                    sb.AppendLine("\t\t\towl:onProperty expr:hasSet");
                    sb.AppendLine("\t\t] ;");
                    sb.AppendLine("\t" + "rdfs:subClassOf ");
                    sb.AppendLine("\t\t" + "[");
                    sb.AppendLine("\t\t\t" + "rdf:type owl:Restriction ;");
                    sb.AppendLine("\t\t\t" + "owl:minQualifiedCardinality \"" + 1
                        + "\"^^xsd:nonNegativeInteger ;");
                    sb.AppendLine("\t\t\towl:onProperty expr:hasSet ;");
                    sb.AppendLine("\t\t\t" + "owl:onClass " + defined);
                    sb.AppendLine("\t\t] .");
                    sb.AppendLine();
                }
                else if (docDefined.Aggregation.GetAggregation() == DocAggregationEnum.LIST || docDefined.Aggregation.GetAggregation() == DocAggregationEnum.ARRAY)
                {

                    //Console.Out.WriteLine("defined type --" + docDefined.Aggregation.GetAggregation() + "-- : " + docDefined.Name);

                    int mincard = 0;
                    if (docDefined.Aggregation.AggregationLower != null)
                        mincard = Int32.Parse(docDefined.Aggregation.AggregationLower);
                    int maxcard = 0;
                    if (String.IsNullOrEmpty(docDefined.Aggregation.AggregationUpper) ||
                       !Int32.TryParse(docDefined.Aggregation.AggregationUpper, out maxcard))
                        maxcard = 0;

                    if (docDefined.Aggregation.GetAggregation() == DocAggregationEnum.ARRAY)
                    {
                        mincard = maxcard - mincard + 1;
                        maxcard = mincard;
                    }

                    sb.AppendLine("ifc:" + docDefined.Name);
                    sb.AppendLine("\trdf:type owl:Class ;");
                    sb.Append("\trdfs:subClassOf " + defined + "_List ");

                    //check for cardinality restrictions and add if available
                    string cards = "";
                    if (docDefined.Aggregation.GetAggregationNestingLower() >= 1)
                        cards += WriteMinCardRestr(defined + "_List", "hasNext", mincard, false);
                    if (docDefined.Aggregation.GetAggregationNestingUpper() > 1)
                        cards += WriteMaxCardRestr(defined + "_EmptyList", "hasNext", maxcard, false);
                    cards += ".";
                    sb.AppendLine(cards);
                    sb.AppendLine();

                    if (fullListing)
                    {
                        sb.AppendLine(createListClass(defined));
                    }
                }
            }
            else
            {
                sb.AppendLine("ifc:" + docDefined.Name);
                sb.AppendLine("\trdf:type owl:Class ;");

                sb.AppendLine("\trdfs:subClassOf " + defined + " .");
                sb.AppendLine();

                if (docDefined.Length > 0 || docDefined.Length < 0 || docDefined.Aggregation != null)
                {
                    //TODO: possibly add restrictions here

                    //TYPE IfcGloballyUniqueId = STRING(22) FIXED;
                    //END_TYPE;

                    //TYPE IfcIdentifier = STRING(255);
                    //END_TYPE;

                    //TYPE IfcLabel = STRING(255);
                    //END_TYPE;
                }
            }

            return sb.ToString();
        }
Exemplo n.º 19
0
 public string FormatDefined(DocDefined docDefined)
 {
     return(FormatDefinedFull(docDefined, false));
 }
Exemplo n.º 20
0
 public string FormatDefined(DocDefined docDefined)
 {
     return null; // nothing to define
 }
Exemplo n.º 21
0
 public string FormatDefined(DocDefined docDefined)
 {
     return FormatDefinedFull(docDefined, false);
 }
Exemplo n.º 22
0
        public string FormatDefinedFull(DocDefined docDefined, bool fullListing)
        {
            StringBuilder sb = new StringBuilder();

            string defined = ToOwlClass(docDefined.DefinedType);

            if (docDefined.Aggregation != null)
            {
                string aggtype = docDefined.Aggregation.GetAggregation().ToString().ToLower();

                if (docDefined.Aggregation.GetAggregation() == DocAggregationEnum.SET)
                {
                    //IfcPropertySetDefinitionSet

                    sb.AppendLine("ifc:" + docDefined.Name);
                    sb.AppendLine("\trdf:type owl:Class ;");

                    //TODO:: Add (SELECT) parent classes

                    sb.AppendLine("\trdfs:subClassOf ");
                    sb.AppendLine("\t\t[ ");
                    sb.AppendLine("\t\t\trdf:type owl:Restriction ;");
                    sb.AppendLine("\t\t\towl:allValuesFrom " + defined + " ;");
                    sb.AppendLine("\t\t\towl:onProperty expr:hasSet");
                    sb.AppendLine("\t\t] ;");
                    sb.AppendLine("\t" + "rdfs:subClassOf ");
                    sb.AppendLine("\t\t" + "[");
                    sb.AppendLine("\t\t\t" + "rdf:type owl:Restriction ;");
                    sb.AppendLine("\t\t\t" + "owl:minQualifiedCardinality \"" + 1
                                  + "\"^^xsd:nonNegativeInteger ;");
                    sb.AppendLine("\t\t\towl:onProperty expr:hasSet ;");
                    sb.AppendLine("\t\t\t" + "owl:onClass " + defined);
                    sb.AppendLine("\t\t] .");
                    sb.AppendLine();
                }
                else if (docDefined.Aggregation.GetAggregation() == DocAggregationEnum.LIST || docDefined.Aggregation.GetAggregation() == DocAggregationEnum.ARRAY)
                {
                    //Console.Out.WriteLine("defined type --" + docDefined.Aggregation.GetAggregation() + "-- : " + docDefined.Name);

                    int mincard = 0;
                    if (docDefined.Aggregation.AggregationLower != null)
                    {
                        mincard = Int32.Parse(docDefined.Aggregation.AggregationLower);
                    }
                    int maxcard = 0;
                    if (String.IsNullOrEmpty(docDefined.Aggregation.AggregationUpper) ||
                        !Int32.TryParse(docDefined.Aggregation.AggregationUpper, out maxcard))
                    {
                        maxcard = 0;
                    }

                    if (docDefined.Aggregation.GetAggregation() == DocAggregationEnum.ARRAY)
                    {
                        mincard = maxcard - mincard + 1;
                        maxcard = mincard;
                    }

                    sb.AppendLine("ifc:" + docDefined.Name);
                    sb.AppendLine("\trdf:type owl:Class ;");
                    sb.Append("\trdfs:subClassOf " + defined + "_List ");


                    //check for cardinality restrictions and add if available
                    string cards = "";
                    if (docDefined.Aggregation.GetAggregationNestingLower() >= 1)
                    {
                        cards += WriteMinCardRestr(defined + "_List", "hasNext", mincard, false);
                    }
                    if (docDefined.Aggregation.GetAggregationNestingUpper() > 1)
                    {
                        cards += WriteMaxCardRestr(defined + "_EmptyList", "hasNext", maxcard, false);
                    }
                    cards += ".";
                    sb.AppendLine(cards);
                    sb.AppendLine();

                    if (fullListing)
                    {
                        sb.AppendLine(createListClass(defined));
                    }
                }
            }
            else
            {
                sb.AppendLine("ifc:" + docDefined.Name);
                sb.AppendLine("\trdf:type owl:Class ;");

                sb.AppendLine("\trdfs:subClassOf " + defined + " .");
                sb.AppendLine();

                if (docDefined.Length > 0 || docDefined.Length < 0 || docDefined.Aggregation != null)
                {
                    //TODO: possibly add restrictions here

                    //TYPE IfcGloballyUniqueId = STRING(22) FIXED;
                    //END_TYPE;

                    //TYPE IfcIdentifier = STRING(255);
                    //END_TYPE;

                    //TYPE IfcLabel = STRING(255);
                    //END_TYPE;
                }
            }

            return(sb.ToString());
        }
Exemplo n.º 23
0
 public string FormatDefined(DocDefined docDefined)
 {
     return(null); // nothing to define
 }
Exemplo n.º 24
0
        public string FormatDefinitions(DocProject docProject, DocPublication docPublication, Dictionary <string, DocObject> map, Dictionary <DocObject, bool> included)
        {
            // clear containers
            listPropertiesOutput.Clear();
            addedIndividuals.Clear();
            attribInverses.Clear();
            subTypesOfEntity.Clear();

            StringBuilder sb = new StringBuilder();

            string ifcversion = docProject.GetSchemaIdentifier();

            //string ifcns = "http://www.buildingsmart-tech.org/ifcOWL/" + ifcversion;
            //string ifcns = "http://ifcowl.openbimstandards.org/" + ifcversion;
            string ifcns = "http://www.buildingsmart-tech.org/ifc/" + ifcversion;

            // namespace definitions
            sb.AppendLine("@prefix :      <" + ifcns + "#> .");
            sb.AppendLine("@prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#> .");
            sb.AppendLine("@prefix dce:   <http://purl.org/dc/elements/1.1/> .");
            sb.AppendLine("@prefix owl:   <http://www.w3.org/2002/07/owl#> .");
            sb.AppendLine("@prefix xsd:   <http://www.w3.org/2001/XMLSchema#> .");
            sb.AppendLine("@prefix rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .");
            sb.AppendLine("@prefix vann:  <http://purl.org/vocab/vann/> .");
            sb.AppendLine("@prefix list:  <https://w3id.org/list#> .");
            sb.AppendLine("@prefix expr:  <https://w3id.org/express#> .");
            sb.AppendLine("@prefix ifc:   <" + ifcns + "#> .");
            sb.AppendLine("@prefix cc:    <http://creativecommons.org/ns#> .");
            sb.AppendLine("");

            // ontology definition
            sb.AppendLine("<" + ifcns + ">");
            sb.AppendLine("\ta                              owl:Ontology ;");
            sb.AppendLine("\trdfs:comment                   \"Ontology automatically generated from the EXPRESS schema using the IfcDoc functions developed by Pieter Pauwels ([email protected]) and Walter Terkaj ([email protected]) \" ;");
            sb.AppendLine("\tcc:license                     <http://creativecommons.org/licenses/by/3.0/> ;");
            sb.AppendLine("\tdce:contributor                \"Jakob Beetz ([email protected])\" , \"Maria Poveda Villalon ([email protected])\" ;"); // \"Aleksandra Sojic ([email protected])\" ,
            sb.AppendLine("\tdce:creator                    \"Pieter Pauwels ([email protected])\" , \"Walter Terkaj  ([email protected])\" ;");
            sb.AppendLine("\tdce:date                       \"2015/10/02\" ;");
            sb.AppendLine("\tdce:description                \"OWL ontology for the IFC conceptual data schema and exchange file format for Building Information Model (BIM) data\" ;");
            sb.AppendLine("\tdce:identifier                 \"" + ifcversion + "\" ;");
            sb.AppendLine("\tdce:language                   \"en\" ;");
            sb.AppendLine("\tdce:title                      \"" + ifcversion + "\" ;");
            sb.AppendLine("\tvann:preferredNamespacePrefix  \"ifc\" ;");
            sb.AppendLine("\tvann:preferredNamespaceUri     \"" + ifcns + "\" ;");
            sb.AppendLine("\towl:imports                    <https://w3id.org/express> .");
            sb.AppendLine();

            // check which Inverse Attributes must be discarded because of conflicts
            // get subtypes of an entity
            foreach (DocSection docSection in docProject.Sections)
            {
                foreach (DocSchema docSchema in docSection.Schemas)
                {
                    foreach (DocEntity docEntity in docSchema.Entities)
                    {
                        // get supertype/subtype
                        if (docEntity.BaseDefinition != null)
                        {
                            if (!subTypesOfEntity.ContainsKey(docEntity.BaseDefinition))
                            {
                                subTypesOfEntity.Add(docEntity.BaseDefinition, new HashSet <string>());
                            }
                            subTypesOfEntity[docEntity.BaseDefinition].Add(docEntity.Name);
                        }

                        // check attributes
                        foreach (DocAttribute docAttr in docEntity.Attributes)
                        {
                            if (docAttr.Inverse != null)
                            {
                                var key = new Tuple <string, string>(docAttr.Inverse, docAttr.DefinedType);
                                if (!attribInverses.ContainsKey(key))
                                {
                                    attribInverses.Add(key, 1);
                                }
                                else
                                {
                                    attribInverses[key] += 1;
                                }
                            }
                        }
                    }
                }
            }

            // generate definitions
            foreach (DocSection docSection in docProject.Sections)
            {
                foreach (DocSchema docSchema in docSection.Schemas)
                {
                    foreach (DocType docType in docSchema.Types)
                    {
                        bool use = false;
                        included.TryGetValue(docType, out use);

                        if (use)
                        {
                            if (docType is DocDefined)
                            {
                                DocDefined docDefined = (DocDefined)docType;
                                string     text       = this.FormatDefinedFull(docDefined, true);
                                sb.Append(text);
                            }
                            else if (docType is DocSelect)
                            {
                                DocSelect docSelect = (DocSelect)docType;
                                string    text      = this.FormatSelectFull(docSelect, map, included, true);
                                sb.Append(text);
                            }
                            else if (docType is DocEnumeration)
                            {
                                DocEnumeration docEnumeration = (DocEnumeration)docType;
                                string         text           = this.FormatEnumerationFull(docEnumeration, true);
                                sb.Append(text);
                            }
                        }
                    }

                    foreach (DocEntity docEntity in docSchema.Entities)
                    {
                        bool use = false;
                        included.TryGetValue(docEntity, out use);

                        if (use)
                        {
                            string text = this.FormatEntityFull(docEntity, map, included, true);
                            sb.Append(text);
                        }
                    }
                }
            }
            listPropertiesOutput.Clear();
            return(sb.ToString());
        }
Exemplo n.º 25
0
        /// <summary>
        /// Creates or returns emitted type, or NULL if no such type.
        /// </summary>
        /// <param name="map"></param>
        /// <param name="typename"></param>
        /// <returns></returns>
        public Type RegisterType(string strtype)
        {
            // this implementation maps direct and inverse attributes to fields for brevity; a production implementation would use properties as well

            if (strtype == null)
            {
                return(typeof(SEntity));
            }

            Type type = null;

            // resolve standard types
            switch (strtype)
            {
            case "INTEGER":
                type = typeof(long);
                break;

            case "REAL":
            case "NUMBER":
                type = typeof(double);
                break;

            case "BOOLEAN":
            case "LOGICAL":
                type = typeof(bool);
                break;

            case "STRING":
                type = typeof(string);
                break;

            case "BINARY":
            case "BINARY (32)":
                type = typeof(byte[]);
                break;
            }

            if (type != null)
            {
                return(type);
            }

            // check for existing mapped type
            if (this.m_types.TryGetValue(strtype, out type))
            {
                return(type);
            }

            // look up
            DocObject docType = null;

            if (!this.m_definitions.TryGetValue(strtype, out docType))
            {
                return(null);
            }

            string schema = this.m_namespaces[docType.Name];

            // not yet exist: create it
            TypeAttributes attr = TypeAttributes.Public;

            if (docType is DocEntity)
            {
                attr |= TypeAttributes.Class;

                DocEntity docEntity = (DocEntity)docType;
                if (docEntity.IsAbstract())
                {
                    attr |= TypeAttributes.Abstract;
                }

                Type typebase = RegisterType(docEntity.BaseDefinition);

                // calling base class may result in this class getting defined (IFC2x3 schema with IfcBuildingElement), so check again
                if (this.m_types.TryGetValue(strtype, out type))
                {
                    return(type);
                }

                TypeBuilder tb = this.m_module.DefineType(schema + "." + docType.Name, attr, typebase);

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

                // custom attributes (required for JSON serialization)
                ConstructorInfo        conContract           = (typeof(DataContractAttribute).GetConstructor(new Type[] { }));
                PropertyInfo           propContractReference = typeof(DataContractAttribute).GetProperty("IsReference");
                CustomAttributeBuilder cbContract            = new CustomAttributeBuilder(conContract, new object[] { }, new PropertyInfo[] { propContractReference }, new object[] { false }); // consider setting IsReference to true if/when serializers like JSON support such referencing
                tb.SetCustomAttribute(cbContract);

                // interfaces implemented by type (SELECTS)
                foreach (DocDefinition docdef in this.m_definitions.Values)
                {
                    if (docdef is DocSelect)
                    {
                        DocSelect docsel = (DocSelect)docdef;
                        foreach (DocSelectItem dsi in docsel.Selects)
                        {
                            if (strtype.Equals(dsi.Name))
                            {
                                // register
                                Type typeinterface = this.RegisterType(docdef.Name);
                                tb.AddInterfaceImplementation(typeinterface);
                            }
                        }
                    }
                }

                Dictionary <string, FieldInfo> mapField = new Dictionary <string, FieldInfo>();
                this.m_fields.Add(tb, mapField);

                ConstructorInfo conMember = typeof(DataMemberAttribute).GetConstructor(new Type[] { /*typeof(int)*/ });
                ConstructorInfo conLookup = typeof(DataLookupAttribute).GetConstructor(new Type[] { typeof(string) });

                PropertyInfo propMemberOrder = typeof(DataMemberAttribute).GetProperty("Order");

                int order = 0;
                foreach (DocAttribute docAttribute in docEntity.Attributes)
                {
                    // exclude derived attributes
                    if (String.IsNullOrEmpty(docAttribute.Derived))
                    {
                        Type typefield = RegisterType(docAttribute.DefinedType);
                        if (typefield == null)
                        {
                            typefield = typeof(object); // excluded from scope
                        }
                        if (docAttribute.AggregationType != 0)
                        {
                            if (docAttribute.AggregationAttribute != null)
                            {
                                // nested collection, e.g. IfcCartesianPointList3D
                                typefield = typeof(List <>).MakeGenericType(new Type[] { typefield });
                            }

                            typefield = typeof(List <>).MakeGenericType(new Type[] { typefield });
                        }
                        else if (typefield.IsValueType && docAttribute.IsOptional)
                        {
                            typefield = typeof(Nullable <>).MakeGenericType(new Type[] { typefield });
                        }

                        FieldBuilder fb = tb.DefineField(docAttribute.Name, typefield, FieldAttributes.Public); // public for now
                        mapField.Add(docAttribute.Name, fb);

                        if (String.IsNullOrEmpty(docAttribute.Inverse))
                        {
                            // direct attributes are fields marked for serialization
                            //CustomAttributeBuilder cb = new CustomAttributeBuilder(conMember, new object[] { order });
                            CustomAttributeBuilder cb = new CustomAttributeBuilder(conMember, new object[] {}, new PropertyInfo[] { propMemberOrder }, new object[] { order });
                            fb.SetCustomAttribute(cb);
                            order++;
                        }
                        else
                        {
                            // inverse attributes are fields marked for lookup
                            CustomAttributeBuilder cb = new CustomAttributeBuilder(conLookup, new object[] { docAttribute.Inverse });
                            fb.SetCustomAttribute(cb);
                        }
                    }
                }


                // remove from typebuilder
                this.m_types.Remove(strtype);

                type = tb; // avoid circular conditions -- generate type afterwords
            }
            else if (docType is DocSelect)
            {
                attr |= TypeAttributes.Interface | TypeAttributes.Abstract;
                TypeBuilder tb = this.m_module.DefineType(schema + "." + docType.Name, attr);

                // interfaces implemented by type (SELECTS)
                foreach (DocDefinition docdef in this.m_definitions.Values)
                {
                    if (docdef is DocSelect)
                    {
                        DocSelect docsel = (DocSelect)docdef;
                        foreach (DocSelectItem dsi in docsel.Selects)
                        {
                            if (strtype.Equals(dsi.Name))
                            {
                                // register
                                Type typeinterface = this.RegisterType(docdef.Name);
                                tb.AddInterfaceImplementation(typeinterface);
                            }
                        }
                    }
                }

                type = tb.CreateType();
            }
            else if (docType is DocEnumeration)
            {
                DocEnumeration docEnum = (DocEnumeration)docType;
                EnumBuilder    eb      = this.m_module.DefineEnum(schema + "." + docType.Name, TypeAttributes.Public, typeof(int));

                for (int i = 0; i < docEnum.Constants.Count; i++)
                {
                    DocConstant docConst = docEnum.Constants[i];
                    eb.DefineLiteral(docConst.Name, (int)i);
                }

                type = eb.CreateType();
            }
            else if (docType is DocDefined)
            {
                DocDefined docDef = (DocDefined)docType;
                attr |= TypeAttributes.Sealed;

                if (docDef.DefinedType == docDef.Name)
                {
                    return(null);
                }

                TypeBuilder tb = this.m_module.DefineType(schema + "." + docType.Name, attr, typeof(ValueType));

                // interfaces implemented by type (SELECTS)
                foreach (DocDefinition docdef in this.m_definitions.Values)
                {
                    if (docdef is DocSelect)
                    {
                        DocSelect docsel = (DocSelect)docdef;
                        foreach (DocSelectItem dsi in docsel.Selects)
                        {
                            if (strtype.Equals(dsi.Name))
                            {
                                // register
                                Type typeinterface = RegisterType(docdef.Name);
                                tb.AddInterfaceImplementation(typeinterface);
                            }
                        }
                    }
                }

                Type typeliteral = RegisterType(docDef.DefinedType);
                if (typeliteral != null)
                {
                    if (docDef.Aggregation != null && docDef.Aggregation.AggregationType != 0)
                    {
                        typeliteral = typeof(List <>).MakeGenericType(new Type[] { typeliteral });
                    }
                    else
                    {
                        FieldInfo fieldval = typeliteral.GetField("Value");
                        while (fieldval != null)
                        {
                            typeliteral = fieldval.FieldType;
                            fieldval    = typeliteral.GetField("Value");
                        }
                    }

                    FieldBuilder fieldValue = tb.DefineField("Value", typeliteral, FieldAttributes.Public);

                    type = tb.CreateType();

                    Dictionary <string, FieldInfo> mapField = new Dictionary <string, FieldInfo>();
                    mapField.Add("Value", fieldValue);
                    this.m_fields.Add(type, mapField);
                }
            }

            this.m_types.Add(strtype, type);
            return(type);
        }
Exemplo n.º 26
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
                    {
                    }
                }
            }
        }
Exemplo n.º 27
0
        /// <summary>
        /// Creates or returns emitted type, or NULL if no such type.
        /// </summary>
        /// <param name="map"></param>
        /// <param name="typename"></param>
        /// <returns></returns>
        public Type RegisterType(string strtype)
        {
            // this implementation maps direct and inverse attributes to fields for brevity; a production implementation would use properties as well

            if (strtype == null)
            {
                return(typeof(object));
            }

            Type type = null;

            // resolve standard types
            switch (strtype)
            {
            case "INTEGER":
                type = typeof(long);
                break;

            case "REAL":
            case "NUMBER":
                type = typeof(double);
                break;

            case "BOOLEAN":
            case "LOGICAL":
                type = typeof(bool);
                break;

            case "STRING":
                type = typeof(string);
                break;

            case "BINARY":
            case "BINARY (32)":
                type = typeof(byte[]);
                break;
            }

            if (type != null)
            {
                return(type);
            }

            // check for existing mapped type
            if (this.m_types.TryGetValue(strtype, out type))
            {
                return(type);
            }

            // look up
            DocObject docType = null;

            if (!this.m_definitions.TryGetValue(strtype, out docType))
            {
                return(null);
            }

            string schema = this.m_namespaces[docType.Name];

            // not yet exist: create it
            TypeAttributes attr = TypeAttributes.Public;

            if (docType is DocEntity)
            {
                attr |= TypeAttributes.Class;

                DocEntity docEntity = (DocEntity)docType;
                if (docEntity.IsAbstract)
                {
                    attr |= TypeAttributes.Abstract;
                }

                Type typebase = RegisterType(docEntity.BaseDefinition);

                // calling base class may result in this class getting defined (IFC2x3 schema with IfcBuildingElement), so check again
                if (this.m_types.TryGetValue(strtype, out type))
                {
                    return(type);
                }

                TypeBuilder tb = this.m_module.DefineType(this.m_rootnamespace + schema + "." + docType.Name, attr, typebase);

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

                // custom attributes (required for JSON serialization)
                ConstructorInfo        conContract           = (typeof(DataContractAttribute).GetConstructor(new Type[] { }));
                PropertyInfo           propContractReference = typeof(DataContractAttribute).GetProperty("IsReference");
                CustomAttributeBuilder cbContract            = new CustomAttributeBuilder(conContract, new object[] { }, new PropertyInfo[] { propContractReference }, new object[] { false });      // consider setting IsReference to true if/when serializers like JSON support such referencing
                tb.SetCustomAttribute(cbContract);


                string displayname = docType.Name;
                if (displayname != null)
                {
                    ConstructorInfo        conReq = typeof(DisplayNameAttribute).GetConstructor(new Type[] { typeof(string) });
                    CustomAttributeBuilder cabReq = new CustomAttributeBuilder(conReq, new object[] { displayname });
                    tb.SetCustomAttribute(cabReq);
                }

                string description = docType.Documentation;
                if (description != null)
                {
                    ConstructorInfo        conReq = typeof(DescriptionAttribute).GetConstructor(new Type[] { typeof(string) });
                    CustomAttributeBuilder cabReq = new CustomAttributeBuilder(conReq, new object[] { description });
                    tb.SetCustomAttribute(cabReq);
                }


                // interfaces implemented by type (SELECTS)
                foreach (DocDefinition docdef in this.m_definitions.Values)
                {
                    if (docdef is DocSelect)
                    {
                        DocSelect docsel = (DocSelect)docdef;
                        foreach (DocSelectItem dsi in docsel.Selects)
                        {
                            if (strtype.Equals(dsi.Name))
                            {
                                // register
                                Type typeinterface = this.RegisterType(docdef.Name);
                                tb.AddInterfaceImplementation(typeinterface);
                            }
                        }
                    }
                }

                Dictionary <string, FieldInfo> mapField = new Dictionary <string, FieldInfo>();
                this.m_fields.Add(tb, mapField);

                ConstructorInfo conMember  = typeof(DataMemberAttribute).GetConstructor(new Type[] { /*typeof(int)*/ });
                ConstructorInfo conInverse = typeof(InversePropertyAttribute).GetConstructor(new Type[] { typeof(string) });

                PropertyInfo propMemberOrder = typeof(DataMemberAttribute).GetProperty("Order");

                int order = 0;
                foreach (DocAttribute docAttribute in docEntity.Attributes)
                {
                    DocObject docRef = null;
                    if (docAttribute.DefinedType != null)
                    {
                        this.m_definitions.TryGetValue(docAttribute.DefinedType, out docRef);
                    }

                    // exclude derived attributes
                    if (String.IsNullOrEmpty(docAttribute.Derived))
                    {
                        Type typefield = RegisterType(docAttribute.DefinedType);
                        if (typefield == null)
                        {
                            typefield = typeof(object);                             // excluded from scope
                        }
                        if (docAttribute.AggregationType != 0)
                        {
                            if (docAttribute.AggregationAttribute != null)
                            {
                                // list of list
                                switch (docAttribute.AggregationAttribute.GetAggregation())
                                {
                                case DocAggregationEnum.SET:
                                    typefield = typeof(ISet <>).MakeGenericType(new Type[] { typefield });
                                    break;

                                case DocAggregationEnum.LIST:
                                default:
                                    typefield = typeof(IList <>).MakeGenericType(new Type[] { typefield });
                                    break;
                                }
                            }

                            switch (docAttribute.GetAggregation())
                            {
                            case DocAggregationEnum.SET:
                                typefield = typeof(ISet <>).MakeGenericType(new Type[] { typefield });
                                break;

                            case DocAggregationEnum.LIST:
                            default:
                                typefield = typeof(IList <>).MakeGenericType(new Type[] { typefield });
                                break;
                            }
                        }
                        else if (typefield.IsValueType && docAttribute.IsOptional)
                        {
                            typefield = typeof(Nullable <>).MakeGenericType(new Type[] { typefield });
                        }

                        FieldBuilder fb = tb.DefineField("_" + docAttribute.Name, typefield, FieldAttributes.Private);
                        mapField.Add(docAttribute.Name, fb);


                        PropertyBuilder pb = RegisterProperty(docAttribute.Name, typefield, tb, fb);


                        if (String.IsNullOrEmpty(docAttribute.Inverse))
                        {
                            // direct attributes are fields marked for serialization
                            CustomAttributeBuilder cb = new CustomAttributeBuilder(conMember, new object[] { }, new PropertyInfo[] { propMemberOrder }, new object[] { order });
                            pb.SetCustomAttribute(cb);
                            order++;

                            // mark if required
                            if (!docAttribute.IsOptional)
                            {
                                ConstructorInfo        conReq = typeof(RequiredAttribute).GetConstructor(new Type[] { });
                                CustomAttributeBuilder cabReq = new CustomAttributeBuilder(conReq, new object[] { });
                                pb.SetCustomAttribute(cabReq);
                            }
                        }
                        else
                        {
                            // inverse attributes are fields marked for lookup
                            CustomAttributeBuilder cb = new CustomAttributeBuilder(conInverse, new object[] { docAttribute.Inverse });
                            pb.SetCustomAttribute(cb);
                        }

                        // XML
                        ConstructorInfo        conXSD;
                        CustomAttributeBuilder cabXSD;
                        if (docAttribute.AggregationAttribute == null && (docRef is DocDefined || docRef is DocEnumeration))
                        {
                            conXSD = typeof(XmlAttributeAttribute).GetConstructor(new Type[] { });
                            cabXSD = new CustomAttributeBuilder(conXSD, new object[] { });
                            pb.SetCustomAttribute(cabXSD);
                        }
                        else
                        {
                            switch (docAttribute.XsdFormat)
                            {
                            case DocXsdFormatEnum.Element:
                                conXSD = typeof(XmlElementAttribute).GetConstructor(new Type[] { typeof(string) });
                                cabXSD = new CustomAttributeBuilder(conXSD, new object[] { docAttribute.DefinedType });
                                pb.SetCustomAttribute(cabXSD);
                                break;

                            case DocXsdFormatEnum.Attribute:
                                conXSD = typeof(XmlElementAttribute).GetConstructor(new Type[] { });
                                cabXSD = new CustomAttributeBuilder(conXSD, new object[] { });
                                pb.SetCustomAttribute(cabXSD);
                                break;

                            case DocXsdFormatEnum.Hidden:
                                conXSD = typeof(XmlIgnoreAttribute).GetConstructor(new Type[] { });
                                cabXSD = new CustomAttributeBuilder(conXSD, new object[] { });
                                pb.SetCustomAttribute(cabXSD);
                                break;
                            }
                        }

                        // documentation
                        string fielddisplayname = docAttribute.Name;
                        if (displayname != null)
                        {
                            ConstructorInfo        conReq = typeof(DisplayNameAttribute).GetConstructor(new Type[] { typeof(string) });
                            CustomAttributeBuilder cabReq = new CustomAttributeBuilder(conReq, new object[] { fielddisplayname });
                            pb.SetCustomAttribute(cabReq);
                        }

                        string fielddescription = docAttribute.Documentation;
                        if (description != null)
                        {
                            ConstructorInfo        conReq = typeof(DescriptionAttribute).GetConstructor(new Type[] { typeof(string) });
                            CustomAttributeBuilder cabReq = new CustomAttributeBuilder(conReq, new object[] { fielddescription });
                            pb.SetCustomAttribute(cabReq);
                        }
                    }
                }


                // remove from typebuilder
                this.m_types.Remove(strtype);

                type = tb;                 // avoid circular conditions -- generate type afterwords
            }
            else if (docType is DocSelect)
            {
                attr |= TypeAttributes.Interface | TypeAttributes.Abstract;
                TypeBuilder tb = this.m_module.DefineType(this.m_rootnamespace + schema + "." + docType.Name, attr);

                // interfaces implemented by type (SELECTS)
                foreach (DocDefinition docdef in this.m_definitions.Values)
                {
                    if (docdef is DocSelect)
                    {
                        DocSelect docsel = (DocSelect)docdef;
                        foreach (DocSelectItem dsi in docsel.Selects)
                        {
                            if (strtype.Equals(dsi.Name))
                            {
                                // register
                                Type typeinterface = this.RegisterType(docdef.Name);
                                tb.AddInterfaceImplementation(typeinterface);
                            }
                        }
                    }
                }

                type = tb.CreateType();
            }
            else if (docType is DocEnumeration)
            {
                DocEnumeration docEnum = (DocEnumeration)docType;
                EnumBuilder    eb      = this.m_module.DefineEnum(schema + "." + docType.Name, TypeAttributes.Public, typeof(int));

                for (int i = 0; i < docEnum.Constants.Count; i++)
                {
                    DocConstant  docConst = docEnum.Constants[i];
                    FieldBuilder fb       = eb.DefineLiteral(docConst.Name, (int)i);

                    foreach (DocLocalization docLocal in docConst.Localization)
                    {
                        CustomAttributeBuilder cab = docLocal.ToCustomAttributeBuilder();
                        if (cab != null)
                        {
                            fb.SetCustomAttribute(cab);
                        }
                    }
                }

                type = eb.CreateType();
            }
            else if (docType is DocDefined)
            {
                DocDefined docDef = (DocDefined)docType;
                attr |= TypeAttributes.Sealed;

                if (docDef.DefinedType == docDef.Name)
                {
                    return(null);
                }

                TypeBuilder tb = this.m_module.DefineType(this.m_rootnamespace + schema + "." + docType.Name, attr, typeof(ValueType));

                // interfaces implemented by type (SELECTS)
                foreach (DocDefinition docdef in this.m_definitions.Values)
                {
                    if (docdef is DocSelect)
                    {
                        DocSelect docsel = (DocSelect)docdef;
                        foreach (DocSelectItem dsi in docsel.Selects)
                        {
                            if (strtype.Equals(dsi.Name))
                            {
                                // register
                                Type typeinterface = RegisterType(docdef.Name);
                                tb.AddInterfaceImplementation(typeinterface);
                            }
                        }
                    }
                }

                Type typeliteral = RegisterType(docDef.DefinedType);
                if (typeliteral != null)
                {
                    if (docDef.Aggregation != null && docDef.Aggregation.AggregationType != 0)
                    {
                        switch (docDef.Aggregation.GetAggregation())
                        {
                        case DocAggregationEnum.SET:
                            typeliteral = typeof(ISet <>).MakeGenericType(new Type[] { typeliteral });
                            break;

                        case DocAggregationEnum.LIST:
                        default:
                            typeliteral = typeof(IList <>).MakeGenericType(new Type[] { typeliteral });
                            break;
                        }
                    }
                    else
                    {
#if false // now use direct type -- don't recurse
                        FieldInfo fieldval = typeliteral.GetField("Value");
                        while (fieldval != null)
                        {
                            typeliteral = fieldval.FieldType;
                            fieldval    = typeliteral.GetField("Value");
                        }
#endif
                    }

                    FieldBuilder fieldValue = tb.DefineField("Value", typeliteral, FieldAttributes.Public);

                    RegisterProperty("Value", typeliteral, tb, fieldValue);



                    type = tb.CreateType();

                    Dictionary <string, FieldInfo> mapField = new Dictionary <string, FieldInfo>();
                    mapField.Add("Value", fieldValue);
                    this.m_fields.Add(type, mapField);
                }
            }

            this.m_types.Add(strtype, type);
            return(type);
        }
Exemplo n.º 28
0
 private void toolStripMenuItemInsertDefined_Click(object sender, EventArgs e)
 {
     TreeNode tnParent = this.treeView.SelectedNode;
     DocSchema docSchema = (DocSchema)tnParent.Tag;
     DocType docType = new DocDefined();
     InitDefinition(docType);
     docSchema.Types.Add(docType);
     this.treeView.SelectedNode = this.LoadNode(tnParent.Nodes[0], docType, null, true);
     toolStripMenuItemEditRename_Click(this, e);
 }
Exemplo n.º 29
0
 public static string FormatDefined(DocDefined docDefined, Dictionary <string, DocObject> map)
 {
     return(FormatDefinedSimple(docDefined) + FormatTypeWrapper(docDefined, map));
 }
Exemplo n.º 30
0
        internal static void ImportXsdSimple(IfcDoc.Schema.XSD.simpleType simple, DocSchema docSchema, string name)
        {
            string thename = simple.name;
            if (simple.name == null)
            {
                thename = name;
            }

            if (simple.restriction != null && simple.restriction.enumeration.Count > 0)
            {
                DocEnumeration docEnum = new DocEnumeration();
                docSchema.Types.Add(docEnum);
                docEnum.Name = thename;
                docEnum.Documentation = ImportXsdAnnotation(simple.annotation);
                foreach (IfcDoc.Schema.XSD.enumeration en in simple.restriction.enumeration)
                {
                    DocConstant docConst = new DocConstant();
                    docConst.Name = en.value;
                    docConst.Documentation = ImportXsdAnnotation(en.annotation);

                    docEnum.Constants.Add(docConst);
                }
            }
            else
            {
                DocDefined docDef = new DocDefined();
                docDef.Name = thename;
                docDef.Documentation = ImportXsdAnnotation(simple.annotation);
                if (simple.restriction != null)
                {
                    docDef.DefinedType = ImportXsdType(simple.restriction.basetype);
                }
                docSchema.Types.Add(docDef);
            }
        }
Exemplo n.º 31
0
        public void Load()
        {
            svg s = null;

            using (FormatXML format = new FormatXML(this.m_filename, typeof(svg), "http://www.w3.org/2000/svg"))
            {
                format.Load();
                s = format.Instance as svg;
            }

            if (s == null)
            {
                return;
            }

            // apply diagram to existing schema elements
            foreach (g group in s.g)
            {
                // primitive
                DocDefinition docDef = null;
                switch (group.id)
                {
                case "INTEGER":
                case "REAL":
                case "BOOLEAN":
                case "LOGICAL":
                case "STRING":
                case "BINARY":
                    docDef      = new DocPrimitive();
                    docDef.Name = group.id;
                    m_schema.Primitives.Add((DocPrimitive)docDef);
                    break;

                default:
                    docDef = this.m_schema.GetDefinition(group.id);
                    break;
                }

                if (docDef != null)
                {
                    docDef.DiagramRectangle = LoadRectangle(group);

                    // attributes, supertype...
                    if (docDef is DocEntity)
                    {
                        DocEntity docEnt = (DocEntity)docDef;
                        LoadTree(group, docEnt.Tree);

                        foreach (g subgroup in group.groups)
                        {
                            foreach (DocAttribute docAttr in docEnt.Attributes)
                            {
                                if (docAttr.Name.Equals(subgroup.id))
                                {
                                    LoadLine(subgroup, docAttr.DiagramLine);

                                    if (subgroup.text.Count == 1)
                                    {
                                        double ax = Double.Parse(subgroup.text[0].x) / CtlExpressG.Factor;
                                        double ay = Double.Parse(subgroup.text[0].y) / CtlExpressG.Factor;

                                        docAttr.DiagramLabel   = new DocRectangle();
                                        docAttr.DiagramLabel.X = ax;
                                        docAttr.DiagramLabel.Y = ay;
                                    }

                                    break;
                                }
                            }
                        }

                        // base type???
                    }
                    else if (docDef is DocDefined)
                    {
                        DocDefined docDefined = (DocDefined)docDef;
                        LoadLine(group, docDefined.DiagramLine);
                    }
                    else if (docDef is DocSelect)
                    {
                        DocSelect docSelect = (DocSelect)docDef;
                        LoadTree(group, docSelect.Tree);
                    }
                }
                else
                {
                    // schema ref
                    DocSchema docTargetSchema = this.m_project.GetSchema(group.id);
                    if (docTargetSchema != null)
                    {
                        DocSchemaRef docSchemaRef = new DocSchemaRef();
                        docSchemaRef.Name = group.id;
                        this.m_schema.SchemaRefs.Add(docSchemaRef);

                        foreach (g subgroup in group.groups)
                        {
                            DocDefinition docTargetDef = docTargetSchema.GetDefinition(subgroup.id);
                            if (docTargetDef != null)
                            {
                                DocDefinitionRef docDefRef = new DocDefinitionRef();
                                docDefRef.Name = subgroup.id;
                                docSchemaRef.Definitions.Add(docDefRef);
                                docDefRef.DiagramRectangle = LoadRectangle(subgroup);

                                LoadTree(subgroup, docDefRef.Tree);
                            }
                        }
                    }
                    else
                    {
                        // primitive?

                        // page targets
                        DocPageTarget docPageTarget = new DocPageTarget();
                        docPageTarget.Name = group.id;
                        this.m_schema.PageTargets.Add(docPageTarget);
                        docPageTarget.DiagramRectangle = LoadRectangle(group);
                        //...docPageTarget.Definition =
                        LoadLine(group, docPageTarget.DiagramLine);

                        foreach (g subgroup in group.groups)
                        {
                            DocPageSource docPageSource = new DocPageSource();
                            docPageSource.Name = subgroup.id;
                            docPageTarget.Sources.Add(docPageSource);
                            docPageSource.DiagramRectangle = LoadRectangle(subgroup);
                        }
                    }
                }
            }
        }
Exemplo n.º 32
0
        public static void LoadAssembly(DocProject project, Assembly assem)
        {
            // look through classes of assembly
            foreach (Type t in assem.GetTypes())
            {
                if (t.Namespace != null)
                {
                    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.SortSection();
                    }

                    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)
                    {
                        PropertyInfo[] fields = t.GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);
                        if (fields.Length > 0)
                        {
                            Type typeField = fields[0].PropertyType;

                            DocDefined docDefined = new DocDefined();
                            docSchema.Types.Add(docDefined);
                            docDef = docDefined;
                            docDefined.DefinedType = FormatCSC.GetExpressType(typeField);

                            if (typeField.IsGenericType)
                            {
                                Type typeGeneric = typeField.GetGenericTypeDefinition();
                                typeField = typeField.GetGenericArguments()[0];
                                if (typeGeneric == typeof(ISet <>) ||
                                    typeGeneric == typeof(HashSet <>))
                                {
                                    docDefined.Aggregation = new DocAttribute();
                                    docDefined.Aggregation.AggregationType = (int)DocAggregationEnum.SET;
                                }
                                else if (typeGeneric == typeof(IList <>) ||
                                         typeGeneric == typeof(List <>))
                                {
                                    docDefined.Aggregation = new DocAttribute();
                                    docDefined.Aggregation.AggregationType = (int)DocAggregationEnum.LIST;
                                }
                            }

                            MaxLengthAttribute mxa = (MaxLengthAttribute)fields[0].GetCustomAttribute(typeof(MaxLengthAttribute));
                            if (mxa != null)
                            {
                                docDefined.Length = mxa.Length;
                            }
                        }
                    }
                    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 != null)
                        {
                            if (t.BaseType != typeof(object) && t.BaseType.Name != "SEntity")                             // back-compat for reflecting on IfcDoc types to generate Express
                            {
                                docEntity.BaseDefinition = t.BaseType.Name;
                            }
                        }

                        docEntity.IsAbstract = t.IsAbstract;

                        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.Public | BindingFlags.DeclaredOnly);
                        foreach (PropertyInfo field in fields)
                        {
                            DocAttribute docAttr = new DocAttribute();
                            docAttr.Name = field.Name;

                            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 <>) ||
                                         typeGeneric == typeof(HashSet <>))
                                {
                                    docAttr.AggregationType = (int)DocAggregationEnum.SET;
                                }
                                else if (typeGeneric == typeof(IList <>) ||
                                         typeGeneric == typeof(List <>))
                                {
                                    docAttr.AggregationType = (int)DocAggregationEnum.LIST;
                                }
                            }

                            // primitives
                            docAttr.DefinedType = FormatCSC.GetExpressType(typeField);

                            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();
                            }

                            DescriptionAttribute da = (DescriptionAttribute)field.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
#if false
                        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);
                            }
                        }
#endif
                    }

                    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();

                Type[] typeInherit = null;
                if (t.BaseType != null)
                {
                    typeInherit = t.BaseType.GetInterfaces();
                }

                if (typeInterfaces.Length > 0)
                {
                    foreach (Type typeI in typeInterfaces)
                    {
                        if (typeInherit == null || !typeInherit.Contains <Type>(typeI))
                        {
                            DocSelect docSelect = project.GetDefinition(typeI.Name) as DocSelect;
                            if (docSelect != null)
                            {
                                DocSelectItem docItem = new DocSelectItem();
                                docItem.Name = t.Name;
                                docSelect.Selects.Add(docItem);
                            }
                        }
                    }
                }
            }
        }