コード例 #1
0
        public async Task AddFavoriteAlert(AlertFavoriteDTO alertFavorite)
        {
            try
            {
                if (alertFavorite == null) return;

                if (!await CheckIfEmptyFieldInAlertFavorite(alertFavorite))
                {
                    if (await CheckIfAlertFavoriteAlreadyExist(alertFavorite))
                    {
                        alertFavorite.IdUser = App.CurrentUserEnvironment.User.IdUser;
                        App.CurrentUserEnvironment.LsAlertFavorites.Add(alertFavorite);
                        var id = await _dataService.InsertAlertFavorite(alertFavorite);
                        alertFavorite.IdAlertFavorite = id;
                    }
                }
            }
            catch (WebException)
            {
                await _dialogService.ShowError(Resources.TimeoutError
                    , Resources.WebErrorTitle
                    , Resources.WebErrorButtonText, null);
            }
            catch (TimeoutException e)
            {
                await _dialogService.ShowError(e, Resources.TimeoutErrorTitle
                    , Resources.WebErrorButtonText
                    , null);
            }
            return;
        }
コード例 #2
0
 public async Task <int> InsertPurchase(string key, string data, string signature, PlateformeVersionEnum platform)
 {
     try
     {
         var purchase = new PurchaseDTO()
         {
             IdUser     = App.CurrentUserEnvironment.User.IdUser,
             InnerData  = data,
             Signature  = signature,
             StoreId    = (int)platform,
             VersionApp = App.Locator.Login.VersionApplication,
             KeyProduct = key
         };
         return(await _dataService.InsertInAppPurchase(purchase));
     }
     catch (TimeoutException)
     {
         await _dialogService.ShowError(
             Resources.TimeoutError
             , Resources.TimeoutErrorTitle
             , Resources.Close, null);
     }
     catch (WebException)
     {
         await _dialogService.ShowError(
             Resources.TimeoutError
             , Resources.TimeoutErrorTitle
             , Resources.Close, null);
     }
     catch (Exception)
     {
         await _dialogService.ShowError(
             Resources.UnexpectedError
             , Resources.UnexpectedErrorTitle
             , Resources.Close, null);
     }
     return(-1);
 }
コード例 #3
0
        public async Task <bool> GetTransactionHistoricByUser()
        {
            try
            {
                var response = await _dataService.OperationHistoric();

                if (response == null)
                {
                    await _dialogService.ShowMessage(Resources.UnexpectedError, Resources.UnexpectedErrorTitle);
                }
                LsOperation = response != null ? response : LsOperation;
                return(true);
            }
            catch (TimeoutException)
            {
                await _dialogService.ShowError(
                    Resources.TimeoutError
                    , Resources.TimeoutErrorTitle
                    , Resources.Close, null);
            }
            catch (WebException)
            {
                await _dialogService.ShowError(
                    Resources.TimeoutError
                    , Resources.TimeoutErrorTitle
                    , Resources.Close, null);
            }
            catch (Exception)
            {
                await _dialogService.ShowError(
                    Resources.UnexpectedError
                    , Resources.UnexpectedErrorTitle
                    , Resources.Close, null);
            }
            return(false);
        }
コード例 #4
0
        /// <summary>
        /// Add a seekios
        /// </summary>
        private async Task <bool> InsertSeekios(string seekiosName, string imei, string pin, byte[] seekiosPicture)
        {
            try
            {
                _dialogService.ShowLoadingLayout();
                var seekiosToAdd = new SeekiosDTO();
                seekiosToAdd.Imei           = imei;
                seekiosToAdd.SeekiosName    = seekiosName.ToUpperCaseFirst();
                seekiosToAdd.PinCode        = pin;
                seekiosToAdd.SeekiosPicture = seekiosPicture == null ? null : Convert.ToBase64String(seekiosPicture);
                // Add seekios in the database
                seekiosToAdd = await _dataService.InsertSeekios(seekiosToAdd);

                if (seekiosToAdd == null || seekiosToAdd.Idseekios <= 0)
                {
                    _dialogService.HideLoadingLayout();
                    return(false);
                }
                // Add seekios in local data
                App.CurrentUserEnvironment.LsSeekios.Add(seekiosToAdd);
                _dialogService.HideLoadingLayout();
                return(true);
            }
            catch (TimeoutException)
            {
                await _dialogService.ShowError(
                    Resources.TimeoutError
                    , Resources.TimeoutErrorTitle
                    , Resources.Close, null);
            }
            catch (WebException)
            {
                await _dialogService.ShowError(
                    Resources.TimeoutError
                    , Resources.TimeoutErrorTitle
                    , Resources.Close, null);
            }
            catch (Exception)
            {
                await _dialogService.ShowError(
                    Resources.UnexpectedError
                    , Resources.UnexpectedErrorTitle
                    , Resources.Close, null);
            }
            _dialogService.HideLoadingLayout();
            return(false);
        }
コード例 #5
0
        /// <summary>
        /// Delete a seekios
        /// </summary>
        public async Task <int> DeleteSeekios()
        {
            if (SeekiosSelected == null)
            {
                return(-1);
            }
            try
            {
                int res = await _dataService.DeleteSeekios(SeekiosSelected.Idseekios);

                if (res == 1)
                {
                    var modes = App.CurrentUserEnvironment.LsMode.Where(x => x.Seekios_idseekios == SeekiosSelected.Idseekios);
                    if (modes?.Count() > 0)
                    {
                        foreach (var mode in modes)
                        {
                            var alerts = App.CurrentUserEnvironment.LsAlert.Where(x => x.IdMode == mode.Idmode);
                            if (alerts?.Count() > 0)
                            {
                                foreach (var alert in alerts)
                                {
                                    // Remove recipients
                                    App.CurrentUserEnvironment.LsAlertRecipient.RemoveAll(x => x.IdAlert == alert.IdAlert);
                                }
                            }
                            // Remove alerts
                            App.CurrentUserEnvironment.LsAlert.RemoveAll(x => x.IdMode == mode.Idmode);
                        }
                        // Remove modes
                        App.CurrentUserEnvironment.LsMode.RemoveAll(x => x.Seekios_idseekios == SeekiosSelected.Idseekios);
                    }
                    // Remove locations
                    App.CurrentUserEnvironment.LsLocations.RemoveAll(x => x.Seekios_idseekios == SeekiosSelected.Idseekios);
                    // Remove seekios
                    App.CurrentUserEnvironment.LsSeekios.Remove(SeekiosSelected);
                    App.Locator.ListSeekios.ActivityNeedsUIToBeUpdated = true;
                    await _dialogService.ShowMessage(Resources.DeleteSeekiosSuccess, Resources.DeleteSeekiosTitle);

                    return(1);
                }
                else if (res == -1)
                {
                    await _dialogService.ShowMessage(Resources.MySeekios_DeleteSeekios_Title, Resources.UnexpectedErrorTitle);

                    return(-1);
                }
                return(-1);
            }
            catch (TimeoutException)
            {
                await _dialogService.ShowError(
                    Resources.TimeoutError
                    , Resources.TimeoutErrorTitle
                    , Resources.Close, null);
            }
            catch (WebException)
            {
                await _dialogService.ShowError(
                    Resources.TimeoutError
                    , Resources.TimeoutErrorTitle
                    , Resources.Close, null);
            }
            catch (Exception)
            {
                await _dialogService.ShowError(
                    Resources.UnexpectedError
                    , Resources.UnexpectedErrorTitle
                    , Resources.Close, null);
            }
            return(-1);
        }
コード例 #6
0
        /// <summary>
        /// Get the locations on the last month
        /// </summary>
        public async Task GetLocationsBySeekios(int idSeekios, DateTime lowerDate, DateTime upperDate, bool requestNewData = false)
        {
            // if there is any seekios already present in the list
            // we don't need to take the data from the bdd
            if (requestNewData || (LsSeekiosLocations != null && !LsSeekiosLocations.Any(a => a.IdSeekios == idSeekios)))
            {
                // if the date the user wants if lower than the actual date
                // we need to take the data from the bdd
                if (lowerDate <= CurrentLowerDate)
                {
                    if (LsSeekiosLocations.Any(a => a.IdSeekios == idSeekios))
                    {
                        try
                        {
                            var index = LsSeekiosLocations.FindIndex(0, LsSeekiosLocations.Count, (e) => e.IdSeekios == idSeekios);
                            SelectedSeekiosLocations.LsLocations = await _dataService.Locations(idSeekios, lowerDate, upperDate);

                            if (null != SelectedSeekiosLocations.LsLocations && index > -1 && null != LsSeekiosLocations[index]) //we have to check
                            {
                                LsSeekiosLocations[index].LsLocations = SelectedSeekiosLocations.LsLocations.OrderBy(l => l.DateLocationCreation).ToList();
                            }
                        }
                        catch (TimeoutException)
                        {
                            await _dialogService.ShowError(
                                Resources.TimeoutError
                                , Resources.TimeoutErrorTitle
                                , Resources.Close, null);
                        }
                        catch (WebException)
                        {
                            await _dialogService.ShowError(
                                Resources.TimeoutError
                                , Resources.TimeoutErrorTitle
                                , Resources.Close, null);
                        }
                        catch (Exception)
                        {
                            await _dialogService.ShowError(
                                Resources.UnexpectedError
                                , Resources.UnexpectedErrorTitle
                                , Resources.Close, null);
                        }
                    }
                    else
                    {
                        LocationUpperLowerDates limitDates = null;
                        try
                        {
                            limitDates = await _dataService.LowerDateAndUpperDate(idSeekios);
                        }
                        catch (TimeoutException)
                        {
                            await _dialogService.ShowError(
                                Resources.TimeoutError
                                , Resources.TimeoutErrorTitle
                                , Resources.Close, null);
                        }
                        catch (WebException)
                        {
                            await _dialogService.ShowError(
                                Resources.TimeoutError
                                , Resources.TimeoutErrorTitle
                                , Resources.Close, null);
                        }
                        catch (Exception)
                        {
                            await _dialogService.ShowError(
                                Resources.UnexpectedError
                                , Resources.UnexpectedErrorTitle
                                , Resources.Close, null);
                        }

                        if (limitDates != null)
                        {
                            List <LocationDTO> locationsBySeekios = null;
                            try
                            {
                                locationsBySeekios = await _dataService.Locations(idSeekios, lowerDate, upperDate);
                            }
                            catch (TimeoutException)
                            {
                                await _dialogService.ShowError(
                                    Resources.TimeoutError
                                    , Resources.TimeoutErrorTitle
                                    , Resources.Close, null);
                            }
                            catch (WebException)
                            {
                                await _dialogService.ShowError(
                                    Resources.TimeoutError
                                    , Resources.TimeoutErrorTitle
                                    , Resources.Close, null);
                            }
                            catch (Exception)
                            {
                                await _dialogService.ShowError(
                                    Resources.UnexpectedError
                                    , Resources.UnexpectedErrorTitle
                                    , Resources.Close, null);
                            }

                            if (locationsBySeekios != null)
                            {
                                SelectedSeekiosLocations = new SeekiosLocations
                                {
                                    IdSeekios      = idSeekios,
                                    LimitUpperDate = limitDates.UppderDate,
                                    LimitLowerDate = limitDates.LowerDate,
                                    LsLocations    = locationsBySeekios.OrderBy(l => l.DateLocationCreation).ToList()
                                };
                            }
                            //si LimitLowerDate est trop ancien ? en 1970 ? alors on prend une date par defaut ?
                            //TODO: peut etre prendre la date du point le plus ancien ?
                            //ex: json est => "{\"LowerDate\":\"\\/Date(0+0000)\\/\",\"UppderDate\":\"\\/Date(1475851229000+0000)\\/\"}"
                            if (SelectedSeekiosLocations.LimitLowerDate <= new DateTime(1970, 1, 1, 1, 0, 0))
                            {
                                SelectedSeekiosLocations.LimitLowerDate = DateHelper.GetDateTimeFromOneMonthAgo();
                            }
                            LsSeekiosLocations.Add(SelectedSeekiosLocations);
                        }
                    }
                }
            }
            else
            {
                if (LsSeekiosLocations == null)
                {
                    LsSeekiosLocations = new List <SeekiosLocations>();
                }
                SeekiosLocations locations = LsSeekiosLocations.FirstOrDefault(a => a.IdSeekios == idSeekios);//si on l'a deja on le recupere
                //il faut recuperer la liste, l'ordonner et la croiser avec LsSeekiosLocations...
                //todo: check if locations is null ?
                ModeDTO[] mm = App.CurrentUserEnvironment.LsMode.Where(m => m.Seekios_idseekios == App.Locator.DetailSeekios.SeekiosSelected.Idseekios).ToArray();
                foreach (ModeDTO mode in mm)
                {
                    List <LocationDTO> pp = App.CurrentUserEnvironment.LsLocations.Where(el => el.Mode_idmode == mode.Idmode).ToList();
                    //.OrderBy(el => el.DateLocationCreation).ToList();
                    foreach (LocationDTO l in pp)
                    {
                        if (!locations.LsLocations.Any(item => item.Idlocation == l.Idlocation))
                        {
                            locations.LsLocations.Add(l);
                        }
                    }
                }
                locations.LsLocations = locations.LsLocations.OrderBy(el => el.DateLocationCreation).ToList();
                App.Locator.Historic.SelectedSeekiosLocations = locations;
            }
            if (SelectedSeekiosLocations != null && SelectedSeekiosLocations.LimitLowerDate != null &&
                SelectedSeekiosLocations.LimitLowerDate.HasValue &&
                SelectedSeekiosLocations.LimitLowerDate > CurrentLowerDate)
            {
                CurrentLowerDate = SelectedSeekiosLocations.LimitLowerDate.Value;
                await OnGetLocationsComplete.Invoke(true, null);
            }
            else
            {
                await OnGetLocationsComplete.Invoke(false, null);
            }
        }
コード例 #7
0
        /// <summary>
        /// Modify SOS alert, depending of the SOSAlert variable
        /// </summary>
        public async Task <bool> InsertOrUpdateAlertSOS(string title, string content)
        {
            try
            {
                // Adding alert sos
                if (CurrentAlertSOS == null)
                {
                    // Create a new alert with recipient to add
                    var alertWithRecipientToAdd = new AlertWithRecipientDTO
                    {
                        IdAlertType  = (int)AlertDefinitionEnum.Email,
                        IdMode       = null,
                        Title        = title,
                        Content      = content,
                        LsRecipients = LsRecipients,
                    };
                    // Add the alert with recipient in the database
                    var alertId = await _dataService.InsertAlertSOSWithRecipient(App.Locator.DetailSeekios.SeekiosSelected.Idseekios, alertWithRecipientToAdd);

                    // Something wrong
                    if (alertId <= 0)
                    {
                        return(false);
                    }
                    else
                    {
                        // Update the local values
                        App.Locator.AddSeekios.UpdatingSeekios.AlertSOS_idalert = alertId;
                        alertWithRecipientToAdd.IdAlert = alertId;
                        App.CurrentUserEnvironment.LsAlert.Add(alertWithRecipientToAdd);
                        App.CurrentUserEnvironment.LsSeekios[App.CurrentUserEnvironment.LsSeekios.IndexOf(App.Locator.AddSeekios.UpdatingSeekios)].AlertSOS_idalert = alertId;
                        foreach (var recipient in LsRecipients)
                        {
                            recipient.IdAlert = alertId;
                        }
                        App.CurrentUserEnvironment.LsAlertRecipient.AddRange(LsRecipients);
                        CurrentAlertSOS = alertWithRecipientToAdd;
                        return(true);
                    }
                }
                // Modify alert sos
                else
                {
                    // Create a new alert with recipient to update
                    var alertWithRecipientToUpdate = new AlertWithRecipientDTO
                    {
                        IdAlert      = CurrentAlertSOS.IdAlert,
                        IdAlertType  = (int)AlertDefinitionEnum.Email,
                        IdMode       = null,
                        Title        = title,
                        Content      = content,
                        LsRecipients = LsRecipients,
                    };
                    foreach (var recipient in alertWithRecipientToUpdate.LsRecipients)
                    {
                        recipient.IdAlert = alertWithRecipientToUpdate.IdAlert;
                    }
                    // Update the alert with recipient in the database
                    if (await _dataService.UpdateAlertSOSWithRecipient(App.Locator.DetailSeekios.SeekiosSelected.Idseekios, alertWithRecipientToUpdate) > 0)
                    {
                        CurrentAlertSOS.Title   = title;
                        CurrentAlertSOS.Content = content;
                        App.CurrentUserEnvironment.LsAlert.RemoveAll(r => r.IdAlert == CurrentAlertSOS.IdAlert);
                        App.CurrentUserEnvironment.LsAlert.Add(alertWithRecipientToUpdate);
                        App.CurrentUserEnvironment.LsAlertRecipient.RemoveAll(r => r.IdAlert == CurrentAlertSOS.IdAlert);
                        App.CurrentUserEnvironment.LsAlertRecipient.AddRange(LsRecipients);
                    }
                    return(true);
                }
            }
            catch (TimeoutException)
            {
                await _dialogService.ShowError(
                    Resources.TimeoutError
                    , Resources.TimeoutErrorTitle
                    , Resources.Close, null);
            }
            catch (WebException)
            {
                await _dialogService.ShowError(
                    Resources.TimeoutError
                    , Resources.TimeoutErrorTitle
                    , Resources.Close, null);
            }
            catch (Exception)
            {
                await _dialogService.ShowError(
                    Resources.UnexpectedError
                    , Resources.UnexpectedErrorTitle
                    , Resources.Close, null);
            }
            return(false);
        }
コード例 #8
0
        /// <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);
        }
コード例 #9
0
        public async Task <bool> Connect(string deviceModel
                                         , string platform
                                         , string version
                                         , string uniqueDeviceId
                                         , string countryCode)
        {
            App.Locator.ListSeekios.IsNotFromLogin = false;
            if (string.IsNullOrEmpty(Email) ||
                string.IsNullOrEmpty(Password) ||
                string.IsNullOrEmpty(deviceModel) ||
                string.IsNullOrEmpty(version) ||
                string.IsNullOrEmpty(uniqueDeviceId))
            {
                // TODO : handle custom alert msg
                return(false);
            }
            var connectOk = false;

            IsLoading = true;
            try
            {
                var passHash = Password;
                passHash                   = CryptographyHelper.CalculatePasswordMD5Hash(Email, Password);
                DataService.Email          = Email;
                DataService.Pass           = passHash;
                App.CurrentUserEnvironment = await _dataService.GetUserEnvironment(App.Locator.Login.VersionApplication,
                                                                                   platform,
                                                                                   deviceModel,
                                                                                   version,
                                                                                   uniqueDeviceId,
                                                                                   countryCode);

                // The app need an update
                if (App.CurrentUserEnvironment == null)
                {
                    RemoveSavedCredentials();
                    App.IsAppNeedUpdate = true;
                    _navigationService.NavigateTo(App.NEED_UPDATE_PAGE);
                    return(false);
                }
                // Authentication failed
                else if (App.CurrentUserEnvironment.User == null)
                {
                    return(false);
                }
                // Authentication succeeded
                else
                {
                    InitTimers();
                    connectOk = true;
                }
            }
            catch (TimeoutException)
            {
                await _dialogService.ShowError(
                    Resources.TimeoutError
                    , Resources.TimeoutErrorTitle
                    , Resources.Close, null);
            }
            catch (WebException)
            {
                await _dialogService.ShowError(
                    Resources.TimeoutError
                    , Resources.TimeoutErrorTitle
                    , Resources.Close, null);
            }
            catch (Exception)
            {
                await _dialogService.ShowError(
                    Resources.UnexpectedError
                    , Resources.UnexpectedErrorTitle
                    , Resources.Close, null);
            }
            finally
            {
                IsLoading = false;
            }
            // save data and navigate to seekios list if the user is correctly authenticated
            if (connectOk)
            {
                SaveCurrentCredentials();
                if (GetSavedFirstLaunchTuto())
                {
                    _navigationService.NavigateTo(App.LIST_SEEKIOS_PAGE);
                }
                else
                {
                    _navigationService.NavigateTo(App.TUTORIAL_BACKGROUND_FIRST_LAUNCH_PAGE);
                }
            }
            Password = string.Empty;
            AppTimer = ServiceLocator.Current.GetInstance <ITimer>();
            return(connectOk);
        }
コード例 #10
0
        /// <summary>
        ///  Update user
        /// </summary>
        public async Task <int> UpdateUser(string email, string phoneNumber, string firstName, string lastName)
        {
            try
            {
                // Check if internet is available
                if (!App.DeviceIsConnectedToInternet)
                {
                    await _dialogService.ShowMessage(Resources.WebErrorTitle, Resources.WebErrorButtonText);

                    return(-2);
                }

                // Update user data
                App.CurrentUserEnvironment.User.Email       = email;
                App.CurrentUserEnvironment.User.FirstName   = firstName.ToUpperCaseFirst();
                App.CurrentUserEnvironment.User.LastName    = lastName.ToUpperCaseFirst();
                App.CurrentUserEnvironment.User.UserPicture = UserPicture == null ? App.CurrentUserEnvironment.User.UserPicture : Convert.ToBase64String(UserPicture);

                // Show the loading layout
                _dialogService.ShowLoadingLayout();

                if (await _dataService.UpdateUser(App.CurrentUserEnvironment.User) == 1)
                {
                    // Hide the loading layout
                    _dialogService.HideLoadingLayout();
                    return(1);
                }
                else
                {
                    // Error message
                    await _dialogService.ShowMessage(Resources.UpdateUserFailedTitle, Resources.UpdateUserFailedContent);

                    // Hide the loading layout
                    _dialogService.HideLoadingLayout();
                    return(-1);
                }
            }
            catch (TimeoutException)
            {
                await _dialogService.ShowError(
                    Resources.TimeoutError
                    , Resources.TimeoutErrorTitle
                    , Resources.Close, null);
            }
            catch (WebException)
            {
                await _dialogService.ShowError(
                    Resources.TimeoutError
                    , Resources.TimeoutErrorTitle
                    , Resources.Close, null);
            }
            catch (Exception)
            {
                await _dialogService.ShowError(
                    Resources.UnexpectedError
                    , Resources.UnexpectedErrorTitle
                    , Resources.Close, null);
            }
            _dialogService.HideLoadingLayout();
            return(-1);
        }
コード例 #11
0
        /// <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);
        }