Esempio n. 1
0
        public async void Login(string address, string userID, SecureString password, string dataBaseName)
        {
            this.HasError = false;
            this.BeginProgress();

            try
            {
                this.ProgressMessage = Resources.Message_ConnectingToServer;
                if (await this.cremaHost.Dispatcher.InvokeAsync(() => CremaBootstrapper.IsOnline(address, userID, password)) == true)
                {
                    if (AppMessageBox.ShowQuestion(Resources.Message_SameIDConnected) == false)
                    {
                        this.ProgressMessage = string.Empty;
                        this.EndProgress();
                        this.HasError = false;
                        return;
                    }
                }
                await this.OpenAsync(address, userID, password);

                if (dataBaseName != string.Empty)
                {
                    await this.LoadAsync(dataBaseName);
                }
                else
                {
                    this.EndProgress();
                    this.dataBase     = null;
                    this.dataBaseName = null;
                    this.address      = null;
                    this.Refresh();
                    this.ProgressMessage = string.Empty;
                }
            }
            catch (TimeoutException e)
            {
                CremaLog.Error(e);
                this.ErrorMessage = Resources.Message_ConnectionFailed;
            }
            catch (EndpointNotFoundException e)
            {
                CremaLog.Error(e);
                this.ErrorMessage = Resources.Message_ConnectionFailed;
            }
            catch (Exception e)
            {
                CremaLog.Error(e);
                this.ErrorMessage = e.Message;
                if (this.IsOpened == true)
                {
                    AppMessageBox.ShowError(e.Message);
                }
            }
            finally
            {
                this.EndProgress(this.ProgressMessage);
            }
        }