示例#1
0
        private DeviceCreationInfo CreateTestInfo()
        {
            dynamic settings = new SettingsObject();
            settings.name = "ProperDeviceName";
            settings.displayName = "ProperDisplayName";

            return new Module.DeviceCreationInfo(settings, new Module.ServiceManager(), new Module.DeviceManager());
        }
示例#2
0
        public SettingsObject LoadSettingsObject(XmlNode node)
        {
            var settings = new SettingsObject();

            // Copy in attributes
            foreach (XmlAttribute attribute in node.Attributes)
                settings[attribute.Name.ToLower()] = attribute.Value;

            if (node.InnerText.Length > 0)
                settings["value"] = node.InnerText;

            bool hasChildren = node.ChildNodes.Count > 0 && node.FirstChild.GetType() != typeof(XmlText);
            if (!hasChildren)
                return settings;

            // Parse children & set up values
            foreach (XmlNode child in node.ChildNodes)
            {
                string name = child.Name.ToLower();

                // Disregard any XmlText nodes since they're not a proper child.
                bool hasGrandChildren = child.ChildNodes.Count > 0 && child.FirstChild.GetType() != typeof(XmlText);
                bool isArray = hasGrandChildren && child.Attributes.Count == 0;
                if (hasGrandChildren)
                {
                    // Detect if we should fold a subtree into an array
                    foreach (XmlNode grandChild in child.ChildNodes)
                    {
                        string grandChildName = grandChild.Name.ToLower();

                        // Assume all grand children in an array will be named '<name>' under a parent named '<name>s'
                        if (grandChildName + "s" != name)
                        {
                            isArray = false;
                            break;
                        }
                    }
                }

                if (isArray)
                {
                    // Fold array items into a list
                    var list = new List<object>();
                    foreach (XmlNode subchild in child.ChildNodes)
                        list.Add(LoadSettingsObject(subchild));
                    settings[name] = list;
                }
                else if (hasGrandChildren || child.Attributes.Count > 0)
                {
                    // Treat this as a sub-object & recursively process it.
                    settings[name] = LoadSettingsObject(child);
                }
                else
                {
                    // Normal value, fold it into current object directly
                    settings[name] = child.InnerText;
                }
            }

            return settings;
        }