public IActionResult ShowNewsFor2Favourites(List <string> currentFavouritePlayerNames, List <NewsItems> newsItemsList)
        {
            int numberOfFavorites = 2;

            for (int i = 0; i < numberOfFavorites; i++)
            {
                NewsItems newsItems = new NewsItems();
                newsItems = _newsApiRepository.GetNews(currentFavouritePlayerNames[i]);
                newsItemsList.Add(newsItems);
            }

            NewsItems combinedItemsFrom2Players = new NewsItems();

            combinedItemsFrom2Players.items = new List <Item>();

            Dictionary <int, bool> playerHasTwoItems = new Dictionary <int, bool>();

            playerHasTwoItems.Add(0, true);
            playerHasTwoItems.Add(1, true);

            //check that each player actually has at least 2 results
            for (int i = 0; i < numberOfFavorites; i++)
            {
                if (newsItemsList[i].items.Count() < NewsItemsThresholdWhen2FavouritesExist)
                {
                    playerHasTwoItems[i] = false;
                }
            }

            return(DisplayNewsDependingOnItemsFrom2Favourites(currentFavouritePlayerNames, newsItemsList, numberOfFavorites, combinedItemsFrom2Players, playerHasTwoItems));
        }
        private IActionResult ShowNewsFor3OrMoreFavourites(List <string> currentFavouritePlayerNames, List <NewsItems> newsItemsList)
        {
            NewsItems newsItems = new NewsItems();
            Dictionary <int, bool> playerHasOneItem = new Dictionary <int, bool>();

            playerHasOneItem.Add(0, true);
            playerHasOneItem.Add(1, true);
            playerHasOneItem.Add(2, true);

            int numberOfFavorites = 3;

            for (int i = 0; i < numberOfFavorites; i++)
            {
                newsItems = _newsApiRepository.GetNews(currentFavouritePlayerNames[i]);
                newsItemsList.Add(newsItems);
            }

            //check that each favourite player has at least 1 news item
            for (int i = 0; i < numberOfFavorites; i++)
            {
                if (newsItemsList[i].items.Count() < NewsItemsThresholdWhen3OrMoreFavouritesExist)
                {
                    playerHasOneItem[i] = false;
                }
            }

            return(DisplayNewsDependingOnNewsItemsFrom3Favourites(currentFavouritePlayerNames, newsItemsList, playerHasOneItem, numberOfFavorites));
        }
Ejemplo n.º 3
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");
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Creates and adds the data to the viewmodels
 /// </summary>
 public void LoadData(bool reload)
 {
     if (!IsEssentialsLoaded)
     {
         LoadInfo();
         LoadAssociations();
         LoadSettings();
         try
         {
             LoadFaceBookSettings();
         }
         catch (Exception)
         {
             //NIET INGELOGD
         }
     }
     if (!reload)
     {
         return;
     }
     RestoItems.Clear();
     NewsItems.Clear();
     ActivityItems.Clear();
     SchamperItems.Clear();
     _fromCache = DateTime.Now.AddMinutes(-60) < _cacheTime;
     if (!_fromCache && !HasConnection)
     {
         _fromCache = true;
     }
     LoadNews();
     LoadResto();
     LoadActivities();
     LoadSchamper();
 }
Ejemplo n.º 5
0
        private async Task ExecuteLoadItemsCommand()
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                using (var httpClient = new HttpClient())
                {
                    var feed           = "http://api.espn.com/v1/sports/soccer/fifa.world/news?apikey=trs58u4j7gw4aat7ck8dsmgc";
                    var responseString = await httpClient.GetStringAsync(feed);

                    NewsItems.Clear();
                    var items = await ParseFeed(responseString);

                    foreach (var item in items)
                    {
                        newsItems.Add(item);
                    }
                }
            }
            catch (Exception)
            {
                var page = new ContentPage();
                page.DisplayAlert("Error", "Unable to load News.", "OK", null);
            }

            IsBusy = false;
        }
Ejemplo n.º 6
0
        public ActionResult NewsItem(int id)
        {
            DataModel dataModel = new DataModel();

            dataModel.SelectedNewsItem = NewsItems.GetNewsItemByNewsItemId(id);
            return(View(dataModel));
        }
        public NewsItemdetailView(NewsItems newsitemData)
        {
            InitializeComponent();

            this.Title = "Details";

            ImageNews.Source = newsitemData.ImageUrl;

            NewsTitle.Text = newsitemData.Title;

            DescriptionTitle.Text = newsitemData.Description;
        }
Ejemplo n.º 8
0
 public bool AddNewsItem(NewsItem news)
 {
     if (news != null)
     {
         if (_containerDAL.Save(news))
         {
             NewsItems.Add(news);
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 9
0
 public bool RemoveNewsItem(NewsItem news)
 {
     if (news != null)
     {
         NewsItems.Remove(news);
         if (containerDAL.Delete(news.Id))
         {
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 10
0
 public bool RemoveNewsItem(NewsItem news)
 {
     if (news != null)
     {
         if (_containerDAL.Delete(news.Id))
         {
             int index = NewsItems.FindIndex(i => i.Id == news.Id);
             NewsItems.RemoveAt(index);
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 11
0
        public bool AddNewsItem(NewsItem news)
        {
            if (news != null)
            {
                INewsItemDTO dTO = news;

                if (containerDAL.Save(dTO))
                {
                    NewsItems.Add(news);
                    return(true);
                }
            }
            return(false);
        }
        public NewsItems GetNews(string query)
        {
            NewsItems newsItems = new NewsItems();

            var client  = new RestClient($"https://bing-news-search1.p.rapidapi.com/news/search?freshness=Day&textFormat=Raw&safeSearch=Off&q={query}");
            var request = new RestRequest(Method.GET);

            request.AddHeader("x-rapidapi-host", "bing-news-search1.p.rapidapi.com");
            request.AddHeader("x-rapidapi-key", API_KEY);
            request.AddHeader("x-bingapis-sdk", "true");
            IRestResponse response = client.Execute(request);

            return(JsonConvert.DeserializeObject <NewsItems>(response.Content));
        }
Ejemplo n.º 13
0
        public ActionResult AddNews(DataModel dataModel)
        {
            dataModel.SelectedNewsItem.Created = DateTime.Now;
            if (dataModel.SelectedNewsItem.Id == 0)
            {
                NewsItems.InsertNewsItem(dataModel.SelectedNewsItem);
            }
            else
            {
                NewsItems.UpdateNewsItem(dataModel.SelectedNewsItem);
            }

            return(RedirectToAction("NewsList", "News"));
        }
Ejemplo n.º 14
0
        void ExecuteLoadItemsCommand()
        {
            IsBusy = true;

            newsServiceSubscription = NewsService.Get("https://feeds.bbci.co.uk/news/uk/rss.xml")
                                      .ObserveOn(SynchronizationContext.Current)
                                      .Subscribe(OnNext, OnError, OnComplete);

            void OnNext(IEnumerable <NewsItem> items)
            {
                var newsItems = items.ToList();

                if (!newsItems.Any())
                {
                    return;
                }

                //newsItems = items.OrderByDescending(i => i.PubDate).ToList();
                var news = new List <News>();

                foreach (var newsItem in newsItems)
                {
                    news.Add(new News
                    {
                        Title     = newsItem.Title.Text,
                        Summary   = newsItem.Description.Text,
                        Thumbnail = newsItem.MediaThumbnail.Url,
                        Url       = newsItem.Link.AbsoluteUri
                    });
                }

                NewsItems.ReplaceRange(news);
            }

            void OnError(Exception ex)
            {
                IsBusy        = false;
                ErrorOccurred = true;
                Debug.WriteLine(ex);
            }

            void OnComplete()
            {
                IsBusy = false;

                ErrorOccurred &= !NewsItems.Any();
            }
        }
Ejemplo n.º 15
0
        void UpdateNewsStatus(StatusE statusID)
        {
            try
            {
                int i = 0;

                string    newsIDs = string.Empty;
                NewsItems news    = new NewsItems();

                foreach (DataGridViewRow row in dataGridView1.Rows)
                {
                    if (row.Cells[0].Value != null)
                    {
                        if ((bool)row.Cells[0].Value)
                        {
                            Int32 newsId = BaseItem.ToInt32(GridTable.Rows[i]["NewsID"]);

                            newsIDs += "," + newsId.ToString();
                        }
                    }

                    i++;
                }
                if (newsIDs.Length > 0)
                {
                    newsIDs = newsIDs.Remove(0, 1);

                    if (MessageForm.Confirm(this.ParentForm, MsgE.ConfirmItemTask, statusID.ToString().ToLower(), "news") == DialogResult.Yes)
                    {
                        ProgressForm frmProgress = ProgressForm.Show(this, "Updating News Status...");
                        SocketClient.UpdateNewsStatus(statusID, newsIDs);
                        frmProgress.Close();
                        RefreshGrid();
                        MessageForm.Show(this.ParentForm, MsgE.InfoNewsUpdate);
                    }
                }
                else
                {
                    MessageForm.Show(this.ParentForm, MsgE.ErrorSelectCheckBox);
                }
            }
            catch (Exception ex)
            {
                TestDebugger.Instance.WriteError(ex);
                MessageForm.Show(ex);
            }
        }
Ejemplo n.º 16
0
        public ActionResult NewsList(int?page)
        {
            int pageNum = 1;

            if (page != null)
            {
                pageNum = page.Value;
            }
            DataModel dataModel = new DataModel();

            int pageSize = 10;

            dataModel.NewsItems = NewsItems.GetPagedNewsItems(pageNum, pageSize, 0);
            int itemsCount = NewsItems.CountNewsItems(0);

            dataModel.Pager = new Pager(itemsCount, pageNum, pageSize);
            return(View(dataModel));
        }
        private IActionResult threePlayersWithResults(List <NewsItems> newsItemsList, int numberOfFavorites)
        {
            //if all 3 players have at least 1 result, take first result from each newsItems.items for each player
            NewsItems combinedItemsFrom3Favourites = new NewsItems();

            combinedItemsFrom3Favourites.items = new List <Item>();

            for (int i = 0; i < numberOfFavorites; i++)
            {
                for (int j = 0; j < NewsItemsThresholdWhen3OrMoreFavouritesExist; j++)
                {
                    combinedItemsFrom3Favourites.items.Add(newsItemsList[i].items[j]);
                }
            }

            TempData["newsPageTitle"] = "Recent news related to some of your favourite players";
            return(View("NewsList", combinedItemsFrom3Favourites));
        }
Ejemplo n.º 18
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);
            }
        }
Ejemplo n.º 19
0
        public List <NewsItems> All()
        {
            IContentService cs       = Services.ContentService;
            var             home     = cs.GetById(1268);
            var             AllItems = home.Children();

            List <NewsItems> result = new List <NewsItems>();

            foreach (var item in AllItems)
            {
                NewsItems news = new NewsItems();
                news.id               = item.Id;
                news.EventHeadline    = item.GetValue <string>("eventTitle");
                news.EventDescription = item.GetValue <string>("descriptionContent");
                news.EventTime        = item.GetValue <DateTime>("event");
                result.Add(news);
            }
            return(result);
        }
Ejemplo n.º 20
0
        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);
        }
Ejemplo n.º 21
0
        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")
                });
            }
        }
Ejemplo n.º 22
0
        public ActionResult Index()
        {
            DataModel       dataModel = new DataModel();
            List <NewsItem> newsItems = NewsItems.GetFrontNewsItems(30);

            dataModel.FirstNewsItem  = newsItems[0];
            dataModel.SecondNewsItem = newsItems[1];
            dataModel.ThirdNewsItem  = newsItems[2];
            dataModel.FourthNewsItem = newsItems[3];
            dataModel.FifthNewsItem  = newsItems[4];
            dataModel.NewsItems      = new List <NewsItem>();
            foreach (NewsItem newsItem in newsItems)
            {
                if (newsItem.ItemState == ItemState.Enabled)
                {
                    dataModel.NewsItems.Add(newsItem);
                }
            }

            return(View(dataModel));
        }
Ejemplo n.º 23
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();
        }
Ejemplo n.º 24
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;
            }
        }
Ejemplo n.º 25
0
        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);
                            }
                        });
                    });
                });
            });
        }
Ejemplo n.º 26
0
        internal void BeforeSerialize(IModuleProvider moduleProvider)
        {
            var linkSerialization = moduleProvider.QueryModule <ILinkSerializationService>() ?? throw new ModuleNotFoundException(typeof(ILinkSerializationService));

            Contracts = new MakabaEntittyInfoModelContracts()
            {
                BoardInfo       = moduleProvider.ValidateBeforeSerialize <IPostDocument, PostDocument, PostDocumentExternalContract>(BoardInfo),
                HasBannerSize   = BannerSize != null,
                BannerWidth     = BannerSize != null ? BannerSize.Value.Width : 0,
                BannerHeight    = BannerSize != null ? BannerSize.Value.Height : 0,
                BannerImageLink = linkSerialization.Serialize(BannerImageLink),
                BannerBoardLink = linkSerialization.Serialize(BannerBoardLink),
                Icons           = Icons?.Select(i => i != null ? new BoardIconContract()
                {
                    Id        = i.Id,
                    Name      = i.Name,
                    MediaLink = linkSerialization.Serialize(i.MediaLink)
                } : null)?.ToList(),
                Pages     = Pages?.ToList(),
                NewsItems = NewsItems?.Select(i => i != null ? new MakabaBoardPostCollectionInfoNewsItemContract()
                {
                    Date     = i.Date,
                    NewsLink = linkSerialization.Serialize(i.NewsLink),
                    Title    = i.Title
                } : null)?.ToList(),
                AdvertisementItems = AdvertisementItems?.Select(i => i != null ? new MakabaBoardPostCollectionInfoBoardsAdvertisementItemContract()
                {
                    Info      = i.Info,
                    Name      = i.Name,
                    BoardLink = linkSerialization.Serialize(i.BoardLink)
                } : null)?.ToList(),
                AdvertisementBannerLink = linkSerialization.Serialize(AdvertisementBannerLink),
                AdvertisementClickLink  = linkSerialization.Serialize(AdvertisementClickLink),
                Flags = Flags?.ToList()
            };
        }
Ejemplo n.º 27
0
 public static ListEx <NewsItem> GetList(NewsItemsListFilter f)
 {
     return(NewsItems.GetList(f));
 }
Ejemplo n.º 28
0
 public static void UpdateState(Guid id, NewsItemsStates state)
 {
     NewsItems.UpdateState(id, state);
 }
        private IActionResult DisplayNewsDependingOnItemsFrom2Favourites(List <string> currentFavouritePlayerNames, List <NewsItems> newsItemsList, int numberOfFavorites, NewsItems combinedItemsFrom2Players, Dictionary <int, bool> playerHasTwoItems)
        {
            bool notEnoughResultsForEitherPlayer = playerHasTwoItems[0] == false && playerHasTwoItems[1] == false;
            bool onlyPlayer1HasEnoughResults     = playerHasTwoItems[0] == true && playerHasTwoItems[1] == false;
            bool onlyPlayer2HasEnoughResults     = playerHasTwoItems[0] == false && playerHasTwoItems[1] == true;

            if (notEnoughResultsForEitherPlayer)
            {
                return(View("NewsList"));
            }

            else if (onlyPlayer1HasEnoughResults)
            {
                return(RedirectToAction("NewsForSelectedPlayer", new { name = currentFavouritePlayerNames[0] }));
            }

            else if (onlyPlayer2HasEnoughResults)
            {
                return(RedirectToAction("NewsForSelectedPlayer", new { name = currentFavouritePlayerNames[1] }));
            }

            else //display 2 results for each player
            {
                for (int i = 0; i < numberOfFavorites; i++)
                {
                    for (int j = 0; j < NewsItemsThresholdWhen2FavouritesExist; j++)
                    {
                        combinedItemsFrom2Players.items.Add(newsItemsList[i].items[j]);
                    }
                }

                TempData["newsPageTitle"] = "Recent news related to some of your favourite players";

                return(View("NewsList", combinedItemsFrom2Players));
            }
        }
Ejemplo n.º 30
0
 public static void Add(NewsItemContract item)
 {
     NewsItems.Add(item);
 }