Esempio n. 1
0
        private void msg()
        {
            if (this.InvokeRequired)
            {
                this.Invoke(new MethodInvoker(msg));
            }
            else
            {
                switch (msgReceived.cmd)
                {
                case Command.JoinRequestAccepted:
                    lblRemote.Text = msgReceived.senderName;
                    break;

                case Command.Join:
                    lstBoxStudents.Items.Add(msgReceived.senderName);
                    break;

                case Command.Leave:
                    lstBoxStudents.Items.Remove(msgReceived.senderName);
                    break;

                case Command.QuestionRequstAccepted:
                    dlgAskingQuestion = DialogResult.None;
                    using (new TimedDialog(30000))
                    {
                        dlgAskingQuestion = MessageBox.Show("Your question request has been accepted\nClick OK button to start asking your question", "VCES", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                    }
                    Data data = new Data();
                    data.userName = lblUser.Text;
                    if (dlgAskingQuestion == DialogResult.OK)
                    {
                        data.cmd = Command.AskingQuestionStart;

                        serverStream.Write(data.ToByte(), 0, data.ToByte().Length);
                        serverStream.Flush();
                        if (!timer1.Enabled)
                        {
                            timer1.Enabled = true;
                        }
                    }
                    else if (dlgAskingQuestion == DialogResult.Cancel)
                    {
                        data.cmd = Command.AskingQuestionCancel;
                        serverStream.Write(data.ToByte(), 0, data.ToByte().Length);
                        serverStream.Flush();
                    }
                    else
                    {
                        data.cmd = Command.AskingQuestionCancel;
                        serverStream.Write(data.ToByte(), 0, data.ToByte().Length);
                        serverStream.Flush();
                        MessageBox.Show("Your question asking time of 30 seconds is over\nYou cannot continue asking this question.\n\nTo send the request again, use 'Question Request' button.", "VCES - Question Time out", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        btnQuestionRequest.Enabled = true;
                    }
                    break;

                case Command.AskingQuestionStart:
                    picBoxStudent.Visible = true;
                    break;

                case Command.AskingQuestionStop:
                    picBoxStudent.Visible = false;
                    if (timer1.Enabled)
                    {
                        timer1.Enabled = false;
                    }
                    if (threadAudioSend.IsAlive)
                    {
                        audioSend = false;
                        //udpAudioSending.Close();

                        //threadAudioSend.Abort();
                    }
                    btnQuestionRequest.Enabled = true;
                    break;

                case Command.LectureEnded:
                    picBoxTeacher.Image = Image.FromFile("NUMLLOGO.jpg");
                    break;

                case Command.TextMessage:
                    rtChat.Text = rtChat.Text + Environment.NewLine + msgReceived.senderName + " >>   " + msgReceived.chatText + Environment.NewLine;
                    break;
                }
            }
        }
Esempio n. 2
0
        private void btnJoinLeave_Click(object sender, EventArgs e)
        {
            if (btnJoinLeave.Text.Equals("Join"))
            {
                btnJoinLeave.Enabled = false;
                if (!connectToServer())
                {
                    if (MessageBox.Show("Server User is not online right now!", "Server not responding", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == DialogResult.Retry)
                    {
                        btnJoinLeave_Click(sender, e);
                        return;
                    }
                    else
                    {
                        btnJoinLeave.Enabled = true;
                        return;
                    }
                }

                Thread text = new Thread(messageReceived);
                text.Start();



                Data data = new Data();
                data.cmd      = Command.Join;
                data.userName = lblUser.Text;

                byte[] outStream = data.ToByte();

                serverStream.Write(outStream, 0, outStream.Length);
                serverStream.Flush();

                btnJoinLeave.Text          = "Leave";
                btnJoinLeave.Enabled       = true;
                btnQuestionRequest.Enabled = true;
                btnSend.Enabled            = true;
            }
            else if (btnJoinLeave.Text.Equals("Leave"))
            {
                if (MessageBox.Show("Are you sure to leave the  room", "Leave confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    if (tcpClientForStudent.Connected)
                    {
                        Data data = new Data();
                        data.cmd      = Command.Leave;
                        data.userName = lblUser.Text;
                        byte[] outStream = data.ToByte();
                        serverStream.Write(outStream, 0, outStream.Length);
                        serverStream.Flush();
                        tcpClientForStudent.Close();
                        udpAudioReceiving.Close();
                    }

                    sin = new SignIn();
                    sin.txtVCESName.Text = lblUser.Text;

                    this.Dispose();
                    this.Hide();
                    sin.Show();
                    sin.txtPassword.Focus();
                }
            }
        }