コード例 #1
0
        private async void loginButton_Click(object sender, EventArgs e)
        {
            this.Enabled       = false;
            client             = new HttpClient();
            client.BaseAddress = new Uri("http://localhost:21021/");
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            try
            {
                //utworzenie uzytkownika z modelu oraz przesłanie go do funkcji CheckUser
                var url = await CheckUser(new LoginModel()
                {
                    Email = emailInput.Text, Password = passwordInput.Text
                });

                var user = await GetUserAsync(url.PathAndQuery);

                if (user.status != UserModel.UserStatus.Offline)
                {
                    MessageBox.Show("Ten użytkownik jest obecnie zalogowany.", "Informacja");
                }
                else
                {
                    user.status = UserModel.UserStatus.Logged;
                    await PutUser(user.Id, user);

                    user = await GetUserAsync(url.PathAndQuery);

                    this.Hide();
                    var createForm = new UserPanel(url, client, user);
                    createForm.Closed += (s, args) => this.Close();
                    createForm.Show();
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Podano złe dane logowania", "Uwaga!");
            }
            finally
            {
                this.Enabled = true;
            }
        }
コード例 #2
0
        private async void leaveRoomButton_Click(object sender, EventArgs e)
        {
            this.Enabled = false;
            t.Abort();
            try
            {
                var roomBuf = await GetActualRoomMate(this.room.Id);

                this.room = roomBuf;
                if (roomBuf.Players.Count == room.PlayersLimit)
                {
                    //usuwanie gracza z pokoju
                    //Dunno.
                    await DeleteProductAsync(player.Id);

                    this.Hide();
                    var panel = new UserPanel(url, client, user);
                    panel.Closed += (s, ev) => this.Close();
                    panel.Show();
                }
                else if (room.Players.Count == 1)
                {
                    //usuwanie gracza
                    //usuwanie pokoju
                    //Dunno.
                    this.Hide();
                    var panel = new UserPanel(url, client, user);
                    panel.Closed += (s, ev) => this.Close();
                    panel.Show();
                }
            }
            catch (Exception excp)
            {
                MessageBox.Show(excp.Message);
            }
            finally
            {
                this.Enabled = true;
            }
        }