Beispiel #1
0
        public static List <Values> GetPreferredNews(string username)
        {
            Preference uPref = UserPreference(username);
            SpfxNews   news  = ReadNews();
            //List<Values> newsValues = newsL.value.Where(c => c.Category != null).Select(d => d).ToList();
            List <Values> newCatNotNull = news.value.Where(a => a.Category != null).ToList();

            //string[] categories = uPref.News.SelectedCategories;
            string[] categories = { "AI", "Technology", "IT", "CD" };

            //if cat count is zero then return all the news cats
            if (categories.Count() <= 1)
            {
                return(newCatNotNull);
            }

            var prefNews = new List <Values>();

            for (int i = 0; i < categories.Count(); i++)
            {
                var newss = newCatNotNull.Where(w => w.Category == categories[i]);
                prefNews = prefNews.Concat(newss).ToList();
            }

            newCatNotNull = prefNews;
            return(newCatNotNull);
        }
Beispiel #2
0
        //This method is part of spfx changes. This method is to get the sharepoint data and save it to test data location for bot
        public static async System.Threading.Tasks.Task GetNewsFromSPandWriteToFile() // need to decide how many time it will run and update the data file.
        {
            string token = await GetDataHelper.GetAuthenticationToken();

            string   endpoint = "https://avadheshftc.sharepoint.com/sites/EmployeeConnectPrototype/_api/web/lists(guid'01830dd5-78f8-4de7-bb0f-298474a907a9')/items";
            SpfxNews news     = null;

            using (var client = new HttpClient())
            {
                using (var request = new HttpRequestMessage(HttpMethod.Get, endpoint))
                {
                    string location = System.Web.Hosting.HostingEnvironment.MapPath(@"~\TestData\");
                    request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);

                    using (HttpResponseMessage response = await client.SendAsync(request))
                    {
                        if (response.IsSuccessStatusCode)
                        {
                            var json = await response.Content.ReadAsStringAsync();

                            try
                            {
                                news = (new JavaScriptSerializer().Deserialize <SpfxNews>(json));
                                File.WriteAllText(location + "newsMock.json", json);
                            }
                            catch (Exception ex)
                            {
                            }
                        }
                    }
                }
            }
        }
Beispiel #3
0
        public static SpfxNews ReadNews()
        {
            string   file = System.Web.Hosting.HostingEnvironment.MapPath("~/TestData/") + @"/newsMock.json";
            SpfxNews news = new SpfxNews();
            string   json = File.ReadAllText(file).Replace("##BaseURL##", ApplicationSettings.BaseUrl);

            news = new JavaScriptSerializer().Deserialize <SpfxNews>(json);

            return(news);
        }
Beispiel #4
0
        public static void DownloadImages()
        {
            string   file          = System.Web.Hosting.HostingEnvironment.MapPath("~/TestData/") + @"/newsMock.json";
            string   ImageLocation = System.Web.Hosting.HostingEnvironment.MapPath("~/Images_Spfx/");
            SpfxNews newNews       = new SpfxNews();
            string   json          = File.ReadAllText(file).Replace("##BaseURL##", ApplicationSettings.BaseUrl);

            newNews = (new JavaScriptSerializer().Deserialize <SpfxNews>(json));
            List <string> Imageurls = newNews.value.Select(c => c.BannerImageUrl.Url).ToList();

            for (int i = 1; i < Imageurls.Count; i++)
            {
                using (WebClient webclient = new WebClient())
                {
                    webclient.DownloadFileAsync(new Uri(Imageurls[i]), ImageLocation + i + ".jpg"); // images are not opening
                }
            }
        }