Exemplo n.º 1
0
        // __ Impl _______________________________________________________

        private static ObjectData GetObjectFromXml(XDocument xmlDocument)
        {
            ObjectData currentObject = null;
            FieldData currentField = null;

            if (xmlDocument.DescendantNodes().Any())
            {
                currentObject = new ObjectData();
                IEnumerable<XNode> nodes = xmlDocument.DescendantNodes();

                foreach (dynamic node in nodes)
                {
                    if (node is XElement)
                    {
                        string name = node.Name.LocalName;
                        var xnode = node as XElement;
                        switch (name)
                        {
                            case "object":
                                var nameElement =
                                    xnode.Attributes().FirstOrDefault(a => a.Name.LocalName == "name");
                                if (nameElement != null)
                                    currentObject.Name = nameElement.Value;
                                var settigsElement =
                                    xnode.Attributes().FirstOrDefault(a => a.Name.LocalName == "settings");
                                if (settigsElement != null)
                                    currentObject.IsSettingsInt = GetIntFromBoolString(settigsElement.Value);
                                currentObject.IsSingleInstInt =
                                    GetIntFromBoolString(
                                        xnode.Attributes()
                                            .FirstOrDefault(a => a.Name.LocalName == "singleinstance")
                                            .Value);
                                break;
                            case "description":
                                currentObject.Description = node.Value;
                                break;
                            case "field":
                                currentField = new FieldData();
                                currentField.Name =
                                    xnode.Attributes().FirstOrDefault(a => a.Name.LocalName == "name").Value;
                                currentObject.FieldsIndexedByName.Add(currentField.Name, currentField);

                                if (IsClone(node))
                                {
                                    currentField.CloneFrom(
                                        currentObject.FieldsIndexedByName[
                                            xnode.Attributes().FirstOrDefault(a => a.Name.LocalName == "cloneof").Value]);
                                }
                                else
                                {
                                    XAttribute typeElement =
                                        xnode.Attributes().FirstOrDefault(a => a.Name.LocalName == "type");
                                    if (typeElement != null)
                                    {
                                        string typeString = typeElement.Value;
                                        currentField.TypeString = typeString;
                                        currentField.Type = GetFieldTypeFromString(currentField.TypeString);
                                        XAttribute elementsAttribute =
                                            xnode.Attributes().FirstOrDefault(a => a.Name.LocalName == "elements");
                                        if (elementsAttribute !=
                                            null)
                                            currentField.Elements = elementsAttribute.Value;
                                        XAttribute unitsElement =
                                            xnode.Attributes().FirstOrDefault(a => a.Name.LocalName == "units");
                                        if (unitsElement != null)
                                            currentField.Units = unitsElement.Value;
                                        XAttribute elementNamesElement =
                                            xnode.Attributes().FirstOrDefault(a => a.Name.LocalName == "elementnames");
                                        if (
                                            elementNamesElement !=
                                            null)
                                            currentField.ParseElementNamesFromAttribute(elementNamesElement.Value);
                                        XAttribute optionsElement =
                                            xnode.Attributes().FirstOrDefault(a => a.Name.LocalName == "options");
                                        if (optionsElement !=
                                            null)
                                            currentField.ParseOptionsFromAttribute(optionsElement.Value);
                                        XAttribute defaultValueElement =
                                            xnode.Attributes().FirstOrDefault(a => a.Name.LocalName == "defaultvalue");
                                        if (
                                            defaultValueElement !=
                                            null)
                                            currentField.ParseDefaultValuesFromAttribute(defaultValueElement.Value);
                                    }
                                }
                                currentObject.Fields.Add(currentField);
                                break;
                            case "option":
                                currentField.Options.Add(node.Value);
                                break;
                            case "elementname":
                                currentField.ElementNames.Add(node.Value);
                                break;
                        }
                    }
                }
                ExpandDefaultValues(currentObject);
                SortFields(currentObject);

                SummaryGenerator.RegisterObjectId(
                    Hasher.CalculateId(currentObject),
                    string.Format("{0}.{1}", CSharpGenerator.Namespace, currentObject.Name));
            }
            return currentObject;
        }
Exemplo n.º 2
0
        // __ Impl _______________________________________________________


        private static ObjectData GetObjectFromXml(XmlTextReader reader)
        {
            ObjectData currentObject = null;
            FieldData  currentField  = null;

            while (reader.Read())
            {
                if (reader.IsStartElement())
                {
                    switch (reader.Name)
                    {
                    case "object":
                        currentObject                 = new ObjectData();
                        currentObject.Name            = reader.GetAttribute("name");
                        currentObject.IsSettingsInt   = GetIntFromBoolString(reader.GetAttribute("settings"));
                        currentObject.IsSingleInstInt = GetIntFromBoolString(reader.GetAttribute("singleinstance"));
                        break;

                    case "description":
                        currentObject.Description = reader.ReadString();
                        break;

                    case "field":
                        currentField      = new FieldData();
                        currentField.Name = reader.GetAttribute("name");
                        currentObject.FieldsIndexedByName.Add(currentField.Name, currentField);

                        if (IsClone(reader))
                        {
                            currentField.CloneFrom(currentObject.FieldsIndexedByName[reader.GetAttribute("cloneof")]);
                        }
                        else
                        {
                            currentField.TypeString = reader.GetAttribute("type");
                            currentField.Type       = GetFieldTypeFromString(currentField.TypeString);
                            currentField.Elements   = reader.GetAttribute("elements");
                            currentField.Units      = reader.GetAttribute("units");
                            currentField.ParseElementNamesFromAttribute(reader.GetAttribute("elementnames"));
                            currentField.ParseOptionsFromAttribute(reader.GetAttribute("options"));
                            currentField.ParseDefaultValuesFromAttribute(reader.GetAttribute("defaultvalue"));
                        }
                        currentObject.Fields.Add(currentField);
                        break;

                    case "option":
                        currentField.Options.Add(reader.ReadString());
                        break;

                    case "elementname":
                        currentField.ElementNames.Add(reader.ReadString());
                        break;
                    }
                }
            }

            ExpandDefaultValues(currentObject);
            SortFields(currentObject);

            SummaryGenerator.RegisterObjectId(
                Hasher.CalculateId(currentObject),
                string.Format("{0}.{1}", CSharpGenerator.Namespace, currentObject.Name));

            return(currentObject);
        }
Exemplo n.º 3
0
        private static ObjectData GetObjectFromXml(XmlTextReader reader)
        {
            ObjectData currentObject = null;
            FieldData currentField = null;

            while (reader.Read())
            {
                if (reader.IsStartElement())
                {
                    switch (reader.Name)
                    {
                        case "object":
                            currentObject = new ObjectData();
                            currentObject.Name = reader.GetAttribute("name");
                            currentObject.IsSettingsInt = GetIntFromBoolString(reader.GetAttribute("settings"));
                            currentObject.IsSingleInstInt = GetIntFromBoolString(reader.GetAttribute("singleinstance"));
                            break;
                        case "description":
                            currentObject.Description = reader.ReadString();
                            break;
                        case "field":
                            currentField = new FieldData();
                            currentField.Name = reader.GetAttribute("name");
                            currentObject.FieldsIndexedByName.Add(currentField.Name, currentField);

                            if (IsClone(reader))
                            {
                                currentField.CloneFrom(currentObject.FieldsIndexedByName[reader.GetAttribute("cloneof")]);
                            }
                            else
                            {
                                currentField.TypeString = reader.GetAttribute("type");
                                currentField.Type = GetFieldTypeFromString(currentField.TypeString);
                                currentField.Elements = reader.GetAttribute("elements");
                                currentField.Units = reader.GetAttribute("units");
                                currentField.ParseElementNamesFromAttribute(reader.GetAttribute("elementnames"));
                                currentField.ParseOptionsFromAttribute(reader.GetAttribute("options"));
                                currentField.ParseDefaultValuesFromAttribute(reader.GetAttribute("defaultvalue"));
                            }
                            currentObject.Fields.Add(currentField);
                            break;
                        case "option":
                            currentField.Options.Add(reader.ReadString());
                            break;
                        case "elementname":
                            currentField.ElementNames.Add(reader.ReadString());
                            break;
                    }
                }
            }

            ExpandDefaultValues(currentObject);
            SortFields(currentObject);

            SummaryGenerator.RegisterObjectId(
                Hasher.CalculateId(currentObject),
                string.Format("{0}.{1}", CSharpGenerator.Namespace, currentObject.Name));

            return currentObject;
        }