/// <summary> /// Invoke when need add string to lbLog where receive message /// </summary> /// <param name="msg">Added string</param> private void InvokeWriteToLog(string msg) { if (lbLog.InvokeRequired) { AddStringToListBox d = new AddStringToListBox((text) => { InvokeReceiveMessage(text); }); this.Invoke(d, new object[] { msg }); } else { InvokeReceiveMessage(msg); } }
/// <summary> /// Write message to log list /// </summary> /// <param name="agentMessage">Agent message</param> private void WriteMessageToLogList(AgentMessage agentMessage) { string msg = "[" + agentMessage.SenderAgent + "]"; if (agentMessage.MessageType == MessageType.Subscribe) msg += " +" + agentMessage.Subject; else if (agentMessage.MessageType == MessageType.Unsubscribe) msg += " -" + agentMessage.Subject; else if (agentMessage.MessageType == MessageType.Hello) msg += " Установлено соединение с " + agentMessage.SenderAgent; else if (agentMessage.MessageType == MessageType.Bye) msg += " Закрыто соединение с " + agentMessage.SenderAgent; //msg += agentMessage.Subject; if (agentMessage.MessageType == MessageType.Message) { msg += " : "; msg += agentMessage.Text; } if (lbLog.InvokeRequired) { AddStringToListBox d = new AddStringToListBox((text) => { InvokeReceiveMessage(text); }); this.Invoke(d, new object[] { msg }); } else { InvokeReceiveMessage(msg); } }