Esempio n. 1
0
        public static async Task <Dictionary <string, int> > FillGroupsDictionary(bool rewrite, CancellationToken cts)
        {
            var    networkChecker = new NetworkChecker(Instance);
            string resultJson;

            var resourceName = "groups.json";

            var b = File.Exists(GetFileFullPath(resourceName));

            if (rewrite && networkChecker.Check())
            {
                var client = new HttpClient();
                resultJson = await HttpClientSL.GetResponseAsync(client, Instance.groupLink, cts);

                File.WriteAllText(GetFileFullPath(resourceName), resultJson);
            }
            else
            {
                using (var stream = GetEmbeddedResourceStream(resourceName))
                    using (var reader = b ? new StreamReader(GetFileFullPath(resourceName)) : new StreamReader(stream))
                    {
                        resultJson = await reader.ReadToEndAsync();
                    }
            }
            var groups     = JsonConvert.DeserializeObject <GroupRoot>(resultJson);
            var dictionary = groups.Groups.ToDictionary(x => x.Name, x => x.Id);

            return(dictionary);
        }
Esempio n. 2
0
        public async Task<WeekRoot> LoadWeekRootFromWebAsync(DateTime weekDate)
        {
            if (checker.Check() == false)
            {
                throw new NetworkException("No internet connection");
            }                 

            var groupId = settings["groupid"];

            string dateStr = weekDate.ToString("yyyy-M-d", new CultureInfo("ru-RU"));
            var resultJson = await HttpClientSL.GetResponseAsync(client, scheduleLink + groupId + "&date=" + dateStr, new System.Threading.CancellationToken());
            var weekRoot = JsonConvert.DeserializeObject<WeekRoot>(resultJson);
            weekRoot.LastUpdated = DateTime.Now;

            return weekRoot;
        }