Esempio n. 1
0
        private void datagridItems_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex > -1)
            {
                object o = datagridItems.Rows[e.RowIndex].Cells[0].Tag;
                if (o != null)
                {
                    Type objectType = o.GetType();

                    switch (objectType.Name)
                    {
                    case "RssEnclosure":

                        break;

                    case "RssItem":
                        RssItem item = (RssItem)o;
                        DisplayItem(item);


                        break;

                    case "RssChannel":

                        break;

                    default:
                        break;
                    }
                }
            }
        }
Esempio n. 2
0
 void LoadNews()
 {
     StatusStringOn();
     rssItem      = (App.Current as App).News;
     news         = new News(rssItem);
     news.Loaded += new NewsLoaded(news_Loaded);
 }
Esempio n. 3
0
        //============================================================
        //	CLASS SUMMARY
        //============================================================
        /// <summary>
        /// Provides example code for the RssItem class.
        /// </summary>
        public static void ClassExample()
        {
            #region RssItem
            RssFeed feed = new RssFeed();

            feed.Channel.Title       = "Dallas Times-Herald";
            feed.Channel.Link        = new Uri("http://dallas.example.com");
            feed.Channel.Description = "Current headlines from the Dallas Times-Herald newspaper";

            RssItem item = new RssItem();
            item.Title       = "Seventh Heaven! Ryan Hurls Another No Hitter";
            item.Link        = new Uri("http://dallas.example.com/1991/05/02/nolan.htm");
            item.Description = "Texas Rangers pitcher Nolan Ryan hurled the seventh no-hitter of his legendary career on Arlington Appreciation Night, defeating the Toronto Blue Jays 3-0.";
            item.Author      = "[email protected] (Joe Bob Briggs)";

            item.Categories.Add(new RssCategory("sports"));
            item.Categories.Add(new RssCategory("1991/Texas Rangers", "rec.sports.baseball"));

            item.Comments = new Uri("http://dallas.example.com/feedback/1983/06/joebob.htm");
            item.Enclosures.Add(new RssEnclosure(24986239L, "audio/mpeg", new Uri("http://dallas.example.com/joebob_050689.mp3")));
            item.Guid            = new RssGuid("http://dallas.example.com/1983/05/06/joebob.htm");
            item.PublicationDate = new DateTime(2007, 10, 5, 9, 0, 0);
            item.Source          = new RssSource(new Uri("http://la.example.com/rss.xml"), "Los Angeles Herald-Examiner");

            feed.Channel.AddItem(item);
            #endregion
        }
Esempio n. 4
0
        protected void ItemsList_OnItemDataBound(object sender, ListViewItemEventArgs e)
        {
            if (e.Item.ItemType == ListViewItemType.DataItem)
            {
                Literal              PublishDate = (Literal)e.Item.FindControl("PublishDate");
                HyperLink            Link        = (HyperLink)e.Item.FindControl("Link");
                HyperLink            Title       = (HyperLink)e.Item.FindControl("Title");
                Literal              ShortDesc   = (Literal)e.Item.FindControl("ShortDesc");
                HtmlContainerControl PostDesc    = (HtmlContainerControl)e.Item.FindControl("PostDesc");

                PostDesc.Visible = this.ShowPostDescription;

                RssItem item = (RssItem)e.Item.DataItem;

                PublishDate.Text = item.PubDate;

                Link.NavigateUrl  = item.Link;
                Title.Text        = item.Title;
                Title.NavigateUrl = item.Link;

                string shortDesc = item.Description;

                if (item.Description.Length > 130)
                {
                    shortDesc = item.Description.Substring(0, 120) + "...";
                }

                ShortDesc.Text = shortDesc;
            }
        }
        public virtual IActionResult NewProductsRss()
        {
            var feed = new RssFeed(
                $"{_localizationService.GetLocalized(_storeContext.CurrentStore, x => x.Name)}: New products",
                "Information about products",
                new Uri(_webHelper.GetStoreLocation()),
                DateTime.UtcNow);

            if (!_catalogSettings.NewProductsEnabled)
            {
                return(new RssActionResult(feed, _webHelper.GetThisPageUrl(false)));
            }

            var items = new List <RssItem>();

            var products = _productService.GetProductsMarkedAsNew(_storeContext.CurrentStore.Id);

            foreach (var product in products)
            {
                var productUrl         = Url.RouteUrl("Product", new { SeName = _urlRecordService.GetSeName(product) }, _webHelper.CurrentRequestProtocol);
                var productName        = _localizationService.GetLocalized(product, x => x.Name);
                var productDescription = _localizationService.GetLocalized(product, x => x.ShortDescription);
                var item = new RssItem(productName, productDescription, new Uri(productUrl), $"urn:store:{_storeContext.CurrentStore.Id}:newProducts:product:{product.Id}", product.CreatedOnUtc);
                items.Add(item);
                //uncomment below if you want to add RSS enclosure for pictures
                //var picture = _pictureService.GetPicturesByProductId(product.Id, 1).FirstOrDefault();
                //if (picture != null)
                //{
                //    var imageUrl = _pictureService.GetPictureUrl(picture, _mediaSettings.ProductDetailsPictureSize);
                //    item.ElementExtensions.Add(new XElement("enclosure", new XAttribute("type", "image/jpeg"), new XAttribute("url", imageUrl), new XAttribute("length", picture.PictureBinary.Length)));
                //}
            }
            feed.Items = items;
            return(new RssActionResult(feed, _webHelper.GetThisPageUrl(false)));
        }
 private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     if (!(string.IsNullOrEmpty(this.dataGridView1.Columns[e.ColumnIndex].DataPropertyName)))
     {
         RssItem item = _items[e.RowIndex];
     }
 }
        private void LoadRssFeed(XDocument doc, RssFeed feed)
        {
            SetMediaImage(feed, doc);
            feed.Description = doc.Root.Element("channel").GetSafeElementString("description");
            feed.Items       = new ObservableCollection <RssItem>();
            feed.Link        = doc.Root.Element("channel").GetSafeElementString("link");

            foreach (var item in doc.Descendants("item"))
            {
                var newItem = new RssItem()
                {
                    Title       = item.GetSafeElementString("title"),
                    Link        = item.GetSafeElementString("link"),
                    Description = item.GetSafeElementString("description"),
                    PublishDate = item.GetSafeElementDate("pubDate"),
                    Guid        = item.GetSafeElementString("guid"),
                };
                feed.Items.Add(newItem);
            }

            var lastItem = feed.Items.OrderByDescending(i => i.PublishDate).FirstOrDefault();

            if (lastItem != null)
            {
                feed.LastBuildDate = lastItem.PublishDate;
            }
        }
Esempio n. 8
0
File: Rss.cs Progetto: aspcat/CMS
        private RssItem BuildIssueItem(Issue item, string template)
        {
            var link = string.Format("{0}/#!/issue", Config.URL.Domain);

            var rssItem = new RssItem
            {
                Title       = item.Project + " - " + item.Title,
                Link        = new Uri(link),
                Description = Razor.Parse(template, new
                {
                    Title      = item.Title,
                    Project    = item.Project,
                    Statu      = item.Statu,
                    Content    = item.Content,
                    Author     = item.Author,
                    CreateDate = item.CreateDate,
                    Result     = item.Result ?? string.Empty,
                    User       = item.LastEditUser ?? string.Empty,
                    EditDate   = item.LastEditDate ?? DateTime.Now,
                }),
                PubDate = item.CreateDate,
                Author  = item.CreateUser,
                Guid    = new RssGuid {
                    Name = item.IssueId.ToString()
                }
            };

            if (item.Result != null)
            {
                rssItem.Description += string.Format("<br /><br />{0}:<br />{1}", item.LastEditUser,
                                                     item.Result != null ? item.Result.Replace("\r", "<br />") : "");
            }

            return(rssItem);
        }
Esempio n. 9
0
        /// <summary>
        ///     Return a RssFeed object using the XDocument data
        /// </summary>
        /// <param name="doc"></param>
        /// <returns></returns>
        public override RssFeed LoadFeed(XDocument doc)
        {
            var        feed             = new RssFeed();
            XNamespace defaultNamespace = string.Empty;

            SetMediaImage(feed, doc);
            if (doc.Root != null)
            {
                defaultNamespace = doc.Root.GetDefaultNamespace();

                feed.Description = doc.Root.Element("channel").GetSafeElementString("description");
                feed.Items       = new ObservableCollection <RssItem>();
                feed.Link        = doc.Root.Element("channel").GetSafeElementString("link");
            }

            foreach (XElement item in doc.Descendants(defaultNamespace + "item"))
            {
                RssItem rssItem = ParseItem(item);
                feed.Items.Add(rssItem);
            }

            RssItem lastItem = feed.Items.OrderByDescending(i => i.PublishDate).FirstOrDefault();

            if (lastItem != null)
            {
                feed.LastBuildDate = lastItem.PublishDate;
            }

            return(feed);
        }
Esempio n. 10
0
        /// <summary>
        /// Добавление новостей из источника
        /// </summary>
        /// <param name="guid">Идентификатор источника</param>
        /// <param name="items">Новости</param>
        /// <returns></returns>
        private async Task AddItems(Guid guid, ICollection <FeedItem> items)
        {
            foreach (var item in items)
            {
                RssItem rssItem = new RssItem()
                {
                    Description   = item.Description,
                    Enclosure     = item.Content,
                    Link          = item.Link,
                    RssItemGuid   = Guid.NewGuid(),
                    RssSourceGuid = guid,
                    Title         = item.Title
                };

                if (item.PublishingDateString != null)
                {
                    rssItem.PubDate = Convert.ToDateTime(item.PublishingDateString);
                }

                var any = await _context.RssItems
                          .Where(a => a.RssSourceGuid == guid)
                          .Where(b => b.Title.Equals(item.Title)).ToListAsync();

                if (any.Count == 0)
                {
                    _context.RssItems.Add(rssItem);
                    await _context.SaveChangesAsync();
                }
            }
        }
Esempio n. 11
0
        private void saveFeedItems(FeedSource channel)
        {
            RssItemList posts = channel.RssChannel.RssItems;

            for (int i = posts.Count - 1; i >= 0; i--)
            {
                RssItem   post  = posts[i];
                FeedEntry entry = new FeedEntry();

                entry.FeedSource = channel;

                entry.Author   = post.Author;
                entry.Category = post.Category;

                entry.Description = post.Description;
                entry.Link        = post.Link;
                entry.PubDate     = post.PubDate;
                if (entry.PubDate == null || entry.PubDate < new DateTime(1900, 1, 1))
                {
                    entry.PubDate = DateTime.Now;
                }
                entry.Title   = post.Title;
                entry.Created = DateTime.Now;

                FeedEntry savedEntry = entryService.GetByLink(entry.Link);
                if (savedEntry == null)
                {
                    db.insert(entry);
                }
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Gets the request and processes the response.
        /// </summary>
        private static void ProcessRespose(IAsyncResult async)
        {
            RssItem item = (RssItem)async.AsyncState;

            try
            {
                using (HttpWebResponse response = (HttpWebResponse)item.Request.EndGetResponse(async))
                {
                    XmlDocument doc = new XmlDocument();
                    doc.Load(response.GetResponseStream());

                    XmlNodeList nodes = doc.SelectNodes("rss/channel/item");
                    foreach (XmlNode node in nodes)
                    {
                        string   title = node.SelectSingleNode("title").InnerText;
                        string   link  = node.SelectSingleNode("link").InnerText;
                        DateTime date  = DateTime.Now;
                        if (node.SelectSingleNode("pubDate") != null)
                        {
                            date = DateTime.Parse(node.SelectSingleNode("pubDate").InnerText);
                        }

                        item.ItemTitles.Add(title);
                        item.ItemLinks.Add(link);
                    }
                }
            }
            catch
            { }
        }
Esempio n. 13
0
        private void AddRssChildItems(RssItem item, HtmlGenericControl li)
        {
            if (item.ItemTitles.Count > 0 && BlogSettings.Instance.BlogrollVisiblePosts > 0)
            {
                HtmlGenericControl div = new HtmlGenericControl("ul");
                for (int i = 0; i < item.ItemTitles.Count; i++)
                {
                    if (i >= BlogSettings.Instance.BlogrollVisiblePosts)
                    {
                        break;
                    }

                    HtmlGenericControl subLi = new HtmlGenericControl("li");
                    HtmlAnchor         a     = new HtmlAnchor();
                    a.HRef      = item.ItemLinks[i];
                    a.Title     = HttpUtility.HtmlEncode(item.ItemTitles[i]);
                    a.InnerHtml = EnsureLength(item.ItemTitles[i]);

                    subLi.Controls.Add(a);
                    div.Controls.Add(subLi);
                }

                li.Controls.Add(div);
            }
        }
Esempio n. 14
0
        /// <summary>Gets index of specified RSS Item in the collection.</summary>
        /// <param name="items">Target collection.</param>
        /// <param name="item">Target item.</param>
        /// <returns>Index if found, -1 otherwise.</returns>
        public static int IndexOf(RssItemCollection items, RssItem item)
        {
            int idx = 0;

            foreach (RssItem it in items)
            {
                if ((item.Guid == null || item.Guid.Name == null || item.Guid.Name.Length <= 0) &&
                    (it.Guid == null || it.Guid.Name == null || it.Guid.Name.Length <= 0))
                {
                    if (item.Title == it.Title && item.Link == it.Link && item.PubDate == it.PubDate)
                    {
                        return(idx);
                    }
                }
                else if ((item.Guid != null && it.Guid != null) &&
                         (item.Guid.Name != null && item.Guid.Name.Length > 0) &&
                         (item.Guid.Name == it.Guid.Name && item.PubDate == it.PubDate))
                {
                    return(idx);
                }

                idx++;
            }
            return(-1);
        }
        /// <inheritdoc />
        public void StoreDecision(DecisionModel decision)
        {
            this.RemoveAllOccurences(decision);

            string titre = decision.EstSupprimée ? RemovedIndicator + decision.Titre : decision.Titre;
            var    item  = new RssItem
            {
                title       = titre,
                pubDate     = decision.Date.ToString("ddd, dd MMM yyyy HH:mm:ss"),
                description = decision.Description,
                link        = decision.Lien?.ToString(),
                guid        = new Guid {
                    isPermaLink = false, Value = decision.GetHashCode().ToString()
                }
            };

            foreach (Domaine decisionDomaine in decision.Domaines)
            {
                RssChannel channel = this.OpenOrCreateChannelForDomaine(decisionDomaine);
                channel.Add(item);

                var rss = new Rss {
                    channel = new [] { channel }
                };
                var serializer = new XmlSerializer(typeof(Rss));

                IFile file = this._feedsStorageDirectory.CreateOrReturn(FileNameForDomaine(decisionDomaine));

                using (StreamWriter writer = file.CreateWriter())
                    serializer.Serialize(writer, rss);
            }
        }
Esempio n. 16
0
        /// <summary>
        /// 设置RssItem
        /// </summary>
        /// <param name="list"></param>
        /// <param name="channel"></param>
        private void SetRssItems(List <Article> list, RssChannel channel)
        {
            List <RssItem> l = new List <RssItem>();

            foreach (Article article in list)
            {
                FormatArticleUrl(article);

                RssItem item = new RssItem();
                item.Author = article.Author;
                item.Link   = article.LinkUrl;
                item.Title  = article.Title;
                if (!string.IsNullOrEmpty(article.Description))
                {
                    item.Description = article.Description;
                }
                else
                {
                    string content = We7Helper.RemoveHtml(article.Content);
                    content = content.Replace("&nbsp; ", "");
                    content = We7Helper.ConvertTextToHtml(content);
                    if (content.Length > 200)
                    {
                        content = content.Substring(0, 200) + "...";
                    }
                    item.Description = content;
                }

                item.PubDate = article.Created.ToString("yyyy-MM-dd");
                l.Add(item);
            }
            channel.Rssitem = l;
        }
Esempio n. 17
0
        private IEnumerable <RssItem> GetNewsItems(string url)
        {
            List <RssItem> news = new List <RssItem>();

            using (XmlReader reader = XmlReader.Create(url))
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(reader);
                XPathNavigator navigator = doc.CreateNavigator();
                foreach (XPathNavigator item in navigator.Select("//item"))
                {
                    string  title       = GetValue(item, "title");
                    string  link        = GetValue(item, "link");
                    string  description = GetValue(item, "description");
                    string  pubDate     = GetValue(item, "pubDate");
                    RssItem rss         = new RssItem
                    {
                        Title        = title,
                        Url          = link,
                        Introduction = description,
                        Published    = pubDate
                    };

                    news.Add(rss);
                    if (news.Count >= CurrentItem.MaxCount)
                    {
                        break;
                    }
                }
            }
            return(news);
        }
Esempio n. 18
0
        protected override void Render(HtmlTextWriter writer)
        {
            RssChannel channel = new RssChannel();

            TopicCollection topics = RepositoryRegistry.TopicRepository.FindByForumId(forumID);

            foreach (Topic topic in topics)
            {
                RssItem item = new RssItem();
                item.Title       = topic.Name;
                item.Description = topic.Name;
                item.PubDate     = DateTime.Now.ToUniversalTime();
                item.Author      = topic.Author.Name;
                item.Link        = new Uri(ForumApplication.Instance.GetLink(SharePointForumControls.ViewMessages, "topic={0}", topic.Id));
                channel.Items.Add(item);
            }

            channel.Title         = ForumApplication.Instance.Title;
            channel.Description   = ForumApplication.Instance.Title;
            channel.LastBuildDate = channel.Items.LatestPubDate();
            channel.Link          = new Uri(ForumApplication.Instance.BasePath);

            RssFeed feed = new RssFeed();

            feed.Channels.Add(channel);

            Page.Response.Clear();
            Page.Response.ContentType = "text/xml";
            feed.Write(Page.Response.OutputStream);
            Page.Response.End();
        }
Esempio n. 19
0
 protected void OnNewRss(RssItem item)
 {
     if (NewRss != null)
     {
         NewRss(item);
     }
 }
Esempio n. 20
0
        internal static string AddExtensionToXml(SyndicationExtension ext)
        {
            RssFeed feed = new RssFeed(new Uri("http://www.example.com"), "Argotic - Extension Test");

            feed.Channel.Description    = "Test of an extension";
            feed.Channel.ManagingEditor = "*****@*****.**";
            feed.Channel.Webmaster      = "*****@*****.**";
            feed.Channel.Language       = CultureInfo.CurrentCulture;
#if false
            feed.Channel.Image        = new RssImage();
            feed.Channel.Image.Title  = "Example Image Title";
            feed.Channel.Image.Url    = new Uri("http://www.example.com/sample.png");
            feed.Channel.Image.Link   = new Uri("http://www.example.com/");
            feed.Channel.Image.Width  = 32;
            feed.Channel.Image.Height = 32;
#endif
            RssItem item = new RssItem();
            item.Title       = "Item #1";
            item.Link        = new Uri("http://www.example.com/item1.htm");
            item.Description = "text for First Item";

            item.PublicationDate = new DateTime(2010, 8, 1, 0, 0, 1);
            feed.Channel.AddItem(item);

            //			var firstItem = feed.Channel.Items.First();
            //			firstItem.AddExtension(geo);
            item.AddExtension(ext);

            using (var sw = new StringWriter())
                using (var tw = new XmlTextWriter(sw))
                {
                    feed.Save(tw);
                    return(sw.ToString());
                }
        }
Esempio n. 21
0
    private static XmlDocument addRssItem(XmlDocument xmlDocument, RssItem item)
    {
        XmlElement itemElement = xmlDocument.CreateElement("item");

        XmlNode channelElement = xmlDocument.SelectSingleNode("rss/channel");

        XmlElement titleElement = xmlDocument.CreateElement("title");

        titleElement.InnerText = item.Title;

        itemElement.AppendChild(titleElement);

        XmlElement linkElement = xmlDocument.CreateElement("link");

        linkElement.InnerText = item.Link;

        itemElement.AppendChild(linkElement);

        XmlElement descriptionElement = xmlDocument.CreateElement("description");


        descriptionElement.InnerText = item.Description;
        descriptionElement.InnerXml  = "<![CDATA[" + item.cData + "]]>";

        itemElement.AppendChild(descriptionElement);


        // append the item

        channelElement.AppendChild(itemElement);

        return(xmlDocument);
    }
Esempio n. 22
0
        protected override RssItem ParseItem(XElement item)
        {
            var rssItem = new RssItem
            {
                Title = item.GetSafeElementString("title"),
                Link  = item.GetSafeElementString("link"),
                Image = item.GetImage()
            };


            string description = item.GetSafeElementString("description");

            rssItem.Description = !string.IsNullOrEmpty(description)
                ? description
                : item.GetSafeElementString("content");

            rssItem.PublishDate = item.GetSafeElementDate("date", _nsRdfElementsNamespaceUri);
            rssItem.Guid        = item.GetSafeElementString("identifier", _nsRdfElementsNamespaceUri);

            //Use the element's link as guid if necessary
            if (string.IsNullOrEmpty(rssItem.Guid))
            {
                rssItem.Guid = rssItem.Link;
            }

            return(rssItem);
        }
Esempio n. 23
0
        /// <summary>
        /// Сохранение новой записи
        /// </summary>
        /// <param name="item"></param>
        private async Task <int> SaveItem(RssItem item)
        {
            int result = 0;

            try
            {
                using (var connection = GetConnection())
                    using (var command = connection.CreateCommand())
                    {
                        command.CommandText = "INSERT INTO items (id, title, description, date, link)" +
                                              " VALUES (@id, @title, @description, @date, @link)";
                        command.Parameters.AddWithValue("id", item.Id);
                        command.Parameters.AddWithValue("title", item.Title);
                        command.Parameters.AddWithValue("description", item.Description);
                        command.Parameters.AddWithValue("date", item.Date);
                        command.Parameters.AddWithValue("link", item.Link);

                        await connection.OpenAsync();

                        result = await command.ExecuteNonQueryAsync();
                    }
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"Ошибка в {nameof(SaveItem)}: {ex.Message}");
            }

            return(result);
        }
        public static bool Add(RssItem rssItem, bool isDaily)
        {
            bool returnValue = false;

            if (rssItem != null)
            {
                lock (_LockObject)
                {
                    while (Maximum > 0 && _Items.Count >= Maximum)
                    {
                        _Items.RemoveAt(0);
                    }

                    if (isDaily)
                    {
                        SetDailyItem(rssItem, DateTime.Now);
                    }

                    if (!_Items.Contains(rssItem))
                    {
                        _Items.Add(rssItem);

                        returnValue = true;
                    }
                }
            }

            return(returnValue);
        }
Esempio n. 25
0
        public RssItem GetFeed()
        {
            // To save on hitting bandwidth let's only hit the server 1 in 10 times
            if (timesUpdated > 10)
            {
                timesUpdated = 0;
            }

            RssItem item = null;

            if (timesUpdated < 1)
            {
                var client = new RssClient();
                var feed   = client.GetRssFeed(new Uri(this.feedUrl));
                this.feedItems = feed?.Items;

                item = feed?.Items?.FirstOrDefault();
            }
            else
            {
                if (this.feedItems != null)
                {
                    int i = this.randomGenerator.Next(this.feedItems.Count() - 1);
                    item = this.feedItems.Skip(i).FirstOrDefault();
                }
            }

            timesUpdated++;
            return(item);
        }
Esempio n. 26
0
        private RssItem GetItemFor(AllFeed feed, PluginContainer SelectedPlugin)
        {
            string folder =
                FileManager.RemovePath(
                    FileManager.GetDirectory(SelectedPlugin.AssemblyLocation));

            folder = folder.Replace("/", "");
            if (!folder.ToLowerInvariant().EndsWith("plugin"))
            {
                folder += "plugin";
            }
            folder = folder.ToLower();

            RssItem itemToReturn = null;

            string whatToLookFor = folder + ".plug";

            // We're going to narrow things down a bit here:
            whatToLookFor = ">" + whatToLookFor + @"</a>";

            foreach (var item in feed.Items)
            {
                var description = item.Description.ToLower();

                if (description.Contains(whatToLookFor))
                {
                    itemToReturn = item;
                    break;
                }
            }

            return(itemToReturn);
        }
Esempio n. 27
0
 /* ----------------------------------------------------------------- */
 ///
 /// Convert
 ///
 /// <summary>
 /// Convert メソッドを実行します。
 /// </summary>
 ///
 /* ----------------------------------------------------------------- */
 private string Convert(RssItem src, LockSetting setting) =>
 new TitleConverter().Convert(
     new object[] { src, setting },
     typeof(string),
     null,
     CultureInfo.CurrentCulture
     ) as string;
        public virtual async Task <IActionResult> NewProductsRss([FromServices] IWebHelper webHelper)
        {
            var feed = new RssFeed(
                string.Format("{0}: New products", _storeContext.CurrentStore.GetLocalized(x => x.Name, _workContext.WorkingLanguage.Id)),
                "Information about products",
                new Uri(webHelper.GetStoreLocation(false)),
                DateTime.UtcNow);

            if (!_catalogSettings.NewProductsEnabled)
            {
                return(new RssActionResult(feed, webHelper.GetThisPageUrl(false)));
            }

            var items = new List <RssItem>();

            var products = (await _productService.SearchProducts(
                                storeId: _storeContext.CurrentStore.Id,
                                visibleIndividuallyOnly: true,
                                markedAsNewOnly: true,
                                orderBy: ProductSortingEnum.CreatedOn,
                                pageSize: _catalogSettings.NewProductsNumber)).products;

            foreach (var product in products)
            {
                string productUrl         = Url.RouteUrl("Product", new { SeName = product.GetSeName(_workContext.WorkingLanguage.Id) }, webHelper.IsCurrentConnectionSecured() ? "https" : "http");
                string productName        = product.GetLocalized(x => x.Name, _workContext.WorkingLanguage.Id);
                string productDescription = product.GetLocalized(x => x.ShortDescription, _workContext.WorkingLanguage.Id);
                var    item = new RssItem(productName, productDescription, new Uri(productUrl), String.Format("urn:store:{0}:newProducts:product:{1}", _storeContext.CurrentStore.Id, product.Id), product.CreatedOnUtc);
                items.Add(item);
            }
            feed.Items = items;
            return(new RssActionResult(feed, webHelper.GetThisPageUrl(false)));
        }
Esempio n. 29
0
        private void RemoveHistoryBtn_Click(object sender, EventArgs e)
        {
            RssItem item = (RssItem)HistoryListbox.SelectedItem;

            controller.History.Remove(item);
            HistoryListbox.Items.Remove(item);
        }
Esempio n. 30
0
        public void GetFeed(RssFile file)
        {
            var rssFormatter = RssParser.GetFeed(file.AtomLink);

            file.LastUpdateDate = rssFormatter.LastUpdatedTime;
            file.Description    = rssFormatter.Description.Text;
            file.Language       = rssFormatter.Language;
            file.Title          = rssFormatter.Title.Text;


            foreach (SyndicationItem item in rssFormatter.Items)
            {
                RssItem rssItem = new RssItem
                {
                    Title       = item.Title.Text,
                    Description = item.Summary.Text,
                    PublishDate = item.PublishDate.DateTime,
                    RssFileId   = file.Id,
                    Link        = item.Id
                };
                _rssItemRepository.AddRssItem(rssItem);
            }
            ListenServiceClient service = new ListenServiceClient();

            service.FireDatabaseEvents();
        }
        public static void AddItem(RssItem item)
        {
            GetRssFeed(Path);
            if (_channel != null)
            {
                _channel.Items.Add(item);
                _channel.LastBuild = item.PubDate;

                WriteRss(Path);
            }
        }
Esempio n. 32
0
        //加入Rss新闻为预处理
        public void AddRssItem(string title)
        {
            SQLiteDS.RssItemRow row = mf.DS.RssItem.FindByTitle(title);
            RssItem rsit = new RssItem();
            rsit.Site = row.Site;
            rsit.Title = row.Title;
            rsit.PubDate = row.PubDate;
            rsit.Link = row.Link;
            rsit.IsRead = row.Link;
            rsit.Content = row.Content;

            ListViewItem lv = new ListViewItem(rsit.Title);
            lv.Tag = rsit;
            listView1.Items.Add(lv);
        }
Esempio n. 33
0
        /// <summary>
        /// Adds a blog to the item collection and start retrieving the blogs.
        /// </summary>
        private static void AddBlog(string name, string description, string feedUrl, string website, string xfn)
        {
            RssItem item = new RssItem();
              item.RssUrl = feedUrl;
              item.WebsiteUrl = website;
              item.Name = name;
              item.Description = description;
              item.Xfn = xfn;

              item.Request = (HttpWebRequest)WebRequest.Create(feedUrl);
              item.Request.Credentials = CredentialCache.DefaultNetworkCredentials;

              _Items.Add(item);

              item.Request.BeginGetResponse(ProcessRespose, item);
        }
Esempio n. 34
0
        private static RssItem ParseItem(XElement item)
        {
            var rssItem = new RssItem {Title = item.GetSafeElementString("title")};

            string description = item.GetSafeElementString("description");
            rssItem.Description = !string.IsNullOrEmpty(description)
                ? description
                : item.GetSafeElementString("content");

            rssItem.Image = item.GetImage();
            rssItem.PublishDate = item.GetSafeElementDate("published") ?? item.GetSafeElementDate("updated");
            rssItem.Guid = item.GetSafeElementString("id");
            rssItem.Link = item.GetLink("alternate");

            return rssItem;
        }
Esempio n. 35
0
 public void ReLoad()
 {
     listView1.Items.Clear();
     var q = from p in mf.DS.RssItem.AsEnumerable()
             where p.IsRead == "待处理"
             select p;
     foreach (var it in q)
     {
         RssItem rssit = new RssItem();
         rssit.Title = it.Title;
         rssit.Site = it.Site;
         rssit.PubDate = it.PubDate;
         rssit.Link = it.Link;
         rssit.Content = it.Content;
         rssit.IsRead = it.IsRead;
         ListViewItem lv = new ListViewItem(it.Title);
         lv.Tag = rssit;
         listView1.Items.Add(lv);
     }
 }
Esempio n. 36
0
        protected override RssItem ParseItem(XElement item)
        {
            var rssItem = new RssItem
            {
                Title = item.GetSafeElementString("title"),
                Link = item.GetSafeElementString("link"),
                PublishDate = item.GetSafeElementDate("pubDate"),
                Guid = item.GetSafeElementString("guid"),
                Image = item.GetImage()
            };

            string description = item.GetSafeElementString("description");
            rssItem.Description = !string.IsNullOrEmpty(description)
                ? description
                : item.GetSafeElementString("content");

            //Use the element's link as guid if necessary
            if (string.IsNullOrEmpty(rssItem.Guid))
                rssItem.Guid = rssItem.Link;

            return rssItem;
        }
Esempio n. 37
0
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);

        RssFeed feed = new RssFeed();

        feed.Channel.Link = new Uri("http://blag.Jiyuu.org/");
        feed.Channel.Title = "אנימה בלאג";
        feed.Channel.Description = "סיכום הפוסטים האחרונים שאונדקסו בבלאג";

        List<BlogPost> posts = AggregationManager.GetPosts(null, null).Take(15).ToList();

        RssItem item;
        foreach (BlogPost post in posts)
        {
            item = new RssItem();
            item.Title = post.Title;
            item.Link = new Uri(post.Link);
            item.Description = post.Summary;

            Argotic.Extensions.Core.SiteSummaryContentSyndicationExtension contentExt = new Argotic.Extensions.Core.SiteSummaryContentSyndicationExtension();
            contentExt.Context.Encoded = "";// HttpUtility.HtmlDecode(string.Format(@"<dir=""rtl"" style=""text-align: right;"" trbidi=""on"">{0}</div>", post.Summary));
            //Argotic.Extensions.Core.SiteSummaryContentItem content = new Argotic.Extensions.Core.SiteSummaryContentItem();
            //content.Content = new XCData(string.Format(@"<dir=""rtl"" style=""text-align: right;"" trbidi=""on"">{0}</div>", post.Summary)).ToString();
            //contentExt.Context.Items.Add(content);
            item.AddExtension(contentExt);
            item.PublicationDate = post.PublicationTS;
            feed.Channel.AddItem(item);

        }

        //using (FileStream stream = new FileStream("SimpleRssFeed.xml", FileMode.Create, FileAccess.Write))
        //{
        Response.ContentType = "application/rss+xml";
        Response.Write(feed.CreateNavigator().OuterXml);

        //}
    }
Esempio n. 38
0
        //点击自动批量下载新闻正文
        public void ReLoadSelectFrmListView(TreeNode tn)
        {
            NavUrl nu = tn.Tag as NavUrl;

            List<RssItem> listRss = new List<RssItem>();

            listView1.Items.Clear();
            var q = from p in mf.DS.RssItem.AsEnumerable()
                    where p.ChannelCode.StartsWith(nu.Code) && p.IsRead == "F"
                    orderby p.PubDate descending, p.Title
                    select p;
            foreach (var i in q)
            {
                RssItem ri = new RssItem(mf.DS, i.RssItemID, i.SiteName, i.ChannelCode, i.Title, i.Link, Convert.ToDateTime(i.PubDate)
                , i.IsRead, i.Content);
                ri.uplist = new UpdataListView(_UplistView);
                listRss.Add(ri);
            }
            //todo:这里可否运行多线程的自动下载内容部分?然后改一下,listview表中项的背景显示。

            //保存RssItem数据 由于更改了RssItem类,有strat()方法,得到的RssItem对象。

            //多线程启动了下载内容部分。
            for (int i = 0; i < listRss.Count; i++)
            {
                if (listRss[i].Content == "")
                {
                    listRss[i].Start();
                }
                else
                {
                    DownContent(listRss[i].Link);
                }

            }
            //存盘吗???
            //  mf.SaveRssItemToDB(mf.DS.RssItem);
        }
Esempio n. 39
0
        public static RssFeed GenerateNewsRSS(DateTime StartTime, DateTime EndTime)
        {
            RssFeed ObjRss = SetRssAndChannel("اخبار سایت", "آخرین اخبار سایت", "http://www.hossein-shirazi.com/DSD/NewsList.aspx");

            RssChannel ObjRSSChannel = ObjRss.Channels[0];

            /////////////////////////////////////////////////////////////////////////////////////////////

            ObjRSSChannel.Image = SetRssImage();
            ////////////////////////////////////////////////////////////////////////////////////////////////
            long RecordCount;
            List<News> newsList = News_DataProvider.GetNews(out RecordCount, null, null, StartTime, EndTime, News_DataProvider.NewsStatusType.Confirmed);

            if (newsList.Count > 0)
            {
                foreach (News Item in newsList)
                {
                    RssItem ObjRSSItem = new RssItem
                                             {
                                                 Author = PersianDateTime.MiladiToPersian(Item.CreateDateTime).ToShortDateString(),
                                                 Title = Item.Summary,
                                                 Description = Item.Body,
                                                 Comments = new Uri("http://Kids.bmi.ir/InfoBox/ShowNews.aspx?newsId=" + Item.NewsId).ToString(),
                                                 Link = new Uri("http://Kids.bmi.ir/InfoBox/ShowNews.aspx?newsId=" + Item.NewsId),
                                                 PubDate = Item.CreateDateTime
                                             };

                    ObjRSSChannel.Items.Add(ObjRSSItem);
                }
            }
            else
            {
                RssItem ObjRSSItem = new RssItem { Title = "No Data Available!", Description = "No Data Available!" };
                ObjRSSChannel.Items.Add(ObjRSSItem);
            }
            return ObjRss;
        }
Esempio n. 40
0
        //采集规则
        private void CaijiRule(object e)
        {
            clNode cn = e as clNode;
            #region 新浪规则
            //判断新浪sina网站的Url需要截取
            // if (cn.Name.Contains("sina"))
            if (cn.Link.Contains("sina.com.cn"))
            {
                //加载RSS新闻数据
                Regex regex = new Regex(@"(?<=[=]).*");
                //http://go.rss.sina.com.cn/redirect.php?url=http://tech.sina.com.cn/it/2013-11-16/09198919884.shtml
                XElement rssData = XElement.Load(cn.Link);

                //取出新闻标题,转成RssItem对象,并暂存到列表控件中
                var itemQuery = from item in rssData.Descendants(XName.Get("item"))
                                select new
                                {
                                    Title = item.Element(XName.Get("title")).Value.Trim(),
                                    Link = regex.Match(item.Element(XName.Get("link")).Value).ToString(),
                                    PubDate = item.Element(XName.Get("pubDate")).Value
                                };
                foreach (var result in itemQuery)
                {

                    //查数据库中是否已有相同标题,没有再追加!
                    if (!(mf.DS.RssItem.Contains(mf.DS.RssItem.FindByTitle(result.Title))))
                    {
                        RssItem it = new RssItem(cn.ParentTx, result.Title.Trim(), result.Link, Convert.ToDateTime(result.PubDate), "未读", "");
                        ListViewItem lv = new ListViewItem(new string[] { it.Title, it.PubDate.ToString("MM-dd HH:mm:ss"), cn.ParentTx });
                        lv.Tag = it;

                        SQLiteDS.RssItemRow rssRow = mf.DS.RssItem.AddRssItemRow(cn.ParentTx, result.Title, result.Link, Convert.ToDateTime(result.PubDate), "未读", "");
                        mf.rssTap.Update(rssRow);
                    }

                }
            }
            #endregion

            #region 网易规则
            //判断163的RSS,提取url时址址数据在guid中
            ////163网易
            ////http://news.163.com/13/1114/02/9DK05PBU0001124J.html
            ////http://news.163.com/13/1114/02/9DK05PBU0001124J_all.html
            if (cn.Name.Contains("163"))
            {
                //加载RSS新闻数据
                //string s1 = "http://news.163.com/13/1114/02/9DK05PBU0001124J.html";
                //string s = s1.Insert(s1.LastIndexOf('.'),"_all");
                //MessageBox.Show(s);

                XElement rssData = XElement.Load(cn.Link);

                //取出新闻标题,转成RssItem对象,并暂存到列表控件中
                var itemQuery = from item in rssData.Descendants(XName.Get("item"))
                                select new
                                {
                                    Title = item.Element(XName.Get("title")).Value.Trim(),
                                    Link = item.Element(XName.Get("guid")).Value,
                                    PubDate = item.Element(XName.Get("pubDate")).Value
                                };
                foreach (var result in itemQuery)
                {

                    //查数据库中是否已有相同标题,没有再追加!
                    if (!(mf.DS.RssItem.Contains(mf.DS.RssItem.FindByTitle(result.Title))))
                    {
                        RssItem it = new RssItem(cn.ParentTx, result.Title.Trim(), (result.Link.Insert(result.Link.LastIndexOf("."), "_all")), Convert.ToDateTime(result.PubDate), "未读", "");
                        ListViewItem lv = new ListViewItem(new string[] { it.Title, it.PubDate.ToString("MM-dd HH:mm:ss"), cn.ParentTx });
                        lv.Tag = it;

                        SQLiteDS.RssItemRow rssRow = mf.DS.RssItem.AddRssItemRow(cn.ParentTx, result.Title, (result.Link.Insert(result.Link.LastIndexOf("."), "_all")), Convert.ToDateTime(result.PubDate), "未读", "");
                        mf.rssTap.Update(rssRow);
                    }

                }
            }
            #endregion

            #region 新华网规则
            if (cn.Name.Contains("xinhuanet"))
            {
                //加载RSS新闻数据
                XElement rssData = XElement.Load(cn.Link);

                //看来只能用正规截取了!
                //<link>http://news.xinhuanet.com/shuhua/2013-11/16/c_125712954.htm</link>
                //Sat,16-Nov-2013 11:33:12 GMT
                //<description>
                Regex regex = new Regex(@"(?<=<\/link>)(.*?)(?=<description>)");
                //想到的办法:一是通过xelement对象,正规取得;二是在源码中加入pubDate标签。
                //取出新闻标题,转成RssItem对象,并暂存到列表控件中
                #region test
                //var i = rssData.Descendants(XName.Get("item")).First();
                //MessageBox.Show(i.ToString());//保留了xelement格式。
                //去除标题的a标签。
                Regex regTitle = new Regex(@"</?.+?>");
                //去除连接中的双引号
                //string s="\"http://news.xinhuanet.com/edu/2013-10/11/c_125515383.htm\"";
                //MessageBox.Show(s.Replace("\"", ""));
                #endregion
                var itemQuery = from item in rssData.Descendants(XName.Get("item"))
                                select new
                                {
                                    Title = regTitle.Replace(item.Element(XName.Get("title")).Value.Trim(), ""),
                                    Link = item.Element(XName.Get("link")).Value.Replace("\"", ""),
                                    PubDate = regex.Match(item.ToString()).ToString()
                                    //PubDate = item.Element(XName.Get("pubDate")).Value

                                };

                foreach (var result in itemQuery)
                {

                    //查数据库中是否已有相同标题,没有再追加!
                    if (!(mf.DS.RssItem.Contains(mf.DS.RssItem.FindByTitle(result.Title))))
                    {
                        RssItem it = new RssItem(cn.ParentTx, result.Title.Trim(), result.Link, Convert.ToDateTime(result.PubDate), "未读", "");
                        ListViewItem lv = new ListViewItem(new string[] { it.Title, it.PubDate.ToString("MM-dd HH:mm:ss"), cn.ParentTx });
                        lv.Tag = it;

                        SQLiteDS.RssItemRow rssRow = mf.DS.RssItem.AddRssItemRow(cn.ParentTx, result.Title, result.Link, Convert.ToDateTime(result.PubDate), "未读", "");
                        mf.rssTap.Update(rssRow);
                    }

                }
            }
            #endregion

            #region FT中文
            //加入全文采集规则 http://www.ftchinese.com/story/001053357?full=y
            if (cn.Name.Contains("ftchinese"))
            {

                XElement rssData = XElement.Load(cn.Link);

                //取出新闻标题,转成RssItem对象,并暂存到列表控件中
                var itemQuery = from item in rssData.Descendants(XName.Get("item"))
                                select new
                                {
                                    Title = item.Element(XName.Get("title")).Value.Trim(),
                                    Link = item.Element(XName.Get("link")).Value,
                                    PubDate = item.Element(XName.Get("pubDate")).Value
                                };
                foreach (var result in itemQuery)
                {

                    //查数据库中是否已有相同标题,没有再追加!
                    if (!(mf.DS.RssItem.Contains(mf.DS.RssItem.FindByTitle(result.Title + "?full=y"))))
                    {
                        RssItem it = new RssItem(cn.ParentTx, result.Title.Trim(), (result.Link + "?full=y"), Convert.ToDateTime(result.PubDate), "未读", "");
                        ListViewItem lv = new ListViewItem(new string[] { it.Title, it.PubDate.ToString("MM-dd HH:mm:ss"), cn.ParentTx });
                        lv.Tag = it;

                        SQLiteDS.RssItemRow rssRow = mf.DS.RssItem.AddRssItemRow(cn.ParentTx, result.Title, (result.Link + "?full=y"), Convert.ToDateTime(result.PubDate), "未读", "");
                        mf.rssTap.Update(rssRow);
                    }

                }
            }
            #endregion

            else
            {
                #region 正常规则
                try
                {
                    //加载RSS新闻数据
                    XElement rssData = XElement.Load(cn.Link);

                    //取出新闻标题,转成RssItem对象,并暂存到列表控件中
                    var itemQuery = from item in rssData.Descendants(XName.Get("item"))
                                    select new
                                    {
                                        Title = item.Element(XName.Get("title")).Value.Trim(),
                                        Link = item.Element(XName.Get("link")).Value,
                                        PubDate = item.Element(XName.Get("pubDate")).Value
                                    };

                    foreach (var result in itemQuery)
                    {
                        //查数据库中是否已有相同标题,没有再追加!
                        if (!(mf.DS.RssItem.Contains(mf.DS.RssItem.FindByTitle(result.Title))))
                        {
                            RssItem it = new RssItem(cn.ParentTx, result.Title.Trim(), result.Link, Convert.ToDateTime(result.PubDate), "未读", "");
                            ListViewItem lv = new ListViewItem(new string[] { it.Title, it.PubDate.ToString("MM-dd HH:mm:ss"), cn.ParentTx });
                            lv.Tag = it;

                            SQLiteDS.RssItemRow rssRow = mf.DS.RssItem.AddRssItemRow(cn.ParentTx, result.Title, result.Link, Convert.ToDateTime(result.PubDate), "未读", "");
                            mf.rssTap.Update(rssRow);
                        }

                    }

                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
                #endregion
            }
        }
 public TorrentRssWatcherEventArgs(RssFilter matchedFilter, RssItem item)
     : base(item.Link)
 {
     this.matchedFilter = matchedFilter;
     this.item = item;
 }
Esempio n. 42
0
        private void AddRssChildItems(RssItem item, HtmlGenericControl li)
        {
            if (item.ItemTitles.Count > 0 && BlogSettings.Instance.BlogrollVisiblePosts > 0)
              {
            HtmlGenericControl div = new HtmlGenericControl("ul");
                for (int i = 0; i < item.ItemTitles.Count; i++)
                {
                    if (i >= BlogSettings.Instance.BlogrollVisiblePosts) break;

                    HtmlGenericControl subLi = new HtmlGenericControl("li");
                    HtmlAnchor a = new HtmlAnchor();
                    a.HRef = item.ItemLinks[i];
                    a.Title = HttpUtility.HtmlEncode(item.ItemTitles[i]);
                    a.InnerHtml = EnsureLength(item.ItemTitles[i]);

                    subLi.Controls.Add(a);
                    div.Controls.Add(subLi);
                }

            li.Controls.Add(div);
              }
        }
Esempio n. 43
0
        void OnLoopUpdate(object sender, EventArgs e)
        {
            if ((DateTime.Now - lastUrlUpdate_) > TimeSpan.FromMinutes(10))
            {
                var doc = new XmlDocument();
                try
                {
                    doc.Load(Marquee.RemoteUrl);
                    var nodes = doc.GetElementsByTagName("item");
                    items_.Clear();
                    foreach (var elem in nodes.OfType<XmlElement>())
                    {
                        RssItem item = new RssItem();
                        item.title = elem.GetElementsByTagName("title")[0].InnerText;
                        item.link = elem.GetElementsByTagName("link")[0].InnerText;
                        items_.Add(item);
                    }
                    itr_ = items_.GetEnumerator();
                }
                catch (Exception ex)
                {
                    var msg = string.Format("url: {0} - {1}", Marquee.RemoteUrl, ex.Message);
                    System.Diagnostics.Debug.WriteLine(msg);
                }
                lastUrlUpdate_ = DateTime.Now;
            }

            ShowNext();
        }
Esempio n. 44
0
        /// <summary>
        /// Rss导航新闻列表事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void NavNodeClik(object sender, TreeNodeMouseClickEventArgs e)
        {
            var q = from p in mf.DS.RssItem.AsEnumerable()
                    where p.IsRead == "未读"
                    orderby p.PubDate descending, p.Title
                    select p;

            if (e.Node.Text == "RSS")
            {
                //listBox1.Items.Clear();
                listView1.Items.Clear();
                var q1 = from p in q
                         orderby p.PubDate descending, p.Title
                         select p;

                foreach (var item in q1)
                {
                    RssItem rsit = new RssItem();
                    rsit.Site = item.Site;
                    rsit.Title = item.Title;
                    rsit.Link = item.Link;
                    rsit.PubDate = item.PubDate;
                    rsit.IsRead = item.IsRead;
                    rsit.Content = item.Content;
                    //listBox1.Items.Add(rsit);
                    ListViewItem lv = new ListViewItem(new string[] { rsit.Title, rsit.PubDate.ToString("MM-dd HH:mm:ss"), rsit.Site });
                    lv.Tag = rsit;
                    listView1.Items.Add(lv);
                }
            }
            if (e.Node.Parent != null && e.Node.Nodes.Count > 0)
            {
                #region 加载数据

                //listBox1.Items.Clear();
                listView1.Items.Clear();
                var q2 = from p in mf.DS.RssItem.AsEnumerable()
                         where p.IsRead == "未读" && p.Site == e.Node.Text
                         orderby p.PubDate descending, p.Title
                         select p;
                foreach (var item in q2)
                {
                    RssItem rsit = new RssItem();
                    rsit.Site = item.Site;
                    rsit.Title = item.Title;
                    rsit.Link = item.Link;
                    rsit.PubDate = item.PubDate;
                    rsit.IsRead = item.IsRead;
                    rsit.Content = item.Content;

                    //listBox1.Items.Add(rsit);
                    //加入临时列表;
                    //DBRssItem.Add(rsit);
                    ListViewItem lv = new ListViewItem(new string[] { rsit.Title, rsit.PubDate.ToString("MM-dd HH:mm:ss"), rsit.Site });
                    lv.Tag = rsit;
                    listView1.Items.Add(lv);
                }

                #endregion

            }
            if (e.Node.GetNodeCount(false) == 0)
            {
                if (e.Node.Tag != null)
                {
                    listView1.Items.Clear();
                    //Thread t = new Thread(new ParameterizedThreadStart(CaijiRule));
                    //object cn = new clNode(e.Node.Parent.Text, e.Node.Name, e.Node.Tag.ToString(), e.Node.Text);
                    //t.IsBackground = true;
                    //t.Start(cn);
                   // CaijiRule(new clNode(e.Node.Parent.Text, e.Node.Name, e.Node.Tag.ToString(), e.Node.Text));
                }
            }
        }
Esempio n. 45
0
 /// <summary>Inserts an item into this collection at a specified index.</summary>
 /// <param name="index">The zero-based index of the collection at which to insert the item.</param>
 /// <param name="item">The item to insert into this collection.</param>
 public void Insert(int index, RssItem.RssItem item)
 {
     pubDateChanged = true;
     List.Insert(index, item);
 }
Esempio n. 46
0
 /// <summary>Copies the entire RssItemCollection to a compatible one-dimensional <see cref="Array"/>, starting at the specified index of the target array.</summary>
 /// <param name="array">The one-dimensional RssItem Array that is the destination of the elements copied from RssItemCollection. The Array must have zero-based indexing.</param>
 /// <param name="index">The zero-based index in array at which copying begins.</param>
 /// <exception cref="ArgumentNullException">array is a null reference (Nothing in Visual Basic).</exception>
 /// <exception cref="ArgumentOutOfRangeException">index is less than zero.</exception>
 /// <exception cref="ArgumentException">array is multidimensional. -or- index is equal to or greater than the length of array.-or-The number of elements in the source RssItemCollection is greater than the available space from index to the end of the destination array.</exception>
 public void CopyTo(RssItem.RssItem[] array, int index)
 {
     List.CopyTo(array, index);
 }
Esempio n. 47
0
    public static string PrepareTwitterStatus(RssItem item)
    {
        string postString;
        string titleString = string.Empty;
        bool tainted = false;

        // This wee little bit of information should ensure we don't add any &#39; shit into the string
        foreach (char oneChar in item.Title.ToCharArray())
        {
            if ( (oneChar == ';') && (tainted) )
            {
                tainted = false;
                continue;
            }
            else if (oneChar == '&')
            {
                tainted = true;
                continue;
            }
            else if (oneChar == ';')
            {
                continue;
            }
            else
            {
                if (!tainted)
                    titleString += oneChar;
            }
        }

        if (item.Title.Length > 124)
        {
            postString = titleString.Substring(0,124);
            postString += ".. ";
        }
        else
        {
            postString = titleString;
        }

        Console.WriteLine(item.Link);
        postString += string.Format(": {0}", FetchTinyUrl(item.Link));

        return postString;
    }
        public static RssChannel GetRssFeed(string path)
        {
            Path = path;
            if (_channel == null)
            {
                _channel = new RssChannel();
                _channel.Items = new List<RssItem>();

                try
                {
                    // Parse RSS
                    using (XmlReader reader = XmlReader.Create(path))
                    {
                        // Get channel Info
                        if (!reader.ReadToFollowing("channel")) return null;

                        if (reader.ReadToFollowing("title"))
                        {
                            _channel.Title = reader.ReadElementContentAsString();
                        }
                        if (reader.ReadToFollowing("description"))
                        {
                            _channel.Description = reader.ReadElementContentAsString();
                        }
                        if (reader.ReadToFollowing("link"))
                        {
                            _channel.Link = reader.ReadElementContentAsString();
                        }
                        if (reader.ReadToFollowing("lastBuildDate"))
                        {
                            _channel.LastBuild = StringToDateTime(reader.ReadElementContentAsString());
                        }
                        if (reader.ReadToFollowing("pubDate"))
                        {
                            _channel.PubDate = StringToDateTime(reader.ReadElementContentAsString());
                        }
                        if (reader.ReadToFollowing("ttl"))
                        {
                            _channel.Ttl = reader.ReadElementContentAsInt();
                        }

                        // Get items
                        while (reader.ReadToFollowing("item"))
                        {
                            RssItem item = new RssItem();

                            if (reader.ReadToFollowing("title"))
                            {
                                item.Title = reader.ReadElementContentAsString();
                            }
                            if (reader.ReadToFollowing("description"))
                            {
                                item.Description = reader.ReadElementContentAsString();
                            }
                            if (reader.ReadToFollowing("link"))
                            {
                                item.Link = reader.ReadElementContentAsString();
                            }
                            if (reader.ReadToFollowing("guid"))
                            {
                                item.GuID = reader.ReadElementContentAsInt();
                            }
                            if (reader.ReadToFollowing("pubDate"))
                            {
                                item.PubDate = StringToDateTime(reader.ReadElementContentAsString());
                            }

                            // Add the new item
                            _channel.Items.Add(item);
                        }
                    }

                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    _channel = null;
                }
            }

            return _channel;
        }
Esempio n. 49
0
 public void AddRssItem(RssItem item)
 {
     _rss = addRssItem(_rss, item);
 }
Esempio n. 50
0
    private static XmlDocument addRssItem(XmlDocument xmlDocument, RssItem item)
    {
        XmlElement itemElement = xmlDocument.CreateElement("item");

        XmlNode channelElement = xmlDocument.SelectSingleNode("rss/channel");

        XmlElement titleElement = xmlDocument.CreateElement("title");

        titleElement.InnerText = item.Title;

        itemElement.AppendChild(titleElement);

        XmlElement linkElement = xmlDocument.CreateElement("link");

        linkElement.InnerText = item.Link;

        itemElement.AppendChild(linkElement);

        XmlElement descriptionElement = xmlDocument.CreateElement("description");

        descriptionElement.InnerText = item.Description;

        itemElement.AppendChild(descriptionElement);

        // append the item

        channelElement.AppendChild(itemElement);

        return xmlDocument;
    }
Esempio n. 51
0
        private void AddRssChildItems(RssItem item, HtmlGenericControl li)
        {
            if (item.Items.Count > 0 && BlogSettings.Instance.BlogrollVisiblePosts > 0)
              {
            HtmlGenericControl div = new HtmlGenericControl("ul");
            int i = 0;
            foreach (string key in item.Items.Keys)
            {
              if (i >= BlogSettings.Instance.BlogrollVisiblePosts) break;

              HtmlGenericControl subLi = new HtmlGenericControl("li");
              HtmlAnchor a = new HtmlAnchor();
              a.HRef = item.Items[key];
              a.Title = HttpUtility.HtmlEncode(key);
              a.InnerHtml = EnsureLength(key);

              subLi.Controls.Add(a);
              div.Controls.Add(subLi);
              i++;
            }

            li.Controls.Add(div);
              }
        }
        private void XMLHasFinished(IAsyncResult theResult)
        {
            RefreshNewsDelegate del = (RefreshNewsDelegate)((AsyncResult)theResult).AsyncDelegate;
            List<RssItem> lstItems = del.EndInvoke(theResult);

            if (lstItems.Count > 0)
            {
                theItem = lstItems.First();
            }

            this.Dispatcher.BeginInvoke(new System.Windows.Forms.MethodInvoker(delegate()
            {
                if (theItem != null)
                {
                    blogText.ClearValue(FlowDocumentReader.DocumentProperty);
                    try
                    {
                        FlowDocument theDocument = XamlReader.Load(new XmlTextReader(new StringReader(theItem.Description))) as FlowDocument;
                        theDocument.Background = App.Current.Resources["LightAreaFill"] as RadialGradientBrush;
                        ParseLinks(theDocument);

                        //insert the date and the title
                        Paragraph pgDateAndTitle = new Paragraph();
                        pgDateAndTitle.FontFamily = App.Current.Resources["FontFamily"] as FontFamily;
                        pgDateAndTitle.FontWeight = FontWeights.Bold;
                        pgDateAndTitle.FontSize = 20;
                        pgDateAndTitle.Inlines.Add(new Run(theItem.Title));
                        pgDateAndTitle.Inlines.Add(new LineBreak());
                        pgDateAndTitle.Inlines.Add(new Run(theItem.Published.ToString("yyyy-MM-dd HH:mm:ss")));
                        theDocument.Blocks.InsertBefore(theDocument.Blocks.FirstBlock, pgDateAndTitle);

                        blogText.Document = theDocument;

                        btnFullArticle.IsEnabled = true;
                    }
                    catch (Exception ex)
                    {
                        Paragraph myErrorParagraph = new Paragraph();
                        myErrorParagraph.FontSize = 18;
                        myErrorParagraph.FontFamily = App.Current.Resources["FontFamily"] as FontFamily;
                        myErrorParagraph.Inlines.Add(new Run(myVariables.UnableToDisplayRSS));
                        myErrorParagraph.Inlines.Add(new LineBreak());
                        myErrorParagraph.Inlines.Add(new Run(ex.Message));
                        FlowDocument myErrorDocument = new FlowDocument();
                        myErrorDocument.Background = App.Current.Resources["LightAreaFill"] as RadialGradientBrush;
                        myErrorDocument.Blocks.Add(myErrorParagraph);
                        blogText.Document = myErrorDocument;
                    }
                }
            }), System.Windows.Threading.DispatcherPriority.Normal);
        }
Esempio n. 53
0
 /// <summary>Adds a specified item to this collection.</summary>
 /// <param name="item">The item to add.</param>
 /// <returns>The zero-based index of the added item.</returns>
 public int Add(RssItem.RssItem item)
 {
     pubDateChanged = true;
     return List.Add(item);
 }
Esempio n. 54
0
        private void writeItem(RssItem.RssItem item, int channelHashCode)
        {
            if (this.writer == null)
                throw new InvalidOperationException("RssWriter has been closed, and can not be written to.");
            if (item == null)
                throw new ArgumentNullException("Item must be instanciated with data to be written.");
            if (!this.wroteChannel)
                throw new InvalidOperationException("Channel must be written first, before writing an item.");

            this.BeginDocument();

            this.writer.WriteStartElement("item");
            switch (this.rssVersion)
            {
                case RssVersion.RSS090:
                case RssVersion.RSS10:
                case RssVersion.RSS091:
                    WriteElement("title", item.Title, true);
                    WriteElement("description", item.Description, false);
                    WriteElement("link", item.Link, true);
                    break;
                case RssVersion.RSS20:
                    if ((item.Title == RssDefault.String) && (item.Description == RssDefault.String))
                        throw new ArgumentException("item title and description cannot be null");
                    goto case RssVersion.RSS092;
                case RssVersion.RSS092:
                    WriteElement("title", item.Title, false);
                    WriteElement("description", item.Description, false);
                    WriteElement("link", item.Link, false);
                    if (item.Source != null)
                    {
                        this.writer.WriteStartElement("source");
                        WriteAttribute("url", item.Source.Url, true);
                        this.writer.WriteString(item.Source.Name);
                        this.writer.WriteEndElement();
                    }
                    if (item.Enclosure != null)
                    {
                        this.writer.WriteStartElement("enclosure");
                        WriteAttribute("url", item.Enclosure.Url, true);
                        WriteAttribute("length", item.Enclosure.Length, true);
                        WriteAttribute("type", item.Enclosure.Type, true);
                        this.writer.WriteEndElement();
                    }
                    foreach (RssCategory category in item.Categories)
                        if (category.Name != RssDefault.String)
                        {
                            this.writer.WriteStartElement("category");
                            WriteAttribute("domain", category.Domain, false);
                            this.writer.WriteString(category.Name);
                            this.writer.WriteEndElement();
                        }
                    break;
            }
            if (this.rssVersion == RssVersion.RSS20)
            {
                WriteElement("author", item.Author, false);
                WriteElement("comments", item.Comments, false);
                if ((item.Guid != null) && (item.Guid.Name != RssDefault.String))
                {
                    this.writer.WriteStartElement("guid");
                    try
                    {
                        this.WriteAttribute("isPermaLink", (bool) item.Guid.PermaLink, false);
                    }
                    catch
                    {
                    }
                    this.writer.WriteString(item.Guid.Name);
                    this.writer.WriteEndElement();
                }
                WriteElement("pubDate", item.PubDate, false);

                foreach (RssModule rssModule in this._rssModules)
                {
                    if (rssModule.IsBoundTo(channelHashCode))
                    {
                        foreach (RssModuleItemCollection rssModuleItemCollection in rssModule.ItemExtensions)
                        {
                            if (rssModuleItemCollection.IsBoundTo(item.GetHashCode()))
                                this.writeSubElements(rssModuleItemCollection, rssModule.NamespacePrefix);
                        }
                    }
                }
            }
            this.writer.WriteEndElement();
            this.writer.Flush();
        }
Esempio n. 55
0
 /// <summary>Determines whether the RssItemCollection contains a specific element.</summary>
 /// <param name="rssItem">The RssItem to locate in the RssItemCollection.</param>
 /// <returns>true if the RssItemCollection contains the specified value; otherwise, false.</returns>
 public bool Contains(RssItem.RssItem rssItem)
 {
     return List.Contains(rssItem);
 }
Esempio n. 56
0
 /// <summary>
 ///     Writes an RSS item
 /// </summary>
 /// <exception cref="InvalidOperationException">Either the RssWriter has already been closed, or the caller is attempting to write an RSS item before an RSS channel.</exception>
 /// <exception cref="ArgumentNullException">Item must be instanciated with data, before calling Write.</exception>
 /// <param name="item"> RSS item to write </param>
 public void Write(RssItem.RssItem item)
 {
     // NOTE: Standalone items cannot adhere to modules, hence -1 is passed. This may not be the case, however, no examples have been seen where this is legal.
     this.writeItem(item, -1);
 }
Esempio n. 57
0
 /// <summary>Searches for the specified RssItem and returns the zero-based index of the first occurrence within the entire RssItemCollection.</summary>
 /// <param name="rssItem">The RssItem to locate in the RssItemCollection.</param>
 /// <returns>The zero-based index of the first occurrence of RssItem within the entire RssItemCollection, if found; otherwise, -1.</returns>
 public int IndexOf(RssItem.RssItem rssItem)
 {
     return List.IndexOf(rssItem);
 }
Esempio n. 58
0
        private RssFeed ReadRssFeed(int feedID, string webSource)
        {
            database.Rss dbRss = new de.dhoffmann.mono.adfcnewsapp.buslog.database.Rss();
            RssFeed ret = new RssFeed();

            try
            {
                XDocument doc = XDocument.Parse(webSource);

                var channel = doc.Descendants("channel");

                if (channel != null)
                {
                    var qTitle = channel.Descendants("title").First();
                    string title = null;

                    if (qTitle != null)
                        title = FromHtml(qTitle.Value);

                    var qLink = channel.Descendants("link").First();
                    string link = null;

                    if (qLink != null)
                        link = qLink.Value;

                    var qDescription = channel.Descendants("description").First();
                    string description = null;

                    if (qDescription != null)
                        description = FromHtml(qDescription.Value);

                    DateTime lastBuildDate = DateTime.MinValue;
                    try
                    {
                        var qLastBuildDate = channel.Descendants("lastBuildDate").First();

                        // TODO prüfen
                        if (qLastBuildDate != null)
                            lastBuildDate = DateTime.Parse(qLastBuildDate.Value);
                    }
                    catch(Exception)
                    { ; }

                    ret.Header = new RssHeader()
                    {
                        FeedID = feedID,
                        Title = title,
                        Link = link,
                        Description = description,
                        LastBuildDate = lastBuildDate
                    };

                    // Das Datum der letzten Daten importieren
                    DateTime? dbLastBuildDate = dbRss.GetLastBuildDate(feedID);
                    dbLastBuildDate = null;

                    // Müssen die Items wirklich geparsed werden?
                    if(!dbLastBuildDate.HasValue || (ret != null && ret.Header != null && ret.Header.LastBuildDate.HasValue && dbLastBuildDate.Value < ret.Header.LastBuildDate.Value))
                    {
                        var items = doc.Descendants("item");

                        if (items != null)
                        {
                            List<RssItem> rssItems = new List<RssItem>();

                            foreach (var item in items)
                            {
                                RssItem rssItem = new RssItem();

                                rssItem.FeedID = feedID;

                                var qiTitle = item.Descendants("title").First();

                                if (qiTitle != null)
                                    rssItem.Title = FromHtml(qiTitle.Value);

                                var qiLink = item.Descendants("link").First();
                                if (qiLink != null)
                                    rssItem.Link = qiLink.Value;

                                var qiDescription = item.Descendants("description").First();

                                if (qiDescription != null)
                                    rssItem.Description = FromHtml(qiDescription.Value);

                                // Nicht alle haben diesen Node
                                try
                                {
                                    var qiCategory = item.Descendants("category").First();

                                    if (qiCategory != null)
                                        rssItem.Category = FromHtml(qiCategory.Value);
                                }
                                catch(Exception)
                                { ; }

                                try
                                {
                                    // TODO prüfen!!
                                    var qiPubDate = item.Descendants("pubDate").First();
                                    if (qiPubDate != null)
                                        rssItem.PubDate = DateTime.Parse(qiPubDate.Value);
                                }
                                catch(Exception)
                                { ; }

                                rssItems.Add(rssItem);
                            }

                            ret.Items = rssItems;
                        }
                    }
                }
            }
            catch(Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("ex: " + ex.ToString());
            }

            return ret;
        }
Esempio n. 59
0
 /// <summary>Removes a specified item from this collection.</summary>
 /// <param name="item">The item to remove.</param>
 public void Remove(RssItem.RssItem item)
 {
     pubDateChanged = true;
     List.Remove(item);
 }
Esempio n. 60
0
File: lb.cs Progetto: mono/lb
    public void RenderRSS(string output, IList entries, int start, int end)
    {
        RssChannel channel = MakeChannel ();

        for (int i = start; i < end; i++){
            int idx = entries.Count - i - 1;
            if (idx < 0)
                continue;

            DayEntry d = (DayEntry) entries [idx];

            Hashtable substitutions = new Hashtable ();
            FillEntrySubstitutions (substitutions, d, config.BlogWebDirectory, false);
            StringWriter description = new StringWriter (new StringBuilder (d.Body.Length));
            Translate (d.Body, description, substitutions);

            StringWriter sw = new StringWriter (new StringBuilder (d.Body.Length));
            Render (sw, entries, idx, "", false, false);
            RssItem item = new RssItem ();
            item.Author = config.Author;
            item.Description = description.ToString ();
            item.Guid = new RssGuid ();
            item.Guid.Name = config.BlogWebDirectory + d.PermaLink;
            item.Link = new Uri (item.Guid.Name);
            item.Guid.PermaLink = DBBool.True;

            item.PubDate = d.Date.ToUniversalTime ();
            if (d.Caption == ""){
                Console.WriteLine ("No caption for: " + d.DateCaption);
                d.Caption = d.DateCaption;
            }
            item.Title = d.Caption;

            channel.Items.Add (item);
        }

        FileStream o = CreateFile (output);
        XmlTextWriter xtw = new XmlTextWriter (o, new UTF8Encoding (false));
        Rss20Writer w = new Rss20Writer (xtw);

        w.Write (channel);
        w.Close ();
    }