Exemple #1
0
        public NewsReaderViewModel()
        {
            IRSSChannel channel = new RSSChannel("channel 1 title", "channel 1 description", "channel 1 link");

            IRSSStory story = new RSSStory("channel 1 story 1 title", "channel 1 story 1 description", "channel 1 story 1 link");

            channel.Stories.Add(story);

            story = new RSSStory("channel 1 story 2 title", "channel 1 story 2 description", "channel 1 story 2 link");
            channel.Stories.Add(story);

            story = new RSSStory("channel 1 story 3 title", "channel 1 story 3 description", "channel 1 story 3 link");
            channel.Stories.Add(story);

            channels.Add(channel);

            channel = new RSSChannel("channel 2 title", "channel 2 description", "channel 2 link");

            story = new RSSStory("channel 2 story 1 title", "channel 2 story 1 description", "channel 2 story 1 link");
            channel.Stories.Add(story);

            story = new RSSStory("channel 2 story 2 title", "channel 2 story 2 description", "channel 2 story 2 link");
            channel.Stories.Add(story);

            channels.Add(channel);
        }
        public RSSChannel GetRSSChannelInfo(RSSChannel channel)
        {
            try
            {
                try
                {
                    HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(channel.Link);
                    webRequest.Timeout           = 500;
                    webRequest.AllowAutoRedirect = false;
                    HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse();

                    var rssChannel  = XElement.Load(channel.Link);
                    var channelNode = rssChannel.Descendants("channel").First();

                    channel.Title       = channelNode.Element("title")?.Value;
                    channel.Description = channelNode.Element("description")?.Value;
                    channel.Link        = channelNode.Element("link")?.Value;
                }
                catch (System.Net.WebException e)
                {
                    Console.WriteLine(e.Message);
                }
            }
            catch (Exception e)
            {
                channel.Title       = "RSS Down";
                channel.Description = e.Message;
            }

            return(channel);
        }
Exemple #3
0
        /// <summary>
        ///		Obtiene el builder XML de un objeto RSS
        /// </summary>
        private MLFile GetFile(RSSChannel rss)
        {
            MLFile file = new MLFile();
            MLNode node = file.Nodes.Add(RSSConstTags.cnstStrRoot);

            // Añade los atributos de la cabecera
            node.NameSpaces.AddRange(rss.Extensions.GetNameSpaces(rss));
            node.Attributes.Add("version", "2.0");
            // Añade los datos del canal
            node = node.Nodes.Add(RSSConstTags.cnstStrChannel);
            // Obtiene el XML de los datos
            node.Nodes.Add(RSSConstTags.cnstStrChannelTitle, rss.Title);
            node.Nodes.Add(RSSConstTags.cnstStrChannelLink, rss.Link);
            node.Nodes.Add(RSSConstTags.cnstStrChannelLanguage, rss.Language);
            node.Nodes.Add(RSSConstTags.cnstStrChannelCopyright, rss.Copyright);
            node.Nodes.Add(RSSConstTags.cnstStrChannelDescription, rss.Description);
            node.Nodes.Add(RSSConstTags.cnstStrChannelLastBuildDate,
                           DateTimeHelper.ToStringRfc822(rss.LastBuildDate));
            // Obtiene el XML de la imagen
            AddImage(node, rss.Logo);
            // Obtiene el XML de las extensiones
            rss.Extensions.AddNodesExtension(node);
            // Obtiene el XML de los elementos
            AddItems(node, rss.Entries);
            // Devuelve los datos
            return(file);
        }
Exemple #4
0
        public static RSSChannel GetChannelFromString(string xml)
        {
            var xdoc = new XmlDocument();

            xdoc.LoadXml(xml);

            var channel     = xdoc.SelectSingleNode("rss/channel");
            var returnValue = new RSSChannel
            {
                Title       = channel.SelectSingleNode("title").GetString(),
                Link        = channel.SelectSingleNode("link").GetString(),
                Description = channel.SelectSingleNode("description").GetString(),
                Pubdate     = channel.SelectSingleNode("pubDate").GetDateTime(),
                Items       = new List <RSSItem>()
            };

            var items = xdoc.SelectNodes("rss/channel/item");

            foreach (XmlNode item in items)
            {
                returnValue.Items.Add(new RSSItem
                {
                    Title       = item.SelectSingleNode("title").GetString(),
                    ItemLink    = item.SelectSingleNode("link").GetString(),
                    Description = item.SelectSingleNode("description").GetString(),
                    Pubdate     = item.SelectSingleNode("pubDate").GetDateTime()
                });
            }
            return(returnValue);
        }
Exemple #5
0
        //public static async Task<IList<ArticleModel>> GetArticles(Uri rssLink, CancellationToken? cancellationToken = null)
        //{
        //    var feed = await new SyndicationClient().RetrieveFeedAsync(rssLink);
        //    if (cancellationToken.HasValue && cancellationToken.Value.IsCancellationRequested) return null;
        //    var articles = feed.Items.Select(item => new ArticleModel
        //    {
        //        Title = item.Title.Text,
        //        Summary = item.Summary == null
        //            ? string.Empty
        //            : item.Summary.Text.RegexRemove("\\&.{0,4}\\;").RegexRemove("<.*?>"),
        //        Author = item.Authors.Select(a => a.NodeValue).FirstOrDefault(),
        //        Link = item.ItemUri ?? item.Links.Select(l => l.Uri).FirstOrDefault(),
        //        PublishedDate = item.PublishedDate
        //    })
        //    .ToList();
        //    return articles;
        //}

        /// <summary>
        /// Retrieves feed data from the server and updates the appropriate FeedViewModel properties.
        /// </summary>
        public static async Task <RSSChannel> GetFeedAsync(Uri rssLink, CancellationToken?cancellationToken = null)
        {
            try
            {
                using (HttpClient hc = new HttpClient())
                {
                    string result = await hc.GetStringAsync(rssLink);

                    RSSChannel feed = GetChannelFromString(result);

                    if (cancellationToken.HasValue && cancellationToken.Value.IsCancellationRequested)
                    {
                        return(null);
                    }
                    return(feed);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                if (!cancellationToken.HasValue || !cancellationToken.Value.IsCancellationRequested)
                {
                    //feedViewModel.IsInError = true;
                    //feedViewModel.ErrorMessage = feedViewModel.Articles.Count == 0 ? BAD_URL_MESSAGE : NO_REFRESH_MESSAGE;
                }
                return(null);
            }
        }
Exemple #6
0
        /// <summary>
        ///		Interpreta los datos de un archivo XML
        /// </summary>
        public RSSChannel Parse(MLFile fileML)
        {
            RSSChannel rss = null;

            // Recorre los nodos del documento
            if (fileML != null)
            {
                foreach (MLNode node in fileML.Nodes)
                {
                    if (node.Name.Equals(RSSConstTags.cnstStrRoot))
                    {
                        // Crea el objeto
                        rss = new RSSChannel();
                        // Lee los espacios de nombres de las extensiones
                        rss.Dictionary.LoadNameSpaces(node);
                        // Lee los datos
                        foreach (MLNode channel in node.Nodes)
                        {
                            if (channel.Name.Equals(RSSConstTags.cnstStrChannel))
                            {
                                ParseChannel(channel, rss);
                            }
                        }
                    }
                }
            }
            // Devuelve el objeto RSS
            return(rss);
        }
Exemple #7
0
        /// <summary>
        ///		Interpreta los datos del canal
        /// </summary>
        private void ParseChannel(MLNode channel, RSSChannel rss)
        {
            foreach (MLNode node in channel.Nodes)
            {
                switch (node.Name)
                {
                case RSSConstTags.cnstStrChannelTitle:
                    rss.Title = node.Value;
                    break;

                case RSSConstTags.cnstStrChannelDescription:
                    rss.Description = node.Value;
                    break;

                case RSSConstTags.cnstStrChannelLink:
                    rss.Link = node.Value;
                    break;

                case RSSConstTags.cnstStrChannelLanguage:
                    rss.Language = node.Value;
                    break;

                case RSSConstTags.cnstStrChannelCopyright:
                    rss.Copyright = node.Value;
                    break;

                case RSSConstTags.cnstStrChannelPubDate:
                    rss.PubDate = node.Value.GetDateTime(DateTime.Now);
                    break;

                case RSSConstTags.cnstStrChannelLastBuildDate:
                    rss.LastBuildDate = node.Value.GetDateTime(DateTime.Now);
                    break;

                case RSSConstTags.cnstStrChannelManagingEditor:
                    rss.Editor = node.Value;
                    break;

                case RSSConstTags.cnstStrChannelManagingWebMaster:
                    rss.WebMaster = node.Value;
                    break;

                case RSSConstTags.cnstStrChannelGenerator:
                    rss.Generator = node.Value;
                    break;

                case RSSConstTags.cnstStrChannelImage:
                    rss.Logo = ParseImage(node);
                    break;

                case RSSConstTags.cnstStrItem:
                    rss.Entries.Add(ParseEntry(node, rss));
                    break;

                default:
                    rss.Extensions.Parse(node, rss, rss.Dictionary);
                    break;
                }
            }
        }
Exemple #8
0
        /// <summary>
        ///		Interpreta los nodos de un elemento
        /// </summary>
        private RSSEntry ParseEntry(MLNode objMLEntry, RSSChannel channel)
        {
            RSSEntry entry = new RSSEntry();

            // Interpreta los nodos
            foreach (MLNode node in objMLEntry.Nodes)
            {
                switch (node.Name)
                {
                case RSSConstTags.cnstStrItemTitle:
                    entry.Title = node.Value;
                    break;

                case RSSConstTags.cnstStrItemLink:
                    entry.Link = node.Value;
                    break;

                case RSSConstTags.cnstStrItemDescription:
                    entry.Content = node.Value;
                    break;

                case RSSConstTags.cnstStrItemCategory:
                    entry.Categories.Add(ParseCategory(node));
                    break;

                case RSSConstTags.cnstStrItemPubDate:
                    entry.DateCreated = node.Value.GetDateTime(DateTime.Now);
                    break;

                case RSSConstTags.cnstStrItemGuid:
                    entry.GUID = ParseGuid(node);
                    break;

                case RSSConstTags.cnstStrItemEnclosure:
                    entry.Enclosures.Add(ParseEnclosure(node));
                    break;

                case RSSConstTags.cnstStrItemAuthor:
                    entry.Authors.Add(ParseAuthor(node));
                    break;

                default:
                    entry.Extensions.Parse(node, entry, channel.Dictionary);
                    break;
                }
            }
            // Devuelve la entrada
            return(entry);
        }
        /// <summary>
        ///		Obtiene los datos de un feed
        /// </summary>
        private RSSChannel GetFeedData()
        {
            RSSChannel channel    = new RSSChannel();
            int        itemsWrite = 0;

            // Ordena por fecha
            Data.Files.SortByDate(false);
            // Añade las propiedades del canal
            channel.Link          = CombineUrl(Processor.Project.URLBase, Processor.Project.PageMain);
            channel.Logo          = new RSSImage(Processor.Project.URLBase, "Imagen", channel.Link);
            channel.Author        = new RSSAuthor(Processor.Project.WebMaster);
            channel.Copyright     = Processor.Project.Copyright;
            channel.Title         = Processor.Project.Name;
            channel.Description   = Processor.Project.Description;
            channel.Editor        = Processor.Project.Editor;
            channel.LastBuildDate = DateTime.Now;
            // Añade las entradas del canal
            foreach (Pages.FileTargetModel file in Data.Files)
            {
                if (file.File.FileType == Model.Solutions.FileModel.DocumentType.Document &&
                    file.ShowAtRss && file.ShowMode == Model.Documents.DocumentModel.ShowChildsMode.None &&
                    itemsWrite < ItemsRSS)
                {
                    RSSEntry rssEntry = new RSSEntry();
                    Model.Documents.DocumentModel document;

                    // Carga el documento compilado en corto
                    document = new Application.Bussiness.Documents.DocumentBussiness().Load(Processor.Project,
                                                                                            file.GetFullFileNameCompiledShort(Processor));
                    // Asigna los valores a la entrada
                    rssEntry.Authors.Add(new RSSAuthor(Processor.Project.WebMaster));
                    // entry.Categories.Add();
                    rssEntry.Content     = document.Content;
                    rssEntry.Link        = CombineUrl(Processor.Project.URLBase, file.RelativeFullFileNameTarget);
                    rssEntry.Title       = file.Title;
                    rssEntry.DateCreated = file.DateUpdate;
                    // Añade la entrada al canal
                    channel.Entries.Add(rssEntry);
                    // Incrementa el número de entradas escritas
                    itemsWrite++;
                }
            }
            // Devuelve los datos del canal
            return(channel);
        }
Exemple #10
0
        /// <summary>
        ///		Convierte las entradas RSS
        /// </summary>
        private void ConvertEntriesRSS(RSSChannel rss)
        {
            foreach (RSSEntry entry in rss.Entries)
            {
                foreach (Syndication.FeedExtensions.ExtensionBase extension in entry.Extensions)
                {
                    if (extension is Syndication.FeedExtensions.RSSContent.Data.RSSContentData)
                    {
                        Syndication.FeedExtensions.RSSContent.Data.RSSContentData content = extension as Syndication.FeedExtensions.RSSContent.Data.RSSContentData;

                        if (content != null)
                        {
                            entry.Content = content.ContentEncoded;
                        }
                    }
                }
            }
        }
Exemple #11
0
        /// <summary>
        /// Retrieves feed data from the server and updates the appropriate FeedViewModel properties.
        /// </summary>
        public static async Task <RSSChannel> GetFeedAsync(Uri rssLink)
        {
            try
            {
                using (HttpClient hc = new HttpClient())
                {
                    string result = await hc.GetStringAsync(rssLink);

                    RSSChannel feed = GetChannelFromString(result);
                    return(feed);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                return(null);
            }
        }
Exemple #12
0
        /// <summary>
        ///		Convierte un archivo RSS en un archivo Atom
        /// </summary>
        public RSSChannel Convert(AtomChannel channel)
        {
            RSSChannel rss = new RSSChannel();

            // Convierte los datos del canal
            rss.Title       = channel.Title.Content;
            rss.Generator   = channel.Generator.Name;
            rss.Description = channel.Info.Content;
            if (channel.Links.Count > 0)
            {
                rss.Link = channel.Links[0].Href;
            }
            rss.LastBuildDate = channel.LastUpdated;
            // Añade las extensiones
            ConvertExtension(channel.Extensions, rss.Extensions);
            // Añade las entradas
            ConvertEntries(channel, rss);
            // Devuelve el objeto Atom
            return(rss);
        }
Exemple #13
0
        /// <summary>
        ///		Convierte las entradas Atom en entradas RSS
        /// </summary>
        private void ConvertEntries(AtomChannel channel, RSSChannel rss)
        {
            foreach (AtomEntry channelEntry in channel.Entries)
            {
                RSSEntry rssEntry = new RSSEntry();

                // Convierte los datos de la entrada
                rssEntry.GUID.ID     = channelEntry.ID;
                rssEntry.Title       = channelEntry.Title.Content;
                rssEntry.Content     = channelEntry.Content.Content;
                rssEntry.DateCreated = channelEntry.DatePublished;
                // Vínculos
                if (channelEntry.Links.Count > 0)
                {
                    rssEntry.Link = channelEntry.Links[0].Href;
                }
                foreach (AtomLink channelLink in channelEntry.Links)
                {
                    if (channelLink.LinkType.Equals("enclosure"))
                    {
                        rssEntry.Enclosures.Add(ConvertLink(channelLink));
                    }
                }
                // Autores
                foreach (AtomPeople channelAuthor in channelEntry.Authors)
                {
                    rssEntry.Authors.Add(new RSSAuthor(channelAuthor.Name));
                }
                // Categorías
                foreach (AtomCategory channelCategory in channelEntry.Categories)
                {
                    rssEntry.Categories.Add(new RSSCategory(channelCategory.Name));
                }
                // Convierte las extensiones
                ConvertExtension(channelEntry.Extensions, rssEntry.Extensions);
                // Añade la entrada al objeto Atom
                rss.Entries.Add(rssEntry);
            }
        }
Exemple #14
0
        /// <summary>
        ///		Convierte un archivo RSS en un archivo Atom
        /// </summary>
        public AtomChannel Convert(RSSChannel rss)
        {
            AtomChannel channel = new AtomChannel();

            // Convierte los datos del canal
            channel.ID                = new Guid().ToString();
            channel.Title             = ConvertText(rss.Title);
            channel.Generator         = ConvertGenerator(rss.Generator);
            channel.ConvertLineBreaks = true;
            channel.Info              = ConvertText(rss.Description);
            channel.Subtitle          = ConvertText("");
            channel.Links.Add(ConvertLink(rss.Link, AtomLink.AtomLinkType.Self));
            channel.LastUpdated = rss.LastBuildDate;
            channel.Icon        = rss.Logo.Url;
            channel.Logo        = rss.Logo.Url;
            // Añade las extensiones
            ConvertExtension(rss.Extensions, channel.Extensions);
            // Añade las entradas
            ConvertEntries(rss, channel);
            // Devuelve el objeto Atom
            return(channel);
        }
        private void _Download_RSS(object sender, RoutedEventArgs e)
        {
            SP_episodes.Children.Clear(); // clear stackpannel
            SP_episodesCtrls.Children.Clear();

            if (!LinkExists(TBOX_LinkBar.Text, curDir + @"\RSSLinks.txt"))
            {
                using (TextWriter tw = new StreamWriter(curDir + @"\RSSLinks.txt", true)) {
                    tw.WriteLine(TBOX_LinkBar.Text);
                    tw.Close();
                }
            }

            rssChannel = new RSSChannel(TBOX_LinkBar.Text);
            InitializeDLDirectories(rssChannel.Title);

            TBLK_Content.Text  = rssChannel.Title + "\n";
            TBLK_Content.Text += rssChannel.Link + "\n";
            TBLK_Content.Text += rssChannel.Description + "\n";
            TBLK_Content.Text += rssChannel.Language + "\n";
            TBLK_Content.Text += rssChannel.Copyright + "\n";
            TBLK_Content.Text += rssChannel.ManagingEditor + "\n";
            TBLK_Content.Text += rssChannel.WebMaster + "\n";
            TBLK_Content.Text += rssChannel.PubDate + "\n";
            TBLK_Content.Text += rssChannel.LastBuildDate + "\n";
            TBLK_Content.Text += rssChannel.Catagory + "\n";
            TBLK_Content.Text += rssChannel.Generator + "\n";
            TBLK_Content.Text += rssChannel.Docs + "\n";
            TBLK_Content.Text += rssChannel.Rating + "\n";

            List <RSSItem> rssItems = rssChannel.GetItemRange(0, 30);

            for (int i = 0; i < rssItems.Count; i++)
            {
                Episode episode = new Episode(this, rssItems[i], i);
                episodes.Add(episode);
            }
        }
Exemple #16
0
        /// <summary>
        ///		Convierte las entradas RSS en entradas Atom
        /// </summary>
        private void ConvertEntries(RSSChannel rss, AtomChannel channel)
        {
            foreach (RSSEntry rssEntry in rss.Entries)
            {
                AtomEntry channelEntry = new AtomEntry();

                // Convierte los datos de la entrada
                channelEntry.ID            = rssEntry.ID;
                channelEntry.Title         = ConvertText(rssEntry.Title);
                channelEntry.Content       = ConvertText(rssEntry.Content);
                channelEntry.DateIssued    = rssEntry.DateCreated;
                channelEntry.DateCreated   = rssEntry.DateCreated;
                channelEntry.DateModified  = rssEntry.DateCreated;
                channelEntry.DateUpdated   = rssEntry.DateCreated;
                channelEntry.DatePublished = rssEntry.DateCreated;
                // Vínculos
                channelEntry.Links.Add(ConvertLink(rssEntry.Link, AtomLink.AtomLinkType.Self));
                foreach (RSSEnclosure rssEnclosure in rssEntry.Enclosures)
                {
                    channelEntry.Links.Add(ConvertLink(rssEnclosure));
                }
                // Autores
                foreach (RSSAuthor rssAuthor in rssEntry.Authors)
                {
                    channelEntry.Authors.Add(ConvertAuthor(rssAuthor));
                }
                // Categorías
                foreach (RSSCategory rssCategory in rssEntry.Categories)
                {
                    channelEntry.Categories.Add(ConvertCategory(rssCategory));
                }
                // Convierte las extensiones
                ConvertExtension(rssEntry.Extensions, channelEntry.Extensions);
                // Añade la entrada al objeto Atom
                channel.Entries.Add(channelEntry);
            }
        }
        public ICollection <RSSItem> GetRSSItemsFromRSSChannel(RSSChannel channel)
        {
            try
            {
                var rssChannel = XElement.Load(channel.Link);

                var q = rssChannel.Descendants("item").Select(x =>
                                                              new RSSItem
                {
                    Link        = x.Element("link")?.Value,
                    Description = x.Element("description")?.Value,
                    Title       = x.Element("title")?.Value,
                    Author      = x.Element("author")?.Value,
                    PublishDate = DateTime.Parse(x.Element("pubDate")?.Value),
                    Image       = x.Element("image")?.Value,
                });
                return(q.ToList());
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(new List <RSSItem>());
            }
        }
 public RSSFeed()
 {
     channel = new RSSChannel();
 }
Exemple #19
0
 /// <summary>
 ///		Obtiene el XML de un canal RSS
 /// </summary>
 public string GetXML(RSSChannel rss)
 {
     return(new XMLWriter().ConvertToString(GetFile(rss)));
 }
Exemple #20
0
        public IRSSChannel RSSContextMenu(IRSSChannel channel)
        {
            GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);

            if (dlg == null)
            {
                return(null);
            }

            dlg.Reset();
            dlg.SetHeading("RSS Feeds");
            dlg.Add("Search");
            dlg.Add("Update selected");
            dlg.Add("Update all");
            dlg.DoModal(GUIWindowManager.ActiveWindow);

            switch (dlg.SelectedLabelText)
            {
            case "Update selected":
            {
                if (channel == null)
                {
                    return(null);
                }
                if (channel != null)
                {
                    channel.Update();
                }
                return(null);
            }

            case "Update all":
            {
                RSSChannelManager.Instance().UpdateChannels(true);
                return(null);
            }

            case "Search":
            {
                VirtualKeyboard keyboard = (VirtualKeyboard)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_VIRTUAL_KEYBOARD);
                keyboard.Reset();
                keyboard.Text = "";
                keyboard.DoModal(GUIWindowManager.ActiveWindow);

                if (!keyboard.IsConfirmed)
                {
                    return(null);
                }

                Regex re = new Regex(keyboard.Text, RegexOptions.IgnoreCase);

                RSSChannel search = new RSSChannel("MediaPortal");
                if (channel != null && channel.Url != "MediaPortal")
                {
                    foreach (RSSItem item in channel.Items)
                    {
                        if (re.IsMatch(item.Title))
                        {
                            search.Items.Add(item);
                        }
                    }
                }
                //this.ShowSelectedRSS() = search;
                //UpdateListItems();
                return(search);
            }
            }
            return(null);
        }
Exemple #21
0
        public bool LoadRssChannels(ConfigData _config)
        {
            XmlDocument       xmlDoc         = _config.MyTorrentsConfiguration;
            RSSChannelManager channelManager = RSSChannelManager.Instance();
            XmlNodeList       nodes          = xmlDoc.SelectSingleNode("config/feed").ChildNodes;

            foreach (XmlNode node in nodes)
            {
                IRSSChannel rssChannel = null;
                string      type       = "";
                if (node.Name == "rss")
                {
                    type = "rss";
                }
                if (node.Name == "atom")
                {
                    type = "atom";
                }
                XmlNodeList nUrls = node.SelectNodes("url");
                if (nUrls.Count >= 2)
                {
                    //combined!
                    XmlNode nTitle = node.SelectSingleNode("title");
                    XmlNode nDesc  = node.SelectSingleNode("description");

                    if (nTitle == null || nDesc == null)
                    {
                        continue;
                    }
                    RSSCombined combined = new RSSCombined(nTitle.InnerText, nDesc.InnerText);

                    foreach (XmlNode nUrl in node.SelectNodes("url"))
                    {
                        RSSChannel channel = new RSSChannel(nUrl.InnerText);

                        combined.Channels.Add(channel);
                    }
                    rssChannel = combined;
                }
                else
                {
                    if (node.SelectSingleNode("transform") != null)
                    {
                        XmlNode nurl         = node.SelectSingleNode("url");
                        XmlNode trans        = node.SelectSingleNode("transform/origin");
                        XmlNode basedownload = node.SelectSingleNode("transform/basedownload");
                        rssChannel = new RSSChannel(nurl.InnerText, new Regex(trans.InnerText, RegexOptions.IgnoreCase), basedownload.InnerText);
                    }
                    else
                    {
                        XmlNode nUrl = node.SelectSingleNode("url");
                        rssChannel = new RSSChannel(nUrl.InnerText);
                    }
                }
                XmlNode expireTime = node.SelectSingleNode("expires");

                if (expireTime == null)
                {
                    //5minutes
                    rssChannel.ExpireTime = new TimeSpan(0, 5, 0);
                }
                else
                {
                    rssChannel.ExpireTime = new TimeSpan(0, 0, Convert.ToInt32(expireTime.InnerText));
                }
                rssChannel.Type = type;
                channelManager.Channels.Add(rssChannel);
            }

            Log.Instance().Print("Started RssChanel");


            return(true);
        }
Exemple #22
0
        /// <summary>
        /// Get Rss Channel(Feed) Data
        /// </summary>
        /// <param name="channelUrl"></param>
        /// <returns></returns>
        public async Task <RSSChannel> GetRSSChannel(string channelUrl)
        {
            RSSChannel returnValue = null;

            IsBusy = true;
            using (HttpClient hc = new HttpClient())
            {
                try
                {
                    var result = await hc.GetAsync(channelUrl);

                    if (result != null && result.IsSuccessStatusCode == true)
                    {
                        var data = await result.Content.ReadAsStringAsync();

                        if (data != null)
                        {
                            //xml을 xElement라는 객체로 바로 파싱해서 사용한다.
                            XElement xmlRSS = XElement.Parse(data);

                            var q1 = from rss in xmlRSS.Descendants("channel")
                                     let hasImage = string.IsNullOrEmpty(StaticFunctions.GetString(rss.Element("image"))) == true ? false : true
                                                    select new RSSChannel()
                            {
                                title       = StaticFunctions.GetString(rss.Element("title")),
                                link        = StaticFunctions.GetString(rss.Element("link")),
                                description = StaticFunctions.GetString(rss.Element("description")),
                                pubdate     = StaticFunctions.GetDateTime(rss.Element("pubDate")),
                                language    = StaticFunctions.GetString(rss.Element("language")),
                                copyright   = StaticFunctions.GetString(rss.Element("copyright")),
                                webmaster   = StaticFunctions.GetString(rss.Element("webMaster")),
                                generator   = StaticFunctions.GetString(rss.Element("generator")),
                                docs        = StaticFunctions.GetString(rss.Element("docs")),
                                ttl         = StaticFunctions.GetInt(rss.Element("ttl")),
                                image       = hasImage ? new RSSImage()
                                {
                                    url   = StaticFunctions.GetString(rss.Element("image").Element("url")),
                                    title = StaticFunctions.GetString(rss.Element("image").Element("title")),
                                    link  = StaticFunctions.GetString(rss.Element("image").Element("link")),
                                } : null,
                                items = new System.Collections.ObjectModel.ObservableCollection <RSSItem>()
                            };

                            var q2 = from item in xmlRSS.Descendants("item")
                                     let hasImage = string.IsNullOrEmpty(StaticFunctions.GetString(item.Element("image"))) == true ? false : true
                                                    select new RSSItem()
                            {
                                title       = StaticFunctions.GetString(item.Element("title")),
                                link        = StaticFunctions.GetString(item.Element("link")),
                                description = StaticFunctions.GetString(item.Element("description")),
                                category    = StaticFunctions.GetString(item.Element("category")),
                                pubdate     = StaticFunctions.GetDateTime(item.Element("pubDate")),
                                Image_link  = hasImage ? StaticFunctions.GetString(item.Element("image").Element("link")) : StaticFunctions.GetString(item.Element("link")),
                                Image_title = hasImage ? StaticFunctions.GetString(item.Element("image").Element("title")) : StaticFunctions.GetString(item.Element("title")),
                                Image_url   = hasImage ? StaticFunctions.GetString(item.Element("image").Element("url")) : null,
                            };

                            if (q1.Count() > 0)
                            {
                                returnValue = q1.First();
                                foreach (var item in q2)
                                {
                                    returnValue.items.Add(item);
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.Message);
                }
            }
            IsBusy = false;
            return(returnValue);
        }
Exemple #23
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="channel"></param>
 /// <param name="outputStream"></param>
 public RSSRoot(RSSChannel channel, System.IO.Stream outputStream)
 {
     _channel = channel;
     _outputStream = outputStream;
 }
Exemple #24
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="channel"></param>
 /// <param name="image"></param>
 /// <param name="outputStream"></param>
 public RSSRoot(RSSChannel channel, RSSImage image, System.IO.Stream outputStream)
 {
     _image = image;
     _channel = channel;
     _outputStream = outputStream;
 }
 public RSSFeed()
 {
     channel = new RSSChannel();
 }
Exemple #26
0
 /// <summary>
 ///		Graba los datos de un objeto RSS en un archivo XML
 /// </summary>
 public void Save(RSSChannel rss, string fileName)
 {
     new XMLWriter().Save(fileName, GetFile(rss));
 }