예제 #1
0
        public MainViewModel(INavigationService navigationService, IRssService rssService)
        {
            this.navigationService = navigationService;
            this.rssService = rssService;

            this.FeedCategories = new ObservableCollection<RssFeed>
                {
                    new RssFeed { Title = "Developer", RssUrl = @"http://blogs.esri.com/esri/arcgis/category/developer/feed" },
                    new RssFeed { Title = "ArcGIS Online", RssUrl = @"http://blogs.esri.com/esri/arcgis/category/arcgis-online/feed" },
                    new RssFeed { Title = "Editing", RssUrl = @"http://blogs.esri.com/esri/arcgis/category/editing/feed" },
                    new RssFeed { Title = "Mobile", RssUrl = @"http://blogs.esri.com/esri/arcgis/category/mobile/feed" },
                    new RssFeed { Title = "Mapping", RssUrl = @"http://blogs.esri.com/esri/arcgis/category/mapping/feed" },
                    new RssFeed { Title = "Analysis & Geoprocessing", RssUrl = @"http://blogs.esri.com/esri/arcgis/category/subject-analysis-and-geoprocessing/feed" },
                    new RssFeed { Title = "Services", RssUrl = @"http://blogs.esri.com/esri/arcgis/category/services/feed" },
                    new RssFeed { Title = "Web", RssUrl = @"http://blogs.esri.com/esri/arcgis/category/web/feed" },
                    new RssFeed { Title = "Geodata", RssUrl = @"http://blogs.esri.com/esri/arcgis/category/geodata/feed" },
                    new RssFeed { Title = "3D GIS", RssUrl = @"http://blogs.esri.com/esri/arcgis/category/subject-3d-gis/feed" },
                    new RssFeed { Title = "Imagery", RssUrl = @"http://blogs.esri.com/esri/arcgis/category/subject-imagery/feed" },
                    new RssFeed { Title = "Python", RssUrl = @"http://blogs.esri.com/esri/arcgis/category/subject-python/feed" }
                };

            this.LoadingText = string.Format("Loading feed...");

            this.rssFeed = new RssFeed { RssUrl = FeedUrl, Title = "ArcGIS Blogs" };

            if (!this.IsOffline)
            {
                this.LoadFeed();
            }
        }
예제 #2
0
        public void LoadRssFeed(XDocument doc, RssFeed feed)
        {
            SetMediaImage(feed, doc);
            feed.Description = doc.Root.Element("channel").GetSafeElementString("description");
            feed.Items = new ObservableCollection<RssItem>();
            feed.Link = doc.Root.Element("channel").GetSafeElementString("link");

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

                var content = item.Descendants(NS_RSSCONTENT + "encoded");
                foreach (var xElement in content)
                {
                    newItem.Content = xElement.Value;
                }

                feed.Items.Add(newItem);
            }

            var lastItem = feed.Items.OrderByDescending(i => i.PublishDate).FirstOrDefault();
            if (lastItem != null)
            {
                feed.LastBuildDate = lastItem.PublishDate;
            }
        }
        protected override void OnActivate()
        {
            if (ParameterSink.Parameter != null && ParameterSink.Parameter is RssFeed)
            {
                this.RssFeed = ParameterSink.Parameter as RssFeed;

                if (!this.IsOffline)
                {
                    this.LoadFeed();
                }
            }

            base.OnActivate();
        }
예제 #4
0
        public RssFeed GetFeedDataFromReader(XmlReader reader)
        {
            var doc = XDocument.Load(reader);

            var feed = new RssFeed();

            var defaultNamespace = doc.Root.GetDefaultNamespace();
            if (defaultNamespace.NamespaceName.EndsWith("Atom"))
            {
                LoadAtomFeed(doc, feed);
            }
            else
            {
                LoadRssFeed(doc, feed);
            }

            return feed;
        }
예제 #5
0
        public void LoadAtomFeed(XDocument doc, RssFeed feed)
        {
            SetMediaImage(feed, doc);
            feed.Description = doc.Root.GetSafeElementString("summary");
            feed.Items = new ObservableCollection<RssItem>();
            feed.LastBuildDate = doc.Root.GetSafeElementDate("updated");
            feed.Link = doc.Root.GetLink("self");

            foreach (var item in doc.Root.Elements(doc.Root.GetDefaultNamespace() + "entry"))
            {
                var newItem = new RssItem()
                                  {
                                      Title = item.GetSafeElementString("title"),
                                      Description = item.GetSafeElementString("description"),
                                      PublishDate = item.GetSafeElementDate("published"),
                                      Guid = item.GetSafeElementString("id"),
                                      Link = item.GetLink("alternate")
                                  };
                feed.Items.Add(newItem);
            }
        }
예제 #6
0
        public void NavigateToCategoryFeed(RssFeed selectedItem)
        {
            if (selectedItem == null)
            {
                return;
            }

            ParameterSink.Parameter = selectedItem;

            this.navigationService.UriFor<RssCategoryFeedViewModel>().Navigate();
        }
예제 #7
0
        private void SetMediaImage(RssFeed feed, XDocument doc)
        {
            var image = doc.Root.Descendants(NS_ITUNES + "image").FirstOrDefault();
            if (image != null)
            {
                feed.ImageUri = new Uri(image.Attribute("href").Value);
                return;
            }

            var thumbnail = doc.Element(NS_MEDIA + "thumbnail");
            if (thumbnail != null)
            {
                feed.ImageUri = new Uri(thumbnail.Value);
                return;
            }

            // if all else fails...
            feed.ImageUri = new Uri("/Resources/Images/RssFeed.png", UriKind.Relative);
        }