/*public void OnGet() * { * using (var webClient = new WebClient()) * { * string jsonString = webClient.DownloadString("https://data.cdc.gov/resource/9mfq-cb36.json"); * JSchema schema = JSchema.Parse(System.IO.File.ReadAllText("casesDeathsSchema.json")); * JArray jsonArray = JArray.Parse(jsonString); * IList<string> validationEvents = new List<string>(); * if (jsonArray.IsValid(schema, out validationEvents)) * { * var casesDeaths = CasesDeaths.FromJson(jsonString); * ViewData["CasesDeaths"] = casesDeaths; * } * else * { * foreach (string evt in validationEvents) * { * Console.WriteLine(evt); * ViewData["CasesDeaths"] = new CasesDeaths(); * } * } * * } * }*/ public void OnGet() { using (var webClient = new WebClient()) { string usCasesData = webClient.DownloadString("https://data.cdc.gov/resource/9mfq-cb36.json"); JSchema schema = JSchema.Parse(System.IO.File.ReadAllText("casesDeathsSchema.json")); JArray jsonArray = JArray.Parse(usCasesData); IList <string> validationEvents = new List <string>(); if (jsonArray.IsValid(schema, out validationEvents)) { var casesDeaths1 = CasesDeaths.FromJson(usCasesData); ViewData["CasesDeaths"] = casesDeaths1; } else { _logger.LogError("US Cases and deaths json validation failed"); foreach (string evt in validationEvents) { _logger.LogWarning($"Error while validating US cases and deaths schema {evt}"); Console.WriteLine(evt); ViewData["ModernaVaccineDistributionAllocations"] = new ModernaVaccineDistributionAllocations(); } } } }
public void OnGet() { using (var webClient = new WebClient()) { string modernaData = webClient.DownloadString("https://data.cdc.gov/resource/b7pe-5nws.json"); JSchema modernaSchema = JSchema.Parse(System.IO.File.ReadAllText("modernaSchema.json")); JArray jsonArray = JArray.Parse(modernaData); IList <string> validationEvents = new List <string>(); var currentWeek1 = jsonArray[0]; var currentWeek = currentWeek1["week_of_allocations"]; List <ModernaVaccineDistributionAllocations> currentWeekAllocations = new List <ModernaVaccineDistributionAllocations>(); if (jsonArray.IsValid(modernaSchema, out validationEvents)) { JArray result_array = new JArray(); JArray jarray = new JArray(); var length_arr = jsonArray.Count(); foreach (JObject i in jsonArray .Where(obj => obj["week_of_allocations"].ToString() == currentWeek.ToString())) { result_array.Add(i); } string result_string = result_array.ToString(); ModernaVaccineDistributionAllocations[] modernaAllocations = ModernaVaccineDistributionAllocations.FromJson(result_string); ViewData["ModernaVaccineDistributionAllocations"] = modernaAllocations; ViewData["CurrentWeek"] = currentWeek; } else { _logger.LogError("moderna json validation failed"); foreach (string evt in validationEvents) { _logger.LogWarning($"Error while validating moderna schema {evt}"); /*Console.WriteLine(evt);*/ ViewData["ModernaVaccineDistributionAllocations"] = new ModernaVaccineDistributionAllocations[] { }; } } } }
public void OnPost() { var jurisdiction = Request.Form["jurisdiction"]; using (var webClient = new WebClient()) { string modernaData = webClient.DownloadString("https://data.cdc.gov/resource/saz5-9hgg.json"); JSchema modernaschema = JSchema.Parse(System.IO.File.ReadAllText("modernaSchema.json")); JArray jsonArray = JArray.Parse(modernaData); IList <string> validationEvents = new List <string>(); var currentWeek1 = jsonArray[0]; var currentWeek = currentWeek1["week_of_allocations"]; if (jsonArray.IsValid(modernaschema, out validationEvents)) { JArray result_array = new JArray(); JArray jarray = new JArray(); foreach (JObject i in jsonArray .Where(obj => obj["jurisdiction"].Value <string>() == jurisdiction)) { result_array.Add(i); } string result_string = result_array.ToString(); var modernaAllocations = ModernaVaccineDistributionAllocations.FromJson(result_string); ViewData["ModernaVaccineDistributionAllocations"] = modernaAllocations; ViewData["Jurisdiction"] = jurisdiction; ViewData["CurrentWeek"] = currentWeek; } else { foreach (string evt in validationEvents) { Console.WriteLine(evt); ViewData["ModernaVaccineDistributionAllocations"] = new ModernaVaccineDistributionAllocations(); } } } }