Пример #1
0
        /// <summary>
        /// Print text stored in log file to chat window.
        /// </summary>
        private void PrintLog(int lines)
        {
            // Store all lins of the log file
            string[] log = CchatLog.ReadFromLog();

            // Iterate through last set of lines until end of log
            for (int i = log.Length - lines - 1; i < log.Length; i++)
            {
                chatBox.AppendText(log.ElementAt(i) + "\r\n");
            }
        }
Пример #2
0
        /// <summary>
        /// Create application instance.
        /// </summary>
        public Form1()
        {
            InitializeComponent();
            //InitBrowser();

            CchatLog.CreateLog();
            PrintLog(20);
            ScrollToBottom(chatBox);
            startServerIPBox.Text     = CchatConnectionInfo.GetServerIP();
            startServerPortBox.Text   = CchatConnectionInfo.GetPort();
            connectServerPortBox.Text = CchatConnectionInfo.GetPort();
        }
Пример #3
0
        private void dataSender_DoWork(object sender, DoWorkEventArgs e)
        {
            if (client != null && client.Connected)
            {
                if (image_to_send != null)
                {
                    // Convert Image to bytes
                    byte[] imageBytes = CchatImage.GetByteArrayFromImage(image_to_send);
                    // Store length of the byte array of the Image
                    string imageLength = "" + imageBytes.Length;
                    // Send the length
                    streamWriter.WriteLine(imageLength);
                    // Send the Image
                    binaryWriter.Write(imageBytes, 0, imageBytes.Length);
                    // Show Image to self
                    PrintImage(image_to_send);
                    // Clean up old image to send
                    image_to_send = null;
                    // Wait before sending next
                    Thread.Sleep(1000);
                }

                if (text_to_send != null)
                {
                    // Send text written in the textbox
                    streamWriter.WriteLine(MSG_PREFIX_RECEIVER + text_to_send);
                    // Show text written to self
                    PrintText(MSG_PREFIX_SENDER + text_to_send);
                    // Store text written in textbox to log
                    CchatLog.WriteToLog(MSG_PREFIX_SENDER + text_to_send);
                    // Clean up old text to send
                    text_to_send = null;
                }
            }
            else
            {
                PrintText(MSG_ERROR_SEND_DATA);
                return;
            }
        }