Ejemplo n.º 1
0
        public CovidStats GetCoronaInformation()
        {
            var client  = new RestClient("https://api.collectapi.com/corona/countriesData");
            var request = new RestRequest(Method.GET).AddParameter("country", "Turkey");

            request.AddHeader("authorization", "apikey 6L6crjOSv7ARGetMUth1nf:0FxCOOpzVG5VpIGpLhkiDK");
            request.AddHeader("content-type", "application/json");
            IRestResponse data     = client.Execute(request);
            string        response = data.Content.ToString();

            JToken     token      = JObject.Parse(response);
            var        result     = token.SelectToken("result");
            CovidStats covidStats = JsonConvert.DeserializeObject <CovidStats>(result.ToString());

            return(covidStats);
        }
Ejemplo n.º 2
0
        private CovidStats GetCovidStatsFromAPI()
        {
            try
            {
                if (APILastCallDate.Equals(DateTime.MinValue))
                {
                    APILastCallDate = DateTime.Now;
                }
                _apiCoronaObject = new APICoronaInformation();
                covidStatsCached = _apiCoronaObject.GetCoronaInformation();
                LoadRealObject   = true;
                APILastCallDate  = DateTime.Now;
                return(covidStatsCached);
            }

            catch
            {
                LoadRealObject = false;
                return(null);
            }
        }
Ejemplo n.º 3
0
        public CovidStats GetCoronaInformation()
        {
            LoadRealObject = false;
            CovidStats covidStats = null;
            TimeSpan   span       = DateTime.Now.Subtract(APILastCallDate);


            if (_apiCoronaObject == null || span.TotalMinutes > 1)
            {
                covidStats = GetCovidStatsFromAPI();
            }


            if (!LoadRealObject) // uzak nesne oluştu mu?
            {
                return(covidStatsCached);
            }
            else
            {
                return(covidStats);
            }
        }
Ejemplo n.º 4
0
        static void Main()
        {
            ICoronaInformation proxy = new ProxyCoronaInformation();

            do
            {
                Console.Clear();


                CovidStats covidStats = proxy.GetCoronaInformation();
                covidStats = proxy.GetCoronaInformation();

                string outputString = String.Format("###########################################\n" +
                                                    "Toplam Vaka Sayısı: {0}\n" +
                                                    "Bugünkü Vaka Sayısı: {1}\n" +
                                                    "Bugünkü Vefat Sayısı: {2}\n" +
                                                    "Toplam Vefat Sayısı: {3}\n" +
                                                    "Toplam İyileşen Sayısı: {4}\n" +
                                                    "Aktif Vaka Sayısı: {5}\n" +
                                                    "###########################################", covidStats.TotalCases, covidStats.NewCases, covidStats.NewDeaths, covidStats.TotalDeaths, covidStats.TotalRecovered, covidStats.ActiveCases.Replace("99999999999", ""));
                Console.WriteLine(outputString);
            }while (Console.ReadKey().Key != ConsoleKey.Enter);
        }