Пример #1
0
        private async Task getHistoricalTimeLine()
        {
            try
            {
                string response = string.Empty;

                DeserializeJSON deserializeJson = new DeserializeJSON();
                if (Properties.Settings.Default.isInternet)
                {
                    GETHandler apiHandler = new GETHandler();

                    apiHandler.endPoint = string.Format("https://covid19.mathdro.id/api/daily");
                    response            = apiHandler.GETRequest();
                }
                else
                {
                    response = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @"\APIJson\daily.json";
                }
                //Getting data from json.
                await CreateStatsGraph(deserializeJson.getHistoricalTimeline(response));


                await Task.CompletedTask;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Пример #2
0
        private async Task getAllCountryName()
        {
            string response = string.Empty;

            DeserializeJSON deserializeJson = new DeserializeJSON();

            if (Properties.Settings.Default.isInternet)
            {
                GETHandler apiHandler = new GETHandler();

                apiHandler.endPoint = string.Format("https://disease.sh/v2/countries");
                response            = apiHandler.GETRequest();
            }
            else
            {
                response = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @"\APIJson\countries.json";
            }
            //Getting data from json.
            var countrynamedata = deserializeJson.getAllCountryName(response);


            foreach (var item in countrynamedata)
            {
                comboBox1.Items.Add(string.Format("{0}", item.ToString()));
            }

            await Task.CompletedTask;
        }
        private void BuildHistoricalCacheForInstrument(Instrument InstrumentToCache)
        {
            HistoricalQuote oH = new HistoricalQuote(null, null, null);
            DateTime        oDataFromNeeded          = DateTime.Now;
            bool            bReadMore                = false;
            bool            bAllHistoricalDataNeeded = true;

            string FullPath = GetFullPathOfHistoricalDataForInstrument(InstrumentToCache);

            if (File.Exists(FullPath))
            {
                oH = (HistoricalQuote)DeserializeJSON.DeserializeObjectFromFile(FullPath);
                if (oH == null)
                {
                    return;
                }

                //get the latest date to see if we need to add
                if (oH.HistoricalQuoteDetails != null && oH.HistoricalQuoteDetails.Count > 0 && (DateTime.Now.Date - oH.HistoricalQuoteDetails.Max(h => h.Date).Date.AddDays(1).Date).Days >= 1)
                {
                    bReadMore = true;
                    bAllHistoricalDataNeeded = false;
                    oDataFromNeeded          = oH.HistoricalQuoteDetails.Max(h => h.Date).Date.AddDays(1).Date;
                }
                else
                {
                    //all is up to date!
                    bAllHistoricalDataNeeded = false;
                }
            }

            if (!bReadMore && bAllHistoricalDataNeeded)
            {
                try
                {
                    oH = GetHistoricalQuoteOnline(InstrumentToCache, m_oCurrentExchange);
                    SerializeJSONdata.SerializeObject(oH, FullPath);
                }
                catch (Exception ex)
                {
                    ImperaturGlobal.GetLog().Error(string.Format("Couldn't retreive and save data for {0}", InstrumentToCache.Symbol), ex);
                }
            }
            else if (bReadMore)
            {
                try
                {
                    HistoricalQuote oHnew = GetHistoricalQuoteOnline(InstrumentToCache, m_oCurrentExchange, oDataFromNeeded);

                    oH.HistoricalQuoteDetails.AddRange(oHnew.HistoricalQuoteDetails.Where(h => h.Date.Date > oDataFromNeeded.Date).ToList());
                    SerializeJSONdata.SerializeObject(oH, FullPath);
                }
                catch (Exception ex)
                {
                    ImperaturGlobal.GetLog().Error(string.Format("Couldn't retreive and save data for {0}", InstrumentToCache.Symbol), ex);
                }
            }
        }
Пример #4
0
        private async Task getCountryData(string _countryname)
        {
            try
            {
                string          response        = string.Empty;
                DeserializeJSON deserializeJson = new DeserializeJSON();
                if (Properties.Settings.Default.isInternet)
                {
                    GETHandler apiHandler = new GETHandler();

                    apiHandler.endPoint = string.Format(
                        string.Format("https://disease.sh/v2/countries/{0}", _countryname));
                    response = apiHandler.GETRequest();
                }
                else
                {
                    response = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)
                               + string.Format(@"\APIJson\{0}.json", _countryname);
                }
                //Getting data from json.
                var countrydata = deserializeJson.getSpecificCountryData(response, _countryname);

                //cases, todayCases, deaths, todayDeaths, recovered, active, critical, flag, iso2, iso3
                lblcases.Text      = string.Format("{0:n0}", countrydata.Item1);
                lbltodaycases.Text = string.Format("{0:n0}", countrydata.Item2);
                lbldeath.Text      = string.Format("{0:n0}", countrydata.Item3);
                lbltodaydeath.Text = string.Format("{0:n0}", countrydata.Item4);
                lblrecovered.Text  = string.Format("{0:n0}", countrydata.Item5);
                lblactive.Text     = string.Format("{0:n0}", countrydata.Item6);
                lblcritical.Text   = string.Format("{0:n0}", countrydata.Item7);

                _cases     = countrydata.Item1;
                _recovered = countrydata.Item5;
                _death     = countrydata.Item3;

                if (Properties.Settings.Default.isInternet)
                {
                    pictureBox1.LoadAsync(countrydata.Item8);
                }
                else
                {
                }
                lbliso2.Text = countrydata.Item9;
                lbliso3.Text = countrydata.Item10;

                await Task.CompletedTask;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Пример #5
0
        private async Task downloadJson()
        {
            try
            {
                string response = string.Empty;

                GETHandler apiHandler = new GETHandler();

                DeserializeJSON deserializeJson = new DeserializeJSON();

                apiHandler.endPoint = string.Format("https://disease.sh/v2/countries");
                response            = apiHandler.GETRequest();

                //Getting data from json.
                var countrynamedata = deserializeJson.getAllCountryName(response);
                if (countrynamedata.Count() >= 1)
                {
                    bunifuProgressBar1.MaximumValue = countrynamedata.Count() + 3;

                    foreach (var item in countrynamedata)
                    {
                        SetStatus(Classes.OpenURL.DownloadJson(
                                      string.Format("https://disease.sh/v2/countries/{0}",
                                                    item.ToString()), item.ToString()));
                    }

                    SetStatus(Classes.OpenURL.DownloadJson("https://disease.sh/v2/all", "all"));

                    SetStatus(Classes.OpenURL.DownloadJson("https://disease.sh/v2/countries/", "countries"));

                    SetStatus(Classes.OpenURL.DownloadJson("https://covid19.mathdro.id/api/daily", "daily"));



                    lblDescription.Text = "Download Complete.";
                }
                else
                {
                    bunifuProgressBar1.MaximumValue = 1;
                    SetStatus("Can't Connect to API");
                    bunifuButton1.Visible = true;
                }
                await Task.CompletedTask;
            }
            catch (Exception ex)
            {
                lblDescription.Text = ex.Message;
            }
        }
Пример #6
0
        private async Task getCountriesDataAsync()
        {
            try
            {
                string response = string.Empty;

                DeserializeJSON deserializeJson = new DeserializeJSON();

                if (Properties.Settings.Default.isInternet)
                {
                    GETHandler apiHandler = new GETHandler();
                    apiHandler.endPoint = string.Format("https://disease.sh/v2/countries");
                    response            = apiHandler.GETRequest();
                }
                else
                {
                    response = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @"\APIJson\countries.json";
                }

                DisposeUserControl(flowLayoutPanel1);
                DisposeUserControl(flowLayoutPanel2);

                //Getting data from json.
                var countriesdata = deserializeJson.getCountriesData(response);
                ////putting the data to the label and long
                var newcountriesdata = countriesdata.OrderByDescending(item => item.Item2).ToList().GetRange(0, 3);
                foreach (var item in countriesdata)
                {
                    AddCountryCard(item.Item1, item.Item2, item.Item4);
                }

                foreach (var item in newcountriesdata)
                {
                    AddTopCountryCard(item.Item1, _totalcases, item.Item2, item.Item3);
                }

                countriesdata.Clear();
                newcountriesdata.Clear();

                await Task.CompletedTask;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Пример #7
0
        private void UpdateQuotesFromExternalSource()
        {
            if (m_oQuotes == null)
            {
                //first try to read the file
                try
                {
                    string FileToRead = "";
                    foreach (string f in Directory.EnumerateFiles(string.Format(@"{0}\{1}\{2}", ImperaturGlobal.SystemData.SystemDirectory, ImperaturGlobal.SystemData.QuoteDirectory, ImperaturGlobal.SystemData.DailyQuoteDirectory), string.Format("{0}*", ImperaturGlobal.SystemData.QuoteFile), SearchOption.TopDirectoryOnly))
                    {
                        string time = f.Substring(f.Length - 5).Replace(";", ":");
                        string date = f.Substring(f.Length - 15).Substring(0, 10);
                        if (Convert.ToDateTime(string.Format("{0} {1}", date, time)).CompareTo(DateTime.Now.AddMinutes(
                                                                                                   -Convert.ToDouble(ImperaturGlobal.SystemData.QuoteRefreshTime)
                                                                                                   )) > 0)
                        {
                            FileToRead = f;
                            break;
                        }
                    }


                    if (FileToRead != "")
                    {
                        m_oQuotes = (List <Quote>)DeserializeJSON.DeserializeObjectFromFile(@FileToRead.ToString());
                    }
                    else
                    {
                        m_oQuotes = GetQuotesFromExternalSource(ImperaturGlobal.SystemData.ULR_Quotes).Where(x => x != null).ToList();
                        if (m_oQuotes.Count() > 0)
                        {
                            SerializeJSONdata.SerializeObject(m_oQuotes, string.Format(@"{0}\{1}\{2}\{3}{4}{5}", ImperaturGlobal.SystemData.SystemDirectory, ImperaturGlobal.SystemData.QuoteDirectory, ImperaturGlobal.SystemData.DailyQuoteDirectory, ImperaturGlobal.SystemData.QuoteFile, DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString().Replace(":", ";")));
                        }
                    }
                }
                catch (Exception ex)
                {
                    //read from external source
                    m_oQuotes = GetQuotesFromExternalSource(ImperaturGlobal.SystemData.ULR_Quotes).Where(x => x != null).ToList();
                    //save if results obtained
                }
            }
        }
Пример #8
0
        private async Task GetDataAsync(string _url)
        {
            try
            {
                string response = string.Empty;

                DeserializeJSON deserializeJson = new DeserializeJSON();

                if (Properties.Settings.Default.isInternet)
                {
                    GETHandler apiHandler = new GETHandler();

                    apiHandler.endPoint = string.Format(_url);
                    response            = apiHandler.GETRequest();
                }
                else
                {
                    response = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @"\APIJson\countries.json";
                }

                var covidtogrid = deserializeJson.getDataToGrid(response);

                foreach (var item in covidtogrid)
                {
                    bunifuDataGridView1.Rows.Add(new object[]
                    {
                        item.Item1,
                        item.Item2, item.Item3,
                        item.Item4, item.Item5,
                        item.Item6, item.Item7,
                        item.Rest.Item1
                    });
                }

                await Task.CompletedTask;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Пример #9
0
        private async Task downloadJson1(string ccountry)
        {
            try
            {
                string response = string.Empty;

                GETHandler apiHandler = new GETHandler();

                DeserializeJSON deserializeJson = new DeserializeJSON();

                apiHandler.endPoint = string.Format("https://disease.sh/v2/countries");
                response            = apiHandler.GETRequest();

                var countrynamedata = deserializeJson.getAllCountryName(response);

                Console.WriteLine(countrynamedata.Count().ToString());
                if (countrynamedata.Count() > 0)
                {
                    //Getting data from json.

                    bunifuProgressBar1.MaximumValue = 1;

                    SetStatus(Classes.OpenURL.DownloadJson(
                                  string.Format("https://disease.sh/v2/countries/{0}",
                                                ccountry), ccountry));

                    lblDescription.Text = "Download Complete.";
                }
                else
                {
                    bunifuProgressBar1.MaximumValue = 1;
                    SetStatus("Download Failed");
                    bunifuButton1.Visible = true;
                }
                await Task.CompletedTask;
            }
            catch (Exception ex)
            {
                lblDescription.Text = ex.Message;
            }
        }
Пример #10
0
        private ImperaturData ReadImperaturDataFromSystemLocation(string SystemLocation)
        {
            ImperaturData oD = new ImperaturData();

            try
            {
                oD = (ImperaturData)DeserializeJSON.DeserializeObjectFromFile(string.Format(@"{0}\{1}", SystemLocation, SystemDataFile));
            }
            catch (Exception ex)
            {
                if (Directory.Exists(SystemLocation))
                {
                    ImperaturGlobal.GetLogWithDirectory(SystemLocation).Info("Could not read the system data file!");
                    throw new Exception("SystemDataFile could not be read, major error!");
                }
                else
                {
                    throw new Exception("Systemlocation does not exists, major error!");
                }
            }
            return(oD);
        }
Пример #11
0
        private async Task getCovidDataAsync()
        {
            try
            {
                string response = string.Empty;

                DeserializeJSON deserializeJson = new DeserializeJSON();
                if (Properties.Settings.Default.isInternet)
                {
                    GETHandler apiHandler = new GETHandler();
                    apiHandler.endPoint = string.Format("https://disease.sh/v2/all");
                    response            = apiHandler.GETRequest();
                }
                else
                {
                    response = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @"\APIJson\all.json";
                }
                //Getting data from json. (totalcases, todaycases, deaths, todaydeahts, recovered, active, Updated)
                var coviddata = deserializeJson.getDailyData(response);
                //putting the data to the label and long
                lbltotalcases.Text  = string.Format("{0:n0}", coviddata.Item1);
                lbltodaycases.Text  = string.Format("+{0:n0}", coviddata.Item2);
                lbldeath.Text       = string.Format("{0:n0}", coviddata.Item3);
                lbltodaydeaths.Text = string.Format("+{0:n0}", coviddata.Item4);
                lblrecovered.Text   = string.Format("{0:n0}", coviddata.Item5);
                lblactive.Text      = string.Format("Active: {0:n0}", coviddata.Item6);
                lblupdated.Text     = coviddata.Item7;

                _totalcases = coviddata.Item1;
                _death      = coviddata.Item2;
                _recovered  = coviddata.Item3;

                await Task.CompletedTask;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Пример #12
0
 public static HistoricalQuote HistoricalQuote(Instrument Instrument)
 {
     return((HistoricalQuote)DeserializeJSON.DeserializeObjectFromFile(GetHistoricalPriceCacheBuilder().GetFullPathOfHistoricalDataForInstrument(Instrument)));
 }
Пример #13
0
        public static Task PasteTask(BehaviorSource behaviorSource, TaskSerializer serializer)
        {
            Dictionary <int, Task> dictionary = new Dictionary <int, Task>();

            return(DeserializeJSON.DeserializeTask(behaviorSource, MiniJSON.Deserialize(serializer.serialization) as Dictionary <string, object>, ref dictionary, serializer.unityObjects));
        }