Ejemplo n.º 1
0
        async public void AsyncTryConnectToServer()
        {
            await Task.Run(() =>
            {
                try
                {
                    ClientLogic.Connected   = false;
                    ConnectForm connectForm = new ConnectForm();
                    connectForm.ShowDialog();
                    if (ClientLogic.Registered)
                    {
                        if (!CreateRequests.Authorization(ClientLogic.Email, ClientLogic.Password))
                        {
                            RegistrationForm registrationForm = new RegistrationForm(this);
                            Invoke((MethodInvoker)(() =>
                            {
                                this.Hide();
                                registrationForm.ShowDialog();
                            }));
                        }
                    }
                    else
                    {
                        RegistrationForm registrationForm = new RegistrationForm(this);
                        Invoke((MethodInvoker)(() =>
                        {
                            this.Hide();
                            registrationForm.ShowDialog();
                        }));
                    }

                    ClientLogic.messengerForm = this;

                    Task receive = new Task(() => { ClientLogic.GetServerAnswer(); });
                    receive.Start();
                    Invoke((MethodInvoker)(() =>
                    {
                        UsernameLable.Text = ClientLogic.Username;
                    }));
                    ClientLogic.Connected = true;
                }
                catch (Exception)
                {
                    MessageBox.Show("AsyncTryConnectToServer() Error.");
                }
            });
        }
Ejemplo n.º 2
0
        private void LoginButton_Click(object sender, EventArgs e)
        {
            if (UsernameOrEmailBox.Text == string.Empty)
            {
                MessageBox.Show("Поле з нік нейм і електронною поштою не може залишатися порожнім.");
                return;
            }
            else if (PasswordBox.Text == string.Empty)
            {
                MessageBox.Show("Поле з паролем повинно бути заповнене. Вигадайте важкий пароль, адже це захист Вашого аккаунта.");
                return;
            }

            if (CreateRequests.Authorization(UsernameOrEmailBox.Text, PasswordBox.Text))
            {
                ClientLogic.Registered = true;
                Close();
            }
        }