コード例 #1
0
        protected override void DoLoadData()
        {
            ExceptionUtility.Try(() =>
            {
                base.DoLoadData();
                List <ConfigSettingViewModel> settings = new List <ConfigSettingViewModel>();

                string username = String.Empty;
                string password = String.Empty;
                string server   = String.Empty;

                if (User.Current != null)
                {
                    username = User.Current.Username;
                    password = User.Current.Password;
                    server   = User.Current.ServerUri;
                }
                else
                {
                    #if DEBUG
                    {
                        //username = "******";
                        // password = "******";
                        //  server = "ws://172.16.16.243:8080/service";
                        //server = "wss://raincloud.aquamonix.com.au:444/service";
                        //server = "ws://127.0.0.1:8080/service";
                    }
                    #endif
                }

                //if no server, default to default
                if (String.IsNullOrEmpty(server))
                {
                    server = AppSettings.GetAppSettingValue(AppSettings.DefaultAppServerUriAppSettingName, String.Empty);
                }

                this._navBarView.ShowHideCancelButton(User.Current != null && User.Current.HasConfig && DataCache.HasDevices);

                settings.Add(new ConfigSettingViewModel()
                {
                    ControlType = ConfigSettingControlType.TextField, Type = ConfigSettingType.Username, CurrentValue = username
                });
                settings.Add(new ConfigSettingViewModel()
                {
                    ControlType = ConfigSettingControlType.TextField, Type = ConfigSettingType.Password, CurrentValue = password
                });
                settings.Add(new ConfigSettingViewModel()
                {
                    ControlType = ConfigSettingControlType.TextField, Type = ConfigSettingType.ServerUri, CurrentValue = ServerAliases.UriToAlias(server)
                });

                this._logoutButton.Hidden = true;
                if (User.Current != null && User.Current.HasConfig && ServiceContainer.UserService.IsConnected)
                {
                    this._logoutButton.Hidden = false;
                    //settings.Add(new ConfigSettingViewModel() { ControlType = ConfigSettingControlType.Button, Type = ConfigSettingType.LogoutButton, Valid = true });
                }

                foreach (var setting in settings)
                {
                    if (setting.Type == ConfigSettingType.LogoutButton)
                    {
                        setting.OnValueChanged = (obj) =>
                        {
                            this.Logout();
                        };
                    }
                    else
                    {
                        setting.OnValueChanged = (obj) => { this.ValidateForm(); }
                    };
                }

                this._tableViewController.LoadData(settings);
                this._tableViewController.SetCallbacks(async() =>
                {
                    await ServiceContainer.UserService.LogOut();
                    SubmitForm();
                });

                this.ValidateForm();
            });
        }
コード例 #2
0
            public void LoadCellValues(ConfigSettingViewModel setting)
            {
                ExceptionUtility.Try(() =>
                {
                    this._setting          = setting;
                    this._label.Hidden     = true;
                    this._textField.Hidden = true;
                    this._button.Hidden    = true;

                    switch (setting.ControlType)
                    {
                    case ConfigSettingControlType.TextField:
                        this._label.Hidden     = false;
                        this._textField.Hidden = false;

                        switch (setting.Type)
                        {
                        case ConfigSettingType.Username:
                            this._label.Text                       = StringLiterals.UsernameTextFieldPlaceholder;
                            this._textField.Placeholder            = StringLiterals.UsernameTextFieldPlaceholder;
                            this._textField.MaxLength              = 40;
                            this._textField.AutocorrectionType     = UITextAutocorrectionType.No;
                            this._textField.AutocapitalizationType = UITextAutocapitalizationType.None;
                            this._textField.ReturnKeyType          = UIReturnKeyType.Next;
                            this._textField.SecureTextEntry        = false;
                            this._textField.ValidationFunction     = (s) =>
                            {
                                if (s != null)
                                {
                                    s = s.Trim();
                                }

                                if (String.IsNullOrEmpty(s))
                                {
                                    _textField.TextColor = Colors.ErrorTextColor;
                                    return("Please enter a username");
                                }
                                else
                                {
                                    _textField.TextColor = UIColor.DarkGray;
                                }

                                return(null);
                            };
                            break;

                        case ConfigSettingType.Password:
                            this._label.Text                       = StringLiterals.PasswordTextFieldPlaceholder;
                            this._textField.Placeholder            = StringLiterals.PasswordTextFieldPlaceholder;
                            this._textField.MaxLength              = 40;
                            this._textField.ReturnKeyType          = UIReturnKeyType.Next;
                            this._textField.AutocorrectionType     = UITextAutocorrectionType.No;
                            this._textField.AutocapitalizationType = UITextAutocapitalizationType.None;
                            this._textField.SecureTextEntry        = true;
                            this._textField.ValidationFunction     = (s) =>
                            {
                                if (s != null)
                                {
                                    s = s.Trim();
                                }

                                if (String.IsNullOrEmpty(s))
                                {
                                    _textField.TextColor = Colors.ErrorTextColor;
                                    return("Please enter a password");
                                }
                                else
                                {
                                    _textField.TextColor = UIColor.DarkGray;
                                }

                                return(null);
                            };
                            break;

                        case ConfigSettingType.ServerUri:
                            this._label.Text                       = StringLiterals.ServerUriTextFieldPlaceholder;
                            this._textField.Placeholder            = StringLiterals.ServerUriTextFieldPlaceholder;
                            this._textField.MaxLength              = 150;
                            this._textField.ReturnKeyType          = UIReturnKeyType.Done;
                            this._textField.AutocorrectionType     = UITextAutocorrectionType.No;
                            this._textField.AutocapitalizationType = UITextAutocapitalizationType.None;
                            this._textField.SecureTextEntry        = false;
                            this._textField.ValidationFunction     = (s) =>
                            {
                                if (s != null)
                                {
                                    s = s.Trim();
                                }

                                if ((!AllowSubmitWithEmptyUriField) && String.IsNullOrEmpty(s))
                                {
                                    _textField.TextColor = Colors.ErrorTextColor;
                                    return("Please enter a server url");
                                }
                                else if (ValidateUriFormat && !Uri.IsWellFormedUriString(ServerAliases.AliasToUri(s), UriKind.Absolute))
                                {
                                    _textField.TextColor = Colors.ErrorTextColor;
                                    return("Please enter a valid url");
                                }
                                else
                                {
                                    _textField.TextColor = UIColor.DarkGray;
                                }

                                if ((!AllowSubmitWithEmptyUriField) && s.Length <= 4)
                                {
                                    _textField.TextColor = Colors.ErrorTextColor;
                                    return("Server url must be greater than 4 characters");
                                }
                                else
                                {
                                    _textField.TextColor = UIColor.DarkGray;
                                }

                                return(null);
                            };
                            break;
                        }
                        this._textField.Text = setting.CurrentValue;
                        break;

                    case ConfigSettingControlType.Button:
                        this._button.Hidden = false;

                        switch (setting.Type)
                        {
                        case ConfigSettingType.LogoutButton:
                            this._button.SetTitle(StringLiterals.LogoutButtonText, UIControlState.Normal);
                            this._button.SetTitle(StringLiterals.LogoutButtonText, UIControlState.Disabled);
                            this._button.SetTitleColor(Colors.ErrorTextColor, UIControlState.Normal);
                            break;
                        }

                        break;
                    }
                });
            }
コード例 #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);
            }
        }