Пример #1
0
 private async void TextBoxSend_KeyDown(object o, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Enter)
     {
         e.SuppressKeyPress = true;
         if (!string.IsNullOrWhiteSpace(currentSendTextBox.Text))
         {
             string timestamp = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss");
             AppendPendingMessage(Username, tabControlConversations.SelectedTab.Text, timestamp, currentSendTextBox.Text);
             AppendChatLog(Username, tabControlConversations.SelectedTab.Text, timestamp, currentSendTextBox.Text);
             currentReadTextBox.AppendText(Username + "> " + currentSendTextBox.Text + "\n");
             string msg = currentSendTextBox.Text;
             currentSendTextBox.Clear();
             currentSendTextBox.Select(0, 0);
             if (!ServerCommunicator.Communicating)
             {
                 ServerCommunicator.Communicating = true;
                 if (await ServerCommunicator.SendMessage(Username, tabControlConversations.SelectedTab.Text, timestamp, msg))
                 {
                     //Ta bort från pending_messages.xml
                     RemovePendingMessage();
                 }
                 ServerCommunicator.Communicating = false;
             }
         }
     }
 }
Пример #2
0
        private async void Tick(object s, EventArgs e)
        {
            Timer.Stop();
            if (await ServerCommunicator.CheckConnection(Username))
            {
                textBoxServerStatus.BackColor = Color.DarkOliveGreen;
                textBoxServerStatus.Text      = "Connected";
            }
            else
            {
                textBoxServerStatus.BackColor = Color.DarkRed;
                textBoxServerStatus.Text      = "Disconnected";
            }
            LoadUsers();
            if (tabControlConversations.SelectedTab != null)
            {
                //Hämta timestamp
                string timestamp = LoadTimestamp(tabControlConversations.SelectedTab.Text);
                if (string.IsNullOrWhiteSpace(timestamp))
                {
                    timestamp = DateTime.UtcNow.AddSeconds(-30).ToString("yyyy-MM-dd HH:mm:ss");
                }

                LoadChatLog(tabControlConversations.SelectedTab.Text, timestamp);
            }
            //Ta bort pending_messages
            if (!ServerCommunicator.Communicating)
            {
                ServerCommunicator.Communicating = true;
                File.SetAttributes(Configurator.PendingMessagesPath, FileAttributes.Normal);
                XmlDocument doc = new XmlDocument();
                doc.Load(Configurator.PendingMessagesPath);
                XmlNode messages     = doc.SelectSingleNode("/pending_messages");
                XmlNode childMessage = messages.FirstChild;
                doc = null;

                if (childMessage != null && await ServerCommunicator.SendMessage(Username, childMessage.Attributes["receiver"].Value, childMessage.Attributes["timestamp"].Value, childMessage.InnerText))
                {
                    RemovePendingMessage();
                }
                ServerCommunicator.Communicating = false;
                File.SetAttributes(Configurator.PendingMessagesPath, FileAttributes.Hidden | FileAttributes.ReadOnly);
            }
            Timer.Start();
        }