Пример #1
0
        // ---------------- Functions ----------------

        public static RssBotConfig ParseConfig(string fileName)
        {
            if (File.Exists(fileName) == false)
            {
                throw new FileNotFoundException("Can not find Rss Bot Config " + fileName);
            }

            XmlDocument doc = new XmlDocument();

            doc.Load(fileName);

            XmlNode rootNode = doc.DocumentElement;

            if (rootNode.Name != rootXmlElementName)
            {
                throw new XmlException(
                          "Root XML node should be named \"" + rootXmlElementName + "\".  Got: " + rootNode.Name
                          );
            }

            RssBotConfig config = new RssBotConfig();

            foreach (XmlNode childNode in rootNode.ChildNodes)
            {
                if (childNode.Name == "feed")
                {
                    Feed feed = new Feed();

                    foreach (XmlNode feedNode in childNode.ChildNodes)
                    {
                        switch (feedNode.Name)
                        {
                        case "url":
                            feed.Url = feedNode.InnerText;
                            break;

                        case "refreshinterval":
                            long minutes = long.Parse(feedNode.InnerText);
                            feed.RefreshInterval = TimeSpan.FromMinutes(minutes);
                            break;

                        case "channel":
                            feed.AddChannel(feedNode.InnerText);
                            break;
                        }
                    }

                    config.AddFeed(feed);
                }
            }

            config.Validate();

            return(config);
        }