Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            #region Write Update RSS Feed

            #region 101
            RssItem item = new RssItem();
            item.Title = "105";
            item.Comments = "1.0.0.105";
            item.Description = "Freies Funknetz Switcher Version 1.0.0.105\n\n" +
                               "* \"Bake wiederholen\" Text  in \"Bake aktiviert\" geändert\n" +
                               "* Fehler gefixt der dazu geführt hat dass eine Bake ununterbrochen wiederholt wurde\n"+
                               "* Voice Schaltung nocheinmal überarbeitet jetzt erfolgt nurnoch eine Deaktiviert/Aktiviert\n"+
                               "  Meldung und sonst keine Änderung im Verhalten des Switchers\n";

            item.PubDate = DateTime.Now.ToUniversalTime();
            item.Link = new System.Uri("http://dropbox.schrankmonster.de/dropped/FFN-Switcher-105.zip");
            #endregion

            RssChannel channel = new RssChannel();
            channel.Items.Add(item);

            channel.Title = "Freies Funknetz Switcher Tool Update Channel";
            channel.Description = "Updates for FFN Switcher";
            channel.Link = new System.Uri("http://dropbox.schrankmonster.de/FFNSwitcher.xml");
            channel.Generator = "FFN Switcher Update Tool";
            channel.LastBuildDate = DateTime.Now;

            RssFeed feed = new RssFeed();
            feed.Channels.Add(channel);
            feed.Write("FFNSwitcher.xml");
            #endregion
        }
Ejemplo n.º 2
0
Archivo: Rss.cs Proyecto: joargp/CMS
        public void BuildIssue()
        {
            var data =
                Proxy.Repository<Issue>()
                    .GetAll(p=>!p.IsDeleted)
                    .OrderByDescending(p => p.CreateDate)
                    .Take(50);
            var channel = new RssChannel
            {
                Title = string.Format("{0} - Issues", Config.Literal.SITE_NAME),
                Link = new Uri(Config.URL.Domain),
                Description = string.Format("{0} - Issues", Config.Literal.SITE_NAME),
                PubDate = DateTime.Now,
                LastBuildDate = DateTime.Now,
                Language = "zh-cn",
                Copyright = Config.Literal.COPYRIGHT
            };

            var template = File.ReadAllText(Config.Path.PHYSICAL_ROOT_PATH + "bin/RSS/issue.cshtml");

            foreach (var item in data)
            {
                channel.Items.Add(BuildIssueItem(item, template));
            }
            var feed = new RssFeed(Encoding.UTF8);
            feed.Channels.Add(channel);
            feed.Write(Config.Path.PHYSICAL_ROOT_PATH + Config.Path.ISSUES_RSS_PATH);
        }
Ejemplo n.º 3
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();
		}
Ejemplo n.º 4
0
        public void RenderRssChannel(RssChannel rssChannel)
        {
            RssFeed rssFeed = new RssFeed();

            rssFeed.Channels.Add(rssChannel);
            this.Response.ContentType = "text/xml";

            rssFeed.Write(this.Response.OutputStream);
            this.Response.End();
        }
Ejemplo n.º 5
0
Archivo: Rss.cs Proyecto: 441023065/CMS
 private RssChannel BuildCommentRssChannel()
 {
     var now = DateTime.Now;
     var channel = new RssChannel
                       {
                           Title = string.Format("{0} - 评论", Config.Literal.SITE_NAME),
                           Link = new Uri(Config.URL.Domain),
                           Description = string.Format("{0} - 评论", Config.Literal.DESCRIPTION),
                           PubDate = now,
                           LastBuildDate = now,
                           Language = "zh-cn",
                           Copyright = Config.Literal.COPYRIGHT
                       };
     return channel;
 }
        public static RssChannel ConvertToRssChannel(StoryCollection stories, string title, string description, string link, Host host)
        {
            RssChannel channel = new RssChannel();
            channel.Title = title;
            channel.Description = description;
            channel.Link = new System.Uri(link);
            channel.Language = "en-us";
            channel.Generator = host.SiteTitle + " - " + host.TagLine;
            channel.Docs = "";
            channel.TimeToLive = 30;
            channel.Copyright = "Atweb Publishing Ltd.";

            if (stories.Count == 0) {
                RssItem item = new RssItem();
                item.Title = " ";
                item.Description = " ";
                item.PubDate = DateTime.Now.ToUniversalTime();

                channel.Items.Add(item);
            } else {

                foreach (Story story in stories) {
                    string storyUrl = host.RootUrl + UrlFactory.CreateUrl(UrlFactory.PageName.ViewStory, story.StoryIdentifier, CategoryCache.GetCategory(story.CategoryID, host.HostID).CategoryIdentifier);

                    //TODO: GJ: add category info

                    RssItem item = new RssItem();
                    item.Title = story.Title;
                    item.Description = story.Description + " <br /><br /><br />" + Incremental.Common.Web.Helpers.ControlHelper.RenderControl(new Incremental.Kick.Web.Controls.StoryDynamicImage(story.Url, host));
                    item.PubDate = story.PublishedOn.ToUniversalTime();
                    RssGuid guid = new RssGuid();
                    guid.Name = storyUrl;
                    guid.PermaLink = true;
                    item.Guid = guid;
                    item.Link = new Uri(storyUrl);

                    channel.Items.Add(item);
                }
            }

            return channel;
        }
Ejemplo n.º 7
0
        private void writeChannel(RssChannel channel)
        {
            if (writer == null)
            {
                throw new InvalidOperationException("RssWriter has been closed, and can not be written to.");
            }
            if (channel == null)
            {
                throw new ArgumentNullException("Channel must be instanciated with data to be written.");
            }

            if (wroteChannel)
            {
                writer.WriteEndElement();
            }
            else
            {
                wroteChannel = true;
            }

            BeginDocument();

            writer.WriteStartElement("channel");
            WriteElement("title", channel.Title, true);
            WriteElement("description", channel.Description, true);
            WriteElement("link", channel.Link, true);
            if (channel.Image != null)
            {
                writer.WriteStartElement("image");
                WriteElement("title", channel.Image.Title, true);
                WriteElement("url", channel.Image.Url, true);
                WriteElement("link", channel.Image.Link, true);
                switch (rssVersion)
                {
                case RssVersion.RSS091:
                case RssVersion.RSS092:
                case RssVersion.RSS20:
                    WriteElement("description", channel.Image.Description, false);
                    WriteElement("width", channel.Image.Width, false);
                    WriteElement("height", channel.Image.Height, false);
                    break;
                }
                writer.WriteEndElement();
            }
            switch (rssVersion)
            {
            case RssVersion.RSS091:
            case RssVersion.RSS092:
            case RssVersion.RSS20:
                WriteElement("language", channel.Language, rssVersion == RssVersion.RSS091);
                WriteElement("copyright", channel.Copyright, false);
                WriteElement("managingEditor", channel.ManagingEditor, false);
                WriteElement("webMaster", channel.WebMaster, false);
                WriteElement("pubDate", channel.PubDate, false);
                WriteElement("lastBuildDate", channel.LastBuildDate, false);
                if (channel.Docs != RssDefault.String)
                {
                    WriteElement("docs", channel.Docs, false);
                }
                else
                {
                    switch (rssVersion)
                    {
                    case RssVersion.RSS091:
                        WriteElement("docs", "http://my.netscape.com/publish/formats/rss-spec-0.91.html", false);
                        break;

                    case RssVersion.RSS092:
                        WriteElement("docs", "http://backend.userland.com/rss092", false);
                        break;

                    case RssVersion.RSS20:
                        WriteElement("docs", "http://backend.userland.com/rss", false);
                        break;
                    }
                }
                WriteElement("rating", channel.Rating, false);
                string[] Days = { "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday" };
                for (int i = 0; i <= 6; i++)
                {
                    if (channel.SkipDays[i])
                    {
                        writer.WriteStartElement("skipDays");
                        for (int i2 = 0; i2 <= 6; i2++)
                        {
                            if (channel.SkipDays[i2])
                            {
                                WriteElement("day", Days[i2], false);
                            }
                        }
                        writer.WriteEndElement();
                        break;
                    }
                }
                for (int i = 0; i <= 23; i++)
                {
                    if (channel.SkipHours[i])
                    {
                        writer.WriteStartElement("skipHours");
                        for (int i2 = 0; i2 <= 23; i2++)
                        {
                            if (channel.SkipHours[i2])
                            {
                                WriteElement("hour", i2 + 1, false);
                            }
                        }
                        writer.WriteEndElement();
                        break;
                    }
                }
                break;
            }
            switch (rssVersion)
            {
            case RssVersion.RSS092:
            case RssVersion.RSS20:
                if (channel.Categories != null)
                {
                    foreach (RssCategory category in channel.Categories)
                    {
                        if (category.Name != RssDefault.String)
                        {
                            writer.WriteStartElement("category");
                            WriteAttribute("domain", category.Domain, false);
                            writer.WriteString(category.Name);
                            writer.WriteEndElement();
                        }
                    }
                }
                if (channel.Cloud != null)
                {
                    writer.WriteStartElement("cloud");
                    WriteElement("domain", channel.Cloud.Domain, false);
                    WriteElement("port", channel.Cloud.Port, false);
                    WriteElement("path", channel.Cloud.Path, false);
                    WriteElement("registerProcedure", channel.Cloud.RegisterProcedure, false);
                    if (channel.Cloud.Protocol != RssCloudProtocol.Empty)
                    {
                        WriteElement("Protocol", channel.Cloud.Protocol, false);
                    }
                    writer.WriteEndElement();
                }
                break;
            }
            if (rssVersion == RssVersion.RSS20)
            {
                if (channel.Generator != RssDefault.String)
                {
                    WriteElement("generator", channel.Generator, false);
                }
                else
                {
                    WriteElement("generator", "RSS.NET: http://www.rssdotnet.com/", false);
                }
                WriteElement("ttl", channel.TimeToLive, false);

                // RSS Modules
                foreach (RssModule rssModule in this._rssModules)
                {
                    if (rssModule.IsBoundTo(channel.GetHashCode()))
                    {
                        foreach (RssModuleItem rssModuleItem in rssModule.ChannelExtensions)
                        {
                            if (rssModuleItem.SubElements.Count == 0)
                            {
                                WriteElement(rssModule.NamespacePrefix + ":" + rssModuleItem.Name, rssModuleItem.Text, rssModuleItem.IsRequired);
                            }
                            else
                            {
                                writeSubElements(rssModuleItem.SubElements, rssModule.NamespacePrefix);
                            }
                        }
                    }
                }
            }
            if (channel.TextInput != null)
            {
                writer.WriteStartElement("textinput");
                WriteElement("title", channel.TextInput.Title, true);
                WriteElement("description", channel.TextInput.Description, true);
                WriteElement("name", channel.TextInput.Name, true);
                WriteElement("link", channel.TextInput.Link, true);
                writer.WriteEndElement();
            }
            foreach (RssItem item in channel.Items)
            {
                writeItem(item, channel.GetHashCode());
            }
            writer.Flush();
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Handles the Load event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void Page_Load(object sender, EventArgs e)
        {
            //get project id
            if (Request.QueryString["pid"] != null)
                projectId = Convert.ToInt32(Request.Params["pid"]);
            //get feed id
            if (Request.QueryString["channel"] != null)
                channelId = Convert.ToInt32(Request.Params["channel"]);

            if (projectId != 0)
            {
                //Security Checks
                if (!User.Identity.IsAuthenticated && Project.GetProjectById(projectId).AccessType == Globals.ProjectAccessType.Private)
                    Response.Redirect("~/Errors/AccessDenied.aspx", true);
                else if (User.Identity.IsAuthenticated && Project.GetProjectById(projectId).AccessType == Globals.ProjectAccessType.Private && !Project.IsUserProjectMember(User.Identity.Name, projectId))
                    Response.Redirect("~/Errors/AccessDenied.aspx", true);

                projectName = Project.GetProjectById(projectId).Name;
            }
            else
            {
                if(!User.Identity.IsAuthenticated)
                    Response.Redirect("~/Errors/AccessDenied.aspx", true);
            }

            channel = new RssChannel();
            feed = new RssFeed();

            switch (channelId)
            {
                case 1:
                    MilestoneFeed();
                    break;
                case 2:
                    CategoryFeed();
                    break;
                case 3:
                    StatusFeed();
                    break;
                case 4:
                    PriorityFeed();
                    break;
                case 5:
                    TypeFeed();
                    break;
                case 6:
                    AssigneeFeed();
                    break;
                case 7:
                    FilteredIssuesFeed();
                    break;
                case 8:
                    RelevantFeed();
                    break;
                case 9:
                    AssignedFeed();
                    break;
                case 10:
                    OwnedFeed();
                    break;
                case 11:
                    CreatedFeed();
                    break;
                case 12:
                    AllFeed();
                    break;
                case 13:
                    QueryFeed();
                    break;
                case 14:
                    OpenIssuesFeed();
                    break;
                case 15:
                    MonitoredIssuesFeed();
                    break;
                case 16:
                    MyIssuesAssignedFeed();
                    break;
                case 17:
                    MyIssuesClosedFeed();
                    break;
                case 18:
                    MyIssuesOwnedFeed();
                    break;
                case 19:
                    MyIssuesCreatedFeed();
                    break;

            }

            channel.PubDate = DateTime.Now;
            channel.LastBuildDate = channel.Items.LatestPubDate();
            channel.Link = new System.Uri(HostSetting.GetHostSetting("DefaultUrl") + "Rss.aspx?" + Request.QueryString.ToString());

            try
            {
                feed.Channels.Add(channel);
                //feed.Encoding = System.Text.Encoding.UTF8;
                Response.ContentType = "text/xml";
                feed.Write(Response.OutputStream);
                Response.End();
            }
            catch
            {
                //exception
            }
        }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            RssFeed r = new RssFeed();

            r.Version = RssVersion.RSS20;

            RssItem ri1a = new RssItem();
            ri1a.Author = "Test Author 1a";
            ri1a.Title = "Test Title 1a";
            ri1a.Description = "Test Description 1a";
            ri1a.Link = new Uri("http://www.yourserver.com/");
            ri1a.PubDate = DateTime.Now;

            RssItem ri1b = new RssItem();
            ri1b.Author = "Test Author 1b";
            ri1b.Title = "Test Title 1b";
            ri1b.Description = "Test Description 1b";
            ri1b.Link = new Uri("http://www.yourserver.com/");
            ri1b.PubDate = DateTime.Now;

            RssChannel rc1 = new RssChannel();
            rc1.Items.Add(ri1a);
            rc1.Items.Add(ri1b);
            rc1.Title = "Test Channel Title 1";
            rc1.Description = "Test Channel Description 1";
            rc1.Link = new Uri("http://www.yourserver.com/channel.html");
            rc1.PubDate = DateTime.Now;

            r.Channels.Add(rc1);

            RssPhotoAlbumCategoryPhotoPeople pacpp = new RssPhotoAlbumCategoryPhotoPeople("John Doe");

            RssPhotoAlbumCategoryPhoto pacp1 = new RssPhotoAlbumCategoryPhoto(DateTime.Now.Subtract(new TimeSpan(2, 12, 0, 0)), "Test Photo Description 1", new Uri("http://www.yourserver.com/PhotoAlbumWeb/GetPhoto.aspx?PhotoID=123"), pacpp);
            RssPhotoAlbumCategoryPhoto pacp2 = new RssPhotoAlbumCategoryPhoto(DateTime.Now.Subtract(new TimeSpan(2, 10, 0, 0)), "Test Photo Description 2", new Uri("http://www.yourserver.com/PhotoAlbumWeb/GetPhoto.aspx?PhotoID=124"));
            RssPhotoAlbumCategoryPhoto pacp3 = new RssPhotoAlbumCategoryPhoto(DateTime.Now.Subtract(new TimeSpan(2, 10, 0, 0)), "Test Photo Description 2", new Uri("http://www.yourserver.com/PhotoAlbumWeb/GetPhoto.aspx?PhotoID=125"));
            RssPhotoAlbumCategoryPhotos pacps = new RssPhotoAlbumCategoryPhotos();
            pacps.Add(pacp1);
            pacps.Add(pacp2);

            RssPhotoAlbumCategory pac1 = new RssPhotoAlbumCategory("Test Photo Album Category 1", "Test Photo Album Category Description 1", DateTime.Now.Subtract(new TimeSpan(5, 10, 0, 0)), DateTime.Now, pacps);
            RssPhotoAlbumCategory pac2 = new RssPhotoAlbumCategory("Test Photo Album Category 2", "Test Photo Album Category Description 2", DateTime.Now.Subtract(new TimeSpan(9, 10, 0, 0)), DateTime.Now, pacp3);
            RssPhotoAlbumCategories pacs = new RssPhotoAlbumCategories();
            pac1.BindTo(ri1a.GetHashCode());
            pac2.BindTo(ri1b.GetHashCode());
            pacs.Add(pac1);
            pacs.Add(pac2);

            RssPhotoAlbum pa = new RssPhotoAlbum(new Uri("http://your.web.server/PhotoAlbumWeb"), pacs);

            pa.BindTo(rc1.GetHashCode());

            r.Modules.Add(pa);

            RssItem ri2 = new RssItem();
            ri2.Author = "Test Author 2";
            ri2.Title = "Test Title 2";
            ri2.Description = "Test Description 2";
            ri2.Link = new Uri("http://www.yourotherserver.com/");
            ri2.PubDate = DateTime.Now;

            RssChannel rc2 = new RssChannel();
            rc2.Items.Add(ri2);
            rc2.Title = "Test Channel Title 2";
            rc2.Description = "Test Channel Description 2";
            rc2.Link = new Uri("http://www.yourotherserver.com/channel.html");
            rc2.PubDate = DateTime.Now;

            r.Channels.Add(rc2);

            r.Write("out.xml");

            RssBlogChannel rbc = new RssBlogChannel(new Uri("http://www.google.com"), new Uri("http://www.google.com"), new Uri("http://www.google.com"), new Uri("http://www.google.com"));
        }
Ejemplo n.º 10
0
 /// <summary>Writes an RSS channel</summary>
 /// <exception cref="InvalidOperationException">RssWriter has been closed, and can not be written to.</exception>
 /// <exception cref="ArgumentNullException">Channel must be instanciated with data, before calling Write.</exception>
 /// <param name="channel">RSS channel to write</param>
 public void Write(RssChannel channel)
 {
     writeChannel(channel);
 }
Ejemplo n.º 11
0
        private void WriteSkipDays(RssChannel channel)
        {
            bool elementOpened = false;

            foreach(Day d in channel.SkipDays.Days)
            {
                if (!elementOpened)
                {
                    Writer.WriteStartElement("skipDays");
                    elementOpened = true;
                }

                WriteElement("day", d.ToString(), false);
            }

            if (elementOpened)
                Writer.WriteEndElement();
        }
Ejemplo n.º 12
0
		/// <summary>Inserts a channel into this collection at a specified index.</summary>
		/// <param name="index">The zero-based index of the collection at which to insert the channel.</param>
		/// <param name="channel">The channel to insert into this collection.</param>
		public void Insert(int index, RssChannel channel)
		{
			List.Insert(index, channel);
		}
Ejemplo n.º 13
0
        protected void DisplayChannel(Rss.RssChannel channel)
        {
            datagridItems.Rows.Clear();

            lblChannelSummary.Text = channel.Summary;
            lblChannelTitle.Text   = channel.Title;

            int ParentIndex;

            ParentIndex = 0;
            int ParentRow = ParentIndex + 1;



            string ChannelTitle;

            ChannelTitle = channel.Title;


            int gridRowNbr = ParentIndex + 1;

            ParentIndex = -1;
            foreach (RssItem item in channel.Items)
            {
                ///---------------------------------------
                ///
                DataGridViewRow         row         = new DataGridViewRow();
                DataGridViewTextBoxCell date        = new DataGridViewTextBoxCell();
                DataGridViewTextBoxCell title       = new DataGridViewTextBoxCell();
                DataGridViewTextBoxCell description = new DataGridViewTextBoxCell();
                DataGridViewTextBoxCell duration    = new DataGridViewTextBoxCell();
                DataGridViewTextBoxCell rating      = new DataGridViewTextBoxCell();

                datagridItems.Columns[0].Width = 75;
                datagridItems.Columns[1].Width = (int)((double)(datagridItems.Width - 225) * (double).6);
                datagridItems.Columns[2].Width = (int)((double)(datagridItems.Width - 225) * (double).39);
                datagridItems.Columns[3].Width = 75;
                datagridItems.Columns[4].Width = 75;



                if (gridRowNbr % 2 == 0)
                {
                    row.DefaultCellStyle.BackColor = Color.LightSteelBlue;
                }
                else
                {
                    row.DefaultCellStyle.BackColor = Color.AliceBlue;
                }



                date.Value  = item.PubDate;
                date.Tag    = item;
                title.Value = item.Title;

                if (item.Duration == null || item.Duration == "")
                {
                    duration.Value = "None";
                }
                else
                {
                    duration.Value = item.Duration;
                }

                if (item.Subtitle == null || item.Subtitle == "")
                {
                    description.Value = "None";
                }
                else
                {
                    description.Value = item.Subtitle;
                }


                if (item.Rating == null || item.Rating == "")
                {
                    rating.Value = "None";
                }
                else
                {
                    rating.Value = item.Rating;
                }

                row.Cells.Add(date);
                row.Cells.Add(title);
                row.Cells.Add(description);
                row.Cells.Add(duration);
                row.Cells.Add(rating);

                datagridItems.Rows.Add(row);

                gridRowNbr++;
            }
            if (datagridItems.Rows.Count > 0)
            {
                datagridItems.Rows[0].Selected = false;
                datagridItems.Rows[0].Selected = true;
            }
        }
Ejemplo n.º 14
0
 /// <summary>Determines whether the RssChannelCollection contains a specific element.</summary>
 /// <param name="rssChannel">The RssChannel to locate in the RssChannelCollection.</param>
 /// <returns>true if the RssChannelCollection contains the specified value; otherwise, false.</returns>
 public bool Contains(RssChannel rssChannel)
 {
     return(List.Contains(rssChannel));
 }
Ejemplo n.º 15
0
 /// <summary>Searches for the specified RssChannel and returns the zero-based index of the first occurrence within the entire RssChannelCollection.</summary>
 /// <param name="rssChannel">The RssChannel to locate in the RssChannelCollection.</param>
 /// <returns>The zero-based index of the first occurrence of RssChannel within the entire RssChannelCollection, if found; otherwise, -1.</returns>
 public int IndexOf(RssChannel rssChannel)
 {
     return(List.IndexOf(rssChannel));
 }
Ejemplo n.º 16
0
        /// <summary>Reads the next RssElement from the stream.</summary>
        /// <returns>An RSS Element</returns>
        /// <exception cref="InvalidOperationException">RssReader has been closed, and can not be read.</exception>
        /// <exception cref="System.IO.FileNotFoundException">RSS file not found.</exception>
        /// <exception cref="System.Xml.XmlException">Invalid XML syntax in RSS file.</exception>
        /// <exception cref="System.IO.EndOfStreamException">Unable to read an RssElement. Reached the end of the stream.</exception>
        public RssElement Read()
        {
            bool       readData     = false;
            bool       pushElement  = true;
            RssElement rssElement   = null;
            int        lineNumber   = -1;
            int        linePosition = -1;

            if (this.reader == null)
            {
                throw new InvalidOperationException("RssReader has been closed, and can not be read.");
            }

            do
            {
                pushElement = true;
                try
                {
                    readData = this.reader.Read();
                }
                catch (EndOfStreamException e)
                {
                    throw new EndOfStreamException("Unable to read an RssElement. Reached the end of the stream.", e);
                }
                catch (XmlException e)
                {
                    if (lineNumber != -1 || linePosition != -1)
                    {
                        if (this.reader.LineNumber == lineNumber && this.reader.LinePosition == linePosition)
                        {
                            throw this.exceptions.LastException;
                        }
                    }

                    lineNumber   = this.reader.LineNumber;
                    linePosition = this.reader.LinePosition;

                    this.exceptions.Add(e); // just add to list of exceptions and continue :)
                }
                if (readData)
                {
                    string readerName = this.reader.Name.ToLower();
                    switch (this.reader.NodeType)
                    {
                    case XmlNodeType.Element:
                    {
                        if (this.reader.IsEmptyElement)
                        {
                            break;
                        }
                        this.elementText = new StringBuilder();

                        switch (readerName)
                        {
                        case "item":
                            // is this the end of the channel element? (absence of </channel> before <item>)
                            if (!this.wroteChannel)
                            {
                                this.wroteChannel = true;
                                rssElement        = this.channel;                                          // return RssChannel
                                readData          = false;
                            }

                            this.item = new RssItem();         // create new RssItem
                            this.channel.Items.Add(this.item);
                            break;

                        case "source":
                            this.source      = new RssSource();
                            this.item.Source = this.source;
                            for (int i = 0; i < this.reader.AttributeCount; i++)
                            {
                                this.reader.MoveToAttribute(i);
                                switch (this.reader.Name.ToLower())
                                {
                                case "url":
                                    try
                                    {
                                        this.source.Url = new Uri(this.reader.Value);
                                    }
                                    catch (Exception e)
                                    {
                                        this.exceptions.Add(e);
                                    }
                                    break;
                                }
                            }
                            break;

                        case "enclosure":
                            this.enclosure      = new RssEnclosure();
                            this.item.Enclosure = this.enclosure;
                            for (int i = 0; i < this.reader.AttributeCount; i++)
                            {
                                this.reader.MoveToAttribute(i);
                                switch (this.reader.Name.ToLower())
                                {
                                case "url":
                                    try
                                    {
                                        this.enclosure.Url = new Uri(this.reader.Value);
                                    }
                                    catch (Exception e)
                                    {
                                        this.exceptions.Add(e);
                                    }
                                    break;

                                case "length":
                                    try
                                    {
                                        this.enclosure.Length = int.Parse(this.reader.Value);
                                    }
                                    catch (Exception e)
                                    {
                                        this.exceptions.Add(e);
                                    }
                                    break;

                                case "type":
                                    this.enclosure.Type = this.reader.Value;
                                    break;
                                }
                            }
                            break;

                        case "guid":
                            this.guid      = new RssGuid();
                            this.item.Guid = this.guid;
                            for (int i = 0; i < this.reader.AttributeCount; i++)
                            {
                                this.reader.MoveToAttribute(i);
                                switch (this.reader.Name.ToLower())
                                {
                                case "ispermalink":
                                    try
                                    {
                                        this.guid.PermaLink = bool.Parse(this.reader.Value);
                                    }
                                    catch (Exception e)
                                    {
                                        this.exceptions.Add(e);
                                    }
                                    break;
                                }
                            }
                            break;

                        case "category":
                            this.category = new RssCategory();
                            if ((string)this.xmlNodeStack.Peek() == "channel")
                            {
                                this.channel.Categories.Add(this.category);
                            }
                            else
                            {
                                this.item.Categories.Add(this.category);
                            }
                            for (int i = 0; i < this.reader.AttributeCount; i++)
                            {
                                this.reader.MoveToAttribute(i);
                                switch (this.reader.Name.ToLower())
                                {
                                case "url":
                                    goto case "domain";

                                case "domain":
                                    this.category.Domain = this.reader.Value;
                                    break;
                                }
                            }
                            break;

                        case "channel":
                            this.channel   = new RssChannel();
                            this.textInput = null;
                            this.image     = null;
                            this.cloud     = null;
                            this.source    = null;
                            this.enclosure = null;
                            this.category  = null;
                            this.item      = null;
                            break;

                        case "image":
                            this.image         = new RssImage();
                            this.channel.Image = this.image;
                            break;

                        case "textinput":
                            this.textInput         = new RssTextInput();
                            this.channel.TextInput = this.textInput;
                            break;

                        case "cloud":
                            pushElement        = false;
                            this.cloud         = new RssCloud();
                            this.channel.Cloud = this.cloud;
                            for (int i = 0; i < this.reader.AttributeCount; i++)
                            {
                                this.reader.MoveToAttribute(i);
                                switch (this.reader.Name.ToLower())
                                {
                                case "domain":
                                    this.cloud.Domain = this.reader.Value;
                                    break;

                                case "port":
                                    try
                                    {
                                        this.cloud.Port = ushort.Parse(this.reader.Value);
                                    }
                                    catch (Exception e)
                                    {
                                        this.exceptions.Add(e);
                                    }
                                    break;

                                case "path":
                                    this.cloud.Path = this.reader.Value;
                                    break;

                                case "registerprocedure":
                                    this.cloud.RegisterProcedure = this.reader.Value;
                                    break;

                                case "protocol":
                                    switch (this.reader.Value.ToLower())
                                    {
                                    case "xml-rpc":
                                        this.cloud.Protocol = RssCloudProtocol.XmlRpc;
                                        break;

                                    case "soap":
                                        this.cloud.Protocol = RssCloudProtocol.Soap;
                                        break;

                                    case "http-post":
                                        this.cloud.Protocol = RssCloudProtocol.HttpPost;
                                        break;

                                    default:
                                        this.cloud.Protocol = RssCloudProtocol.Empty;
                                        break;
                                    }
                                    break;
                                }
                            }
                            break;

                        case "rss":
                            for (int i = 0; i < this.reader.AttributeCount; i++)
                            {
                                this.reader.MoveToAttribute(i);
                                if (this.reader.Name.ToLower() == "version")
                                {
                                    switch (this.reader.Value)
                                    {
                                    case "0.91":
                                        this.rssVersion = RssVersion.RSS091;
                                        break;

                                    case "0.92":
                                        this.rssVersion = RssVersion.RSS092;
                                        break;

                                    case "2.0":
                                        this.rssVersion = RssVersion.RSS20;
                                        break;

                                    default:
                                        this.rssVersion = RssVersion.NotSupported;
                                        break;
                                    }
                                }
                            }
                            break;

                        case "rdf":
                            for (int i = 0; i < this.reader.AttributeCount; i++)
                            {
                                this.reader.MoveToAttribute(i);
                                if (this.reader.Name.ToLower() == "version")
                                {
                                    switch (this.reader.Value)
                                    {
                                    case "0.90":
                                        this.rssVersion = RssVersion.RSS090;
                                        break;

                                    case "1.0":
                                        this.rssVersion = RssVersion.RSS10;
                                        break;

                                    default:
                                        this.rssVersion = RssVersion.NotSupported;
                                        break;
                                    }
                                }
                            }
                            break;

                        case "geo:lat":
                        case "geo:long":
                        case "geo:point":
                        case "georss:point":
                        case "georss:elev":
                        case "georss:radius":
                            if (this.item.GeoPoint == null)
                            {
                                this.item.GeoPoint = new RssGeoPoint();
                            }
                            break;
                        }
                        if (pushElement)
                        {
                            this.xmlNodeStack.Push(readerName);
                        }
                        break;
                    }

                    case XmlNodeType.EndElement:
                    {
                        if (this.xmlNodeStack.Count == 1)
                        {
                            break;
                        }
                        string childElementName  = (string)this.xmlNodeStack.Pop();
                        string parentElementName = (string)this.xmlNodeStack.Peek();
                        switch (childElementName)                                 // current element
                        {
                        // item classes
                        case "item":
                            rssElement = this.item;
                            readData   = false;
                            break;

                        case "source":
                            this.source.Name = this.elementText.ToString();
                            rssElement       = this.source;
                            readData         = false;
                            break;

                        case "enclosure":
                            rssElement = this.enclosure;
                            readData   = false;
                            break;

                        case "guid":
                            this.guid.Name = this.elementText.ToString();
                            rssElement     = this.guid;
                            readData       = false;
                            break;

                        case "category":                                         // parent is either item or channel
                            this.category.Name = this.elementText.ToString();
                            rssElement         = this.category;
                            readData           = false;
                            break;

                        // channel classes
                        case "channel":
                            if (this.wroteChannel)
                            {
                                this.wroteChannel = false;
                            }
                            else
                            {
                                this.wroteChannel = true;
                                rssElement        = this.channel;
                                readData          = false;
                            }
                            break;

                        case "textinput":
                            rssElement = this.textInput;
                            readData   = false;
                            break;

                        case "image":
                            rssElement = this.image;
                            readData   = false;
                            break;

                        case "cloud":
                            rssElement = this.cloud;
                            readData   = false;
                            break;
                        }
                        switch (parentElementName)                                 // parent element
                        {
                        case "item":
                            switch (childElementName)
                            {
                            case "title":
                                this.item.Title = this.elementText.ToString();
                                break;

                            case "link":
                                this.item.Link = new Uri(this.elementText.ToString());
                                break;

                            case "description":
                                this.item.Description = this.elementText.ToString();
                                break;

                            case "author":
                                this.item.Author = this.elementText.ToString();
                                break;

                            case "comments":
                                this.item.Comments = this.elementText.ToString();
                                break;

                            case "pubdate":
                                try
                                {
                                    this.item.PubDate = DateTime.Parse(this.elementText.ToString());
                                }
                                catch (Exception e)
                                {
                                    try {
                                        string tmp = this.elementText.ToString();
                                        tmp  = tmp.Substring(0, tmp.Length - 5);
                                        tmp += "GMT";
                                        this.item.PubDate = DateTime.Parse(tmp);
                                    }
                                    catch
                                    {
                                        this.exceptions.Add(e);
                                    }
                                }
                                break;

                            case "geo:lat":
                                try
                                {
                                    this.item.GeoPoint.Lat = float.Parse(this.elementText.ToString());
                                }
                                catch (Exception e)
                                {
                                    this.exceptions.Add(e);
                                }
                                break;

                            case "geo:long":
                                try
                                {
                                    this.item.GeoPoint.Lon = float.Parse(this.elementText.ToString());
                                }
                                catch (Exception e)
                                {
                                    this.exceptions.Add(e);
                                }
                                break;

                            case "georss:point":
                                try
                                {
                                    string[] coords = this.elementText.ToString().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                                    if (coords.Length == 2)
                                    {
                                        this.item.GeoPoint.Lat = float.Parse(coords[0]);
                                        this.item.GeoPoint.Lon = float.Parse(coords[1]);
                                    }
                                }
                                catch (Exception e)
                                {
                                    this.exceptions.Add(e);
                                }
                                break;
                            }
                            break;

                        case "channel":
                            switch (childElementName)
                            {
                            case "title":
                                this.channel.Title = this.elementText.ToString();
                                break;

                            case "link":
                                try
                                {
                                    this.channel.Link = new Uri(this.elementText.ToString());
                                }
                                catch (Exception e)
                                {
                                    this.exceptions.Add(e);
                                }
                                break;

                            case "description":
                                this.channel.Description = this.elementText.ToString();
                                break;

                            case "language":
                                this.channel.Language = this.elementText.ToString();
                                break;

                            case "copyright":
                                this.channel.Copyright = this.elementText.ToString();
                                break;

                            case "managingeditor":
                                this.channel.ManagingEditor = this.elementText.ToString();
                                break;

                            case "webmaster":
                                this.channel.WebMaster = this.elementText.ToString();
                                break;

                            case "rating":
                                this.channel.Rating = this.elementText.ToString();
                                break;

                            case "pubdate":
                                try
                                {
                                    this.channel.PubDate = DateTime.Parse(this.elementText.ToString());
                                }
                                catch (Exception e)
                                {
                                    this.exceptions.Add(e);
                                }
                                break;

                            case "lastbuilddate":
                                try
                                {
                                    this.channel.LastBuildDate = DateTime.Parse(this.elementText.ToString());
                                }
                                catch (Exception e)
                                {
                                    this.exceptions.Add(e);
                                }
                                break;

                            case "generator":
                                this.channel.Generator = this.elementText.ToString();
                                break;

                            case "docs":
                                this.channel.Docs = this.elementText.ToString();
                                break;

                            case "ttl":
                                try
                                {
                                    this.channel.TimeToLive = int.Parse(this.elementText.ToString());
                                }
                                catch (Exception e)
                                {
                                    this.exceptions.Add(e);
                                }
                                break;
                            }
                            break;

                        case "image":
                            switch (childElementName)
                            {
                            case "url":
                                try
                                {
                                    this.image.Url = new Uri(this.elementText.ToString());
                                }
                                catch (Exception e)
                                {
                                    this.exceptions.Add(e);
                                }
                                break;

                            case "title":
                                this.image.Title = this.elementText.ToString();
                                break;

                            case "link":
                                try
                                {
                                    this.image.Link = new Uri(this.elementText.ToString());
                                }
                                catch (Exception e)
                                {
                                    this.exceptions.Add(e);
                                }
                                break;

                            case "description":
                                this.image.Description = this.elementText.ToString();
                                break;

                            case "width":
                                try
                                {
                                    this.image.Width = Byte.Parse(this.elementText.ToString());
                                }
                                catch (Exception e)
                                {
                                    this.exceptions.Add(e);
                                }
                                break;

                            case "height":
                                try
                                {
                                    this.image.Height = Byte.Parse(this.elementText.ToString());
                                }
                                catch (Exception e)
                                {
                                    this.exceptions.Add(e);
                                }
                                break;
                            }
                            break;

                        case "textinput":
                            switch (childElementName)
                            {
                            case "title":
                                this.textInput.Title = this.elementText.ToString();
                                break;

                            case "description":
                                this.textInput.Description = this.elementText.ToString();
                                break;

                            case "name":
                                this.textInput.Name = this.elementText.ToString();
                                break;

                            case "link":
                                try
                                {
                                    this.textInput.Link = new Uri(this.elementText.ToString());
                                }
                                catch (Exception e)
                                {
                                    this.exceptions.Add(e);
                                }
                                break;
                            }
                            break;

                        case "skipdays":
                            if (childElementName == "day")
                            {
                                this.channel.SkipDays |= Day.Parse(this.elementText.ToString());
                            }
                            break;

                        case "skiphours":
                            if (childElementName == "hour")
                            {
                                this.channel.SkipHours |= Hour.Parse(this.elementText.ToString());
                            }
                            break;
                        }
                        break;
                    }

                    case XmlNodeType.Text:
                        this.elementText.Append(this.reader.Value);
                        break;

                    case XmlNodeType.CDATA:
                        this.elementText.Append(this.reader.Value);
                        break;
                    }
                }
            }while (readData);
            return(rssElement);
        }
Ejemplo n.º 17
0
 /// <summary>Adds a specified channel to this collection.</summary>
 /// <param name="channel">The channel to add.</param>
 /// <returns>The zero-based index of the added channel.</returns>
 public int Add(RssChannel channel)
 {
     return(List.Add(channel));
 }
Ejemplo n.º 18
0
        /// <summary>Reads the next RssElement from the stream.</summary>
        /// <returns>An RSS Element</returns>
        /// <exception cref="InvalidOperationException">RssReader has been closed, and can not be read.</exception>
        /// <exception cref="System.IO.FileNotFoundException">RSS file not found.</exception>
        /// <exception cref="System.Xml.XmlException">Invalid XML syntax in RSS file.</exception>
        /// <exception cref="System.IO.EndOfStreamException">Unable to read an RssElement. Reached the end of the stream.</exception>
        public RssElement Read()
        {
            bool       readData     = false;
            bool       pushElement  = true;
            RssElement rssElement   = null;
            int        lineNumber   = -1;
            int        linePosition = -1;

            if (reader == null)
            {
                throw new InvalidOperationException("RssReader has been closed, and can not be read.");
            }

            do
            {
                pushElement = true;
                try
                {
                    readData = reader.Read();
                }
                catch (System.IO.EndOfStreamException e)
                {
                    throw new System.IO.EndOfStreamException("Unable to read an RssElement. Reached the end of the stream.", e);
                }
                catch (System.Xml.XmlException e)
                {
                    if (lineNumber != -1 || linePosition != -1)
                    {
                        if (reader.LineNumber == lineNumber && reader.LinePosition == linePosition)
                        {
                            throw exceptions.LastException;
                        }
                    }

                    lineNumber   = reader.LineNumber;
                    linePosition = reader.LinePosition;

                    exceptions.Add(e); // just add to list of exceptions and continue :)
                }
                if (readData)
                {
                    string readerName = reader.Name.ToLower();
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:
                    {
                        if (reader.IsEmptyElement && reader.AttributeCount == 0)
                        {
                            break;
                        }
                        elementText = new StringBuilder();

                        switch (readerName)
                        {
                        case "item":
                            // is this the end of the channel element? (absence of </channel> before <item>)
                            if (!wroteChannel)
                            {
                                wroteChannel = true;
                                rssElement   = channel;           // return RssChannel
                                readData     = false;
                            }
                            item = new RssItem();             // create new RssItem
                            channel.Items.Add(item);
                            break;

                        //case "source":
                        //    source = new RssSource();
                        //    item.Source = source;
                        //    for (int i = 0; i < reader.AttributeCount; i++)
                        //    {
                        //        reader.MoveToAttribute(i);
                        //        switch (reader.Name.ToLower())
                        //        {
                        //            case "url":
                        //                try
                        //                {
                        //                    source.Url = reader.Value;
                        //                }
                        //                catch (Exception e)
                        //                {
                        //                    exceptions.Add(e);
                        //                }
                        //                break;
                        //        }
                        //    }
                        //    break;
                        //case "pubdate":
                        //    try
                        //    {
                        //        item.PubDate = W3CDateTime.Parse(elementText.ToString()).DateTime;
                        //    }
                        //    catch (Exception e)
                        //    {
                        //        try
                        //        {
                        //            string tmp = elementText.ToString();
                        //            tmp = tmp.Substring(0, tmp.LastIndexOf(" "));
                        //            tmp += " GMT";
                        //            item.PubDate = DateTime.Parse(tmp);
                        //        }
                        //        catch
                        //        {
                        //            exceptions.Add(e);
                        //        }
                        //    }
                        //    break;
                        case "enclosure":
                            enclosure      = new RssEnclosure();
                            item.Enclosure = enclosure;
                            for (int i = 0; i < reader.AttributeCount; i++)
                            {
                                reader.MoveToAttribute(i);
                                switch (reader.Name.ToLower())
                                {
                                case "url":
                                    try
                                    {
                                        enclosure.Url = reader.Value;
                                    }
                                    catch (Exception e)
                                    {
                                        exceptions.Add(e);
                                    }
                                    break;

                                case "length":
                                    try
                                    {
                                        enclosure.Length = int.Parse(reader.Value);
                                    }
                                    catch (Exception)
                                    {
                                        enclosure.Length = 0;
                                        //exceptions.Add(e);
                                    }
                                    break;

                                case "type":
                                    enclosure.Type = reader.Value;
                                    break;
                                }
                            }
                            break;

                        case "guid":
                            guid      = new RssGuid();
                            item.Guid = guid;
                            for (int i = 0; i < reader.AttributeCount; i++)
                            {
                                reader.MoveToAttribute(i);
                                switch (reader.Name.ToLower())
                                {
                                case "ispermalink":
                                    try
                                    {
                                        guid.PermaLink = bool.Parse(reader.Value);
                                    }
                                    catch (Exception e)
                                    {
                                        exceptions.Add(e);
                                    }
                                    break;
                                }
                            }
                            break;

                        case "channel":
                            channel   = new RssChannel();
                            image     = null;
                            enclosure = null;
                            item      = null;
                            break;

                        case "image":
                            image         = new RssImage();
                            channel.Image = image;
                            break;

                        case "rss":
                            for (int i = 0; i < reader.AttributeCount; i++)
                            {
                                reader.MoveToAttribute(i);
                                if (reader.Name.ToLower() == "version")
                                {
                                    switch (reader.Value)
                                    {
                                    case "0.91":
                                        rssVersion = RssVersion.RSS091;
                                        break;

                                    case "0.92":
                                        rssVersion = RssVersion.RSS092;
                                        break;

                                    case "2.0":
                                        rssVersion = RssVersion.RSS20;
                                        break;

                                    default:
                                        rssVersion = RssVersion.NotSupported;
                                        break;
                                    }
                                }
                            }
                            break;

                        case "rdf":
                            for (int i = 0; i < reader.AttributeCount; i++)
                            {
                                reader.MoveToAttribute(i);
                                if (reader.Name.ToLower() == "version")
                                {
                                    switch (reader.Value)
                                    {
                                    case "0.90":
                                        rssVersion = RssVersion.RSS090;
                                        break;

                                    case "1.0":
                                        rssVersion = RssVersion.RSS10;
                                        break;

                                    default:
                                        rssVersion = RssVersion.NotSupported;
                                        break;
                                    }
                                }
                            }
                            break;
                        }
                        if (pushElement)
                        {
                            xmlNodeStack.Push(readerName);
                        }
                        break;
                    }

                    case XmlNodeType.EndElement:
                    {
                        if (xmlNodeStack.Count == 1)
                        {
                            break;
                        }
                        string childElementName  = (string)xmlNodeStack.Pop();
                        string parentElementName = (string)xmlNodeStack.Peek();
                        switch (childElementName)         // current element
                        {
                        // item classes
                        case "item":
                            rssElement = item;
                            readData   = false;
                            break;

                        //case "source":
                        //    source.Name = elementText.ToString();
                        //    rssElement = source;
                        //    readData = false;
                        //    break;
                        case "enclosure":
                            rssElement = enclosure;
                            readData   = false;
                            break;

                        case "guid":
                            guid.Name  = elementText.ToString();
                            rssElement = guid;
                            readData   = false;
                            break;

                        case "pubdate":
                            rssElement = channel;
                            readData   = false;
                            break;

                        case "channel":
                            if (wroteChannel)
                            {
                                wroteChannel = false;
                            }
                            else
                            {
                                wroteChannel = true;
                                rssElement   = channel;
                                readData     = false;
                            }
                            break;
                        }
                        switch (parentElementName)         // parent element
                        {
                        case "item":
                            switch (childElementName)
                            {
                            case "pubdate":
                                try
                                {
                                    item.PubDate = W3CDateTime.Parse(elementText.ToString()).DateTime;
                                }
                                catch (Exception e)
                                {
                                    try
                                    {
                                        string tmp = elementText.ToString();
                                        tmp          = tmp.Substring(0, tmp.LastIndexOf(" "));
                                        tmp         += " GMT";
                                        item.PubDate = DateTime.Parse(tmp);
                                    }
                                    catch
                                    {
                                        exceptions.Add(e);
                                    }
                                }
                                break;

                            case "title":
                                item.Title = elementText.ToString();
                                break;

                            case "link":
                                item.Link = elementText.ToString();
                                break;

                            case "description":
                                item.Description = elementText.ToString();
                                break;
                            }
                            break;

                        case "channel":
                            switch (childElementName)
                            {
                            case "title":
                                channel.Title = elementText.ToString();
                                break;

                            case "link":
                                try
                                {
                                    channel.Link = elementText.ToString();
                                }
                                catch (Exception e)
                                {
                                    exceptions.Add(e);
                                }
                                break;

                            case "description":
                                channel.Description = elementText.ToString();
                                break;

                            case "pubdate":
                                try
                                {
                                    channel.PubDate = W3CDateTime.Parse(elementText.ToString()).DateTime;
                                }
                                catch (Exception)
                                {
                                    if (elementText.ToString() == "")
                                    {
                                        channel.PubDate = DateTime.Now;
                                    }
                                    else
                                    {
                                        try
                                        {
                                            channel.PubDate = DateTime.Parse(elementText.ToString());
                                        }
                                        catch (Exception e)
                                        {
                                            try
                                            {
                                                string tmp = elementText.ToString();
                                                tmp             = tmp.Substring(0, tmp.LastIndexOf(" "));
                                                tmp            += " GMT";
                                                channel.PubDate = DateTime.Parse(tmp);
                                            }
                                            catch
                                            {
                                                exceptions.Add(e);
                                            }
                                        }
                                    }
                                }
                                break;

                            case "lastbuilddate":
                                try
                                {
                                    channel.LastBuildDate = W3CDateTime.Parse(elementText.ToString()).DateTime;
                                    //channel.LastBuildDate = DateTime.Parse(elementText.ToString());
                                }
                                catch (Exception)
                                {
                                    if (elementText.ToString() == "")
                                    {
                                        channel.LastBuildDate = DateTime.Now;
                                    }
                                    else
                                    {
                                        try
                                        {
                                            channel.LastBuildDate = DateTime.Parse(elementText.ToString());
                                        }
                                        catch (Exception e)
                                        {
                                            try
                                            {
                                                string tmp = elementText.ToString();
                                                tmp  = tmp.Substring(0, tmp.LastIndexOf(" "));
                                                tmp += " GMT";
                                                channel.LastBuildDate = DateTime.Parse(tmp);
                                            }
                                            catch
                                            {
                                                exceptions.Add(e);
                                            }
                                        }
                                    }
                                }
                                break;
                            }
                            break;

                        case "image":
                            switch (childElementName)
                            {
                            case "url":
                                try
                                {
                                    image.Url = elementText.ToString();
                                }
                                catch (Exception e)
                                {
                                    exceptions.Add(e);
                                }
                                break;

                            case "title":
                                image.Title = elementText.ToString();
                                break;

                            case "link":
                                try
                                {
                                    image.Link = elementText.ToString();
                                }
                                catch (Exception e)
                                {
                                    exceptions.Add(e);
                                }
                                break;

                            case "content:encoded":
                                item.Content = elementText.ToString();
                                break;

                            case "description":
                                image.Description = elementText.ToString();
                                break;
                            }
                            break;
                        }
                        break;
                    }

                    case XmlNodeType.Text:
                        elementText.Append(reader.Value);
                        break;

                    case XmlNodeType.CDATA:
                        elementText.Append(reader.Value);
                        break;
                    }
                }
            }while (readData);
            return(rssElement);
        }
Ejemplo n.º 19
0
        private RssChannel ParseChannel(XmlNodeList channelBody)
        {
            channel = new RssChannel();
            try
            {
                XmlNodeList channelNodes = channelBody.Item(0).ChildNodes;
                // find the rss channel in this feed
                //XmlDocument doc = new XmlDocument();
                //doc.Load(reader);
                //XmlNode body = doc.DocumentElement.SelectSingleNode("channel");

                //if (body != null)
                //{

                // loop through the items and pick the important ones
                foreach (XmlNode channelItemNode in channelNodes)
                {
                    switch (channelItemNode.Name.ToLower())
                    {
                    case "title":
                        channel.Title = channelItemNode.InnerText;
                        break;

                    case "link":
                        channel.Link = channelItemNode.InnerText;
                        break;

                    case "description":
                        channel.Description = channelItemNode.InnerText;
                        break;

                    case "pubdate":
                        channel.PubDate = ParseDate(channelItemNode.InnerText);
                        break;

                    case "lastbuilddate":
                        channel.LastBuildDate = ParseDate(channelItemNode.InnerText);
                        break;

                    case "image":
                        if (channelItemNode.ChildNodes.Count > 0)
                        {
                            channel.Image = ParseImage(channelItemNode.ChildNodes);
                        }
                        else
                        {
                            if (channelItemNode.InnerText != null && channelItemNode.InnerText != "")
                            {
                                RssImage rssImage = new RssImage();
                                rssImage.Url  = channelItemNode.InnerText;
                                channel.Image = rssImage;
                            }
                        }
                        break;

                    case "item":
                        RssItem item = ParseItem(channelItemNode.ChildNodes);
                        channel.Items.Add(item);
                        break;
                    }
                    //}
                }
            }
            catch (Exception ex)
            {
                exceptions.Add(ex);
            }
            return(channel);
        }
Ejemplo n.º 20
0
        /// <summary>Reads the next RssElement from the stream.</summary>
        /// <returns>An RSS Element</returns>
        /// <exception cref="InvalidOperationException">RssReader has been closed, and can not be read.</exception>
        /// <exception cref="System.IO.FileNotFoundException">RSS file not found.</exception>
        /// <exception cref="System.Xml.XmlException">Invalid XML syntax in RSS file.</exception>
        /// <exception cref="System.IO.EndOfStreamException">Unable to read an RssElement. Reached the end of the stream.</exception>
        public RssElement Read()
        {
            bool       readData     = false;
            bool       pushElement  = true;
            RssElement rssElement   = null;
            int        lineNumber   = -1;
            int        linePosition = -1;

            if (reader == null)
            {
                throw new InvalidOperationException("RssReader has been closed, and can not be read.");
            }

            do
            {
                pushElement = true;
                try
                {
                    readData = reader.Read();
                }
                catch (System.IO.EndOfStreamException e)
                {
                    throw new System.IO.EndOfStreamException("Unable to read an RssElement. Reached the end of the stream.", e);
                }
                catch (System.Xml.XmlException e)
                {
                    if (lineNumber != -1 || linePosition != -1)
                    {
                        if (reader.LineNumber == lineNumber && reader.LinePosition == linePosition)
                        {
                            throw exceptions.LastException;
                        }
                    }

                    lineNumber   = reader.LineNumber;
                    linePosition = reader.LinePosition;

                    exceptions.Add(e);                     // just add to list of exceptions and continue :)
                }
                if (readData)
                {
                    string readerName = reader.Name.ToLower();
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:
                    {
                        if (reader.IsEmptyElement && readerName != "enclosure")
                        {
                            break;
                        }
                        elementText = new StringBuilder();

                        switch (readerName)
                        {
                        case "item":
                            // is this the end of the channel element? (absence of </channel> before <item>)
                            if (!wroteChannel)
                            {
                                wroteChannel = true;
                                rssElement   = channel;                                               // return RssChannel
                                readData     = false;
                            }
                            item = new RssItem();                                             // create new RssItem
                            channel.Items.Add(item);
                            break;

                        case "source":
                            source      = new RssSource();
                            item.Source = source;
                            for (int i = 0; i < reader.AttributeCount; i++)
                            {
                                reader.MoveToAttribute(i);
                                switch (reader.Name.ToLower())
                                {
                                case "url":
                                    try
                                    {
                                        source.Url = new Uri(reader.Value);
                                    }
                                    catch (Exception e)
                                    {
                                        exceptions.Add(e);
                                    }
                                    break;
                                }
                            }
                            break;

                        case "enclosure":
                            if (reader.AttributeCount == 0)
                            {
                                break;
                            }
                            enclosure      = new RssEnclosure();
                            item.Enclosure = enclosure;
                            for (int i = 0; i < reader.AttributeCount; i++)
                            {
                                reader.MoveToAttribute(i);
                                switch (reader.Name.ToLower())
                                {
                                case "url":
                                    try
                                    {
                                        enclosure.Url = new Uri(reader.Value);
                                    }
                                    catch (Exception e)
                                    {
                                        exceptions.Add(e);
                                    }
                                    break;

                                case "length":
                                    try
                                    {
                                        enclosure.Length = int.Parse(reader.Value);
                                    }
                                    catch (Exception e)
                                    {
                                        exceptions.Add(e);
                                    }
                                    break;

                                case "type":
                                    enclosure.Type = reader.Value;
                                    break;
                                }
                            }
                            break;

                        case "guid":
                            guid      = new RssGuid();
                            item.Guid = guid;
                            for (int i = 0; i < reader.AttributeCount; i++)
                            {
                                reader.MoveToAttribute(i);
                                switch (reader.Name.ToLower())
                                {
                                case "ispermalink":
                                    try
                                    {
                                        guid.PermaLink = bool.Parse(reader.Value);
                                    }
                                    catch (Exception e)
                                    {
                                        exceptions.Add(e);
                                    }
                                    break;
                                }
                            }
                            break;

                        case "category":
                            category = new RssCategory();
                            if ((string)xmlNodeStack.Peek() == "channel")
                            {
                                channel.Categories.Add(category);
                            }
                            else
                            {
                                item.Categories.Add(category);
                            }
                            for (int i = 0; i < reader.AttributeCount; i++)
                            {
                                reader.MoveToAttribute(i);
                                switch (reader.Name.ToLower())
                                {
                                case "url":
                                    goto case "domain";

                                case "domain":
                                    category.Domain = reader.Value;
                                    break;
                                }
                            }
                            break;

                        case "channel":
                            channel   = new RssChannel();
                            textInput = null;
                            image     = null;
                            cloud     = null;
                            source    = null;
                            enclosure = null;
                            category  = null;
                            item      = null;
                            break;

                        case "image":
                            image         = new RssImage();
                            channel.Image = image;
                            break;

                        case "textinput":
                            textInput         = new RssTextInput();
                            channel.TextInput = textInput;
                            break;

                        case "cloud":
                            pushElement   = false;
                            cloud         = new RssCloud();
                            channel.Cloud = cloud;
                            for (int i = 0; i < reader.AttributeCount; i++)
                            {
                                reader.MoveToAttribute(i);
                                switch (reader.Name.ToLower())
                                {
                                case "domain":
                                    cloud.Domain = reader.Value;
                                    break;

                                case "port":
                                    try
                                    {
                                        cloud.Port = ushort.Parse(reader.Value);
                                    }
                                    catch (Exception e)
                                    {
                                        exceptions.Add(e);
                                    }
                                    break;

                                case "path":
                                    cloud.Path = reader.Value;
                                    break;

                                case "registerprocedure":
                                    cloud.RegisterProcedure = reader.Value;
                                    break;

                                case "protocol":
                                    switch (reader.Value.ToLower())
                                    {
                                    case "xml-rpc":
                                        cloud.Protocol = RssCloudProtocol.XmlRpc;
                                        break;

                                    case "soap":
                                        cloud.Protocol = RssCloudProtocol.Soap;
                                        break;

                                    case "http-post":
                                        cloud.Protocol = RssCloudProtocol.HttpPost;
                                        break;

                                    default:
                                        cloud.Protocol = RssCloudProtocol.Empty;
                                        break;
                                    }
                                    break;
                                }
                            }
                            break;

                        case "rss":
                            for (int i = 0; i < reader.AttributeCount; i++)
                            {
                                reader.MoveToAttribute(i);
                                if (reader.Name.ToLower() == "version")
                                {
                                    switch (reader.Value)
                                    {
                                    case "0.91":
                                        rssVersion = RssVersion.RSS091;
                                        break;

                                    case "0.92":
                                        rssVersion = RssVersion.RSS092;
                                        break;

                                    case "2.0":
                                        rssVersion = RssVersion.RSS20;
                                        break;

                                    default:
                                        rssVersion = RssVersion.NotSupported;
                                        break;
                                    }
                                }
                            }
                            break;

                        case "rdf":
                            for (int i = 0; i < reader.AttributeCount; i++)
                            {
                                reader.MoveToAttribute(i);
                                if (reader.Name.ToLower() == "version")
                                {
                                    switch (reader.Value)
                                    {
                                    case "0.90":
                                        rssVersion = RssVersion.RSS090;
                                        break;

                                    case "1.0":
                                        rssVersion = RssVersion.RSS10;
                                        break;

                                    default:
                                        rssVersion = RssVersion.NotSupported;
                                        break;
                                    }
                                }
                            }
                            break;

                        case "torrent:magneturi":
                            if (!reader.HasValue)
                            {
                                break;
                            }
                            break;
                        }
                        if (pushElement)
                        {
                            xmlNodeStack.Push(readerName);
                        }
                        break;
                    }

                    case XmlNodeType.EndElement:
                    {
                        if (xmlNodeStack.Count == 1)
                        {
                            break;
                        }
                        string childElementName  = (string)xmlNodeStack.Pop();
                        string parentElementName = (string)xmlNodeStack.Peek();
                        switch (childElementName)                                 // current element
                        {
                        // item classes
                        case "item":
                            rssElement = item;
                            readData   = false;
                            break;

                        case "source":
                            source.Name = elementText.ToString();
                            rssElement  = source;
                            readData    = false;
                            break;

                        case "enclosure":
                            rssElement = enclosure;
                            readData   = false;
                            break;

                        case "guid":
                            guid.Name  = elementText.ToString();
                            rssElement = guid;
                            readData   = false;
                            break;

                        case "category":                                         // parent is either item or channel
                            category.Name = elementText.ToString();
                            rssElement    = category;
                            readData      = false;
                            break;

                        // channel classes
                        case "channel":
                            if (wroteChannel)
                            {
                                wroteChannel = false;
                            }
                            else
                            {
                                wroteChannel = true;
                                rssElement   = channel;
                                readData     = false;
                            }
                            break;

                        case "textinput":
                            rssElement = textInput;
                            readData   = false;
                            break;

                        case "image":
                            rssElement = image;
                            readData   = false;
                            break;

                        case "cloud":
                            rssElement = cloud;
                            readData   = false;
                            break;
                        }
                        switch (parentElementName)                                 // parent element
                        {
                        case "item":
                            switch (childElementName)
                            {
                            case "title":
                                item.Title = elementText.ToString();
                                break;

                            case "link":
                                item.Link = new Uri(elementText.ToString());
                                break;

                            case "description":
                                item.Description = elementText.ToString();
                                break;

                            case "author":
                                item.Author = elementText.ToString();
                                break;

                            case "comments":
                                item.Comments = elementText.ToString();
                                break;

                            case "pubdate":
                                try
                                {
                                    item.PubDate = DateTime.Parse(elementText.ToString());
                                }
                                catch (Exception e)
                                {
                                    try {
                                        string tmp = elementText.ToString();
                                        tmp          = tmp.Substring(0, tmp.Length - 5);
                                        tmp         += "GMT";
                                        item.PubDate = DateTime.Parse(tmp);
                                    }
                                    catch
                                    {
                                        exceptions.Add(e);
                                    }
                                }
                                break;
                            }
                            break;

                        case "channel":
                            switch (childElementName)
                            {
                            case "title":
                                channel.Title = elementText.ToString();
                                break;

                            case "link":
                                try
                                {
                                    channel.Link = new Uri(elementText.ToString());
                                }
                                catch (Exception e)
                                {
                                    exceptions.Add(e);
                                }
                                break;

                            case "description":
                                channel.Description = elementText.ToString();
                                break;

                            case "language":
                                channel.Language = elementText.ToString();
                                break;

                            case "copyright":
                                channel.Copyright = elementText.ToString();
                                break;

                            case "managingeditor":
                                channel.ManagingEditor = elementText.ToString();
                                break;

                            case "webmaster":
                                channel.WebMaster = elementText.ToString();
                                break;

                            case "rating":
                                channel.Rating = elementText.ToString();
                                break;

                            case "pubdate":
                                try
                                {
                                    channel.PubDate = DateTime.Parse(elementText.ToString());
                                }
                                catch (Exception e)
                                {
                                    exceptions.Add(e);
                                }
                                break;

                            case "lastbuilddate":
                                try
                                {
                                    channel.LastBuildDate = DateTime.Parse(elementText.ToString());
                                }
                                catch (Exception e)
                                {
                                    exceptions.Add(e);
                                }
                                break;

                            case "generator":
                                channel.Generator = elementText.ToString();
                                break;

                            case "docs":
                                channel.Docs = elementText.ToString();
                                break;

                            case "ttl":
                                try
                                {
                                    channel.TimeToLive = int.Parse(elementText.ToString());
                                }
                                catch (Exception e)
                                {
                                    exceptions.Add(e);
                                }
                                break;
                            }
                            break;

                        case "image":
                            switch (childElementName)
                            {
                            case "url":
                                try
                                {
                                    image.Url = new Uri(elementText.ToString());
                                }
                                catch (Exception e)
                                {
                                    exceptions.Add(e);
                                }
                                break;

                            case "title":
                                image.Title = elementText.ToString();
                                break;

                            case "link":
                                try
                                {
                                    image.Link = new Uri(elementText.ToString());
                                }
                                catch (Exception e)
                                {
                                    exceptions.Add(e);
                                }
                                break;

                            case "description":
                                image.Description = elementText.ToString();
                                break;

                            case "width":
                                try
                                {
                                    image.Width = Byte.Parse(elementText.ToString());
                                }
                                catch (Exception e)
                                {
                                    exceptions.Add(e);
                                }
                                break;

                            case "height":
                                try
                                {
                                    image.Height = Byte.Parse(elementText.ToString());
                                }
                                catch (Exception e)
                                {
                                    exceptions.Add(e);
                                }
                                break;
                            }
                            break;

                        case "textinput":
                            switch (childElementName)
                            {
                            case "title":
                                textInput.Title = elementText.ToString();
                                break;

                            case "description":
                                textInput.Description = elementText.ToString();
                                break;

                            case "name":
                                textInput.Name = elementText.ToString();
                                break;

                            case "link":
                                try
                                {
                                    textInput.Link = new Uri(elementText.ToString());
                                }
                                catch (Exception e)
                                {
                                    exceptions.Add(e);
                                }
                                break;
                            }
                            break;

                        case "skipdays":
                            if (childElementName == "day")
                            {
                                switch (elementText.ToString().ToLower())
                                {
                                case "monday":
                                    channel.SkipDays[0] = true;
                                    break;

                                case "tuesday":
                                    channel.SkipDays[1] = true;
                                    break;

                                case "wednesday":
                                    channel.SkipDays[2] = true;
                                    break;

                                case "thursday":
                                    channel.SkipDays[3] = true;
                                    break;

                                case "friday":
                                    channel.SkipDays[4] = true;
                                    break;

                                case "saturday":
                                    channel.SkipDays[5] = true;
                                    break;

                                case "sunday":
                                    channel.SkipDays[6] = true;
                                    break;
                                }
                            }
                            break;

                        case "skiphours":
                            if (childElementName == "hour")
                            {
                                channel.SkipHours[Byte.Parse(elementText.ToString().ToLower())] = true;
                            }
                            break;
                        }
                        break;
                    }

                    case XmlNodeType.Text:
                        elementText.Append(reader.Value);
                        break;

                    case XmlNodeType.CDATA:
                        elementText.Append(reader.Value);
                        break;
                    }
                }
            }while (readData);
            return(rssElement);
        }
Ejemplo n.º 21
0
		/// <summary>Copies the entire RssChannelCollection to a compatible one-dimensional <see cref="Array"/>, starting at the specified index of the target array.</summary>
		/// <param name="array">The one-dimensional RssChannel Array that is the destination of the elements copied from RssChannelCollection. 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 RssChannelCollection is greater than the available space from index to the end of the destination array.</exception>
		public void CopyTo(RssChannel[] array, int index)
		{
			List.CopyTo(array, index);
		}
Ejemplo n.º 22
0
 /// <summary>Inserts a channel into this collection at a specified index.</summary>
 /// <param name="index">The zero-based index of the collection at which to insert the channel.</param>
 /// <param name="channel">The channel to insert into this collection.</param>
 public void Insert(int index, RssChannel channel)
 {
     List.Insert(index, channel);
 }
Ejemplo n.º 23
0
		/// <summary>Searches for the specified RssChannel and returns the zero-based index of the first occurrence within the entire RssChannelCollection.</summary>
		/// <param name="rssChannel">The RssChannel to locate in the RssChannelCollection.</param>
		/// <returns>The zero-based index of the first occurrence of RssChannel within the entire RssChannelCollection, if found; otherwise, -1.</returns>
		public int IndexOf(RssChannel rssChannel)
		{
			return List.IndexOf(rssChannel);
		}
Ejemplo n.º 24
0
 /// <summary>Removes a specified channel from this collection.</summary>
 /// <param name="channel">The channel to remove.</param>
 public void Remove(RssChannel channel)
 {
     List.Remove(channel);
 }
Ejemplo n.º 25
0
		/// <summary>Removes a specified channel from this collection.</summary>
		/// <param name="channel">The channel to remove.</param>
		public void Remove(RssChannel channel)
		{
			List.Remove(channel);
		}
Ejemplo n.º 26
0
        public void ParseTemporaryRss(Object stateInfo)
        {
            DownloadPackage downloadPackage = new DownloadPackage();

            Rss.RssChannel rssChannel = (Rss.RssChannel)stateInfo;
            string         strDir     = Utils.GetValidFolderPath(feedItem.Title);

            string strDownloadlocation;

            if (feedItem.OverrideDownloadsFolder)
            {
                strDownloadlocation = feedItem.DownloadsFolder;
            }
            else
            {
                strDownloadlocation = Settings.Default.DownloadLocation + "\\" + strDir;
            }
            if (!Directory.Exists(strDownloadlocation))
            {
                Directory.CreateDirectory(strDownloadlocation);
            }
            try
            {
                try
                {
                    foreach (Rss.RssItem rssItem in rssChannel.Items)
                    {
                        if (rssItem.Enclosure != null)
                        {
                            bool validUri = false;
                            Uri  uri      = null;
                            try
                            {
                                uri      = new Uri(rssItem.Enclosure.Url);
                                validUri = true;
                            }
                            catch (UriFormatException ex)
                            {
                                boolError = true;
                                if (Settings.Default.LogLevel > 0)
                                {
                                    log.Error(String.Format("Invalid enclosure url for {0} ({1})", feedItem.Title, rssItem.Enclosure.Url), ex);
                                }
                            }
                            if (validUri)
                            {
                                string strPath     = GetValidFilename(uri.LocalPath.Substring(uri.LocalPath.LastIndexOf("/") + 1));
                                string strFilename = Path.Combine(strDownloadlocation, strPath);
                                if (!Directory.Exists(strDownloadlocation))
                                {
                                    Directory.CreateDirectory(strDownloadlocation);
                                }

                                downloadPackage = GetDownloadPackage(rssItem, feedItem, strDownloadlocation);
                                long longDownloadsize = downloadPackage.DownloadSize;

                                if (downloadPackage.strFilename != null)
                                {
                                    strFilename = downloadPackage.strFilename;
                                }

                                if (longDownloadsize > 0)
                                {
                                    if (feedItem.Authenticate == true)
                                    {
                                        string strPassword = EncDec.Decrypt(feedItem.Password, feedItem.Username);
                                        FileFound(feedItem, rssItem.Enclosure.Url, longDownloadsize, downloadPackage.strFilename, rssItem, downloadPackage.ByteRanging);
                                    }
                                    else
                                    {
                                        FileFound(feedItem, rssItem.Enclosure.Url, longDownloadsize, downloadPackage.strFilename, rssItem, downloadPackage.ByteRanging);
                                    }
                                }
                            }
                        }
                        //RetrieverSingleFileComplete(feedItem, downloadPackage);
                        RetrieveCompleteCallback(feedItem, true);
                    }
                }
                catch (WebException wex)
                {
                    if (Settings.Default.LogLevel > 0)
                    {
                        log.Error("Retriever", wex);
                    }
                }
            }
            catch (ThreadAbortException)
            {
                //MessageBox.Show("TA");
            }
        }
Ejemplo n.º 27
0
Archivo: Rss.cs Proyecto: joargp/CMS
 public void BuildPost()
 {
     var data =
         Proxy.Repository<Post>()
             .GetAll(p => p.PostStatus == (int) PostStatusEnum.Publish)
             .OrderByDescending(p => p.CreateDate)
             .Take(10);
     var channel = new RssChannel
     {
         Title = string.Format("{0} - 文章", Config.Literal.SITE_NAME),
         Link = new Uri(Config.URL.Domain),
         Description = string.Format("{0} - 文章", Config.Literal.SITE_NAME),
         PubDate = DateTime.Now,
         LastBuildDate = DateTime.Now,
         Language = "zh-cn",
         Copyright = Config.Literal.COPYRIGHT
     };
     foreach (var item in data)
     {
         channel.Items.Add(CreatePostItem(item));
     }
     var feed = new RssFeed(Encoding.UTF8);
     feed.Channels.Add(channel);
     feed.Write(Config.Path.PHYSICAL_ROOT_PATH + Config.Path.ARTICLES_RSS_PATH);
 }
Ejemplo n.º 28
0
    static void RunOnce()
    {
        if (bloggers == null || File.GetLastWriteTime (bloggersFile) > lastReadOfBloggersFile) {
            lastReadOfBloggersFile = File.GetLastWriteTime (bloggersFile);
            bloggers = BloggerCollection.LoadFromFile (bloggersFile);
        }

        disable_load = false;
        all = (Blogger []) bloggers.Bloggers.ToArray (typeof (Blogger));
        lock (all) {
            next = 10;
            for (int i = 0; i < 10 && i < all.Length; i++) {
                Blogger b = all [i];
                ReadDelegate d = new ReadDelegate (FeedCache.Read);
                d.BeginInvoke (b.Name, b.RssUrl, feed_done, b);
            }
        }

        wait_handle.WaitOne (300000, false);
        disable_load = true;

        for (int i = 0; i < (int) UpdateStatus.MAX; i++) {
            Console.WriteLine ("{0}: {1}", (UpdateStatus) i, counters [i]);
        }

        int error = counters [(int) UpdateStatus.Error];
        int downloaded = counters [(int) UpdateStatus.Downloaded];
        int updated = counters [(int) UpdateStatus.Updated];
        if (error == 0 && downloaded == 0 && updated == 0)
            return;

        outFeed = new RssFeed ();
        RssChannel ch = new RssChannel ();
        ch.Title = "Monologue";
        ch.Generator = "Monologue worker: b-diddy powered";
        ch.Description = "The voices of Mono";
        ch.Link = new Uri ("http://www.go-mono.com/monologue/");

        ArrayList stories = new ArrayList ();

        DateTime minPubDate = DateTime.Now.AddDays (-14);
        foreach (Blogger b in bloggers.BloggersByUrl) {
            if (b.Channel == null) continue;
            foreach (RssItem i in b.Channel.Items) {
                if (i.PubDate == DateTime.MinValue) {
                    b.DateError = true;
                } else if (i.PubDate >= minPubDate) {
                    i.Title = b.Name + ": " + i.Title;
                    i.PubDate = i.PubDate.ToUniversalTime ();
                    stories.Add (i);
                }
            }
        }

        stories.Sort (new ReverseRssItemComparer ());

        foreach (RssItem itm in stories)
            ch.Items.Add (itm);

        if (ch.Items.Count == 0) {
            Settings.Log ("No feeds to store.");
            return;
        }
        outFeed.Channels.Add (ch);
        outFeed.Write (rssOutFile);

        Render ();
    }
Ejemplo n.º 29
0
        private void writeChannel(RssChannel channel)
        {
            if (Writer == null)
                throw new InvalidOperationException("RssWriter has been closed, and cannot be written to.");
            if (channel == null)
                throw new ArgumentNullException("Channel must be instanciated with data to be written.");

            if (ChannelBegun)
                Writer.WriteEndElement();
            else
                ChannelBegun = true;

            BeginDocument();

            Writer.WriteStartElement("channel");
            WriteElement("title", channel.Title, true);
            WriteElement("description", channel.Description, true);
            WriteElement("link", channel.Link, true);

            if (channel.Image != null)
            {
                Writer.WriteStartElement("image");
                WriteElement("title", channel.Image.Title, true);
                WriteElement("url", channel.Image.Url, true);
                WriteElement("link", channel.Image.Link, true);
                WriteElement("description", channel.Image.Description, false);
                WriteElement("width", channel.Image.Width, false);
                WriteElement("height", channel.Image.Height, false);
                Writer.WriteEndElement();
            }

            WriteElement("language", channel.Language, Version == RssVersion.RSS091);
            WriteElement("copyright", channel.Copyright, false);
            WriteElement("managingEditor", channel.ManagingEditor, false);
            WriteElement("webMaster", channel.WebMaster, false);
            WriteElement("pubDate", channel.PubDate, false);
            WriteElement("lastBuildDate", channel.LastBuildDate, false);
            if (channel.Docs != RssDefault.String)
                WriteElement("docs", channel.Docs, false);
            else
                WriteElement("docs", "http://backend.userland.com/rss", false);

            WriteElement("rating", channel.Rating, false);
            WriteSkipDays(channel);
            WriteSkipHours(channel);

            if (channel.Categories != null)
                foreach(RssCategory category in channel.Categories)
                {
                    if (category.Name != RssDefault.String)
                    {
                        Writer.WriteStartElement("category");
                        WriteAttribute("domain", category.Domain, false);
                        Writer.WriteString(category.Name);
                        Writer.WriteEndElement();
                    }
                }

            if (channel.Cloud != null)
            {
                Writer.WriteStartElement("cloud");
                WriteElement("domain", channel.Cloud.Domain, false);
                WriteElement("port", channel.Cloud.Port, false);
                WriteElement("path", channel.Cloud.Path, false);
                WriteElement("registerProcedure", channel.Cloud.RegisterProcedure, false);
                if (channel.Cloud.Protocol != RssCloudProtocol.Empty)
                    WriteElement("Protocol", channel.Cloud.Protocol, false);
                Writer.WriteEndElement();
            }

            if (channel.Generator != RssDefault.String)
                WriteElement("generator", channel.Generator, false);
            else
                WriteElement("generator", "RSS.NET: http://rss-net.sf.net/", false);
            WriteElement("ttl", channel.TimeToLive, false);

            // RSS Modules
            foreach(RssModule rssModule in this._rssModules)
            {
                if(rssModule.IsBoundTo(channel.GetHashCode()))
                {
                    foreach(RssModuleItem rssModuleItem in rssModule.ChannelExtensions)
                    {
                        if(rssModuleItem.SubElements.Count == 0)
                            WriteElement(rssModule.NamespacePrefix + ":" + rssModuleItem.Name, rssModuleItem.Text, rssModuleItem.IsRequired);
                        else
                            writeSubElements(rssModuleItem.SubElements, rssModule.NamespacePrefix);
                    }
                }
            }

            if (channel.TextInput != null)
            {
                Writer.WriteStartElement("textinput");
                WriteElement("title", channel.TextInput.Title, true);
                WriteElement("description", channel.TextInput.Description, true);
                WriteElement("name", channel.TextInput.Name, true);
                WriteElement("link", channel.TextInput.Link, true);
                Writer.WriteEndElement();
            }
            foreach (RssItem item in channel.Items)
            {
                writeItem(item, channel.GetHashCode());
            }
            Writer.Flush();
        }
Ejemplo n.º 30
0
		/// <summary>Reads the next RssElement from the stream.</summary>
		/// <returns>An RSS Element</returns>
		/// <exception cref="InvalidOperationException">RssReader has been closed, and can not be read.</exception>
		/// <exception cref="System.IO.FileNotFoundException">RSS file not found.</exception>
		/// <exception cref="System.Xml.XmlException">Invalid XML syntax in RSS file.</exception>
		/// <exception cref="System.IO.EndOfStreamException">Unable to read an RssElement. Reached the end of the stream.</exception>
		public RssElement Read()
		{
			bool readData = false;
			bool pushElement = true;
			RssElement rssElement = null;
			int lineNumber = -1;
			int linePosition = -1;

			if (reader == null)
				throw new InvalidOperationException("RssReader has been closed, and can not be read.");

			do
			{
				pushElement = true;
				try
				{
					readData = reader.Read();
				}
				catch (System.IO.EndOfStreamException e)
				{
					throw new System.IO.EndOfStreamException("Unable to read an RssElement. Reached the end of the stream.", e);
				}
				catch (System.Xml.XmlException e)
				{
					if (lineNumber != -1 || linePosition != -1)
						if (reader.LineNumber == lineNumber && reader.LinePosition == linePosition)
							throw exceptions.LastException;

					lineNumber = reader.LineNumber;
					linePosition = reader.LinePosition;

					exceptions.Add(e); // just add to list of exceptions and continue :)

                    //// Added, OFxP
                    //if (readData)
                    //{
                    //    continue;
                    //}
				}
				if (readData)
				{
					string readerName = reader.Name.ToLower();
					switch (reader.NodeType)
					{
						case XmlNodeType.Element:
						{
							if (reader.IsEmptyElement)
								break;
							elementText = new StringBuilder();

							switch (readerName)
							{
								case "item":
									// is this the end of the channel element? (absence of </channel> before <item>)
									if (!wroteChannel)
									{
										wroteChannel = true;
										rssElement = channel; // return RssChannel
										readData = false;
									}
									item = new RssItem(); // create new RssItem
									channel.Items.Add(item);
									break;
								case "source":
									source = new RssSource();
									item.Source = source;
									for (int i=0; i < reader.AttributeCount; i++)
									{
										reader.MoveToAttribute(i);
										switch (reader.Name.ToLower())
										{
											case "url":
												try
												{
                                                    // OFxP, fix
                                                    //source.Url = new Uri(reader.Value);
                                                    source.Url = new Uri(reader.Value, true);
												}				
												catch (Exception e)
												{
													exceptions.Add(e);
												}
												break;
										}
									}
									break;
								case "enclosure":
									enclosure = new RssEnclosure();
									item.Enclosure = enclosure;
									for (int i=0; i < reader.AttributeCount; i++)
									{
										reader.MoveToAttribute(i);
										switch (reader.Name.ToLower())
										{
											case "url":
												try
												{
                                                    // OFxP, fix
                                                    //enclosure.Url = new Uri(reader.Value);
                                                    enclosure.Url = new Uri(reader.Value, true);
												}				
												catch (Exception e)
												{
													exceptions.Add(e);
												}
												break;
											case "length":
												try
												{
													enclosure.Length = int.Parse(reader.Value);
												}				
												catch (Exception e)
												{
													exceptions.Add(e);
												}
												break;
											case "type":
												enclosure.Type = reader.Value;
												break;
										}
									}
									break;
								case "guid":
									guid = new RssGuid();
									item.Guid = guid;
									for (int i=0; i < reader.AttributeCount; i++)
									{
										reader.MoveToAttribute(i);
										switch (reader.Name.ToLower())
										{
											case "ispermalink":
												try
												{
													guid.PermaLink = bool.Parse(reader.Value);
												}			
												catch (Exception e)
												{
													exceptions.Add(e);
												}
												break;
										}
									}
									break;
								case "category":
									category = new RssCategory();
									if ((string)xmlNodeStack.Peek() == "channel")
										channel.Categories.Add(category);
									else
										item.Categories.Add(category);
									for (int i=0; i < reader.AttributeCount; i++)
									{
										reader.MoveToAttribute(i);
										switch (reader.Name.ToLower())
										{
											case "url":
												goto case "domain";
											case "domain":
												category.Domain = reader.Value;
												break;
										}
									}
									break;
								case "channel":
									channel = new RssChannel();
									textInput = null;
									image = null;
									cloud = null;
									source = null;
									enclosure = null;
									category = null;
									item = null;
									break;
								case "image":
									image = new RssImage();
									channel.Image = image;
									break;
								case "textinput":
									textInput = new RssTextInput();
									channel.TextInput = textInput;
									break;
								case "cloud":
									pushElement = false;
									cloud = new RssCloud();
									channel.Cloud = cloud;
									for (int i=0; i < reader.AttributeCount; i++)
									{
										reader.MoveToAttribute(i);
										switch (reader.Name.ToLower())
										{
											case "domain":
												cloud.Domain = reader.Value;
												break;
											case "port":
												try
												{
													cloud.Port = ushort.Parse(reader.Value);
												}				
												catch (Exception e)
												{
													exceptions.Add(e);
												}
												break;
											case "path":
												cloud.Path = reader.Value;
												break;
											case "registerprocedure":
												cloud.RegisterProcedure = reader.Value;
												break;
											case "protocol":
											switch (reader.Value.ToLower())
											{
												case "xml-rpc":
													cloud.Protocol = RssCloudProtocol.XmlRpc;
													break;
												case "soap":
													cloud.Protocol = RssCloudProtocol.Soap;
													break;
												case "http-post":
													cloud.Protocol = RssCloudProtocol.HttpPost;
													break;
												default:
													cloud.Protocol = RssCloudProtocol.Empty;
													break;
											}
												break;
										}
									}
									break;
								case "rss":
									for (int i=0; i < reader.AttributeCount; i++)
									{
										reader.MoveToAttribute(i);
										if (reader.Name.ToLower() == "version")
											switch (reader.Value)
											{
												case "0.91":
													rssVersion = RssVersion.RSS091;
													break;
												case "0.92":
													rssVersion = RssVersion.RSS092;
													break;
												case "2.0":
													rssVersion = RssVersion.RSS20;
													break;
												default:
													rssVersion = RssVersion.NotSupported;
													break;
											}
									}
									break;
								case "rdf":
									for (int i=0; i < reader.AttributeCount; i++)
									{
										reader.MoveToAttribute(i);
										if (reader.Name.ToLower() == "version")
											switch (reader.Value)
											{
												case "0.90":
													rssVersion = RssVersion.RSS090;
													break;
												case "1.0":
													rssVersion = RssVersion.RSS10;
													break;
												default:
													rssVersion = RssVersion.NotSupported;
													break;
											}
									}
									break;
							
							}
							if (pushElement)
								xmlNodeStack.Push(readerName);
							break;
						}
						case XmlNodeType.EndElement:
						{
							if (xmlNodeStack.Count == 1)
								break;
							string childElementName = (string)xmlNodeStack.Pop();
							string parentElementName = (string)xmlNodeStack.Peek();
							switch (childElementName) // current element
							{
									// item classes
								case "item":
									rssElement = item;
									readData = false;
									break;
								case "source":
									source.Name = elementText.ToString();
									rssElement = source;
									readData = false;
									break;
								case "enclosure":
									rssElement = enclosure;
									readData = false;
									break;
								case "guid":
									guid.Name = elementText.ToString();
									rssElement = guid;
									readData = false;
									break;
								case "category": // parent is either item or channel
									category.Name = elementText.ToString();
									rssElement = category;
									readData = false;
									break;
									// channel classes
								case "channel":
									if (wroteChannel)
										wroteChannel = false;
									else
									{
										wroteChannel = true;
										rssElement = channel;
										readData = false;
									}
									break;
								case "textinput":
									rssElement = textInput;
									readData = false;
									break;
								case "image":
									rssElement = image;
									readData = false;
									break;
								case "cloud":
									rssElement = cloud;
									readData = false;
									break;
							}
							switch (parentElementName) // parent element
							{
								case "item":
								switch (childElementName)
								{
									case "title":
										item.Title = elementText.ToString();
										break;
									case "link":
                                        // OFxP, fix
										//item.Link = new Uri(elementText.ToString());
                                        item.Link = new Uri(elementText.ToString(), true);
										break;
									case "description":
										item.Description = elementText.ToString();
										break;
									case "author":
										item.Author = elementText.ToString();
										break;
									case "comments":
										item.Comments = elementText.ToString();
										break;
                                    case "dc:date": // Fix for the federalreserve feed.
                                    case "pubdate":
                                        item.PubDate = GeneralHelper.ParseDateTimeWithZone(elementText.ToString());
										break;
								}
									break;
								case "channel":
								switch (childElementName)
								{
									case "title":
										channel.Title = elementText.ToString();
										break;
									case "link":
										try
										{
                                            // OFxP, fix
                                            //channel.Link = new Uri(elementText.ToString());
											channel.Link = new Uri(elementText.ToString(), true);
										}				
										catch (Exception e)
										{
											exceptions.Add(e);
										}
										break;
									case "description":
										channel.Description = elementText.ToString();
										break;
									case "language":
										channel.Language = elementText.ToString();
										break;
									case "copyright":
										channel.Copyright = elementText.ToString();
										break;
									case "managingeditor":
										channel.ManagingEditor = elementText.ToString();
										break;
									case "webmaster":
										channel.WebMaster = elementText.ToString();
										break;
									case "rating":
										channel.Rating = elementText.ToString();
										break;
                                    
                                    case "dc:date": // Fix for the federalreserve feed.
									case "pubdate":
                                        channel.PubDate = GeneralHelper.ParseDateTimeWithZone(elementText.ToString());
										break;
									case "lastbuilddate":
                                        channel.LastBuildDate = GeneralHelper.ParseDateTimeWithZone(elementText.ToString());
										break;
									case "generator":
										channel.Generator = elementText.ToString();
										break;
									case "docs":
										channel.Docs = elementText.ToString();
										break;
									case "ttl":
										try
										{
											channel.TimeToLive = int.Parse(elementText.ToString());
										}				
										catch (Exception e)
										{
											exceptions.Add(e);
										}
										break;
								}
									break;
								case "image":
								switch (childElementName)
								{
									case "url":
										try
										{
                                            // OFxP, fix
                                            //image.Url = new Uri(elementText.ToString());
											image.Url = new Uri(elementText.ToString(), true);
										}				
										catch (Exception e)
										{
											exceptions.Add(e);
										}
										break;
									case "title":
										image.Title = elementText.ToString();
										break;
									case "link":
										try
										{
                                            // OFxP, fix
                                            //image.Link = new Uri(elementText.ToString());
											image.Link = new Uri(elementText.ToString(), true);
										}				
										catch (Exception e)
										{
											exceptions.Add(e);
										}
										break;
									case "description":
										image.Description = elementText.ToString();
										break;
									case "width":
										try
										{
											image.Width = Byte.Parse(elementText.ToString());
										}				
										catch (Exception e)
										{
											exceptions.Add(e);
										}
										break;
									case "height":
										try
										{
											image.Height = Byte.Parse(elementText.ToString());
										}				
										catch (Exception e)
										{
											exceptions.Add(e);
										}
										break;
								}
									break;
								case "textinput":
								switch (childElementName)
								{
									case "title":
										textInput.Title = elementText.ToString();
										break;
									case "description":
										textInput.Description = elementText.ToString();
										break;
									case "name":
										textInput.Name = elementText.ToString();
										break;
									case "link":
										try
										{
                                            // OFxP, fix
                                            //textInput.Link = new Uri(elementText.ToString());
                                            textInput.Link = new Uri(elementText.ToString(), true);
										}				
										catch (Exception e)
										{
											exceptions.Add(e);
										}
										break;
								}
									break;
								case "skipdays":
									if (childElementName == "day")
                                        channel.SkipDays |= Day.Parse(elementText.ToString());
									break;
								case "skiphours":
									if (childElementName == "hour")
										channel.SkipHours |= Hour.Parse(elementText.ToString());
									break;
							}
							break;
						}
						case XmlNodeType.Text:
							elementText.Append(reader.Value);
							break;
						case XmlNodeType.CDATA:
							elementText.Append(reader.Value);
							break;
					}
				}
			}
			while (readData);
			return rssElement;
		}
Ejemplo n.º 31
0
        private void WriteSkipHours(RssChannel channel)
        {
            bool elementOpened = false;

            foreach(Hour h in channel.SkipHours.Hours)
            {
                if (!elementOpened)
                {
                    Writer.WriteStartElement("skipHours");
                    elementOpened = true;
                }

                WriteElement("hour", h.ToString(), false);
            }

            if (elementOpened)
                Writer.WriteEndElement();
        }
Ejemplo n.º 32
0
        static void Main(string[] args)
        {
            RssFeed r = new RssFeed();

            r.Version = RssVersion.RSS20;

            RssItem ri1a = new RssItem();

            ri1a.Author      = "Test Author 1a";
            ri1a.Title       = "Test Title 1a";
            ri1a.Description = "Test Description 1a";
            ri1a.Link        = new Uri("http://www.yourserver.com/");
            ri1a.PubDate     = DateTime.Now;

            RssItem ri1b = new RssItem();

            ri1b.Author      = "Test Author 1b";
            ri1b.Title       = "Test Title 1b";
            ri1b.Description = "Test Description 1b";
            ri1b.Link        = new Uri("http://www.yourserver.com/");
            ri1b.PubDate     = DateTime.Now;

            RssChannel rc1 = new RssChannel();

            rc1.Items.Add(ri1a);
            rc1.Items.Add(ri1b);
            rc1.Title       = "Test Channel Title 1";
            rc1.Description = "Test Channel Description 1";
            rc1.Link        = new Uri("http://www.yourserver.com/channel.html");
            rc1.PubDate     = DateTime.Now;

            r.Channels.Add(rc1);

            RssPhotoAlbumCategoryPhotoPeople pacpp = new RssPhotoAlbumCategoryPhotoPeople("John Doe");

            RssPhotoAlbumCategoryPhoto  pacp1 = new RssPhotoAlbumCategoryPhoto(DateTime.Now.Subtract(new TimeSpan(2, 12, 0, 0)), "Test Photo Description 1", new Uri("http://www.yourserver.com/PhotoAlbumWeb/GetPhoto.aspx?PhotoID=123"), pacpp);
            RssPhotoAlbumCategoryPhoto  pacp2 = new RssPhotoAlbumCategoryPhoto(DateTime.Now.Subtract(new TimeSpan(2, 10, 0, 0)), "Test Photo Description 2", new Uri("http://www.yourserver.com/PhotoAlbumWeb/GetPhoto.aspx?PhotoID=124"));
            RssPhotoAlbumCategoryPhoto  pacp3 = new RssPhotoAlbumCategoryPhoto(DateTime.Now.Subtract(new TimeSpan(2, 10, 0, 0)), "Test Photo Description 2", new Uri("http://www.yourserver.com/PhotoAlbumWeb/GetPhoto.aspx?PhotoID=125"));
            RssPhotoAlbumCategoryPhotos pacps = new RssPhotoAlbumCategoryPhotos();

            pacps.Add(pacp1);
            pacps.Add(pacp2);

            RssPhotoAlbumCategory   pac1 = new RssPhotoAlbumCategory("Test Photo Album Category 1", "Test Photo Album Category Description 1", DateTime.Now.Subtract(new TimeSpan(5, 10, 0, 0)), DateTime.Now, pacps);
            RssPhotoAlbumCategory   pac2 = new RssPhotoAlbumCategory("Test Photo Album Category 2", "Test Photo Album Category Description 2", DateTime.Now.Subtract(new TimeSpan(9, 10, 0, 0)), DateTime.Now, pacp3);
            RssPhotoAlbumCategories pacs = new RssPhotoAlbumCategories();

            pac1.BindTo(ri1a.GetHashCode());
            pac2.BindTo(ri1b.GetHashCode());
            pacs.Add(pac1);
            pacs.Add(pac2);

            RssPhotoAlbum pa = new RssPhotoAlbum(new Uri("http://your.web.server/PhotoAlbumWeb"), pacs);

            pa.BindTo(rc1.GetHashCode());

            r.Modules.Add(pa);

            RssItem ri2 = new RssItem();

            ri2.Author      = "Test Author 2";
            ri2.Title       = "Test Title 2";
            ri2.Description = "Test Description 2";
            ri2.Link        = new Uri("http://www.yourotherserver.com/");
            ri2.PubDate     = DateTime.Now;

            RssChannel rc2 = new RssChannel();

            rc2.Items.Add(ri2);
            rc2.Title       = "Test Channel Title 2";
            rc2.Description = "Test Channel Description 2";
            rc2.Link        = new Uri("http://www.yourotherserver.com/channel.html");
            rc2.PubDate     = DateTime.Now;

            r.Channels.Add(rc2);

            r.Write("out.xml");

            RssBlogChannel rbc = new RssBlogChannel(new Uri("http://www.google.com"), new Uri("http://www.google.com"), new Uri("http://www.google.com"), new Uri("http://www.google.com"));
        }
Ejemplo n.º 33
0
Archivo: Rss.cs Proyecto: 441023065/CMS
 private RssChannel BuildPostRssChannel()
 {
     var now = DateTime.Now;
     var channel = new RssChannel
                       {
                           Title = Config.Literal.SITE_NAME,
                           Link = new Uri(Config.URL.Domain),
                           Description = Config.Literal.DESCRIPTION,
                           PubDate = now,
                           LastBuildDate = now,
                           Language = "zh-cn",
                           Copyright = Config.Literal.COPYRIGHT
                       };
     return channel;
 }
Ejemplo n.º 34
0
		/// <summary>Determines whether the RssChannelCollection contains a specific element.</summary>
		/// <param name="rssChannel">The RssChannel to locate in the RssChannelCollection.</param>
		/// <returns>true if the RssChannelCollection contains the specified value; otherwise, false.</returns>
		public bool Contains(RssChannel rssChannel)
		{
			return List.Contains(rssChannel);
		}
Ejemplo n.º 35
0
    private void writeChannel(RssChannel channel)
    {
      if (writer == null)
      {
        throw new InvalidOperationException("RssWriter has been closed, and can not be written to.");
      }
      if (channel == null)
      {
        throw new ArgumentNullException("Channel must be instanciated with data to be written.");
      }

      if (wroteChannel)
      {
        writer.WriteEndElement();
      }
      else
      {
        wroteChannel = true;
      }

      BeginDocument();

      writer.WriteStartElement("channel");
      WriteElement("title", channel.Title, true);
      WriteElement("description", channel.Description, true);
      WriteElement("link", channel.Link, true);
      if (channel.Image != null)
      {
        writer.WriteStartElement("image");
        WriteElement("title", channel.Image.Title, true);
        WriteElement("url", channel.Image.Url, true);
        WriteElement("link", channel.Image.Link, true);
        switch (rssVersion)
        {
          case RssVersion.RSS091:
          case RssVersion.RSS092:
          case RssVersion.RSS20:
            WriteElement("description", channel.Image.Description, false);
            WriteElement("width", channel.Image.Width, false);
            WriteElement("height", channel.Image.Height, false);
            break;
        }
        writer.WriteEndElement();
      }
      switch (rssVersion)
      {
        case RssVersion.RSS091:
        case RssVersion.RSS092:
        case RssVersion.RSS20:
          WriteElement("language", channel.Language, rssVersion == RssVersion.RSS091);
          WriteElement("copyright", channel.Copyright, false);
          WriteElement("managingEditor", channel.ManagingEditor, false);
          WriteElement("webMaster", channel.WebMaster, false);
          WriteElement("pubDate", channel.PubDate, false);
          WriteElement("lastBuildDate", channel.LastBuildDate, false);
          if (channel.Docs != RssDefault.String)
          {
            WriteElement("docs", channel.Docs, false);
          }
          else
          {
            switch (rssVersion)
            {
              case RssVersion.RSS091:
                WriteElement("docs", "http://my.netscape.com/publish/formats/rss-spec-0.91.html", false);
                break;
              case RssVersion.RSS092:
                WriteElement("docs", "http://backend.userland.com/rss092", false);
                break;
              case RssVersion.RSS20:
                WriteElement("docs", "http://backend.userland.com/rss", false);
                break;
            }
          }
          WriteElement("rating", channel.Rating, false);
          string[] Days = {"monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"};
          for (int i = 0; i <= 6; i++)
          {
            if (channel.SkipDays[i])
            {
              writer.WriteStartElement("skipDays");
              for (int i2 = 0; i2 <= 6; i2++)
              {
                if (channel.SkipDays[i2])
                {
                  WriteElement("day", Days[i2], false);
                }
              }
              writer.WriteEndElement();
              break;
            }
          }
          for (int i = 0; i <= 23; i++)
          {
            if (channel.SkipHours[i])
            {
              writer.WriteStartElement("skipHours");
              for (int i2 = 0; i2 <= 23; i2++)
              {
                if (channel.SkipHours[i2])
                {
                  WriteElement("hour", i2 + 1, false);
                }
              }
              writer.WriteEndElement();
              break;
            }
          }
          break;
      }
      switch (rssVersion)
      {
        case RssVersion.RSS092:
        case RssVersion.RSS20:
          if (channel.Categories != null)
          {
            foreach (RssCategory category in channel.Categories)
            {
              if (category.Name != RssDefault.String)
              {
                writer.WriteStartElement("category");
                WriteAttribute("domain", category.Domain, false);
                writer.WriteString(category.Name);
                writer.WriteEndElement();
              }
            }
          }
          if (channel.Cloud != null)
          {
            writer.WriteStartElement("cloud");
            WriteElement("domain", channel.Cloud.Domain, false);
            WriteElement("port", channel.Cloud.Port, false);
            WriteElement("path", channel.Cloud.Path, false);
            WriteElement("registerProcedure", channel.Cloud.RegisterProcedure, false);
            if (channel.Cloud.Protocol != RssCloudProtocol.Empty)
            {
              WriteElement("Protocol", channel.Cloud.Protocol, false);
            }
            writer.WriteEndElement();
          }
          break;
      }
      if (rssVersion == RssVersion.RSS20)
      {
        if (channel.Generator != RssDefault.String)
        {
          WriteElement("generator", channel.Generator, false);
        }
        else
        {
          WriteElement("generator", "RSS.NET: http://www.rssdotnet.com/", false);
        }
        WriteElement("ttl", channel.TimeToLive, false);

        // RSS Modules
        foreach (RssModule rssModule in this._rssModules)
        {
          if (rssModule.IsBoundTo(channel.GetHashCode()))
          {
            foreach (RssModuleItem rssModuleItem in rssModule.ChannelExtensions)
            {
              if (rssModuleItem.SubElements.Count == 0)
              {
                WriteElement(rssModule.NamespacePrefix + ":" + rssModuleItem.Name, rssModuleItem.Text,
                             rssModuleItem.IsRequired);
              }
              else
              {
                writeSubElements(rssModuleItem.SubElements, rssModule.NamespacePrefix);
              }
            }
          }
        }
      }
      if (channel.TextInput != null)
      {
        writer.WriteStartElement("textinput");
        WriteElement("title", channel.TextInput.Title, true);
        WriteElement("description", channel.TextInput.Description, true);
        WriteElement("name", channel.TextInput.Name, true);
        WriteElement("link", channel.TextInput.Link, true);
        writer.WriteEndElement();
      }
      foreach (RssItem item in channel.Items)
      {
        writeItem(item, channel.GetHashCode());
      }
      writer.Flush();
    }
Ejemplo n.º 36
0
 /// <summary>Writes an RSS channel</summary>
 /// <exception cref="InvalidOperationException">RssWriter has been closed, and can not be written to.</exception>
 /// <exception cref="ArgumentNullException">Channel must be instanciated with data, before calling Write.</exception>
 /// <param name="channel">RSS channel to write</param>
 public void Write(RssChannel channel)
 {
     writeChannel(channel);
 }
Ejemplo n.º 37
0
Archivo: lb.cs Proyecto: mono/lb
    RssChannel MakeChannel()
    {
        RssChannel c = new RssChannel (config.Title, config.Description, new Uri (config.BlogWebDirectory + "/" + config.BlogFileName));

        c.Copyright = config.Copyright;
        c.Generator = "lb#";
        c.ManagingEditor = config.ManagingEditor;
        // c.PubDate = System.DateTime.Now;
        c.PubDate = pubDate;

        return c;
    }
Ejemplo n.º 38
0
		/// <summary>Adds a specified channel to this collection.</summary>
		/// <param name="channel">The channel to add.</param>
		/// <returns>The zero-based index of the added channel.</returns>
		public int Add(RssChannel channel)
		{
			return List.Add(channel);
		}
Ejemplo n.º 39
0
		/// <summary>Closes connection to file.</summary>
		/// <remarks>This baseMethod also releases any resources held while reading.</remarks>
		public void Close()
		{
			textInput = null;
			image = null;
			cloud = null;
			channel = null;
			source = null;
			enclosure = null;
			category = null;
			item = null;
			if (reader!=null)
			{
				reader.Close();
				reader = null;
			}
			elementText = null;
			xmlNodeStack = null;
		}
Ejemplo n.º 40
0
        private void writeChannel(RssChannel channel)
        {
            if (Writer == null)
            {
                throw new InvalidOperationException("RssWriter has been closed, and cannot be written to.");
            }
            if (channel == null)
            {
                throw new ArgumentNullException("Channel must be instanciated with data to be written.");
            }

            if (ChannelBegun)
            {
                Writer.WriteEndElement();
            }
            else
            {
                ChannelBegun = true;
            }

            BeginDocument();

            Writer.WriteStartElement("channel");
            WriteElement("title", channel.Title, true);
            WriteElement("description", channel.Description, true);
            WriteElement("link", channel.Link, true);

            if (channel.Image != null)
            {
                Writer.WriteStartElement("image");
                WriteElement("title", channel.Image.Title, true);
                WriteElement("url", channel.Image.Url, true);
                WriteElement("link", channel.Image.Link, true);
                WriteElement("description", channel.Image.Description, false);
                WriteElement("width", channel.Image.Width, false);
                WriteElement("height", channel.Image.Height, false);
                Writer.WriteEndElement();
            }

            WriteElement("language", channel.Language, Version == RssVersion.RSS091);
            WriteElement("copyright", channel.Copyright, false);
            WriteElement("managingEditor", channel.ManagingEditor, false);
            WriteElement("webMaster", channel.WebMaster, false);
            WriteElement("pubDate", channel.PubDate, false);
            WriteElement("lastBuildDate", channel.LastBuildDate, false);
            if (channel.Docs != RssDefault.String)
            {
                WriteElement("docs", channel.Docs, false);
            }
            else
            {
                WriteElement("docs", "http://backend.userland.com/rss", false);
            }

            WriteElement("rating", channel.Rating, false);
            WriteSkipDays(channel);
            WriteSkipHours(channel);

            if (channel.Categories != null)
            {
                foreach (RssCategory category in channel.Categories)
                {
                    if (category.Name != RssDefault.String)
                    {
                        Writer.WriteStartElement("category");
                        WriteAttribute("domain", category.Domain, false);
                        Writer.WriteString(category.Name);
                        Writer.WriteEndElement();
                    }
                }
            }

            if (channel.Cloud != null)
            {
                Writer.WriteStartElement("cloud");
                WriteElement("domain", channel.Cloud.Domain, false);
                WriteElement("port", channel.Cloud.Port, false);
                WriteElement("path", channel.Cloud.Path, false);
                WriteElement("registerProcedure", channel.Cloud.RegisterProcedure, false);
                if (channel.Cloud.Protocol != RssCloudProtocol.Empty)
                {
                    WriteElement("Protocol", channel.Cloud.Protocol, false);
                }
                Writer.WriteEndElement();
            }

            if (channel.Generator != RssDefault.String)
            {
                WriteElement("generator", channel.Generator, false);
            }
            else
            {
                WriteElement("generator", "RSS.NET: http://rss-net.sf.net/", false);
            }
            WriteElement("ttl", channel.TimeToLive, false);

            // RSS Modules
            foreach (RssModule rssModule in this._rssModules)
            {
                if (rssModule.IsBoundTo(channel.GetHashCode()))
                {
                    foreach (RssModuleItem rssModuleItem in rssModule.ChannelExtensions)
                    {
                        if (rssModuleItem.SubElements.Count == 0)
                        {
                            WriteElement(rssModule.NamespacePrefix + ":" + rssModuleItem.Name, rssModuleItem.Text, rssModuleItem.IsRequired);
                        }
                        else
                        {
                            writeSubElements(rssModuleItem.SubElements, rssModule.NamespacePrefix);
                        }
                    }
                }
            }

            if (channel.TextInput != null)
            {
                Writer.WriteStartElement("textinput");
                WriteElement("title", channel.TextInput.Title, true);
                WriteElement("description", channel.TextInput.Description, true);
                WriteElement("name", channel.TextInput.Name, true);
                WriteElement("link", channel.TextInput.Link, true);
                Writer.WriteEndElement();
            }
            foreach (RssItem item in channel.Items)
            {
                writeItem(item, channel.GetHashCode());
            }
            Writer.Flush();
        }