public async Task generateNEWS() { frameM.IsVisible = true; //adM.IsVisible = true; frameS.IsVisible = true; //adS.IsVisible = true; frameK.IsVisible = true; //adK.IsVisible = true; frameSp.IsVisible = true; //adSp.IsVisible = true; frameE.IsVisible = true; //adE.IsVisible = true; if (Sites.sites.Count == 0) { Sites.addElements(); } MAKEDONIJA.Children.Clear(); SVET.Children.Clear(); EKONOMIJA.Children.Clear(); KULTURA.Children.Clear(); SPORT.Children.Clear(); foreach (var cat in Sites.categories) { if (cat.Equals(Sites.mak) && Preferences.Get("mk", true) == false) { frameM.IsVisible = false; //adM.IsVisible = false; continue; } if (cat.Equals(Sites.svet) && Preferences.Get("sv", true) == false) { frameS.IsVisible = false; //adS.IsVisible = false; continue; } if (cat.Equals(Sites.kultura) && Preferences.Get("kl", true) == false) { frameK.IsVisible = false; //adK.IsVisible = false; continue; } if (cat.Equals(Sites.sport) && Preferences.Get("sp", true) == false) { frameSp.IsVisible = false; //adSp.IsVisible = false; continue; } if (cat.Equals(Sites.ekonomija) && Preferences.Get("ek", true) == false) { frameE.IsVisible = false; //adE.IsVisible = false; continue; } List <string> sites; if (!cat.Equals(Sites.ekonomija)) { Sites.sites.Shuffle(); sites = Sites.sites; } else { Sites.economySites.Shuffle(); sites = Sites.economySites; } //int k = (int)Math.Floor(Preferences.Get("slajder", 0.3) * 6)+1; //BlockingCollection<NewsContent> results = new BlockingCollection<NewsContent>(); List <NewsContent> results = new List <NewsContent>(); await Task.Run(() => { Parallel.For(0, 5, i => { try { var tt = Sites.oneNews(cat, sites[i], 0); results.Add(tt.Result); }catch (Exception e) { } }); }); while (results.Contains(null)) { results.Remove(null); } for (int i = 0; i < results.Count - 1; i++) { for (int j = i + 1; j < results.Count; j++) { string phrase1 = results[i].title.ToLower(); string phrase2 = results[j].title.ToLower(); string[] words2 = phrase2.Split(' '); double isti = 0.0; if (phrase1.Split(' ')[0].Equals(words2[0])) { isti += 15; } foreach (var wrd2 in words2) { if (phrase1.Contains(wrd2)) { isti += 1; } } var percent = (isti / words2.Length) * 100; if (percent > 50) { NewsContent newnw = null; await Task.Run(async() => { newnw = await Sites.oneNews(results[j].category, results[j].site, 2); }); if (!newnw.Equals(null)) { results[j] = newnw; } } } } await shownewNews(results); } CrossMTAdmob.Current.LoadInterstitial("ca-app-pub-6638560950207737/4239069970"); }
private async void getNews() { List <List <NewsContent> > allnews = new List <List <NewsContent> >(); ActivityIndicator ai = new ActivityIndicator() { IsRunning = true, BackgroundColor = Color.Black, Color = Color.FromHex("#FF0266") }; mainStek.Children.Insert(0, ai); if (!category.Equals(Sites.ekonomija)) { await Task.Run(() => { Parallel.For(0, Sites.sites.Count(), i => { var newsList = Sites.oneNewsOrdered(category, Sites.sites[i]); allnews.Add(newsList.Result); }); }); } else { await Task.Run(() => { Parallel.For(0, Sites.economySites.Count(), i => { var newsList = Sites.oneNewsOrdered(category, Sites.economySites[i]); allnews.Add(newsList.Result); }); }); } for (int i = 0; i < allnews.Count; i++) { while (allnews[i].Contains(null)) { allnews[i].Remove(null); } } List <NewsContent> all = new List <NewsContent>(); for (int i = 0; i < min(allnews); i++) { for (int j = 0; j < allnews.Count(); j++) { all.Add(allnews[j][i]); } } for (int i = 0; i < all.Count - 1; i++) { for (int j = i + 1; j < all.Count / 2; j++) { string phrase1 = all[i].title.ToLower(); string phrase2 = all[j].title.ToLower(); string[] words2 = phrase2.Split(' '); double isti = 0.0; if (phrase1.Split(' ')[0].Equals(words2[0])) { isti += 15; } foreach (var wrd2 in words2) { if (phrase1.Contains(wrd2)) { isti += 1; } } var percent = (isti / words2.Length) * 100; if (percent > 50) { NewsContent newnw = null; await Task.Run(async() => { newnw = await Sites.oneNews(all[j].category, all[j].site, 2); }); if (!newnw.Equals(null)) { all[j] = newnw; } } } } ai.IsRunning = false; mainStek.Children.Remove(ai); showNews(all); }