Beispiel #1
0
        public void ProcessNews(object sender, DownloadStringCompletedEventArgs e)
        {
            MemoryStream ms = null;

            if ((e == null && !_fromCache) || (e != null && (e.Error != null || e.Cancelled)))
            {
                _news = true;
                return;
            }
            if (e == null && _fromCache)
            {
                ms = new MemoryStream(Encoding.UTF8.GetBytes(LoadFromStorage("news", ".json")));
            }
            else if (e != null)
            {
                ms = new MemoryStream(Encoding.UTF8.GetBytes(SaveToStorage("news", ".json", e.Result)));
            }
            var serializer = new DataContractJsonSerializer(typeof(ObservableCollection <NewsItemViewModel>));

            if (ms != null)
            {
                var list = (ObservableCollection <NewsItemViewModel>)serializer.ReadObject(ms);
                if (list == null)
                {
                    return;
                }
                foreach (var newsItemView in list)
                {
                    NewsItems.Add(newsItemView);
                }
            }
            _news = true;
            NotifyPropertyChanged("GroupedNews");
        }
 public bool AddNewsItem(NewsItem news)
 {
     if (news != null)
     {
         if (_containerDAL.Save(news))
         {
             NewsItems.Add(news);
             return(true);
         }
     }
     return(false);
 }
        public bool AddNewsItem(NewsItem news)
        {
            if (news != null)
            {
                INewsItemDTO dTO = news;

                if (containerDAL.Save(dTO))
                {
                    NewsItems.Add(news);
                    return(true);
                }
            }
            return(false);
        }
Beispiel #4
0
        public void LoadData(object param = null)
        {
            // Load Trovesaurus data from API
            try
            {
                log.Info("Loading Trovesaurus news, calendar, and streams data");
                if (_StatusTimer == null)
                {
                    StartStatusTimer();
                }
                CheckStatus();

                TrovesaurusApi.RefreshNewsList();
                NewsItems.Clear();
                foreach (var item in TrovesaurusApi.NewsList)
                {
                    NewsItems.Add(item);
                }

                TrovesaurusApi.RefreshCalendarList();
                CalendarItems.Clear();
                foreach (var item in TrovesaurusApi.CalendarList)
                {
                    CalendarItems.Add(item);
                }

                TrovesaurusApi.RefreshStreamList();
                OnlineStreams.Clear();
                foreach (var item in TrovesaurusApi.StreamList)
                {
                    OnlineStreams.Add(item);
                }

                CalendarView.SortDescriptions.Clear();
                CalendarView.SortDescriptions.Add(new SortDescription("EndDateTime", ListSortDirection.Ascending));

                log.Info("Trovesaurus news, calendar, and streams data loaded successfully");
            }
            catch (Exception ex)
            {
                log.Error("Error loading Trovesaurus news, calendar or streams", ex);
            }
        }
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            // If _isNewPageInstance is true, the page constuctor has been called, so
            // state may need to be restored
            if (isNewPageInstance)
            {
                // Define the query to gather all of the to-do items.
                var rssItemsInDb = from RssItem todo in rssItemDb.RssItems
                                   select todo;

                // Execute the query and place the results into a collection.
                ObservableCollection <RssItem> items = new ObservableCollection <RssItem>(rssItemsInDb);
                for (int i = 0; i < items.Count; i++)
                {
                    switch (items[i].ItemType)
                    {
                    case RssItem.RssItemType.News:
                        NewsItems.Add(items[i]);
                        break;

                    case RssItem.RssItemType.Sports:
                        SportsItems.Add(items[i]);
                        break;

                    case RssItem.RssItemType.Twitter:
                        TwitterItems.Add(items[i]);
                        break;
                    }
                }
                if (State.Count > 0)
                {
                    object defaultItem = mainPanorama.Items[(int)State[panoramaIndex]];
                    mainPanorama.SetValue(Panorama.SelectedItemProperty, defaultItem);
                }
                else
                {
                    mainPanorama.DefaultItem = 0;
                }
            }
            // Call the base method.
            base.OnNavigatedTo(e);
        }
        public async Task Init()
        {
            var client = new SyndicationClient();
            var feed   = await client.RetrieveFeedAsync(
                new Uri("http://rss.cnn.com/rss/edition_technology.rss", UriKind.Absolute));

            foreach (var item in feed.Items)
            {
                var element = item.
                              ElementExtensions.FirstOrDefault(e => e.NodeName == "thumbnail");
                var attribute = element.AttributeExtensions.FirstOrDefault(ae => ae.Name == "url");
                var uri       = attribute?.Value;
                var imageUri  = uri ?? "https://pbs.twimg.com/profile_images/508960761826131968/LnvhR8ED.png";
                NewsItems.Add(new NewsItemVmi
                {
                    Title     = item.Title.Text,
                    Image     = imageUri,
                    Published = item.PublishedDate.ToString("g")
                });
            }
        }
Beispiel #7
0
        public override void Process()
        {
            VkApi api = new VkApi();

            api.Authorize(new ApiAuthParams
            {
                ApplicationId = 123456,
                AccessToken   = Token,
                Settings      = Settings.All
            });
            WallGetObject wall = api.Wall.Get(new WallGetParams
            {
                Domain = Channel.Url
            });

            if (wall != null && wall.WallPosts.Count > 0)
            {
                foreach (Post post in wall.WallPosts)
                {
                    if (!Channel.LastSynchronizationDate.HasValue ||
                        (post.Date.HasValue && post.Date >= Channel.LastSynchronizationDate.Value))
                    {
                        NewsItems.Add(new NewsItemContract
                        {
                            ChannelId   = Channel.Id,
                            Date        = post.Date.Value,
                            Title       = post.Text.TruncateSpecialSymbols(),
                            Description = post.Text.TruncateSpecialSymbols(),
                            Text        = post.Text,
                            Url         = $"https://vk.com/{Channel.Url}?w=wall{post.OwnerId}_{post.Id}"
                        });
                    }
                }
            }

            FilterNewsItemsByTags();
            SaveNewsItems();
        }
Beispiel #8
0
        async Task ExecuteLoadItemsCommand()
        {
            IsBusy = true;

            try
            {
                NewsItems.Clear();
                var activities = await DataStore.GetItemsAsync(true);

                foreach (var activity in activities)
                {
                    NewsItems.Add(activity);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            finally
            {
                IsBusy = false;
            }
        }
        private void LoadNewsFeed()
        {
            NewsProvider.GetVideos((videos, exception) =>
            {
                SmartDispatcher.BeginInvoke(() =>
                {
                    NewsItems.Clear();

                    if (videos.Count >= 2)
                    {
                        NewsItems.Add(new NewsItem()
                        {
                            Title     = Properties.Resources.WebTV_DMI,
                            WebTVItem = videos.FirstOrDefault(v => v.Category == "DMI"),
                        });

                        NewsItems.Add(new NewsItem()
                        {
                            Title     = Properties.Resources.WebTV_3D,
                            WebTVItem = videos.FirstOrDefault(v => v.Category == "3D"),
                        });
                    }

                    NewsProvider.GetNewsItems((items, e) =>
                    {
                        SmartDispatcher.BeginInvoke(() =>
                        {
                            foreach (var item in items)
                            {
                                NewsItems.Add(item);
                            }
                        });
                    });
                });
            });
        }
 public static void Add(NewsItemContract item)
 {
     NewsItems.Add(item);
 }
Beispiel #11
0
        private void Parse()
        {
            HtmlNode n = HtmlDocument.GetElementbyId("news-main");

            foreach (var node in n.ChildNodes)
            {
                if (node.GetType() == typeof(HtmlNode) && node.HasAttributes)
                {
                    if (node.Attributes["class"].Value == "g-section news sfe-break-bottom-16")
                    {
                        NewsFeed newsFeed = new NewsFeed();

                        foreach (var feedNode in node.ChildNodes)
                        {
                            if (feedNode.HasAttributes && feedNode.Attributes["class"].Value == "name")
                            {
                                HtmlNode nn = HtmlNode.CreateNode(feedNode.InnerHtml.Trim());
                                newsFeed.NewsLink = new Uri(nn.Attributes["href"].Value);
                                newsFeed.Title    = nn.InnerText;
                            }
                            else if (feedNode.HasAttributes && feedNode.Attributes["class"].Value == "byline")
                            {
                                HtmlNode nn = HtmlNode.CreateNode(feedNode.InnerHtml);
                                newsFeed.Source = nn.NextSibling.InnerText;
                            }
                            else if (feedNode.HasAttributes && feedNode.Attributes["class"].Value == "g-c")
                            {
                                //HtmlNode nn=null;
                                foreach (var div in feedNode.ChildNodes)
                                {
                                    if (div.Name == "div")
                                    {
                                        newsFeed.Snapshot = HtmlNode.CreateNode(div.InnerHtml.Trim()).InnerText;
                                        //nn = div;
                                        break;
                                    }
                                }

                                //HtmlNode nn = HtmlNode.CreateNode(feedNode.NextSibling.InnerHtml);
                                //newsFeed.Snapshot = nn.InnerText;

                                //if (nn != null)
                                //{
                                foreach (var nnn in feedNode.ChildNodes)
                                {
                                    //var i
                                    try
                                    {
                                        if (nnn.HasAttributes && nnn.Attributes["class"].Value == "more-rel")
                                        {
                                            newsFeed.RelatedNewsLinks.Add(new Uri(nnn.Attributes["href"].Value));
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        // Gobble the exception up.
                                    }
                                }
                                //}
                            }
                        }

                        NewsItems.Add(newsFeed);
                    }
                }
            }
        }