Пример #1
0
        /// <summary>
        /// Loads XML from a property bag.
        /// </summary>
        /// <param name="bag"></param>
        /// <returns></returns>
        private static MruList LoadInternal(SimpleXmlPropertyBag bag)
        {
            if (bag == null)
            {
                throw new ArgumentNullException("bag");
            }

            // get...
            MruList list = new MruList(bag.GetInt32Value("Capacity", 20, Cultures.System, OnNotFound.ReturnNull));

            // walk...
            int count = bag.GetInt32Value("Count", 0, Cultures.System, OnNotFound.ThrowException);

            // add...
            ArrayList values = new ArrayList();

            for (int index = 0; index < count; index++)
            {
                // get...
                string name = "Item" + index.ToString();
                values.Add(bag.GetValue(name, null, null, Cultures.System, OnNotFound.ReturnNull));
            }

            // set...
            list.BulkAdd(values);

            // return...
            return(list);
        }
Пример #2
0
        /// <summary>
        /// Loads a bag from an XML element.
        /// </summary>
        /// <param name="element"></param>
        /// <returns></returns>
        private static SimpleXmlPropertyBag LoadInternal(XmlNode node, Type type)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            // create the bag...
            SimpleXmlPropertyBag results = (SimpleXmlPropertyBag)Activator.CreateInstance(type, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance,
                                                                                          null, null, System.Globalization.CultureInfo.InvariantCulture);

            // walk...
            foreach (XmlNode child in node.ChildNodes)
            {
                bool isArray = XmlHelper.GetAttributeBoolean(child, isArrayAttributeName, OnNotFound.ReturnNull);

                // do we have an element?
                if (child is XmlElement)
                {
                    if (isArray == false)
                    {
                        results[child.Name] = XmlHelper.GetElementValue((XmlElement)child);
                    }
                    else
                    {
                        if (child.ChildNodes.Count == 0)
                        {
                            results[child.Name] = null;
                        }
                        else
                        {
                            ArrayList arrayItems = new ArrayList();
                            for (int index = 0; index < child.ChildNodes.Count; index++)
                            {
                                arrayItems.Add(XmlHelper.GetElementValue((XmlElement)child.ChildNodes[index]));
                            }

                            results[child.Name] = arrayItems.ToArray(arrayItems[0].GetType());
                        }
                    }
                }
            }

            // mbr - 20-10-2005 - added...
            results.OnLoadComplete();

            // return...
            return(results);
        }
Пример #3
0
        /// <summary>
        /// Gets the MRU list as XML.
        /// </summary>
        /// <returns></returns>
        public string ToXml()
        {
            SimpleXmlPropertyBag bag = new SimpleXmlPropertyBag();

            bag.Add("Capacity", this.Capacity);
            bag.Add("Count", this.Count);

            // items...
            for (int index = 0; index < this.Count; index++)
            {
                bag.Add("Item" + index.ToString(), this[index]);
            }

            // return...
            string xml = bag.ToXml("Mru");

            return(xml);
        }
Пример #4
0
        /// <summary>
        /// Loads the MRU list from a file.
        /// </summary>
        /// <param name="xmlFilePath"></param>
        /// <returns></returns>
        public static MruList Load(string xmlFilePath)
        {
            if (xmlFilePath == null)
            {
                throw new ArgumentNullException("xmlFilePath");
            }
            if (xmlFilePath.Length == 0)
            {
                throw new ArgumentOutOfRangeException("'xmlFilePath' is zero-length.");
            }

            // get...
            SimpleXmlPropertyBag bag = SimpleXmlPropertyBag.Load(xmlFilePath, typeof(SimpleXmlPropertyBag));

            if (bag == null)
            {
                throw new InvalidOperationException("bag is null.");
            }

            // defer...
            return(LoadInternal(bag));
        }
Пример #5
0
        /// <summary>
        /// Loads the MRU list from an XML stream.
        /// </summary>
        /// <param name="xml"></param>
        /// <returns></returns>
        public static MruList LoadXml(string xml)
        {
            if (xml == null)
            {
                throw new ArgumentNullException("xml");
            }
            if (xml.Length == 0)
            {
                throw new ArgumentException("'xml' is zero-length.");
            }

            // load...
            SimpleXmlPropertyBag bag = SimpleXmlPropertyBag.FromXml(xml, typeof(SimpleXmlPropertyBag));

            if (bag == null)
            {
                throw new InvalidOperationException("'bag' is null.");
            }

            // defer...
            return(LoadInternal(bag));
        }