/// <summary> /// Adds the message. /// </summary> /// <param name="message">The message.</param> public void AddMessage(Message message) { if (this.InvokeRequired) { AddMessageCallback d = new AddMessageCallback(AddMessage); this.Invoke(d, new object[] { message }); } else { checked { Font labelFont = new Font(new FontFamily("Courier New"), 15); string unformattedMessage; if (string.IsNullOrEmpty(message.SenderName)) unformattedMessage = message.MsgText; else unformattedMessage = message.SenderName + ": " + message.MsgText; /*Tuple<int, string> formattedMessage = BreakString47(unformatted_message);*/ Tuple<Size, string> formattedMessage = CalculateLabelSize(unformattedMessage, labelFont, 600); Label label = new Label(); //label.Text = formattedMessage.Item2; label.Text = formattedMessage.Item2; label.Size = formattedMessage.Item1; int heightDelta = label.Height+8;// = lineHeight * formattedMessage.Item1; label.Click += Label_Click; label.DoubleClick += Label_DoubleClick; label.BackColor = Color.Azure; label.ForeColor = Color.Black; label.Font = labelFont; switch (message.MsgType) { case MsgTypes.Dialog: dialogs.AutoScrollPosition = new Point(0,0); label.Location = new Point(0, dialogYPos); dialogYPos += heightDelta; dialogs.Controls.Add(label); break; case MsgTypes.Group: groups.AutoScrollPosition = new Point(0, 0); label.Location = new Point(0, groupsYPos); groupsYPos += heightDelta; groups.Controls.Add(label); break; case MsgTypes.Personal: personal.AutoScrollPosition = new Point(0, 0); label.Location = new Point(0, personalYPos); personalYPos += heightDelta; personal.Controls.Add(label); break; } tempTable.Add(label, message); lastMessageType = message.MsgType; this.Refresh(); } } }
public void AddMessage(string message, Color color) { if (richTextBox1.InvokeRequired) { AddMessageCallback cb = new AddMessageCallback(AddMessageInternal); richTextBox1.BeginInvoke(cb, message, color); } else { AddMessageInternal(message, color); } }
private void AddMessage(string msg) { if (this.listBox1.InvokeRequired) { AddMessageCallback d = new AddMessageCallback(AddMessage); this.Invoke(d, new object[] { msg }); } else { listBox1.Items.Add("[" + DateTime.Now.ToShortTimeString() + "] " + msg); } }
private void AddMessage(string text) { if (this.resTB.InvokeRequired) { AddMessageCallback d = new AddMessageCallback(AddMessage); this.Invoke(d, new object[] { text }); } else { string txt = this.resTB.Text; this.resTB.Text = "\r\n " + DateTime.Now.ToString("dd.MM.yyyy hh:mm:ss.fffff") + " : " + text + txt; // AppLog.AddToLog(text); } }
public void AddMessage(string message) { if (this.flowLayoutPanel1.InvokeRequired) { AddMessageCallback r = new AddMessageCallback(AddMessage); this.Invoke(r, new object[] { message }); } else { WappMessage msg = new WappMessage(message, this.target); this.messages.Add(msg); this.limitMessages(); MessageStore.AddMessage(msg); this.addChatMessage(msg); this.ScrollToBottom(); } }
public void AddMessage(string message) { if (this.flowLayoutPanel1.InvokeRequired) { AddMessageCallback r = new AddMessageCallback(AddMessage); this.Invoke(r, new object[] {message}); } else { WappMessage msg = new WappMessage(message, this.target); this.messages.Add(msg); this.limitMessages(); MessageStore.AddMessage(msg); this.addChatMessage(msg); this.ScrollToBottom(); } }
//Will be a post if postPayload is not blank otherwise it will be a get public static JObject Http(String sUrl, String sUsername, String sPassword, JObject postObj, AddMessageCallback AMessageCallback) { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; try { //Build the web request that will act as a "web service client" AMessageCallback(sUrl); HttpWebRequest loHttp = (HttpWebRequest)WebRequest.Create(sUrl); loHttp.Timeout = 5 * 60 * 1000; loHttp.Credentials = new NetworkCredential(sUsername, sPassword); if (postObj != null) { // set request body String postPayload = JsonConvert.SerializeObject(postObj, Formatting.Indented); loHttp.ContentType = "application/json"; loHttp.Method = "POST"; AMessageCallback(postPayload); using (StreamWriter writer = new StreamWriter(loHttp.GetRequestStream())) writer.Write(postPayload); } else { loHttp.Method = "GET"; } ServicePointManager.ServerCertificateValidationCallback += delegate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return(true); }; //Get the response and load it into a buffer stream HttpWebResponse loWebResponse = (HttpWebResponse)loHttp.GetResponse(); //Copy the contents asynchronously for fastest performance MemoryStream memSt = new MemoryStream(); AsyncStreamCopier aCopy = new AsyncStreamCopier(loWebResponse.GetResponseStream(), memSt); aCopy.StartAndWaitForCompletion(); //Send the response conent back to the caller loWebResponse.Close(); JObject retVal = JsonConvert.DeserializeObject <JObject>(ASCIIEncoding.ASCII.GetString(memSt.ToArray())); //Format the json to be "pretty" AMessageCallback(JsonConvert.SerializeObject(retVal, Formatting.Indented)); return(retVal); } catch (WebException exp) { throw new Exception(String.Format("Error processing request: {0}, Response: {1}", exp.Message, GetResponseContent(exp.Response))); } }