Esempio n. 1
0
        /// <summary>
        /// Добавляет в RSS ленту новые произведения автора
        /// </summary>
        /// <param name="author">Автор</param>
        public void Add(Author author)
        {
            foreach (AuthorText authorText in author.Texts)
            {
                if (authorText.IsNew)
                {
                    RssItem item = new RssItem
                    {
                        Title    = author.Name + " | " + authorText.Name,
                        Link     = authorText.GetFullLink(author),
                        PubDate  = DateTime.Now,
                        Author   = author.Name,
                        Category = author.Category
                    };

                    StringBuilder sb = new StringBuilder();
                    sb.AppendFormat(@"<a href=""{0}""><font size=""+1"" color=TEAL>{1}</font></a>. Категория: {2}.",
                                    author.URL,
                                    author.Name, author.Category);
                    sb.AppendLine("<br>");
                    sb.AppendFormat(@"<a href=""{0}""><font size=""+1"" color=TEAL>{1}</font></a>. Размер: {2} кб.",
                                    authorText.GetFullLink(author), authorText.Name, authorText.Size);
                    sb.AppendLine("<br>");
                    sb.AppendFormat(@"{0} -> {1}", authorText.Genres, authorText.SectionName);
                    sb.AppendLine("<br>");
                    sb.AppendFormat(@"{0}", authorText.Description);
                    item.Description = sb.ToString();

                    item.Guid =
                        (item.Title.GetHashCode() ^ item.Link.GetHashCode() ^ item.Author.GetHashCode() ^
                         item.Category.GetHashCode() ^ item.Description.GetHashCode()).ToString();

                    if (!_dictRssItem.ContainsKey(item.Guid))
                    {
                        _dictRssItem.Add(item.Guid, item);
                        _articles.Insert(0, item);
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Добавляет в RSS ленту новые произведения автора
        /// </summary>
        /// <param name="author">Автор</param>
        public void Add(Author author)
        {
            foreach (AuthorText authorText in author.Texts)
            {
                if (authorText.IsNew)
                {
                    RssItem item = new RssItem
                                       {
                                           Title = author.Name + " | " + authorText.Name,
                                           Link = authorText.GetFullLink(author),
                                           PubDate = DateTime.Now,
                                           Author = author.Name,
                                           Category = author.Category
                                       };

                    StringBuilder sb = new StringBuilder();
                    sb.AppendFormat(@"<a href=""{0}""><font size=""+1"" color=TEAL>{1}</font></a>. Категория: {2}.",
                                    author.URL,
                                    author.Name, author.Category);
                    sb.AppendLine("<br>");
                    sb.AppendFormat(@"<a href=""{0}""><font size=""+1"" color=TEAL>{1}</font></a>. Размер: {2} кб.",
                                    authorText.GetFullLink(author), authorText.Name, authorText.Size);
                    sb.AppendLine("<br>");
                    sb.AppendFormat(@"{0} -> {1}", authorText.Genres, authorText.SectionName);
                    sb.AppendLine("<br>");
                    sb.AppendFormat(@"{0}", authorText.Description);
                    item.Description = sb.ToString();

                    item.Guid =
                        (item.Title.GetHashCode() ^ item.Link.GetHashCode() ^ item.Author.GetHashCode() ^
                         item.Category.GetHashCode() ^ item.Description.GetHashCode()).ToString();

                    if (!_dictRssItem.ContainsKey(item.Guid))
                    {
                        _dictRssItem.Add(item.Guid, item);
                        _articles.Insert(0, item);
                    }
                }
            }
        }
Esempio n. 3
0
        public RssChannel(string text) : this()
        {
            var doc = new XmlDocument();

            doc.LoadXml(text);

            XmlNode root = doc.DocumentElement;

            if (root == null)
            {
                throw new XmlException("Не найден корневой элемент в XML");
            }
            XmlNodeList nodeList = root.ChildNodes;

            foreach (XmlNode chanel in nodeList)
            {
                foreach (XmlNode chanelItem in chanel)
                {
                    if (chanelItem.Name == "title")
                    {
                        _channel.Title = chanelItem.InnerText;
                    }
                    if (chanelItem.Name == "description")
                    {
                        _channel.Description = chanelItem.InnerText;
                    }
                    if (chanelItem.Name == "copyright")
                    {
                        _channel.Copyright = chanelItem.InnerText;
                    }
                    if (chanelItem.Name == "link")
                    {
                        _channel.Link = chanelItem.InnerText;
                    }

                    if (chanelItem.Name == "img")
                    {
                        XmlNodeList imgList = chanelItem.ChildNodes;
                        foreach (XmlNode imgItem in imgList)
                        {
                            if (imgItem.Name == "url")
                            {
                                _channel.ChannelImage.ImageURL = imgItem.InnerText;
                            }
                            if (imgItem.Name == "link")
                            {
                                _channel.ChannelImage.ImageLink = imgItem.InnerText;
                            }
                            if (imgItem.Name == "title")
                            {
                                _channel.ChannelImage.ImageTitle = imgItem.InnerText;
                            }
                        }
                    }

                    if (chanelItem.Name == "item")
                    {
                        XmlNodeList itemsList = chanelItem.ChildNodes;
                        RssItem     rssItem   = new RssItem();

                        foreach (XmlNode item in itemsList)
                        {
                            if (item.Name == "title")
                            {
                                rssItem.Title = ReplaceSpecialSymbolBack(item.InnerXml);
                            }
                            if (item.Name == "link")
                            {
                                rssItem.Link = item.InnerText;
                            }
                            if (item.Name == "description")
                            {
                                rssItem.Description = ReplaceSpecialSymbolBack(item.InnerXml);
                            }
                            if (item.Name == "pubDate")
                            {
                                rssItem.PubDate = DateTime.Parse(item.InnerText);
                            }
                            if (item.Name == "author")
                            {
                                rssItem.Author = ReplaceSpecialSymbolBack(item.InnerXml);
                            }
                            if (item.Name == "category")
                            {
                                rssItem.Category = ReplaceSpecialSymbolBack(item.InnerXml);
                            }
                            if (item.Name == "guid")
                            {
                                rssItem.Guid = item.InnerText;
                            }
                        }
                        _articles.Add(rssItem);
                    }
                }
            }
            foreach (RssItem rssItem in _articles)
            {
                if (!_dictRssItem.ContainsKey(rssItem.Guid))
                {
                    _dictRssItem.Add(rssItem.Guid, rssItem);
                }
            }
        }
Esempio n. 4
0
        public RssChannel(string text)
            : this()
        {
            var doc = new XmlDocument();
            doc.LoadXml(text);

            XmlNode root = doc.DocumentElement;
            if (root == null) throw new XmlException("Не найден корневой элемент в XML");
            XmlNodeList nodeList = root.ChildNodes;

            foreach (XmlNode chanel in nodeList)
            {
                foreach (XmlNode chanelItem in chanel)
                {
                    if (chanelItem.Name == "title")
                    {
                        _channel.Title = chanelItem.InnerText;
                    }
                    if (chanelItem.Name == "description")
                    {
                        _channel.Description = chanelItem.InnerText;
                    }
                    if (chanelItem.Name == "copyright")
                    {
                        _channel.Copyright = chanelItem.InnerText;
                    }
                    if (chanelItem.Name == "link")
                    {
                        _channel.Link = chanelItem.InnerText;
                    }

                    if (chanelItem.Name == "img")
                    {
                        XmlNodeList imgList = chanelItem.ChildNodes;
                        foreach (XmlNode imgItem in imgList)
                        {
                            if (imgItem.Name == "url")
                            {
                                _channel.ChannelImage.ImageURL = imgItem.InnerText;
                            }
                            if (imgItem.Name == "link")
                            {
                                _channel.ChannelImage.ImageLink = imgItem.InnerText;
                            }
                            if (imgItem.Name == "title")
                            {
                                _channel.ChannelImage.ImageTitle = imgItem.InnerText;
                            }
                        }
                    }

                    if (chanelItem.Name == "item")
                    {
                        XmlNodeList itemsList = chanelItem.ChildNodes;
                        RssItem rssItem = new RssItem();

                        foreach (XmlNode item in itemsList)
                        {
                            if (item.Name == "title")
                            {
                                rssItem.Title = ReplaceSpecialSymbolBack(item.InnerXml);
                            }
                            if (item.Name == "link")
                            {
                                rssItem.Link = item.InnerText;
                            }
                            if (item.Name == "description")
                            {
                                rssItem.Description = ReplaceSpecialSymbolBack(item.InnerXml);
                            }
                            if (item.Name == "pubDate")
                            {
                                rssItem.PubDate = DateTime.Parse(item.InnerText);
                            }
                            if (item.Name == "author")
                            {
                                rssItem.Author = ReplaceSpecialSymbolBack(item.InnerXml);
                            }
                            if (item.Name == "category")
                            {
                                rssItem.Category = ReplaceSpecialSymbolBack(item.InnerXml);
                            }
                            if (item.Name == "guid")
                            {
                                rssItem.Guid = item.InnerText;
                            }
                        }
                        _articles.Add(rssItem);
                    }
                }
            }
            foreach (RssItem rssItem in _articles)
            {
                if (!_dictRssItem.ContainsKey(rssItem.Guid))
                    _dictRssItem.Add(rssItem.Guid, rssItem);
            }
        }