Ignore:
Timestamp:
02/14/21 17:54:35 (18 months ago)
Author:
Dimitar Slezenkovski <dslezenkovski@…>
Branches:
master
Children:
472dd7e
Parents:
6e6f04b
Message:

Add cron job for updating data, with Quartz.NET

File:
1 edited

Legend:

Unmodified
Added
Removed
  • FarmatikoServices/Services/ProcessJSONService.cs

    r6e6f04b rf554983  
    1313using GemBox.Spreadsheet;
    1414using System.Text;
     15using FarmatikoData.FarmatikoRepoInterfaces;
    1516
    1617namespace FarmatikoServices.Services
     
    2021
    2122        private readonly ILogger _logger;
     23        private readonly IUpdateDataRepo _repo;
    2224        private readonly IService _service;
    23         public ProcessJSONService(ILogger logger, IService service)
     25        public ProcessJSONService(ILogger logger, IUpdateDataRepo repo, IService service)
    2426        {
    2527            _logger = logger;
     28            _repo = repo;
    2629            _service = service;
    2730        }
     
    7780                bool Success = ReadPharmaciesFromExcel(pathToSave1);
    7881                _logger.LogInformation(Success.ToString() + "1");
    79                /* Success = await ReadPharmaciesFromExcel(pathToSave2);
    80                 _logger.LogInformation(Success.ToString() + "2");*/
     82
     83               
    8184            }
    8285            catch (Exception e)
     
    8891
    8992        //Healthfacilities
    90         public async void GetProcessedHealthFacilitiesFromJSON()
     93        public void GetProcessedHealthFacilitiesFromJSON()
    9194        {
    9295            try
     
    115118                    healthFacility.Email = Convert.ToString(Email);
    116119                    healthFacility.Phone = Convert.ToString(Phone);
    117                     await _service.AddFacility(healthFacility);
    118 
    119                 }
    120 
     120                    _service.AddFacility(healthFacility);
     121
     122                }
     123               
    121124            }
    122125            catch (Exception e)
     
    126129            }
    127130        }
    128         //Pandemics
    129         public async void GetProcessedPandemicsFromJSONApi()
    130         {
    131             try
    132             {
    133                 var Date = DateTime.UtcNow.ToString("yyyy-MM-dd");
    134                 var client = new RestClient($"https://api.covid19tracking.narrativa.com/api/{Date}/country/north_macedonia");
    135                 var response = client.Execute(new RestRequest());
    136                 string original = response.Content;
    137                 var jsonResponsePandemic = JObject.Parse(original);
    138                 var global = JObject.Parse(jsonResponsePandemic.GetValue("total").ToString());
    139                 var TotalConfirmed = long.Parse(global.GetValue("today_confirmed").ToString());
    140                 var TotalDeaths = long.Parse(global.GetValue("today_deaths").ToString());
    141                 var TotalRecovered = long.Parse(global.GetValue("today_new_recovered").ToString());
    142 
    143                 var mk = JObject.Parse(jsonResponsePandemic.GetValue("dates").ToString());
    144 
    145                 var date = JObject.Parse(mk.GetValue(Date).ToString());
    146                 var country = JObject.Parse(date.GetValue("countries").ToString());
    147                 var mkd = JObject.Parse(country.GetValue("North Macedonia").ToString());
    148                 dynamic objP = mkd;
    149                 var TotalMk = Int32.Parse(objP.GetValue("today_confirmed").ToString());
    150                 var TotalDeathsMK = Int32.Parse(objP.GetValue("today_deaths").ToString());
    151                 var TotalRecoveredMK = Int32.Parse(objP.GetValue("today_recovered").ToString());
    152                 var NewMK = Int32.Parse(objP.GetValue("today_new_confirmed").ToString());
    153 
    154                 var Name = "Coronavirus";
    155                 var ActiveMk = TotalMk - (TotalRecoveredMK + TotalDeathsMK);
    156                 var ActiveGlobal = TotalConfirmed - (TotalRecovered + TotalDeaths);
    157 
    158                 Pandemic pandemic = new Pandemic(Name, TotalMk, ActiveMk, TotalDeathsMK, NewMK, TotalConfirmed, TotalDeaths, ActiveGlobal);
    159                 await _service.AddPandemic(pandemic);
    160             }
    161             catch (Exception e)
    162             {
    163                 _logger.LogInformation(e.Message);
    164             }
    165         }
     131             
    166132        //Healthcare workers
    167         public async void GetProcessedHealthcareWorkersFromJSON()
     133        public void GetProcessedHealthcareWorkersFromJSON()
    168134        {
    169135            try
     
    183149                    var Title = Convert.ToString(obj[3]);
    184150
    185                     HealthFacility facility = _service.GetFacilityJSON(Convert.ToString(FacilityName));
     151                    HealthFacility facility = _repo.GetFacilityJSON(Convert.ToString(FacilityName));
    186152
    187153                    if (facility != null && facility != default)
     
    196162                           );
    197163                        HealthcareWorker healthcareWorker = new HealthcareWorker(Name, Branch, Facility, Title);
    198                         await _service.AddWorker(healthcareWorker);
     164                        _service.AddWorker(healthcareWorker);
    199165                    }
    200166                    else
     
    209175                           );
    210176                        HealthcareWorker healthcareWorker = new HealthcareWorker(Name, Branch, Facility, Title);
    211                         await _service.AddWorker(healthcareWorker);
     177                        _service.AddWorker(healthcareWorker);
    212178                    }
    213179                   
    214180
    215181                }
     182               
    216183            }
    217184            catch (Exception e)
     
    221188        }
    222189        //Medicines
    223         public async void GetProcessedMedicinesFromJSON()
     190        public void GetProcessedMedicinesFromJSON()
    224191        {
    225192            try
     
    244211                    Medicine medicine = new Medicine(Convert.ToString(Name), Convert.ToString(Strength), Convert.ToString(Form), Convert.ToString(WayOfIssuing), Convert.ToString(Manufacturer), Price, Convert.ToString(Packaging));
    245212
    246                     await _service.AddMedicines(medicine);
     213                    _service.AddMedicines(medicine);
    247214                }
    248215            }
Note: See TracChangeset for help on using the changeset viewer.