/// <summary> /// The user asked a refresh seekios position on other device /// </summary> public void RefreshSeekiosPositionSignalR(string uidDevice, string idSeekiosStr) { if (string.IsNullOrEmpty(idSeekiosStr)) { return; } if (uidDevice == App.UidDevice) { return; } int idSeekios = 0; if (int.TryParse(idSeekiosStr, out idSeekios)) { var seekios = App.CurrentUserEnvironment.LsSeekios.FirstOrDefault(x => x.Idseekios == idSeekios); if (seekios != null) { // If the seekios is already in refresh state if (LsSeekiosOnDemand.Any(x => x.Seekios.Idseekios == seekios.Idseekios)) { return; } // Udpate the seekios var index = App.CurrentUserEnvironment.LsSeekios.IndexOf(App.CurrentUserEnvironment.LsSeekios.First(x => x.Idseekios == seekios.Idseekios)); App.CurrentUserEnvironment.LsSeekios[index].DateLastOnDemandRequest = DateTime.Now; App.CurrentUserEnvironment.LsSeekios[index].HasGetLastInstruction = false; App.Locator.DetailSeekios.SeekiosSelected = App.CurrentUserEnvironment.LsSeekios[index]; if (_dispatcherService != null) { _dispatcherService.Invoke(() => { // Add the new seekios is the refresh seekios list AddSeekiosOnDemand(seekios, DateTime.Now.AddSeconds(App.TIME_FOR_REFRESH_SEEKIOS_IN_SECOND)); // Raise event for update UI App.Locator.ListSeekios.ActivityNeedsUIToBeUpdated = true; App.Locator.DetailSeekios.ActivityNeedsUIToBeUpdated = true; OnSeekiosRefreshRequestSent?.Invoke(null, null); App.RaiseSeekiosInformationChangedEverywhere(seekios.Idseekios); }); } } } }
/// <summary> /// Refresh seekios position /// </summary> public async Task <bool> RefreshSeekiosPosition() { var seekiosToRefresh = App.Locator.DetailSeekios.SeekiosSelected; try { // If the seekios is already in refresh state if (LsSeekiosOnDemand.Any(x => x.Seekios.Idseekios == seekiosToRefresh.Idseekios)) { return(false); } // If user has enough credits int creditsDispo = 0; if (!int.TryParse(Helper.CreditHelper.TotalCredits, out creditsDispo)) { return(false); } if (creditsDispo <= 0) { var msg = Resources.UserNoRequestLeft; var title = Resources.UserNoRequestLeftTitle; await _dialogService.ShowMessage(msg, title); return(false); } // If the seekios is in power saving, cancel the request if (App.CurrentUserEnvironment.LsSeekios.First(x => x.Idseekios == seekiosToRefresh.Idseekios).IsInPowerSaving == true) { await _dialogService.ShowMessage(Resources.PowerSavingOn , Resources.PowerSavingOnTitle , Resources.PowerSavingTuto , Resources.Close, (result2) => { if (result2) { App.Locator.Parameter.GoToTutorialPowerSaving(); } }); return(false); } // Make the request in BDD _dialogService.ShowLoadingLayout(); var result = await _dataService.RefreshSeekiosLocation(seekiosToRefresh.Idseekios); if (result != 1) { var msg = Resources.RefreshSeekiosFailed; var title = Resources.RefreshSeekiosFailedTitle; _dispatcherService.Invoke(async() => await _dialogService.ShowMessage(msg, title)); } _dialogService.HideLoadingLayout(); // Udpate the seekios var index = App.CurrentUserEnvironment.LsSeekios.IndexOf(App.CurrentUserEnvironment.LsSeekios.First(x => x.Idseekios == seekiosToRefresh.Idseekios)); App.CurrentUserEnvironment.LsSeekios[index].DateLastOnDemandRequest = DateTime.Now; App.CurrentUserEnvironment.LsSeekios[index].HasGetLastInstruction = false; App.Locator.DetailSeekios.SeekiosSelected = App.CurrentUserEnvironment.LsSeekios[index]; // Add the new seekios is the refresh seekios list AddSeekiosOnDemand(seekiosToRefresh, DateTime.Now.AddSeconds(App.TIME_FOR_REFRESH_SEEKIOS_IN_SECOND)); // Raise event for update UI OnSeekiosRefreshRequestSent?.Invoke(null, null); return(true); } catch (TimeoutException) { _dispatcherService.Invoke(async() => await _dialogService.ShowError( Resources.TimeoutError , Resources.TimeoutErrorTitle , Resources.Close, null)); } catch (WebException) { _dispatcherService.Invoke(async() => await _dialogService.ShowError( Resources.TimeoutError , Resources.TimeoutErrorTitle , Resources.Close, null)); } catch (Exception) { _dispatcherService.Invoke(async() => await _dialogService.ShowError( Resources.UnexpectedError , Resources.UnexpectedErrorTitle , Resources.Close, null)); } _dialogService.HideLoadingLayout(); return(false); }