コード例 #1
0
        /// <summary>
        /// Saves the resources to a file located in the Filename property.
        /// </summary>
        public static void SaveResources(AgateResourceCollection resources, string filename)
        {
            XmlDocument doc  = new XmlDocument();
            XmlElement  root = doc.CreateElement("AgateResources");

            XmlHelper.AppendAttribute(root, doc, "Version", "0.3.0");

            doc.AppendChild(root);

            foreach (AgateResource res in resources)
            {
                res.BuildNodes(root, doc);
            }

            doc.Save(filename);
        }
コード例 #2
0
        /// <summary>
        /// Loads the resource information from a stream containing XML data.
        /// This erases all information in the current AgateResourceCollection.
        /// </summary>
        /// <param name="resources"></param>
        /// <param name="stream"></param>
        public static void LoadResources(AgateResourceCollection resources, Stream stream)
        {
            XmlDocument doc = new XmlDocument();

            try
            {
                doc.Load(stream);
            }
            catch (XmlException e)
            {
                throw new AgateResourceException("The XML resource file is malformed.", e);
            }

            XmlNode root;

            try
            {
                root = doc.ChildNodes[0];
                if (root is XmlDeclaration)
                {
                    root = doc.ChildNodes[1];
                }
            }
            catch (XmlException e)
            {
                throw new AgateResourceException("Could not understand root XML element.", e);
            }

            if (root.Attributes["Version"] == null)
            {
                throw new AgateResourceException("XML resource file does not contain the required version attibute.");
            }

            string version = root.Attributes["Version"].Value;

            switch (version)
            {
            case "0.3.1":
            case "0.3.0":
                ReadVersion031(resources, root, version);
                break;

            default:
                throw new AgateResourceException("XML Resource file version " + version + " not supported.");
            }
        }
コード例 #3
0
        private static void ReadVersion031(AgateResourceCollection resources, XmlNode root, string version)
        {
            for (int i = 0; i < root.ChildNodes.Count; i++)
            {
                XmlNode node = root.ChildNodes[i];

                if (node is XmlComment)
                {
                    continue;
                }

                try
                {
                    resources.Add(ReadNode(node, version));
                }
                catch (Exception e)
                {
                    throw new AgateResourceException("An error occurred while reading XML resource file: \r\n"
                                                     + e.Message, e);
                }
            }
        }