コード例 #1
0
ファイル: ModelMetaDataVisitor.cs プロジェクト: npenin/uss
        void Evaluant.Uss.MetaData.IMetaDataVisitor.Process(TypeMetaData type)
        {
            Entity entity = _Model[type.Name, false];

            if (type.Ignore)
            {
                if (entity != null)
                {
                    _Model.Entities.Remove(entity.Type);
                }

                return;
            }

            if (entity == null)
            {
                entity = new Entity(type.Name);
                entity.Model = _Model;
                if (!type.Ignore)
                    _Model.Entities.Add(entity.Type, entity);
            }

            if (type.IsInterface)
            {
                if (entity.Implement != null && entity.Implement != String.Empty)
                    entity.Implement += ",";

                entity.Implement += type.ParentName;

                Entity parent = _Model[type.ParentName];

                if (parent == null)
                {
                    parent = new Entity(type.ParentName);
                    _Model.Entities.Add(type.ParentName, parent);
                }

                parent.IsInterface = true;
            }
            else
            {
                // To override a previous value
                if (type.ParentName != String.Empty && type.ParentName != null && entity.Inherit != type.ParentName)
                    entity.Inherit = type.ParentName;
            }


        }
コード例 #2
0
ファイル: MetaDataFactory.cs プロジェクト: npenin/uss
        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();
        }