Ejemplo n.º 1
0
 private void updateRooms()
 {
     while (true)
     {
         GetRoomsIdRequest  getRoomsIdRequest  = new GetRoomsIdRequest();
         ResponseInfo       response           = app.communicator.SocketSendReceive(JsonSerializer.serializeRequest(getRoomsIdRequest, Constants.GET_ROOMS_ID_REQUEST_CODE)).Result;
         GetRoomsIdResponse getRoomsIdResponse = JsonDeserializer.deserializeResponse <GetRoomsIdResponse>(response.buffer);
         removeRooms(getRoomsIdResponse.ids);
         for (int i = 0; i < getRoomsIdResponse.ids.Length; i++)
         {
             GetRoomDetailsRequest getRoomDetailsRequest = new GetRoomDetailsRequest();
             getRoomDetailsRequest.roomId = getRoomsIdResponse.ids[i];
             ResponseInfo           response1 = app.communicator.SocketSendReceive(JsonSerializer.serializeRequest(getRoomDetailsRequest, Constants.GET_ROOM_DETAILS_REQUEST)).Result;
             GetRoomDetailsResponse getRoomDetailsResponse = JsonDeserializer.deserializeResponse <GetRoomDetailsResponse>(response1.buffer);
             addOrUpdateRoom(getRoomDetailsResponse);
         }
         System.Threading.Thread.Sleep(500);
     }
 }
Ejemplo n.º 2
0
        private void updateRoom()
        {
            while (true)
            {
                GetRoomDetailsRequest getRoomDetailsRequest = new GetRoomDetailsRequest();
                getRoomDetailsRequest.roomId = 0;
                ResponseInfo           response = app.communicator.SocketSendReceive(JsonSerializer.serializeRequest(getRoomDetailsRequest, Constants.GET_ROOM_DETAILS_REQUEST)).Result;
                GetRoomDetailsResponse getRoomDetailsResponse = JsonDeserializer.deserializeResponse <GetRoomDetailsResponse>(response.buffer);

                switch (getRoomDetailsResponse.status)
                {
                case Constants.GET_ROOM_DETAILS_SUCCESS:
                    if (getRoomDetailsResponse.isActive == true)
                    {
                        MyMessageQueue.Enqueue("The admin started the game.");
                        this.Dispatcher.Invoke(() =>
                        {
                            NavigationService ns = NavigationService.GetNavigationService(this);
                            ns.Navigate(new Uri("QuestionScreen.xaml", UriKind.Relative));
                        });
                        thr.Abort();
                        break;
                    }
                    else if (!app.admin && getRoomDetailsResponse.admin == app.username)
                    {
                        MyMessageQueue.Enqueue("You are admin now.");
                        app.admin = true;
                        NewAdminRequest newAdminRequest = new NewAdminRequest();

                        ResponseInfo response1 = app.communicator.SocketSendReceive(JsonSerializer.serializeRequest(newAdminRequest, Constants.NEW_ADMIN_REQUEST)).Result;


                        NewAdminResponse newAdminResponse = JsonDeserializer.deserializeResponse <NewAdminResponse>(response.buffer);
                        switch (newAdminResponse.status)
                        {
                        case Constants.NEW_ADMIN_SUCCESS:
                            this.Dispatcher.Invoke(() =>
                            {
                                NavigationService ns = NavigationService.GetNavigationService(this);
                                ns.Refresh();
                            });
                            thr.Abort();
                            break;
                        }
                    }
                    else
                    {
                        updateRoomUI(getRoomDetailsResponse);
                    }

                    break;

                case Constants.GET_ROOM_DETAILS_NOT_EXIST:

                    MyMessageQueue.Enqueue("The admin closed the room.");
                    this.Dispatcher.Invoke(() =>
                    {
                        NavigationService ns = NavigationService.GetNavigationService(this);
                        ns.Navigate(new Uri("Menu.xaml", UriKind.Relative));
                    });
                    thr.Abort();
                    break;
                }
                System.Threading.Thread.Sleep(100);
            }
        }
Ejemplo n.º 3
0
        private void SaveBTN_Click(object sender, RoutedEventArgs e)
        {
            disableAllButtonsAndText();
            startLoadingAnim();
            bool allFine = true;

            if (String.IsNullOrEmpty(RoomNameBox.Text))
            {
                setError(RoomNameBox, "Field is required.");
                allFine = false;
            }
            else
            {
                Validation.ClearInvalid(RoomNameBox.GetBindingExpression(TextBox.TextProperty));
            }
            MaxPlayersBox.Text = new String(MaxPlayersBox.Text.Where(Char.IsDigit).ToArray());
            if (MaxPlayersBox.Text.Length > 3)
            {
                MaxPlayersBox.Text = MaxPlayersBox.Text.Substring(0, 3);
            }
            if (String.IsNullOrEmpty(MaxPlayersBox.Text))
            {
                setError(MaxPlayersBox, "Field is required.");
                allFine = false;
            }
            else
            {
                int count = int.Parse(MaxPlayersBox.Text);
                if (count > 15)
                {
                    setError(MaxPlayersBox, "Can't be more than 15 players.");
                    allFine = false;
                }
                else if (count < 2)
                {
                    setError(MaxPlayersBox, "Can't be less than 2 players.");
                    allFine = false;
                }
                else
                {
                    Validation.ClearInvalid(MaxPlayersBox.GetBindingExpression(TextBox.TextProperty));
                }
            }
            SecondsBox.Text = new String(SecondsBox.Text.Where(Char.IsDigit).ToArray());
            if (SecondsBox.Text.Length > 3)
            {
                SecondsBox.Text = SecondsBox.Text.Substring(0, 3);
            }
            if (String.IsNullOrEmpty(SecondsBox.Text))
            {
                setError(SecondsBox, "Field is required.");
                allFine = false;
            }
            else
            {
                int count = int.Parse(SecondsBox.Text);
                if (count > 100)
                {
                    setError(SecondsBox, "Can't be more than 100 seconds.");
                    allFine = false;
                }
                else if (count < 10)
                {
                    setError(SecondsBox, "Can't be less than 10 seconds.");
                    allFine = false;
                }
                else
                {
                    Validation.ClearInvalid(SecondsBox.GetBindingExpression(TextBox.TextProperty));
                }
            }
            QuestionsBox.Text = new String(QuestionsBox.Text.Where(Char.IsDigit).ToArray());
            if (QuestionsBox.Text.Length > 3)
            {
                QuestionsBox.Text = QuestionsBox.Text.Substring(0, 3);
            }
            if (String.IsNullOrEmpty(QuestionsBox.Text))
            {
                setError(QuestionsBox, "Field is required.");
                allFine = false;
            }
            else
            {
                int count = int.Parse(QuestionsBox.Text);
                if (count > 20)
                {
                    setError(QuestionsBox, "Can't be more than 20 questions.");
                    allFine = false;
                }
                else if (count < 2)
                {
                    setError(QuestionsBox, "Can't be less than 2 questions.");
                    allFine = false;
                }
                else
                {
                    Validation.ClearInvalid(QuestionsBox.GetBindingExpression(TextBox.TextProperty));
                }
            }

            if (allFine)
            {
                EditRoomRequest editRoomRequest = new EditRoomRequest();
                editRoomRequest.answerTimeout = int.Parse(SecondsBox.Text);
                editRoomRequest.questionCount = int.Parse(QuestionsBox.Text);
                editRoomRequest.maxUsers      = int.Parse(MaxPlayersBox.Text);
                editRoomRequest.roomName      = RoomNameBox.Text;
                app.communicator.SocketSendReceive(JsonSerializer.serializeRequest(editRoomRequest, Constants.EDIT_ROOM_REQUEST)).ContinueWith(task =>
                {
                    ResponseInfo response             = task.Result;
                    EditRoomResponse editRoomResponse = JsonDeserializer.deserializeResponse <EditRoomResponse>(response.buffer);
                    switch (editRoomResponse.status)
                    {
                    case Constants.EDIT_ROOM_SUCCESS:
                        GetRoomDetailsRequest getRoomDetailsRequest = new GetRoomDetailsRequest();
                        getRoomDetailsRequest.roomId = 0;
                        app.communicator.SocketSendReceive(JsonSerializer.serializeRequest(getRoomDetailsRequest, Constants.GET_ROOM_DETAILS_REQUEST)).ContinueWith(task1 =>
                        {
                            ResponseInfo response1 = task1.Result;
                            GetRoomDetailsResponse getRoomDetailsResponse = JsonDeserializer.deserializeResponse <GetRoomDetailsResponse>(response1.buffer);
                            updateRoomTexts(getRoomDetailsResponse);
                            MyMessageQueue.Enqueue("Saved successfully!");
                            enableAllButtonsAndText();
                            stopLoadingAnim();
                        });
                        break;

                    case Constants.EDIT_ROOM_NOT_EXIST:
                        thr.Abort();
                        MyMessageQueue.Enqueue("Room not exist anymore.");
                        this.Dispatcher.Invoke(() =>
                        {
                            NavigationService ns = NavigationService.GetNavigationService(this);
                            ns.Navigate(new Uri("Menu.xaml", UriKind.Relative));
                        });
                        break;
                    }
                });
            }
            else
            {
                enableAllButtonsAndText();
                stopLoadingAnim();
            }
        }