private static async Task <SectionValues> GetV3SectionValuesAsync( IUpstreamEdFiApiInvoker invoker, HttpRequestHeaders headers, SectionLookupKey lookupKey, short schoolYearFromRoute) { // Get the referenced section by natural key var response = await invoker.Get( typeof(V3Section), headers, new[] { new KeyValuePair <string, string>("localCourseCode", lookupKey.LocalCourseCode), new KeyValuePair <string, string>("schoolId", lookupKey.SchoolId.ToString()), new KeyValuePair <string, string>("schoolYear", lookupKey.SchoolYear.ToString()), new KeyValuePair <string, string>("sectionIdentifier", lookupKey.SectionIdentifier), new KeyValuePair <string, string>("sessionName", lookupKey.SessionName), }, schoolYearFromRoute) .ConfigureAwait(false); StreamReader sr = new StreamReader(response.ResponseStream); string responseContent = await sr.ReadToEndAsync().ConfigureAwait(false); if (response.Status == HttpStatusCode.OK) { // Get the Section-derived members var v3Section = JsonConvert.DeserializeObject <V3Section[]>(responseContent, _serializerSettings).SingleOrDefault(); if (v3Section == null) { throw new Exception($"Unable to find referenced Section using the following values: {JsonConvert.SerializeObject(lookupKey, Formatting.Indented)}"); } // Invasive defensive validation against "invalid" data for V2 if (lookupKey.SchoolId != v3Section.LocationReference.SchoolId) { throw new Exception($"Unable to convert the SectionReference from host (v3.1) to client (v2.5) because the LocationReference contains a School that differs from the containing Section, which is not supported under v2.5."); } // TODO: Validate presence of V2 required values, or ensure that V3 requires them (i.e. via required collections) var sectionValues = new SectionValues( classPeriodName: v3Section.SectionClassPeriods.FirstOrDefault()?.ClassPeriodReference.ClassPeriodName ?? "Undefined", classroomIdentificationCode: v3Section.LocationReference.ClassroomIdentificationCode ?? "Undefined", sectionIdentifier: v3Section.SectionIdentifier, sequenceOfCourse: v3Section.SequenceOfCourse ?? -1, retrievedDateTime: DateTime.Now); return(sectionValues); } throw new Exception($"Error obtaining V3 Section resource during mapping of V2 SectionReference: {response.Status} - {responseContent}"); }
public void StartSectionWatch(string section) { SectionValues sectionValues; if (!AverageBreakdown.TryGetValue(section, out sectionValues)) { sectionValues = new SectionValues(); AverageBreakdown[section] = sectionValues; } sectionValues.StartTicks = DateTime.Now.Ticks; }
public void SetValue(string section, string key, string value) { SectionValues values; if (!_settings.TryGetValue(section, out values)) { values = new SectionValues(); _settings.Add(section, values); } int index = values.FindIndex(p => p.Key == key); if (index > -1) { values[index] = new KeyValuePair<string, string>(key, value); } else { values.Add(new KeyValuePair<string, string>(key, value)); } }
public void SetValue(string section, string key, string value) { SectionValues values; if (!_settings.TryGetValue(section, out values)) { values = new SectionValues(); _settings.Add(section, values); } int index = values.FindIndex(p => p.Key == key); if (index > -1) { values[index] = new KeyValuePair <string, string>(key, value); } else { values.Add(new KeyValuePair <string, string>(key, value)); } }