Пример #1
0
        /// <summary>
        /// Handles rendering a feed.
        /// </summary>
        /// <param name="url">The url to read the feed from.</param>
        /// <param name="titlesOnly">Indicates if only titles should be displayed.</param>
        /// <param name="max">The maximum number of entries to display.</param>
        /// <param name="writer">The text writer to write to.</param>
        protected virtual void RenderFeed(string url, bool titlesOnly, int max, WikiPlex.Legacy.HtmlTextWriter writer)
        {
            XmlDocument xdoc = xmlDocumentReader.Read(url);

            Guard.NotNull(xdoc, "url");

            SyndicationFeed feed = syndicationReader.Read(xdoc);

            writer.AddAttribute(WikiPlex.Legacy.HtmlTextWriterAttribute.Class, "rss");
            writer.RenderBeginTag(WikiPlex.Legacy.HtmlTextWriterTag.Div);

            RenderAccentBar(writer, feed.Title);

            for (int i = 0; i < feed.Items.Count(); i++)
            {
                if (i >= max)
                {
                    break;
                }

                SyndicationItem item = feed.Items.ElementAt(i);

                writer.AddAttribute(WikiPlex.Legacy.HtmlTextWriterAttribute.Class, "entry");
                writer.RenderBeginTag(WikiPlex.Legacy.HtmlTextWriterTag.Div);
                writer.AddAttribute(WikiPlex.Legacy.HtmlTextWriterAttribute.Class, "title");
                writer.RenderBeginTag(WikiPlex.Legacy.HtmlTextWriterTag.Div);
                writer.AddAttribute(WikiPlex.Legacy.HtmlTextWriterAttribute.Href, item.Link, false);
                writer.RenderBeginTag(WikiPlex.Legacy.HtmlTextWriterTag.A);
                writer.Write(item.Title);
                writer.RenderEndTag(); //a
                writer.RenderEndTag(); // div

                writer.AddAttribute(WikiPlex.Legacy.HtmlTextWriterAttribute.Class, "moreinfo");
                writer.RenderBeginTag(WikiPlex.Legacy.HtmlTextWriterTag.Div);
                writer.AddAttribute(WikiPlex.Legacy.HtmlTextWriterAttribute.Class, "date");
                writer.RenderBeginTag(WikiPlex.Legacy.HtmlTextWriterTag.Span);
                writer.Write(item.Date);
                writer.RenderEndTag(); // span
                writer.Write(" &nbsp;|&nbsp; ");
                writer.AddAttribute(WikiPlex.Legacy.HtmlTextWriterAttribute.Class, "source");
                writer.RenderBeginTag(WikiPlex.Legacy.HtmlTextWriterTag.Span);
                writer.Write("From ");
                writer.AddAttribute(WikiPlex.Legacy.HtmlTextWriterAttribute.Target, "_blank");
                writer.AddAttribute(WikiPlex.Legacy.HtmlTextWriterAttribute.Href, url, false);
                writer.RenderBeginTag(WikiPlex.Legacy.HtmlTextWriterTag.A);
                writer.Write(feed.Title);
                writer.RenderEndTag(); // a
                writer.RenderEndTag(); // span
                writer.RenderEndTag(); // div

                if (!titlesOnly)
                {
                    writer.RenderBeginTag(WikiPlex.Legacy.HtmlTextWriterTag.P);
                    writer.Write(item.Description);
                    writer.RenderEndTag(); // p
                }

                writer.RenderEndTag(); // div
            }

            RenderAccentBar(writer, feed.Title);
            writer.RenderEndTag(); // div
        }