private string serilizeObject(covidData ob) { string jsonString = String.Empty; try{ covidData = new covidData() { statewise = new List <statewise> { new statewise() { active = "12", confirmed = "13", deaths = "1", recovered = "4", state = "bih", statecode = "12" }, new statewise() { active = "11", confirmed = "33", deaths = "2", recovered = "2", state = "wb", statecode = "13" } } }; jsonString = JsonConvert.SerializeObject(ob); } catch (Exception ex) { Console.WriteLine("Exception while serilizing data"); } return(jsonString); }
public string writeDataIntoFileFromApi() { string text = getDataFromApi(); covidData = deserlizieObject(text); string json = serilizeObject(covidData); writeData(json); return(json); }
private covidData deserlizieObject(string jsonData) { try { covidData = JsonConvert.DeserializeObject <covidData>(jsonData); List <statewise> ss = covidData.statewise; } catch (Exception ex) { Console.WriteLine("Exception while fetching data cfrom api"); } return(covidData); }
// Fill the datagrid using csv file void FillingDataGrid() { var appPath = AppDomain.CurrentDomain.BaseDirectory; string covidCsvPath = appPath + @"/covid19.csv"; if (!File.Exists(covidCsvPath)) { MessageBox.Show("Error. covid19.csv file should be near the .exe file"); // shutdown the app Environment.Exit(0); return; } string[] lines = File.ReadAllLines(appPath + @"/covid19.csv"); int lineCount = lines.Length; covidDataList = new List <covidData>(lineCount - 1); for (int i = 1; i < lineCount; i++) { covidData cdata = new covidData(); cdata.setVariables(ref lines[i]); covidDataList.Add(cdata); } dt = new DataTable(); DataColumn county = new DataColumn("Country", typeof(string)); DataColumn confirmed = new DataColumn("Confirmed", typeof(int)); DataColumn deaths = new DataColumn("Deaths", typeof(int)); DataColumn recovered = new DataColumn("Recovered", typeof(int)); DataColumn active = new DataColumn("Active", typeof(int)); DataColumn newcases = new DataColumn("NewCases", typeof(int)); DataColumn newdeaths = new DataColumn("NewDeaths", typeof(int)); DataColumn newrecovered = new DataColumn("NewRecovered", typeof(int)); DataColumn deathPercent = new DataColumn("DeathOverHundredCases", typeof(float)); DataColumn recoverPercent = new DataColumn("RecoveredOverHundredCases", typeof(float)); DataColumn death100recovered = new DataColumn("DeathsOverHundredRecovered", typeof(float)); DataColumn confirmedLast = new DataColumn("ConfirmedLastWeek", typeof(int)); DataColumn weekchange = new DataColumn("OneWeekChange", typeof(int)); DataColumn weekincrease = new DataColumn("OneWeekIncreasePercent", typeof(float)); DataColumn region = new DataColumn("WHORegion", typeof(string)); dt.Columns.Add(county); dt.Columns.Add(confirmed); dt.Columns.Add(deaths); dt.Columns.Add(recovered); dt.Columns.Add(active); dt.Columns.Add(newcases); dt.Columns.Add(newdeaths); dt.Columns.Add(newrecovered); dt.Columns.Add(deathPercent); dt.Columns.Add(death100recovered); dt.Columns.Add(confirmedLast); dt.Columns.Add(weekchange); dt.Columns.Add(weekincrease); dt.Columns.Add(region); for (int i = 0; i < covidDataList.Count; i++) { DataRow row = dt.NewRow(); row[0] = covidDataList[i].country; row[1] = covidDataList[i].confirmed; row[2] = covidDataList[i].deaths; row[3] = covidDataList[i].recovered; row[4] = covidDataList[i].active; row[5] = covidDataList[i].newCases; row[6] = covidDataList[i].newDeaths; row[7] = covidDataList[i].newRecovered; row[8] = covidDataList[i].deathPercent; row[9] = covidDataList[i].deaths100recovered; row[10] = covidDataList[i].confirmedLast; row[11] = covidDataList[i].weekChange; row[12] = covidDataList[i].weekIncrease; row[13] = covidDataList[i].region; dt.Rows.Add(row); } CovidDataGrid.ItemsSource = dt.DefaultView; }