示例#1
0
        private Type CreateTypeFromConcept(IfdConcept ifdConcept)
        {
            Type type = null;

            if (m_mapDynamicTypes.TryGetValue(ifdConcept.guid, out type))
            {
                return(type);
            }

            // get base definition if any
            Type   typeBase = null;
            string ns       = null;
            IList <IfdConceptInRelationship> listHost = GetRelatedConcepts(ifdConcept.guid, false);

            foreach (IfdConceptInRelationship rel in listHost)
            {
                IfdRelationshipTypeEnum reltype;
                if (Enum.TryParse <IfdRelationshipTypeEnum>(rel.relationshipType, out reltype))
                {
                    switch (reltype)
                    {
                    case IfdRelationshipTypeEnum.SPECIALIZES:     // base type
                        typeBase = CreateTypeFromConcept(rel);
                        break;

                    case IfdRelationshipTypeEnum.GROUPS:     // namespace
                        ns = CreateNamespaceFromConcept(rel);
                        break;
                    }
                    //rel.guid
                }
            }

            // construct a type
            TypeAttributes attr = TypeAttributes.Public | TypeAttributes.Class;
            // abstract...

            string typename = GetConceptIdentifier(ifdConcept);

            try
            {
                TypeBuilder tb = this.m_module.DefineType(ns + "." + typename, attr, typeBase);

                // custom attributes, e.g. guid
                if (ifdConcept.guid != null)
                {
                    Guid guid = GlobalId.Parse(ifdConcept.guid);

                    ConstructorInfo        conReq = typeof(GuidAttribute).GetConstructor(new Type[] { typeof(string) });
                    CustomAttributeBuilder cabReq = new CustomAttributeBuilder(conReq, new object[] { guid.ToString() });
                    tb.SetCustomAttribute(cabReq);
                }

                string displayname = GetConceptName(ifdConcept);
                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 = GetConceptDescription(ifdConcept);
                if (description != null)
                {
                    ConstructorInfo        conReq = typeof(DescriptionAttribute).GetConstructor(new Type[] { typeof(string) });
                    CustomAttributeBuilder cabReq = new CustomAttributeBuilder(conReq, new object[] { description });
                    tb.SetCustomAttribute(cabReq);
                }

                // properties
                IList <IfdConceptInRelationship> listItem = GetRelatedConcepts(ifdConcept.guid, true);
                foreach (IfdConceptInRelationship rel in listItem)
                {
                    IfdRelationshipTypeEnum reltype;
                    if (Enum.TryParse <IfdRelationshipTypeEnum>(rel.relationshipType, out reltype))
                    {
                        switch (reltype)
                        {
                        case IfdRelationshipTypeEnum.ASSIGNS_PROPERTIES:     //...
                            break;
                        }
                    }
                }

                type = tb.CreateType();
                this.m_mapDynamicTypes.Add(ifdConcept.guid, type);
                return(type);
            }
            catch
            {
                return(null); // duplicate??
            }
        }
示例#2
0
        public void Load()
        {
            // prepare map
            Dictionary <string, DocPropertySet> map = new Dictionary <string, DocPropertySet>();

            foreach (DocSection docSection in this.m_project.Sections)
            {
                foreach (DocSchema docSchema in docSection.Schemas)
                {
                    foreach (DocPropertySet docEntity in docSchema.PropertySets)
                    {
                        map.Add(docEntity.Name, docEntity);
                    }
                }
            }

            // use commas for simplicity
            using (System.IO.StreamReader reader = new System.IO.StreamReader(this.m_filename))
            {
                string headerline = reader.ReadLine(); // blank

                // now rows
                while (!reader.EndOfStream)
                {
                    string rowdata = reader.ReadLine();

                    string[] rowcells = rowdata.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

                    if (rowcells.Length > 1)
                    {
                        DocPropertySet docObj  = null;
                        string         ifdguid = rowcells[0];
                        string         ifdname = rowcells[1];

                        Guid guid = GlobalId.Parse(ifdguid);

                        string[] nameparts = ifdname.Split('.');
                        string   psetname  = nameparts[0].Trim();
                        string   propname  = null;
                        if (nameparts.Length == 2)
                        {
                            propname = nameparts[1];
                        }

                        if (map.TryGetValue(psetname, out docObj))
                        {
                            if (propname != null)
                            {
                                foreach (DocProperty docprop in docObj.Properties)
                                {
                                    if (propname.Equals(docprop.Name))
                                    {
                                        // found it
                                        docprop.Uuid = guid;
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                docObj.Uuid = guid;
                            }
                        }
                        else
                        {
                            System.Diagnostics.Debug.WriteLine("IFD (not found): " + psetname);
                        }
                    }
                }
            }
        }