Example #1
0
        public async Task RunChecker(CancellationToken token)
        {
tryAgain:
            try
            {
                await Task.Run(async() =>
                {
                    for (long i = 0; i < long.MaxValue; i++)
                    {
                        token.ThrowIfCancellationRequested();
                        await Task.Delay(120000);

                        var message = await EarthQuakeService.InfoEarthQuake();
                        Device.BeginInvokeOnMainThread(() =>
                        {
                            MessagingCenter.Send <EarthQuake>(message, "TickedMessage");
                        });
                    }
                }, token);
            }
            catch (Exception)
            {
                goto tryAgain;
            }
        }
Example #2
0
        private async Task RefreshData()
        {
            earthQuakeList.Clear();
            var data = await EarthQuakeService.InfoEarthQuake(null);

            try
            {
                foreach (var item in data.result)
                {
                    EarthQuakeList.Add(new Result
                    {
                        Location       = item.Location,
                        Date           = item.Date,
                        Ml             = item.Ml,
                        Depth          = item.Depth,
                        ShareButton    = item.Location + "@" + item.Ml + "@" + item.Date,
                        LocationButton = item.Location + "@" + item.Longitude + "@" + item.Latitude
                    });
                }
                TopLocation = data.result[0].Location;
                TopMl       = data.result[0].Ml;
                TopDepth    = data.result[0].Depth;
                TopDate     = data.result[0].Date;
                char[] ayrac         = { '(' };
                var    shortLocation = data.result[0].Location.Split(ayrac);
                TopShortLocation    = shortLocation[1].ToString().Replace(")", "");
                TopShareInformation = data.result[0].Location + "@" + data.result[0].Ml + "@" + data.result[0].Date;

                var res = (from s in EarthQuakeList
                           where Convert.ToDateTime(s.Date) >= DateTime.Now.AddDays(-1)
                           select s).OrderByDescending(c => c.Ml).First();

                TodayHighestEarthQuake = "Bugün yaşanan en büyük deprem : " + res.Location + " - Şiddet " + res.Ml + "";

                OnPropertyChanged(nameof(EarthQuakeList));

                // TODO : bug / check..
                //DependencyService.Get<IMessage>().LongMessage("Deprem verileri güncellendi...");
            }
            catch (System.Exception ex)
            {
                TopShortLocation = data.result[0].Location;
            }
        }
Example #3
0
        public async Task RefreshData(EarthQuake earthQuakeData)
        {
            try
            {
                #region | Veri Çekimi İşlemi |

                earthQuakeList.Clear();

                if (earthQuakeData == null)
                {
                    earthQuakeData = await EarthQuakeService.InfoEarthQuake();
                }

                var res = (from s in earthQuakeData.result
                           where s.Other == "-" && s.Country == "Türkiye"
                           select s).ToList();

                foreach (var item in res)
                {
                    #region | Boş gelen Location değerini doldurma işlemi |

                    if (item.Location == "- (-)")
                    {
                        char[] _ayrac = { '(' };
                        item.Other = item.Other + "(";
                        var newValue = item.Other.Split(_ayrac);
                        if (newValue.Length > 1)
                        {
                            /*char[] _ayracTwo = { '.' };
                             * var newValueTwo = item.Other.Split(_ayracTwo);
                             * var _countyValue = newValueTwo[1].ToString();
                             *
                             * string _city = newValue[1].ToString().Replace(")", "").Replace(" ", "").Replace(",", "");
                             *
                             * string _county = _countyValue.Replace((_city),"").Replace(")", "").Replace("(", "");*/
                            item.Location = newValue[1].ToString().Replace(")", "").Replace(" ", "").Replace(",", "");
                        }

                        if (newValue[1].ToString() == "")
                        {
                            item.Location = newValue[0].ToString().Replace(")", "").Replace(" ", "").Replace(",", "");
                        }
                    }
                    #endregion

                    #region | Veri basma işlemi |

                    Location userLocation       = new Location(Latitude, Longitude);
                    Location earthquakeLocation = new Location(Convert.ToDouble(item.Latitude), Convert.ToDouble(item.Longitude));
                    double   distanceKM         = Location.CalculateDistance(userLocation, earthquakeLocation, DistanceUnits.Kilometers);

                    EarthQuakeList.Add(new Result
                    {
                        Location       = item.Location,
                        Date           = item.Date,
                        Ml             = item.Ml,
                        Depth          = item.Depth,
                        Latitude       = item.Latitude,
                        Longitude      = item.Longitude,
                        ShareButton    = item.Location + "@" + item.Ml + "@" + item.Date + "@" + item.City,
                        LocationButton = item.Location + "@" + item.Longitude + "@" + item.Latitude,
                        Distance       = Convert.ToInt32(distanceKM).ToString() + "km"
                    });

                    #endregion
                }

                #endregion

                #region | Bugün yaşanan en büyük deprem |

                var todayRes = (from s in res
                                where DateTime.ParseExact(s.Date, "dd.MM.yyyy HH:mm:ss", CultureInfo.InvariantCulture) >= DateTime.Now.AddDays(-1)
                                select s).OrderByDescending(c => c.Ml).First();

                TodayHighestEarthQuake = "Bugün yaşanan en büyük deprem : " + todayRes.Location + " - Şiddet " + todayRes.Ml + "";
                #endregion

                #region | En üstteki deprem verilerini gösterme işlemi |

                TopInformation(res[0]);

                #endregion

                DependencyService.Get <IMessage>().LongMessage("Deprem verileri güncellendi...");
            }
            catch (System.Exception ex)
            {
            }
        }
Example #4
0
 public EarthQuakeController(EarthQuakeService earthQuakeService)
 {
     _earthQuakeService = earthQuakeService;
 }