示例#1
0
        public void Process(ReferenceMetaData reference)
        {
            Entity entity = _Model[reference.ParentType];

            if (entity == null)
            {
                entity = new Entity(reference.ParentType);
                _Model.Entities.Add(entity.Type, entity);
            }

            Reference mref = _Model.GetReference(reference.ParentType, reference.Name);

            if (mref != null && reference.Ignore)
            {
                entity.References.Remove(mref.Name);
                _Model.ClearReferenceCache();
                return;
            }

            if (mref == null)
            {
                mref = new Reference(reference.Name, reference.ParentType, reference.ChildType, reference.IsComposition, reference.FromMany, reference.ToMany);
                entity.References.Add(mref.Name, mref);
            }

            // To override a previous value
            if (mref.IsComposition != reference.IsComposition)
                mref.IsComposition = reference.IsComposition;

            if (mref.FromMany != reference.FromMany)
                mref.FromMany = reference.FromMany;

            if (mref.ToMany != reference.ToMany)
                mref.ToMany = reference.ToMany;

            if (mref.ChildType != reference.ChildType)
                mref.ChildType = reference.ChildType;
        }
示例#2
0
        public static IMetaData[] FromMetaDataFile(XmlReader inStream)
        {
            List<IMetaData> metadata = new List<IMetaData>(100);
            XmlDocument xDoc = new XmlDocument();
            xDoc.Load(inStream);

            // The reason for needing a prefix for the default namespace in our XPath query is due to the fact that in XPath, there is no concept of a default namespace.
            XmlNamespaceManager nsm = new XmlNamespaceManager(xDoc.NameTable);
            nsm.AddNamespace("ns", "http://euss.evaluant.com/schemas/MetaDataModel.xsd");

            foreach (XmlNode n in xDoc.SelectNodes("//ns:Entity", nsm))
            {
                TypeMetaData tmd = new TypeMetaData(n.Attributes["type"].Value, n.Attributes["inherit"] != null ? n.Attributes["inherit"].Value : String.Empty, false);
                tmd.Ignore = n.Attributes["ignore"] != null ? bool.Parse(n.Attributes["ignore"].Value) : false;
                metadata.Add(tmd);

                if (n.Attributes["implement"] != null)
                {
                    foreach (string intf in n.Attributes["implement"].Value.Split(','))
                    {
                        TypeMetaData tmdi = new TypeMetaData(n.Attributes["type"].Value, intf.Trim(), true);
                        metadata.Add(tmd);
                    }
                }

                // Processing sub nodes in the same order as they are declared

                foreach (XmlNode s in n.SelectNodes("ns:*", nsm))
                {
                    switch (s.Name)
                    {
                        case "Attribute":
                            string typeName = TypeResolver.ConvertNamespaceEussToDomain(s.Attributes["type"].Value);

                            Type type = TypeResolver.GetType(typeName);

                            if (type == null)
                                throw new TypeLoadException(String.Concat("The type ", typeName, " could not be found. You should register the assembly containing it."));

                            PropertyMetaData pm = new PropertyMetaData(s.ParentNode.Attributes["type"].Value, s.Attributes["name"].Value, type, s.Attributes["idId"] == null ? false : Convert.ToBoolean(s.Attributes["isId"].Value));

                            if (s.Attributes["values"] != null)
                                pm.Values = s.Attributes["values"].Value.Split();

                            pm.Ignore = s.Attributes["ignore"] != null ? bool.Parse(s.Attributes["ignore"].Value) : false;

                            metadata.Add(pm);
                            break;

                        case "Reference":

                            // fromMany, toMany and composition are false if not specified
                            bool composition = s.Attributes["composition"] == null ? false : bool.Parse(s.Attributes["composition"].Value);
                            bool fromMany = s.Attributes["fromMany"] == null ? false : bool.Parse(s.Attributes["fromMany"].Value);
                            bool toMany = s.Attributes["toMany"] == null ? false : bool.Parse(s.Attributes["toMany"].Value);
                            ReferenceMetaData rmd = new ReferenceMetaData(s.ParentNode.Attributes["type"].Value, s.Attributes["name"].Value, s.Attributes["type"].Value, composition, fromMany, toMany);

                            rmd.Ignore = s.Attributes["ignore"] != null ? bool.Parse(s.Attributes["ignore"].Value) : false;
                            metadata.Add(rmd);
                            break;
                    }

                }
            }
            return metadata.ToArray();
        }