예제 #1
0
 public XmlEntityInstance(XmlEntityType description)
 {
     Description = description;
     foreach (var item in description)
     {
         parameters.Add(new Parameter(item));
     }
     description.ParameterAdded += OnParameterAdded;
 }
예제 #2
0
        public bool AddEntityTypes(XmlEntityType xmlEntityTypes)
        {
            var description = entityTypes
                              .Where(x => x.Name == xmlEntityTypes.Name);

            if (description.Count() == 0)
            {
                entityTypes.Add(xmlEntityTypes);
                return(true);
            }
            return(false);
        }
예제 #3
0
        public static XmlFile Parse(XElement xElement)
        {
            if (xElement == null)
            {
                throw new NullReferenceException();
            }

            XmlFile xml      = new XmlFile();
            var     entities = new List <XmlEntityInstance>();

            foreach (var item in xElement.Descendants("Description"))
            {
                xml.AddEntityTypes((XmlEntityType.Parse(item)));
            }

            foreach (var item in xElement.Descendants("Entity"))
            {
                string name        = item.Attribute("Name").Value;
                var    description = xml.entityTypes
                                     .Where(x => x.Name == name)
                                     .First();
                XmlEntityInstance xmlEntity = new XmlEntityInstance(description);

                foreach (var parameter in description)
                {
                    var value = item.Element(parameter.Name).Value;
                    switch (parameter.ValueType)
                    {
                    case XmlParameterValueType.Double:
                        xmlEntity.SetParameterValue(parameter.Name, double.Parse(value));
                        break;

                    case XmlParameterValueType.Integer:
                        xmlEntity.SetParameterValue(parameter.Name, int.Parse(value));
                        break;

                    case XmlParameterValueType.String:
                        xmlEntity.SetParameterValue(parameter.Name, value);
                        break;
                    }
                }
                xml.AddEntityInstance(xmlEntity);
            }
            return(xml);
        }