Exemplo n.º 1
0
        private void processRequest(string dataFromClient)
        {
            JObject jObject = JObject.Parse(dataFromClient);

            MyTransactionFactory factory     = MyTransactionFactory.getInstance();
            MyBaseTransaction    transaction = factory.createTransaction(jObject);

            switch (transaction.MyTransactioncode)
            {
            case Transaction_Code.sv_disconnect:
                // Nếu server đóng thì client cũng sẽ close session
                MessageBox.Show("You has beend disconnect from server!");
                stop();
                break;

            case Transaction_Code.sv_question:
                MyTr_Sv_Question transQuestion = factory.recreateMyTr_Sv_Question(jObject);
                _currentQuestion = transQuestion.Question;
                updateQuestionToForm(_currentQuestion);
                break;

            case Transaction_Code.sv_end_questions:
                MessageBox.Show("Bài kiểm tra đã kết thúc!");
                clearAllAnswerButton();
                break;
            }
        }
Exemplo n.º 2
0
        public void processRequest(string requestdata)
        {
            JObject jObject = JObject.Parse(requestdata);

            MyTransactionFactory factory     = MyTransactionFactory.getInstance();
            MyBaseTransaction    transaction = factory.createTransaction(jObject);

            switch (transaction.MyTransactioncode)
            {
            case Transaction_Code.cl_client_connect_infor:
                string _password = _currentForm.getPassword();
                MyTr_Client_Connect_Infor transactionoff = (MyTr_Client_Connect_Infor)transaction;
                if (_password == transactionoff.password)
                {
                    // if password is match
                    this.Username = transactionoff.username;
                    MyBaseTransaction info = new MyBaseTransaction();
                    info.MyTransactioncode = Transaction_Code.sv_login_accept;
                    _mysendFactory.sendJsonObject(info);
                    _currentForm.addClientToListView(this);

                    _currentForm.addToReceiverText(">> User có id: " + id + " có tên: " + username);
                }
                else
                {
                    // if password not match
                    _currentForm.addToReceiverText(">> User có id: " + id + " thử kết nối nhưng không đúng mật khẩu.");
                    _mysendFactory.quickSendJsonObject(Transaction_Code.sv_incorrect_info);
                }
                break;

            case Transaction_Code.cl_disconnect:
                Stop();
                _currentForm.addToReceiverText(">> User " + username + "(" + id + ") đã ngắt kết nối!");
                break;

            case Transaction_Code.cl_answer_question:
                MyTr_Cl_AnswerQuestion trans_answer = new MyTr_Cl_AnswerQuestion();
                trans_answer = factory.recreateMyTr_Cl_AnswerQuestion(jObject);
                _currentForm.updateClientAnswer(this, trans_answer.Answer);
                setClientAnswer(trans_answer.Answer, _currentIndexQuestion);
                break;
            }
        }
Exemplo n.º 3
0
        private void processRequest(string dataFromClient)
        {
            JObject jObject = JObject.Parse(dataFromClient);

            MyTransactionFactory factory     = MyTransactionFactory.getInstance();
            MyBaseTransaction    transaction = factory.createTransaction(jObject);

            switch (transaction.MyTransactioncode)
            {
            case Transaction_Code.sv_incorrect_info:
                MessageBox.Show("Password not match!");
                break;

            case Transaction_Code.sv_login_accept:
                Client client = new Client();
                this.Hide();
                client.Show();
                break;

            case Transaction_Code.sv_disconnect:
                MessageBox.Show("Server has been close or not found!");
                break;
            }
        }