Exemple #1
0
        public static FeedModel FromXmlElement(XmlElement xe)
        {
            if (xe.Name != ConfigConsts.ChannelTag)
            {
                throw new BadXmlException();
            }

            FeedModel result = null;

            string linkPath = xe.InnerText;

            try
            {
                result = new FeedModel(linkPath);
            }
            catch (ArgumentException)
            {
                throw new BadXmlException();
            }

            return(result);
        }
Exemple #2
0
 public void RemoveFeed(FeedModel feed)
 {
     FeedsList.Remove(feed);
 }
Exemple #3
0
 public void AddFeed(FeedModel feed)
 {
     FeedsList.Add(feed);
 }
Exemple #4
0
        public static UserModel FromXmlElement(XmlElement xe)
        {
            if (xe.Name != ConfigConsts.UserTag)
            {
                throw new BadXmlException();
            }

            string name;
            int    threadsCount = 0;

            try
            {
                name         = xe.Attributes[ConfigConsts.UserNameAttr].Value;
                threadsCount = Convert.ToInt32(xe.Attributes[ConfigConsts.ThreadsCountTag].Value);
            }
            catch (Exception ex)
            {
                if (ex is XmlException || ex is FormatException || ex is OverflowException)
                {
                    throw new BadXmlException();
                }

                throw;
            }
            UserModel result = new UserModel(name, threadsCount);

            // Read feeds
            XmlElement child = xe.FirstChild as XmlElement;

            if ((child == null) || (child.Name != ConfigConsts.ChannelsListTag))
            {
                throw new BadXmlException();
            }

            foreach (XmlElement channel in child.ChildNodes)
            {
                var feedModel = FeedModel.FromXmlElement(channel);
                feedModel.PropertyChanged += result.FeedModelOnPropertyChanged;
                result.FeedsList.Add(feedModel);
            }

            // Read filters
            child = child.NextSibling as XmlElement;
            if ((child == null) || (child.Name != ConfigConsts.FiltersListTag))
            {
                throw new BadXmlException();
            }

            if (child.ChildNodes.Count == 2)
            {
                foreach (XmlElement filter in child.ChildNodes)
                {
                    var nextFilter = FilterModel.FromXmlElement(filter);
                    if (nextFilter is IncludeFilterModel)
                    {
                        result.IncludeFilter = nextFilter;
                    }
                    else if (nextFilter is ExcludeFilterModel)
                    {
                        result.ExcludeFilter = nextFilter;
                    }
                }
            }
            else
            {
                result.IncludeFilter = new IncludeFilterModel();
                result.ExcludeFilter = new ExcludeFilterModel();
            }

            return(result);
        }