public static EntityConfiguration Create(XmlNode node)
        {
            //XmlReaderSettings sett = new XmlReaderSettings();
            //sett.IgnoreComments = true;
            //sett.IgnoreProcessingInstructions = true;
            //sett.IgnoreWhitespace = true;

            //XmlReader rdr = XmlReader.Create(reader, sett);

            //XmlDocument doc = new XmlDocument();
            //doc.Load(rdr);

            //if ( doc.ChildNodes.Count != 1 )
            //{
            //    EntityConfigurationError err = new EntityConfigurationError(ErrorType.InvalidXmlDocument, "The xml doceument must only one node describing an entity");
            //    return null;
            //}
            //XmlNode node = doc.ChildNodes[0];

            EntityConfiguration entity = new EntityConfiguration();

            entity._name = node.Attributes["name"].Value;

            foreach (XmlNode n in node.ChildNodes)
            {
                if (n.Name == "Usings")
                {
                    foreach (XmlNode nn in n.ChildNodes)
                    {
                        if (nn.Name == "Using")
                        {
                            entity._usings.Add(nn.InnerXml);
                        }
                        else
                        {
                            EntityConfigurationError err = new EntityConfigurationError(ErrorType.UnexpectedNode, string.Format("Node 'Using' expected but '{0}' found", node.FirstChild.Name));
                            return(null);
                        }
                    }
                }
                else if (n.Name == "Namespace")
                {
                    entity._namespace = n.InnerXml;
                }
                else if (n.Name == "Attributes")
                {
                    foreach (XmlNode nn in n.ChildNodes)
                    {
                        EntityAttributeConfiguration attribute = EntityAttributeConfiguration.Create(nn);
                        if (nn != null)
                        {
                            entity._attributes.Add(attribute.Name, attribute);
                        }
                        else
                        {
                            EntityConfigurationError err = new EntityConfigurationError(ErrorType.InvalidStructural, "The 'Attribute' object was not build correctly");
                            return(null);
                        }
                    }
                }
                else if (n.Name == "Properties")
                {
                    foreach (XmlNode nn in n.ChildNodes)
                    {
                        EntityPropertyConfiguration property = EntityPropertyConfiguration.Create(nn);
                        if (property != null)
                        {
                            entity._properties.Add(property.Name, property);
                        }
                        else
                        {
                            EntityConfigurationError err = new EntityConfigurationError(ErrorType.InvalidStructural, "The 'Property' object was not build correctly");
                            return(null);
                        }
                    }
                }
                else
                {
                    EntityConfigurationError err = new EntityConfigurationError(ErrorType.UnexpectedNode, string.Format("Node 'Usings', 'Namespace', 'Attributes' or 'Properties' expected but '{0}' found", node.FirstChild.Name));
                    return(null);
                }
            }

            return(entity);
        }
Beispiel #2
0
        public static EntityPropertyConfiguration Create(XmlNode node)
        {
            EntityPropertyConfiguration property = new EntityPropertyConfiguration();

            if (node.Name != "Property")
            {
                EntityConfigurationError err = new EntityConfigurationError(ErrorType.InvalidXmlDocument, "A start element expected");
                return(null);
            }

            property._name = node.Attributes["name"].InnerXml;

            //if ( node.FirstChild.Name != "Type" )
            //{
            //    EntityConfigurationError err = new EntityConfigurationError(ErrorType.InvalidXmlDocument, string.Format("Node 'Type' expected but {0} found", node.FirstChild.Name));
            //    return null;
            //}
            //property._typeName = node.FirstChild.InnerXml;
            //if ( property.TypeName.StartsWith("List") )
            //    property._isList = true;
            //else
            //    property._isList = false;

            if (node.ChildNodes.Count > 1)
            {
                foreach (XmlNode n in node.ChildNodes)
                {
                    if (n.Name == "Type")
                    {
                        continue;
                    }
                    else if (n.Name == "Attributes")
                    {
                        foreach (XmlNode childNode in n.ChildNodes)
                        {
                            EntityAttributeConfiguration attr = EntityAttributeConfiguration.Create(childNode);
                            if (attr != null)
                            {
                                property._attributes.Add(attr.Name, attr);
                            }
                            else
                            {
                                EntityConfigurationError err = new EntityConfigurationError(ErrorType.InvalidStructural, "The 'Attribute' object was not build correctly");
                                return(null);
                            }
                        }
                    }
                    else if (n.Name == "get")
                    {
                        property._getMethod = n.InnerXml;
                    }
                    else if (n.Name == "set")
                    {
                        property._setMethod = n.InnerXml;
                    }
                    else
                    {
                        EntityConfigurationError err = new EntityConfigurationError(ErrorType.UnexpectedNode, string.Format("Node '{0}' is unexpected", n.Name));
                        return(null);
                    }
                }
            }

            return(property);
        }