Example #1
0
        public async Task RefreshTollRoadsAsync(CancellationToken token)
        {
            try
            {
                var currentTime           = DateTime.UtcNow;
                var timeSpan              = TimeSpan.FromDays(1);
                var shouldUpdateTollRoads = currentTime - _storedSettingsService.LastSyncDateTime > timeSpan;

                if (shouldUpdateTollRoads)
                {
                    var list = await _serverApiService.RefreshTollRoadsAsync(_storedSettingsService.LastSyncDateTime.UnixTime(), token);

                    if (list != null)
                    {
                        _storedSettingsService.LastSyncDateTime = currentTime;
                        _dataBaseStorage.InsertOrUpdateAllTollRoads(list);
                    }
                    else
                    {
                        Insights.Report(new NullReferenceException {
                            Source = "Response, has no roads!"
                        });
                        Mvx.Resolve <IUserInteraction>().Alert("App has not get any roads!", null, "Warning", "Ok");
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }