Exemple #1
0
        public static async System.Threading.Tasks.Task GetPreferencesandWriteToFile() // 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'e8937172-f3f3-478e-97bb-d5699f8d8945')/items";
            SPFXPreferences pref     = 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
                            {
                                pref = (new JavaScriptSerializer().Deserialize <SPFXPreferences>(json));
                                File.WriteAllText(location + "PreferencesMock.json", json);
                            }
                            catch (Exception ex)
                            {
                            }
                        }
                    }
                }
            }
        }
Exemple #2
0
        public static prefValue ReadPrefernecesfromSPData(string userName)
        {
            List <string> prefs = new List <string>();

            string          file        = System.Web.Hosting.HostingEnvironment.MapPath("~/TestData/") + @"/PreferencesMock.json";
            SPFXPreferences preferences = new SPFXPreferences();
            string          json        = File.ReadAllText(file).Replace("##BaseURL##", ApplicationSettings.BaseUrl);

            preferences = new JavaScriptSerializer().Deserialize <SPFXPreferences>(json);

            prefValue prefValue = preferences.value.Where(c => c.UserName == userName).Select(d => d).FirstOrDefault();

            return(prefValue);
        }