private void GetUsersAndMessages(string msg) { string[] msgArr = msg.Split(this.separator); if (msgArr.Length <= 1) { return; } switch (msgArr[0]) { case "UL": this.users.Clear(); for (int i = 1; i < msgArr.Length; i++) { this.users.Add(msgArr[i]); } this.Dispatcher.Invoke(new Action(() => this.lbUsers.Items.Refresh())); break; case "ML": if (this.messages.Count >= 1000) { this.messages.RemoveRange(0, 100); } for (int i = 1; i < msgArr.Length; i += 3) { Message m = new Message(msgArr[i], msgArr[i + 1], msgArr[i + 2]); this.messages.Add(m); } this.Dispatcher.Invoke(new Action(() => this.lbMessages.Items.Refresh())); break; default: break; } }
private void GetMessages() { string request = "GMS" + this.separator; string responce = ""; lock (this.tcpClient) { this.SendRequestToServer(request); responce = this.GetResponseFromServer(); } string[] respArr = responce.Split(this.separator); switch (respArr[0]) { case "OK": if (this.messages.Count >= 1000) { this.messages.RemoveRange(0, 100); } Message msg = null; for (int i = 1; i < respArr.Length; i += 3) { msg = new Message(respArr[i], respArr[i + 1] + ":", respArr[i + 2]); this.messages.Add(msg); } break; case "ERR": MessageBox.Show(respArr[1], "Получение списка сообщений", MessageBoxButton.OK, MessageBoxImage.Warning); break; default: break; } }