Ejemplo n.º 1
0
        private async Task<RssDataGroup> GetFeedAsync(string feedUriString)
        {
            try
            {
                XmlDocument doc = await XmlDocument.LoadFromUriAsync(new Uri(feedUriString));

                // This code is executed after RetrieveFeedAsync returns the SyndicationFeed.
                // Process it and copy the data we want into our FeedData and FeedItem classes.
                RssDataGroup feedData = new RssDataGroup();
                
                IXmlNode node = null;
                node = doc.SelectSingleNode("rss/channel/title");

                if (node != null)
                    feedData.Title = Regex.Replace(node.InnerText, "[a-zA-Z0-9\\.]*", "").Trim();

                if (string.IsNullOrEmpty(feedData.Title))
                    feedData.Title = "أخبار";

                int count = 0;

                foreach (var item in doc.SelectSingleNode("rss/channel").ChildNodes.Where(n => n.NodeName == "item"))
                {
                    RssDataItem feedItem = new RssDataItem();
                    feedItem.Title = item.SelectSingleNode("title").InnerText;
                    feedItem.Group = feedData;

                    string itemXML = item.GetXml();

                    feedItem.Content = Regex.Replace(item.SelectSingleNode("description").InnerText, @"<(.|\n)*?>", string.Empty).Replace("&#160;", "");
                    
                    if (feedItem.Content.Length > 100)
                        feedItem.Description = feedItem.Content.Substring(0, 100) + "...";
                    else
                        feedItem.Description = feedItem.Content;

                    feedItem.Url = item.SelectSingleNode("link").InnerText;

                    //Try to find the image in non standard RSS feeds
                    Match m = Regex.Match(itemXML, "<image>(.*.jpg)</image>");
                    if (m.Success)
                    {
                        string image = m.Groups[1].Value;
                        image = image.Replace("_s2.jpg", "_s4.jpg").Replace("media_thumbnail", "highslide_zoom").Replace("/small/","/large/").Replace("sites/","http://www.almasryalyoum.com/sites/");
                        feedItem.SetImage(image);
                    }
                    else
                    {
                        Match m2 = Regex.Match(itemXML, "(src|url)=(\"|\')(.*.jpg)");
                        if (m2.Success)
                        {
                            string image = m2.Groups[3].Value;
                            image = image.Replace("_s2.jpg", "_s4.jpg").Replace("media_thumbnail", "highslide_zoom").Replace("/small/", "/large/").Replace("sites/", "http://www.almasryalyoum.com/sites/");
                            feedItem.SetImage(image);
                        }
                    }

                    feedData.Items.Add(feedItem);
                    if (count < MaxItemsInGroup)
                    {
                        feedData.ItemsSummary.Add(feedItem);
                    }
                    count++;
                }

                return feedData;
            }
            catch (Exception)
            {
                if (LoadingError != null)
                {
                    LoadingError(this, null);
                }
                return null;
            }
        }
Ejemplo n.º 2
0
        private async Task<List<RssDataGroup>> GetMatchesFeedAsync(string feedUriString)
        {
            try
            {
                XmlDocument doc = await XmlDocument.LoadFromUriAsync(new Uri(feedUriString));

                List<RssDataGroup> list=new List<RssDataGroup>();
                

                foreach (var node in doc.ChildNodes[1].ChildNodes[0].ChildNodes.Where(n=>n.NodeName=="Tour"))
                {
                    RssDataGroup feedData = new RssDataGroup();
                    feedData.Title = node.SelectSingleNode("TourName").InnerText;

                    foreach (var match in node.ChildNodes.Where(n => n.NodeName == "match"))
	                {
		                RssDataItem feedItem = new RssDataItem();
                        feedItem.UniqueId = match.SelectSingleNode("Matchid").InnerText;
                        feedItem.Title = match.SelectSingleNode("team1").InnerText + " - " + match.SelectSingleNode("team2").InnerText;
                        if (match.SelectSingleNode("Team1Score").InnerText == "-" && match.SelectSingleNode("Team2Score").InnerText == "-")
                            feedItem.Description = DateTime.Parse(match.SelectSingleNode("timestamp").InnerText).ToString("hh:mm tt");
                        else
                            feedItem.Description = match.SelectSingleNode("Team1Score").InnerText + " - " + match.SelectSingleNode("Team2Score").InnerText;
                        feedItem.Group = feedData;

                        feedData.Items.Add(feedItem);
                        feedData.ItemsSummary.Add(feedItem);
                    }

                    list.Add(feedData);
                }

                return list;
            }
            catch (Exception ex)
            {
                if (LoadingError != null)
                {
                    LoadingError(this, null);
                }
                return null;
            }
        }