Exemplo n.º 1
0
        private static IDictionary GetDictionary(IDictionary prev,
                                                 XmlNode region,
                                                 string nameAtt,
                                                 string valueAtt)
        {
            Hashtable hashtable;

            if (prev == null)
            {
                hashtable = new Hashtable();
            }
            else
            {
                Hashtable aux = (Hashtable)prev;
                hashtable = (Hashtable)aux.Clone();
            }

            ChoCollectionWrapper result = new ChoCollectionWrapper(hashtable);

            if (region != null)
            {
                result = Read(result, region, nameAtt, valueAtt);
                if (result == null)
                {
                    return(null);
                }
            }

            return(result.UnWrap() as IDictionary);
        }
Exemplo n.º 2
0
        private static NameValueCollection GetNameValues(NameValueCollection prev,
                                                         XmlNode region,
                                                         string nameAtt,
                                                         string valueAtt)
        {
            //ChoGuard.ArgumentNotNull(region, "region");
            NameValueCollection coll = new NameValueCollection();

            if (prev != null)
            {
                coll.Add(prev);
            }

            ChoCollectionWrapper result = new ChoCollectionWrapper(coll);

            if (region != null)
            {
                result = Read(result, region, nameAtt, valueAtt);
                if (result == null)
                {
                    return(null);
                }
            }

            return(result.UnWrap() as NameValueCollection);
        }
        public static IDictionary GetDictionary(IDictionary prev,
                                                XmlNode region,
                                                string nameAtt,
                                                string valueAtt)
        {
            ChoGuard.ArgumentNotNull(region, "region");

            Hashtable hashtable;

            if (prev == null)
            {
                hashtable = new Hashtable();
            }
            else
            {
                Hashtable aux = (Hashtable)prev;
                hashtable = (Hashtable)aux.Clone();
            }

            ChoCollectionWrapper result = new ChoCollectionWrapper(hashtable);

            result = Read(result, region, nameAtt, valueAtt);
            if (result == null)
            {
                return(null);
            }

            return(result.UnWrap() as IDictionary);
        }
Exemplo n.º 4
0
        private static ChoCollectionWrapper ReadAttributes(ChoCollectionWrapper result,
                                                           XmlNode region)
        {
            if (region.Attributes != null && region.Attributes.Count != 0)
            {
                foreach (XmlAttribute attribute in region.Attributes)
                {
                    if (attribute == null)
                    {
                        continue;
                    }
                    result[attribute.Name] = attribute.Value;
                }
            }

            return(result);
        }
        public static NameValueCollection GetNameValuesFromAttributes(NameValueCollection prev,
                                                                      XmlNode region)
        {
            ChoGuard.ArgumentNotNull(region, "region");

            NameValueCollection coll =
                new NameValueCollection();

            if (prev != null)
            {
                coll.Add(prev);
            }

            ChoCollectionWrapper result = new ChoCollectionWrapper(coll);

            result = ReadAttributes(result, region);
            if (result == null)
            {
                return(null);
            }

            return(result.UnWrap() as NameValueCollection);
        }
Exemplo n.º 6
0
        private static NameValueCollection GetNameValuesFromAttributes(NameValueCollection prev,
                                                                       XmlNode region)
        {
            NameValueCollection coll =
                new NameValueCollection();

            if (prev != null)
            {
                coll.Add(prev);
            }

            ChoCollectionWrapper result = new ChoCollectionWrapper(coll);

            if (region != null)
            {
                result = ReadAttributes(result, region);
                if (result == null)
                {
                    return(null);
                }
            }

            return(result.UnWrap() as NameValueCollection);
        }
Exemplo n.º 7
0
        private static ChoCollectionWrapper Read(ChoCollectionWrapper result,
                                                 XmlNode region,
                                                 string nameAtt,
                                                 string valueAtt)
        {
            //if (region.Attributes != null && region.Attributes.Count != 0)
            //    throw new ChoConfigurationException("Unknown attribute", region);

            XmlNode     keyNode;
            XmlNode     valueNode;
            XmlNodeList childs = region.ChildNodes;

            foreach (XmlNode node in childs)
            {
                XmlNodeType ntype = node.NodeType;
                if (ntype == XmlNodeType.Whitespace || ntype == XmlNodeType.Comment)
                {
                    continue;
                }

                if (ntype != XmlNodeType.Element)
                {
                    throw new XmlException("Only XmlElement allowed");
                }

                string nodeName = node.Name;
                if (nodeName == "clear")
                {
                    if (node.Attributes != null && node.Attributes.Count != 0)
                    {
                        throw new XmlException("Unknown attribute");
                    }

                    result.Clear();
                }
                else if (nodeName == "remove")
                {
                    keyNode = null;
                    if (node.Attributes != null)
                    {
                        keyNode = node.Attributes[nameAtt];                         //.RemoveNamedItem(nameAtt);
                    }
                    if (keyNode == null)
                    {
                        throw new XmlException("Required attribute not found");
                    }
                    if (keyNode.Value == String.Empty)
                    {
                        throw new XmlException("Required attribute is empty");
                    }

                    //if (node.Attributes.Count != 0)
                    //    throw new ChoConfigurationException("Unknown attribute", node);

                    result.Remove(keyNode.Value);
                }
                else if (nodeName == "add")
                {
                    keyNode = null;
                    if (node.Attributes != null)
                    {
                        keyNode = node.Attributes[nameAtt];                         //.RemoveNamedItem(nameAtt);
                    }
                    if (keyNode == null)
                    {
                        throw new XmlException("Required attribute not found");
                    }
                    if (keyNode.Value == String.Empty)
                    {
                        throw new XmlException("Required attribute is empty");
                    }

                    valueNode = node.Attributes[valueAtt];                     //.RemoveNamedItem(valueAtt);
                    if (valueNode == null)
                    {
                        throw new XmlException("Required attribute not found");
                    }

                    //if (node.Attributes.Count != 0)
                    //    throw new ChoConfigurationException("Unknown attribute", node);

                    result[keyNode.Value] = valueNode.Value;
                }
                else
                {
                    //throw new ChoConfigurationException("Unknown element", node);
                }
            }

            return(result);
        }