Example #1
0
        public List <AllCountryStatisticsModel> GetAllCountryStats()
        {
            try
            {
                Task <SummaryResponseWrapperModel> task = Task.Run <SummaryResponseWrapperModel>(async() => await GetCovidSummary());
                task.Wait();
                while (task.Result == null)
                {
                    task = Task.Run <SummaryResponseWrapperModel>(async() => await GetCovidSummary());
                    task.Wait();
                }
                SummaryResponseWrapperModel      APIResponse          = task.Result;
                List <AllCountryStatisticsModel> countrySpecificStats = new List <AllCountryStatisticsModel>();
                foreach (var item in APIResponse.Countries)
                {
                    countrySpecificStats.Add(new AllCountryStatisticsModel(item.Country, item.NewConfirmed, item.TotalConfirmed, item.NewDeaths, item.TotalDeaths, item.NewRecovered, item.TotalRecovered));
                }

                List <AllCountryStatisticsModel> countrys = new List <AllCountryStatisticsModel>();
                return(countrySpecificStats);
            }
            catch (Exception exp)
            {
                Console.WriteLine("Failed to get Statistics (StatisticsController.cs GetAllCountryStats(), retrying once..");
                try
                {
                    System.Threading.Thread.Sleep(100);

                    Task <SummaryResponseWrapperModel> task = Task.Run <SummaryResponseWrapperModel>(async() => await GetCovidSummary());
                    task.Wait();
                    SummaryResponseWrapperModel      APIResponse          = task.Result;
                    List <AllCountryStatisticsModel> countrySpecificStats = new List <AllCountryStatisticsModel>();
                    foreach (var item in APIResponse.Countries)
                    {
                        countrySpecificStats.Add(new AllCountryStatisticsModel(item.Country, item.NewConfirmed, item.TotalConfirmed, item.NewDeaths, item.TotalDeaths, item.NewRecovered, item.TotalRecovered));
                    }

                    List <AllCountryStatisticsModel> countrys = new List <AllCountryStatisticsModel>();
                    return(countrySpecificStats);
                }
                catch (Exception exp2)
                {
                    Console.WriteLine("StatisticsController.GetAllCountryStats 2nd Exception, not retrying agian::" + exp);
                    return(null);
                }
            }
        }
Example #2
0
 public IActionResult Summary()
 {
     try
     {
         Task <SummaryResponseWrapperModel> task = Task.Run <SummaryResponseWrapperModel>(async() => await GetCovidSummary());
         task.Wait();
         SummaryResponseWrapperModel APIResponse = task.Result;
         while (task.Result == null)
         {
             task = Task.Run <SummaryResponseWrapperModel>(async() => await GetCovidSummary());
             task.Wait();
         }
         SummaryModel requestedSummary = new SummaryModel();
         requestedSummary.Global  = APIResponse.Global;
         requestedSummary.Country = APIResponse.Countries.Find(i => i.Country == "South Africa");
         return(PartialView("Summary", requestedSummary));
     }
     catch (Exception exp)
     {
         Console.WriteLine(exp);
         return(RedirectToAction("HttpRequestError"));
     }
 }