public static async Task <Model.SubjectProgress> GetProgress(uint u_id, uint s_id) { string url = string.Format("user/{0}/progress?subject_id={1}", u_id, s_id); using (HttpResponseMessage response = await APIclient.GetAsync(url)) { try { response.EnsureSuccessStatusCode(); string response_body = await response.Content.ReadAsStringAsync(); Model.SubjectProgress subject_progress = JsonConvert.DeserializeObject <Model.SubjectProgress>(response_body); return(subject_progress); } catch (HttpRequestException http_exception) { if (response.StatusCode == HttpStatusCode.NotFound) { throw new WebException(http_exception.Message); } else { throw new AuthorizationException(response.StatusCode.ToString()); } } catch (WebException) { throw; } } }
private async void ListViewCollectionsSelectedIndexChanged(object sender, EventArgs e) { if (subject_list == null) { return; } SubjectControl.DataContext = null; SubjectControl.Reset(); SubjectControl.subject = null; SubjectControl.buttonSummary.RaiseEvent(new RoutedEventArgs(Button.ClickEvent)); var index = ListViewCollections.SelectedIndex; if (index == -1) { return; } Model.SubjectLarge subject = new Model.SubjectLarge(); try { subject = await Retry.Do(() => ApiHelper.GetSubject(subject_list[index].subject_id), TimeSpan.FromSeconds(3)); } catch (WebException web_exception) { Console.WriteLine(web_exception.Message); return; } SubjectControl.DataContext = subject; SubjectControl.subject = subject; Model.SubjectProgress subject_progress = new Model.SubjectProgress(); try { subject_progress = await Retry.Do(() => ApiHelper.GetProgress(Settings.Default.UserID, subject.id), TimeSpan.FromSeconds(3)); } catch (WebException web_exception) { Console.WriteLine(web_exception.Message); } catch (AuthorizationException authorization_exception) { Console.WriteLine(authorization_exception.Message); } if (subject_progress != null && subject_progress.eps != null) { foreach (var ep in subject_progress.eps) { foreach (var ep_src in subject.eps) { if (ep.id == ep_src.id) { ep_src.ep_status = ep.status.id; break; } } } } subject.eps_filter(); return; }