Esempio n. 1
0
        private void NavigateToDeviceDetails(DeviceViewModel device)
        {
            try
            {
                ProgressUtility.SafeShow("Getting Device Details", async() =>
                {
                    var response = await ServiceContainer.DeviceService.RequestDevice(device.Device, () => { NavigateToDeviceDetails(device); });

                    MainThreadUtility.InvokeOnMain(() =>
                    {
                        if (response != null && response.IsSuccessful)
                        {
                            var d = response.Body.Devices.Items.FirstOrDefault().Value;
                            if (d == null)
                            {
                                ProgressUtility.Dismiss();
                                AlertUtility.ShowErrorAlert(StringLiterals.Error, StringLiterals.DeviceNotFoundErrorTitle);
                            }
                            else
                            {
                                this.Predecessor = null;
                                ProgressUtility.Dismiss();
                                this.NavigateTo(DeviceDetailsViewController.CreateInstance(d.Id));
                            }
                        }
                    });
                });
            }
            catch (Exception e)
            {
                LogUtility.LogException(e);
            }
        }
Esempio n. 2
0
        protected override void HandleViewDidAppear(bool animated)
        {
            base.HandleViewDidAppear(animated);

            if (this.ShowConnectionError)
            {
                this.ShowConnectionError = false;
                AlertUtility.ShowErrorAlert(StringLiterals.ConnectionError, StringLiterals.AuthFailureMessage);

                Aquamonix.Mobile.IOS.Utilities.WebSockets.ConnectionManager.ReconnectProcess.Begin(showBannerStraightAway: true);
            }
        }
Esempio n. 3
0
        private async void SubmitForm()
        {
            try
            {
                _connectingManually = true;

                if (this._navBarView.DoneButtonEnabled)
                {
                    //var oldUsername = User.Current?.Username;
                    //var oldPassword = User.Current?.Password;
                    //var oldServerUri = User.Current?.ServerUri;

                    var username  = this._tableViewController.Username;
                    var password  = this._tableViewController.Password;
                    var serverUri = this._tableViewController.ServerUri;

                    //set default if no server uri provided
                    if (String.IsNullOrEmpty(serverUri))
                    {
                        serverUri = AppSettings.GetAppSettingValue(AppSettings.DefaultAppServerUriAppSettingName, String.Empty);
                        this._tableViewController.ServerUri = serverUri;
                    }

                    //translate server alias to a uri
                    serverUri = ServerAliases.AliasToUri(serverUri);

                    bool newUser   = false;
                    bool newServer = false;

                    if (User.Current == null)
                    {
                        User.Current = new User();
                    }
                    else
                    {
                        //check if current user is different from prev user
                        newUser   = ((User.Current.Username != null) && User.Current.Username.Trim().ToLower() != username.Trim().ToLower());
                        newServer = ((User.Current.ServerUri != null) && User.Current.ServerUri.Trim().ToLower() != serverUri.Trim().ToLower());
                    }

                    if (newServer || newUser)
                    {
                        await this.LogoutInternal();
                    }

                    User.Current.Username  = username;
                    User.Current.Password  = password;
                    User.Current.ServerUri = serverUri;

                    if (User.Current != null)
                    {
                        await ProgressUtility.SafeShow("Connecting to Server", async() =>
                        {
                            //if reconnect process is running, cancel it
                            if (ConnectionManager.IsReconnecting)
                            {
                                await ConnectionManager.CancelReconnecting();
                            }

                            //here, if we are voluntarily connecting to a new server or new user, we must suppress the automatic reconnect attempt on closing connection
                            if (newUser || newServer)
                            {
                                ConnectionManager.Deinitialize();
                            }

                            WebSocketsClient.ResetWebSocketsClientUrl(new WebSocketsClientIos(), serverUri);
                            ConnectionManager.Initialize();

                            var deviceListVc = DeviceListViewController.CreateInstance();

                            //test connection
                            var response = await ServiceContainer.UserService.RequestConnection(username, password);
                            ProgressUtility.Dismiss();

                            this.ShowError(response);

                            if (response != null && response.IsSuccessful)
                            {
                                //only save the changes after successful login
                                //User.Current.Save();

                                //this.NavigateTo(deviceListVc, inCurrentNavController: false);
                                //PresentViewController(new AquamonixNavController(deviceListVc), true, null);
                                LogUtility.Enabled = true;
                            }
                            else
                            {
                                if (response?.ErrorBody != null && response.ErrorBody.ErrorType == ErrorResponseType.ConnectionTimeout)
                                {
                                    if (DataCache.HasDevices)
                                    {
                                        deviceListVc.ShowConnectionError = true;
                                        this.NavigateTo(deviceListVc, inCurrentNavController: false);
                                    }
                                    else
                                    {
                                        AlertUtility.ShowErrorAlert(StringLiterals.ConnectionError, StringLiterals.UnableToEstablishConnection);
                                        ConnectionManager.CancelReconnecting();
                                    }
                                }
                                // Edited //
                                if (response?.ErrorBody != null && response.ErrorBody.ErrorType == ErrorResponseType.AuthFailure)
                                {
                                    AlertUtility.ShowErrorAlert(StringLiterals.ConnectionError, StringLiterals.AuthFailureMessage);
                                    Caches.ClearCachesForAuthFailure();
                                }

                                this.LoadData();
                            }
                        });
                    }
                }
            }
            catch (Exception e)
            {
                LogUtility.LogException(e);
            }
        }