Example #1
0
        private async void newUserButton_Click(object sender, EventArgs e)
        {
            Cursor = Cursors.WaitCursor;
            DisableAll();
            var statusLabel = new ToolStripStatusLabel("Creating new user");

            statusBar.Items.Add(statusLabel);
            using (var newUserForm = new NewUserForm())
            {
                if (newUserForm.ShowDialog() == DialogResult.OK)
                {
                    var newUserInfo = newUserForm.NewUserInfo;
                    var pathToSave  = newUserForm.PathToSave;
                    try
                    {
                        DisconnectUser();
                        await ServerTransaction.CreateNewUser(newUserInfo, pathToSave);

                        _certificate = new UserCertificate(pathToSave);
                        _currentUser = _certificate;

                        Process addCertificateProcess = new Process();
                        addCertificateProcess.EnableRaisingEvents = false;
                        addCertificateProcess.StartInfo.FileName  = pathToSave;
                        addCertificateProcess.Start();

                        loginLabel.Text = _currentUser.CommonName;

                        var message = string.Format("Welcome {0}.", _currentUser.CommonName);
                        MessageBox.Show(message, "New user", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        _identitiesList.Add(_certificate);

                        await ConnectUser();
                    }
                    catch (UnknownCommadError error)
                    {
                        MessageBox.Show(error.Message);
                    }
                    catch (ServerResponseError error)
                    {
                        MessageBox.Show(error.Message);
                    }
                    catch (AuthenticationError error)
                    {
                        MessageBox.Show(error.Message);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Unexcepted error occured. Click OK to contiune", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
            }
            EnableIdentity();
            if (_connected)
            {
                EnableGroups();
            }
            statusBar.Items.Remove(statusLabel);
            Cursor = Cursors.Arrow;
        }
Example #2
0
        private async void newUserButton_Click(object sender, EventArgs e)
        {
            Cursor = Cursors.WaitCursor;
            DisableAll();
            var statusLabel = new ToolStripStatusLabel("Creating new user");
            statusBar.Items.Add(statusLabel);
            using (var newUserForm = new NewUserForm())
            {
                if (newUserForm.ShowDialog() == DialogResult.OK)
                {
                    var newUserInfo = newUserForm.NewUserInfo;
                    var pathToSave = newUserForm.PathToSave;
                    try
                    {
                        DisconnectUser();
                        await ServerTransaction.CreateNewUser(newUserInfo, pathToSave);

                        _certificate = new UserCertificate(pathToSave);
                        _currentUser = _certificate;

                        Process addCertificateProcess = new Process();
                        addCertificateProcess.EnableRaisingEvents = false;
                        addCertificateProcess.StartInfo.FileName = pathToSave;
                        addCertificateProcess.Start();

                        loginLabel.Text = _currentUser.CommonName;

                        var message = string.Format("Welcome {0}.", _currentUser.CommonName);
                        MessageBox.Show(message, "New user", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        _identitiesList.Add(_certificate);

                        await ConnectUser();
                    }
                    catch (UnknownCommadError error)
                    {
                        MessageBox.Show(error.Message);
                    }
                    catch (ServerResponseError error)
                    {
                        MessageBox.Show(error.Message);
                    }
                    catch (AuthenticationError error)
                    {
                        MessageBox.Show(error.Message);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Unexcepted error occured. Click OK to contiune", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
            }
            EnableIdentity();
            if (_connected)
                EnableGroups();
            statusBar.Items.Remove(statusLabel);
            Cursor = Cursors.Arrow;
        }