/*
         * Name: btnSend_Click
         * Description: This function sends the text that is in the message box, to either
         *           a specific person, or to everyone in the chat
         */
        private void btnSend_Click(object sender, RoutedEventArgs e)
        {
            string message = txtMsg.Text;

            //cuts out blank spaces from the messages on either end
            if (message.Trim().Length > 0)
            {
                //if the user is in the ALL tab
                if (tbControl.SelectedItem == tbAll)
                {
                    txtAll.Text += "You: " + message + "\n";
                    scrollAll.ScrollToBottom();
                    message = SETMessengerUtilities.makeMessage(true, StatusCode.All, Alias, "all", message);
                }
                //if the user is in the private tab
                else if (tbControl.SelectedItem == tbPrivate)
                {
                    txtPrivate.Text += "(" + selected + ") You: " + message + "\n";
                    scrollPrivate.ScrollToBottom();
                    message = SETMessengerUtilities.makeMessage(true, StatusCode.Whisper, Alias, selected, message);
                }

                //sends the message
                ClientPipe.sendMessage(message);
                if (!ClientPipe.connected)
                {
                    MessageBox.Show("The server had an unexpected shutdown. Closing application now...", "Server Fault");
                    this.Close();
                }

                //clears the message box and sets focus to it
                txtMsg.Clear();
                txtMsg.Focus();
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 ///
 /// </summary>
 public void close()
 {
     if (MessageQueue.Exists(mQueueName))
     {
         mq.Close();
         mq.Dispose();
         MessageQueue.Delete(mq.Path);
     }
     if (ClientPipe.connected)
     {
         string message = SETMessengerUtilities.makeMessage(true, StatusCode.ClientDisconnected, MainWindow.Alias);
         ClientPipe.sendMessage(message);
         ClientPipe.disconnect();
     }
 }
Ejemplo n.º 3
0
        /*
         * Name: btnConnect_Click
         * Description: The function handles when the user clicks the connect button.
         *           if both the alias field and the server name field are filled out,
         *           the client will try to connect to the server.
         */
        private void btnConnect_Click(object sender, RoutedEventArgs e)
        {
            if (checkEmpty(txtAlias, txtServerName))
            {
                //colons are not allowed, GET OUT OF HERE TROLLS
                while (txtAlias.Text.Contains(':'))
                {
                    int index = txtAlias.Text.IndexOf(':');
                    txtAlias.Text.Remove(index, 1);
                }

                //take out white spaces on either side of the string
                MainWindow.Alias      = txtAlias.Text.Trim();
                ClientPipe.ServerName = txtServerName.Text;

                //try to connect to the server
                try
                {
                    ClientPipe.connectToServer();

                    string msg = SETMessengerUtilities.makeMessage(true, StatusCode.ClientConnected, MainWindow.Alias);
                    //send the connection message to the server
                    ClientPipe.sendMessage(msg);
                    ClientPipe.connected = true;
                    //closes the start up window so the main window can run
                    this.Close();
                }
                catch (TimeoutException)
                {
                    MessageBox.Show("Your connection time out, make sure you typed the server name correctly", "Connection Timeout Error");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error");
                }
            }
        }