public string DisplayModeRefreshTimeTracking(ModeDTO mode) { if (mode != null && !string.IsNullOrEmpty(mode.Trame)) { var param = mode.Trame.Split(';'); if (param?.Count() >= 2) { int refreshValue = 0; int.TryParse(param[1], out refreshValue); int[] values = new int[] { 1, 2, 3, 4, 5, 10, 15, 30, 60, 120, 180, 240, 300, 360, 720, 1440 }; if (values.Contains(refreshValue)) { return(string.Format(Resources.RefreshRate , refreshValue < 60 ? refreshValue + " min" : refreshValue / 60 + " h")); } else { return(Resources.No); } } else { return(Resources.No); } } else { return(Resources.No); } }
/// <summary> /// Add a seekios to the list OnDemand /// Start the count down /// </summary> public void AddSeekiosOnTracking(SeekiosDTO seekios, ModeDTO mode) { // if a seekios on tracking is already present (protection against double entry) var seekiosOnTrackingAlreadyCreated = App.Locator.Map.LsSeekiosOnTracking.FirstOrDefault(x => x.Seekios.Idseekios == seekios.Idseekios); if (seekiosOnTrackingAlreadyCreated != null) { if (seekiosOnTrackingAlreadyCreated.Timer != null && seekiosOnTrackingAlreadyCreated.Timer.IsRunning) { seekiosOnTrackingAlreadyCreated.Timer.Stop(); } App.Locator.Map.LsSeekiosOnTracking.RemoveAll(x => x.Seekios.Idseekios == seekios.Idseekios); } // setup the seekios on demand var seekiosOnTracking = new SeekiosOnTracking() { Seekios = seekios, Mode = mode }; // get the refresh time var refreshTime = 0; var param = mode.Trame.Split(';'); if (mode.ModeDefinition_idmodeDefinition == (int)ModeDefinitionEnum.ModeZone) { if (param?.Count() > 1) { if (int.TryParse(param[1], out refreshTime)) { seekiosOnTracking.RefreshTime = refreshTime; } } } else { if (param?.Count() > 1) { if (int.TryParse(param[1], out refreshTime)) { seekiosOnTracking.RefreshTime = refreshTime; } } } seekiosOnTracking.Timer = new Timers.Timer(); seekiosOnTracking.Timer.Interval = new TimeSpan(0, 0, 1); // add the seekios in the list that contains all the seekios in refreshing state (OnDemand) App.Locator.Map.LsSeekiosOnTracking.Add(seekiosOnTracking); }
/// <summary> /// Deletes the mode. /// </summary> public async Task <bool> DeleteMode(ModeDTO mode) { App.Locator.ModeSelection.SeekiosUpdated = _seekiosSelected; var result = await App.Locator.ModeSelection.DeleteMode(mode); if (result) { _seekiosSelected.HasGetLastInstruction = false; if (App.Locator.BaseMap.LsSeekiosAlertState.Contains(_seekiosSelected.Idseekios)) { App.Locator.BaseMap.LsSeekiosAlertState.Remove(_seekiosSelected.Idseekios); } SetDataAndStyleToView(); } return(result); }
/// <summary> /// Used to know if the actual tracking is probably missing positions /// If we miss only one position /// </summary> private int CalculateModeTrackingExpectedPositionNumber(ModeDTO mode) { if (mode == null) { return(-1); } DateTime creationDate = mode.DateModeCreation; int refreshRateMin = int.Parse(mode.Trame); double minutesGoneSinceActivation = (DateTime.Now - creationDate).TotalMinutes; // On est pas assez précis pour des valeurs de tracking plus élevées que 1/5min je pense... A voir int positionExpectedNumber = (int)(minutesGoneSinceActivation / refreshRateMin); return(positionExpectedNumber); }
private void InitTimers() { DateTime dateEndRefreshTimer; ModeDTO mode = null; foreach (var seekios in App.CurrentUserEnvironment.LsSeekios) { // seekios on demand if (seekios.DateLastOnDemandRequest.HasValue) { dateEndRefreshTimer = seekios.DateLastOnDemandRequest.Value.AddSeconds(App.TIME_FOR_REFRESH_SEEKIOS_IN_SECOND); if (dateEndRefreshTimer > DateTime.Now) { App.Locator.Map.AddSeekiosOnDemand(seekios, dateEndRefreshTimer); } } // seekios on tracking mode mode = App.CurrentUserEnvironment.LsMode.FirstOrDefault(x => x.Seekios_idseekios == seekios.Idseekios); if (mode != null) { if (mode.ModeDefinition_idmodeDefinition == (int)Enum.ModeDefinitionEnum.ModeTracking) { App.Locator.Map.AddSeekiosOnTracking(seekios, mode); } else if (mode.ModeDefinition_idmodeDefinition == (int)Enum.ModeDefinitionEnum.ModeZone && mode.StatusDefinition_idstatusDefinition != (int)Enum.StatutDefinitionEnum.RAS) { App.Locator.Map.AddSeekiosOnTracking(seekios, mode); } else if (mode.ModeDefinition_idmodeDefinition == (int)Enum.ModeDefinitionEnum.ModeDontMove && mode.StatusDefinition_idstatusDefinition != (int)Enum.StatutDefinitionEnum.RAS) { App.Locator.Map.AddSeekiosOnTracking(seekios, mode); } } } }
/// <summary> /// Select a mode /// </summary> public async Task <bool> SelectMode(ModeDefinitionEnum modeDefinition) { try { // User is out of requests if (int.Parse(CreditHelper.TotalCredits) <= 0) { await _dialogService.ShowMessage(Resources.UserNoRequestLeft , Resources.UserNoRequestLeftTitle); return(false); } // User has no internet if (!App.DeviceIsConnectedToInternet) { await _dialogService.ShowMessage(Resources.NoInternetMessage , Resources.NoInternetTitle); return(false); } // If a mode is already active on the seekios, we display custom popup var modeActive = App.CurrentUserEnvironment.LsMode.FirstOrDefault(el => el.Seekios_idseekios == App.Locator.DetailSeekios.SeekiosSelected.Idseekios); if (modeActive != null) { if (!await _dialogService.ShowChangeModePopup(Resources.ModeChangeTitle , Resources.ModeChangePowerSaving , modeActive.ModeDefinition_idmodeDefinition , (int)modeDefinition , SeekiosUpdated.IsInPowerSaving)) { return(false); } } // Display loading layout _dialogService.ShowLoadingLayout(); // Settings to save offline the preferences for mode zone / don't move var trackingSetting = App.Locator.ModeSelection.LsTrackingSetting.FirstOrDefault(x => x.IdSeekios == App.Locator.DetailSeekios.SeekiosSelected.Idseekios && x.ModeDefinition == modeDefinition); if (trackingSetting == null) { trackingSetting = new TrackingSetting() { IdSeekios = SeekiosUpdated.Idseekios, ModeDefinition = modeDefinition, RefreshTime = MapViewModelBase.RefreshTime, }; App.Locator.ModeSelection.LsTrackingSetting.Add(trackingSetting); } else { trackingSetting.RefreshTime = MapViewModelBase.RefreshTime; } // Create the new mode to add var modeToAddInDb = new ModeDTO { Seekios_idseekios = SeekiosUpdated.Idseekios, Trame = string.Empty, Device_iddevice = App.CurrentUserEnvironment.Device != null ? App.CurrentUserEnvironment.Device.Iddevice : 0, }; // Save the mode in database int idMode = 0; var timeDiffHours = Math.Ceiling((DateTime.Now - DateTime.UtcNow).TotalHours); switch (modeDefinition) { case ModeDefinitionEnum.ModeDontMove: trackingSetting.IsEnable = App.Locator.ModeDontMove.IsTrackingSettingEnable; trackingSetting.IsPowerSavingEnabled = App.Locator.ModeDontMove.IsPowerSavingEnabled; modeToAddInDb.Trame = string.Format("{0};{1}", timeDiffHours, MapViewModelBase.RefreshTime == 0 ? string.Empty : MapViewModelBase.RefreshTime.ToString()); modeToAddInDb.IsPowerSavingEnabled = App.Locator.ModeDontMove.IsPowerSavingEnabled; idMode = await _dataService.InsertModeDontMove(modeToAddInDb, App.Locator.ModeDontMove.LsAlertsModeDontMove); break; case ModeDefinitionEnum.ModeZone: trackingSetting.IsEnable = App.Locator.ModeZone.IsTrackingSettingEnable; trackingSetting.IsPowerSavingEnabled = App.Locator.ModeZone.IsPowerSavingEnabled; modeToAddInDb.Trame = string.Format("{0};{1}", timeDiffHours, App.Locator.ModeZone.CodeTrame(App.Locator.ModeZone.LsAreaCoordsMap)); modeToAddInDb.IsPowerSavingEnabled = App.Locator.ModeZone.IsPowerSavingEnabled; idMode = await _dataService.InsertModeZone(modeToAddInDb, App.Locator.ModeZone.LsAlertsModeZone); break; case ModeDefinitionEnum.ModeTracking: modeToAddInDb.Trame = string.Format("{0};{1}", timeDiffHours, MapViewModelBase.RefreshTime == 0 ? string.Empty : MapViewModelBase.RefreshTime.ToString()); modeToAddInDb.IsPowerSavingEnabled = App.Locator.ModeTracking.IsPowerSavingEnabled; trackingSetting.IsPowerSavingEnabled = App.Locator.ModeTracking.IsPowerSavingEnabled; idMode = await _dataService.InsertModeTracking(modeToAddInDb); break; default: return(false); } // Update power saving state only if the current state of power saving was off if (!App.CurrentUserEnvironment.LsSeekios.First(x => x.Idseekios == SeekiosUpdated.Idseekios).IsInPowerSaving) { SeekiosUpdated.IsInPowerSaving = trackingSetting.IsPowerSavingEnabled; App.CurrentUserEnvironment.LsSeekios.First(x => x.Idseekios == SeekiosUpdated.Idseekios).IsInPowerSaving = trackingSetting.IsPowerSavingEnabled; } // Save the setting tracking offline _saveDataService.SaveData(App.TrackingSetting, JsonConvert.SerializeObject(LsTrackingSetting)); // Update the seekios if (idMode <= 0) { return(false); } SeekiosUpdated.HasGetLastInstruction = false; if (MapViewModelBase.Seekios != null) { MapViewModelBase.Seekios.HasGetLastInstruction = false; } // We locally delete the last mode and the alerts associate foreach (var mode in App.CurrentUserEnvironment.LsMode.Where(x => x.Seekios_idseekios == SeekiosUpdated.Idseekios)) { var idAlerts = App.CurrentUserEnvironment.LsAlert.Where(x => x.IdMode == mode.Idmode).Select(x => x.IdAlert).ToList(); foreach (var idAlert in idAlerts) { App.CurrentUserEnvironment.LsAlertRecipient.RemoveAll(x => x.IdAlert == idAlert); App.CurrentUserEnvironment.LsAlert.RemoveAll(x => x.IdAlert == idAlert); } } App.CurrentUserEnvironment.LsMode.RemoveAll(x => x.Seekios_idseekios == SeekiosUpdated.Idseekios); // Add the mode in local data var modeToAddInLocal = new ModeDTO() { Idmode = idMode, CountOfTriggeredAlert = 0, DateModeCreation = DateTime.UtcNow, Device_iddevice = modeToAddInDb.Device_iddevice, Seekios_idseekios = modeToAddInDb.Seekios_idseekios, StatusDefinition_idstatusDefinition = (int)StatutDefinitionEnum.RAS, Trame = modeToAddInDb.Trame, ModeDefinition_idmodeDefinition = (int)modeDefinition, IsPowerSavingEnabled = modeToAddInDb.IsPowerSavingEnabled }; App.CurrentUserEnvironment.LsMode.Add(modeToAddInLocal); // Handle alerts if it's required switch (modeDefinition) { case ModeDefinitionEnum.ModeDontMove: // configure a bool to execute 2 back actions App.Locator.ListAlert.Seekios = SeekiosUpdated; var dontMoveAlerts = await _dataService.AlertsByMode(modeToAddInDb); if (dontMoveAlerts != null) { foreach (AlertDTO a in dontMoveAlerts) { App.CurrentUserEnvironment.LsAlert.Add(a); } } // Pourquoi on utilise le ModeZoneViewModel pour le DontMove??? App.Locator.ModeDontMove.LsAlertsModeDontMove?.Clear(); break; case ModeDefinitionEnum.ModeZone: // il faut aussi aller chercher les alertes pour le nouveau mode avec leur nouveaux ids... // vider la liste dans ModeZoneVM + ajouter les nlles alertes dans LsAlertes var zoneAlerts = await _dataService.AlertsByMode(modeToAddInDb); if (zoneAlerts != null) { foreach (AlertDTO a in zoneAlerts) { App.CurrentUserEnvironment.LsAlert.Add(a); } } App.Locator.ModeZone.LsAlertsModeZone?.Clear(); break; } // Delete the seekios tracking object because it's a new mode var seekiosOnTrackingToDelete = App.Locator.Map.LsSeekiosOnTracking.FirstOrDefault(x => x.Seekios.Idseekios == SeekiosUpdated.Idseekios); if (seekiosOnTrackingToDelete != null) { if (seekiosOnTrackingToDelete.Timer.IsRunning) { seekiosOnTrackingToDelete.Timer.Stop(); } App.Locator.Map.LsSeekiosOnTracking.RemoveAll(x => x.Seekios.Idseekios == SeekiosUpdated.Idseekios); } // Setup a new seekios tracking object for a new timer if (modeToAddInLocal.ModeDefinition_idmodeDefinition == (int)ModeDefinitionEnum.ModeTracking) { App.Locator.Map.AddSeekiosOnTracking(SeekiosUpdated, modeToAddInLocal); } // Hide loading layout _dialogService.HideLoadingLayout(); 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); }
/// <summary> /// Delete a mode /// </summary> public async Task <bool> DeleteMode(ModeDTO mode) { try { // Display the popup to confirm the action if (mode.StatusDefinition_idstatusDefinition == (int)StatutDefinitionEnum.SeekiosMoved || mode.StatusDefinition_idstatusDefinition == (int)StatutDefinitionEnum.SeekiosOutOfZone) { if (await _dialogService.ShowMessage(string.Empty , Resources.DeleteModeContent , Resources.DeleteModeYes , Resources.DeleteModeNo , null) == false) { return(false); } } else if (App.CurrentUserEnvironment.LsSeekios.First(x => x.Idseekios == App.Locator.DetailSeekios.SeekiosSelected.Idseekios).IsInPowerSaving == true) { if (await _dialogService.ShowMessage(Resources.DeleteModePowerSavingOnContent , Resources.DeleteModeContent , Resources.DeleteModeYes , Resources.DeleteModeNo , null) == false) { return(false); } } else { if (await _dialogService.ShowMessage(string.Empty , Resources.DeleteModeContent , Resources.DeleteModeYes , Resources.DeleteModeNo , null) == false) { return(false); } } // Stop the timer if the seekios is in tracking _dialogService.ShowLoadingLayout(); var seekiosOnTracking = App.Locator.Map.LsSeekiosOnTracking.FirstOrDefault(x => x.Seekios.Idseekios == App.Locator.DetailSeekios.SeekiosSelected.Idseekios); if (seekiosOnTracking != null) { if (seekiosOnTracking.Timer.IsRunning) { seekiosOnTracking.Timer.Stop(); } App.Locator.Map.LsSeekiosOnTracking.Remove(seekiosOnTracking); if (App.Locator.BaseMap.LsSeekiosAlertState.Contains(App.Locator.DetailSeekios.SeekiosSelected.Idseekios)) { App.Locator.BaseMap.LsSeekiosAlertState.Remove(App.Locator.DetailSeekios.SeekiosSelected.Idseekios); } } // Delete the mode in database var result = await _dataService.DeleteMode(mode.Idmode.ToString()); _dialogService.HideLoadingLayout(); if (result == 1) { // Delete the last mode and the alerts associate in local memory var idAlerts = App.CurrentUserEnvironment.LsAlert.Where(x => x.IdMode == mode.Idmode).Select(x => x.IdAlert); foreach (var idAlert in idAlerts) { App.CurrentUserEnvironment.LsAlertRecipient.RemoveAll(x => x.IdAlert == idAlert); App.CurrentUserEnvironment.LsAlert.RemoveAll(x => x.IdAlert == idAlert); } App.CurrentUserEnvironment.LsMode.RemoveAll(x => x.Idmode == mode.Idmode); //await _dialogService.ShowMessage(Resources.DeleteModeSuccess, Resources.DeleteModeSuccessTitle); 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); }
/// <summary> /// Create popup to select a mode /// </summary> /// <param name="callback1">callback for the first button</param> /// <param name="callback2">callback for the second button</param> /// <param name="callback3">callback for the third button</param> /// <returns></returns> public static UIAlertController CreateAlertToPickMode(Action callback1, Action callback2, Action callback3, Action callback4, ModeDTO mode) { var actionSheetAlert = UIAlertController.Create("Modes", "", UIAlertControllerStyle.Alert); int sizeImage = 40; var buttonModeZone = UIAlertAction.Create("Zone" , UIAlertActionStyle.Default , (action) => callback1.Invoke()); var buttonModeDontMove = UIAlertAction.Create("Don't Move" , UIAlertActionStyle.Default , (action) => callback2.Invoke()); var buttonModeTracking = UIAlertAction.Create("Tracking" , UIAlertActionStyle.Default , (action) => callback3.Invoke()); var imageModeZone = UIImage.FromBundle("ModeZone").ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal); var resizeImageModeZone = ImageHelper.ResizeImage(imageModeZone, sizeImage, sizeImage).ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal); var imageModeDontMove = UIImage.FromBundle("ModeDontMove").ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal); var resizeImageModeDontMove = ImageHelper.ResizeImage(imageModeDontMove, sizeImage, sizeImage).ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal); var imageModeTracking = UIImage.FromBundle("ModeTracking").ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal); var resizeImageModeTracking = ImageHelper.ResizeImage(imageModeTracking, sizeImage, sizeImage).ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal); buttonModeZone.SetValueForKey(resizeImageModeZone , new NSString("image")); buttonModeDontMove.SetValueForKey(resizeImageModeDontMove , new NSString("image")); buttonModeTracking.SetValueForKey(resizeImageModeTracking , new NSString("image")); actionSheetAlert.AddAction(buttonModeZone); actionSheetAlert.AddAction(buttonModeDontMove); actionSheetAlert.AddAction(buttonModeTracking); if (mode != null) { if (mode.ModeDefinition_idmodeDefinition == (int)Enum.ModeDefinitionEnum.ModeZone) { buttonModeZone.SetValueForKey(UIColor.FromRGB(98, 218, 115), new NSString("titleTextColor")); } else if (mode.ModeDefinition_idmodeDefinition == (int)Enum.ModeDefinitionEnum.ModeDontMove) { buttonModeDontMove.SetValueForKey(UIColor.FromRGB(98, 218, 115), new NSString("titleTextColor")); } else if (mode.ModeDefinition_idmodeDefinition == (int)Enum.ModeDefinitionEnum.ModeTracking) { buttonModeTracking.SetValueForKey(UIColor.FromRGB(98, 218, 115), new NSString("titleTextColor")); } var buttonDeleteMode = UIAlertAction.Create("Delete Mode" , UIAlertActionStyle.Default , (action) => callback4.Invoke()); buttonDeleteMode.SetValueForKey(UIColor.FromRGB(255, 76, 57), new NSString("titleTextColor")); var imageModeDelete = UIImage.FromBundle("Trash").ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal); var resizeImageModeDelete = ImageHelper.ResizeImage(imageModeDelete, sizeImage, sizeImage).ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal); buttonDeleteMode.SetValueForKey(resizeImageModeDelete, new NSString("image")); actionSheetAlert.AddAction(buttonDeleteMode); imageModeDelete.Dispose(); resizeImageModeDelete.Dispose(); } actionSheetAlert.AddAction(UIAlertAction.Create("Fermer", UIAlertActionStyle.Cancel, null)); imageModeZone.Dispose(); resizeImageModeZone.Dispose(); imageModeDontMove.Dispose(); resizeImageModeDontMove.Dispose(); imageModeTracking.Dispose(); resizeImageModeTracking.Dispose(); return(actionSheetAlert); }
private void SetData() { _user = new UserDTO() { DateLastConnection = DateTime.Now, DateLocation = DateTime.Now, DefaultTheme = 0, Email = "*****@*****.**", FirstName = "TestFirstName", GCMRegistrationToken = "noToken", IsValidate = true, LastName = "TestLastName", LocationLatitude = 0, LocationLongitude = 0, NumberView = 1, Password = "******", PhoneNumber = "33|64564866", RemainingRequest = 1000, SocialNetworkType = 0, SocialNetworkUserId = null, UserPicture = null }; DataService.Email = _user.Email; DataService.Pass = _user.Password; _seekios = new SeekiosDTO() { Idseekios = _idseekios, SeekiosName = "UnitTestSeekios", SeekiosPicture = null, SeekiosDateCreation = DateTime.Now, BatteryLife = 99, SignalQuality = 50, DateLastCommunication = DateTime.Now, LastKnownLocation_longitude = 0.0, LastKnownLocation_latitude = 0.0, LastKnownLocation_altitude = 0.0, LastKnownLocation_accuracy = 0.0, LastKnownLocation_dateLocationCreation = DateTime.Now, Subscription_idsubscription = 2, Category_idcategory = 1, User_iduser = _iduser, HasGetLastInstruction = true, IsAlertLowBattery = true, IsInPowerSaving = false, PowerSaving_hourStart = 0, PowerSaving_hourEnd = 0, AlertSOS_idalert = null, IsRefreshingBattery = false, FreeCredit = 100000000 }; _mode = new ModeDTO() { DateModeCreation = DateTime.Now, Trame = "1", NotificationPush = 0, CountOfTriggeredAlert = 0, LastTriggeredAlertDate = DateTime.Now, Seekios_idseekios = _idseekios, ModeDefinition_idmodeDefinition = (int)SeekiosApp.Enum.ModeDefinitionEnum.ModeTracking, StatusDefinition_idstatusDefinition = 1 }; alertes.Add(new AlertWithRecipientDTO() { IdAlertType = 1, Title = "Test", Content = "Test" }); _alert = new AlertDTO() { IdAlertType = 1, IdMode = _idmode, Title = "Test", Content = "Test" }; var recipients = new List <AlertRecipientDTO>(); recipients.Add(new AlertRecipientDTO() { Email = "*****@*****.**", DisplayName = "TestDisplayname", }); _alertwithrecipient = new AlertWithRecipientDTO() { IdAlert = _idalert, IdAlertType = 3, IdMode = _idmode, Title = "Test", Content = "Test", LsRecipients = recipients }; _listAlertWithRecipient.Add(_alertwithrecipient); }