public Ticket UpdateFromDto(TicketDto ticketDto) { TicketId = ticketDto.id; TitleName = ticketDto.title; CategoryName = ticketDto.group?.title; ReviewText = ticketDto.details; DateReview = !string.IsNullOrEmpty(ticketDto.date_review) ? DateTime.Parse(ticketDto.date_review) : default(DateTime); UserServerId = ticketDto.user?.binary_id; GroupId = ticketDto.group_id; OffersCount = ticketDto.offers_count; ListOfTagTitles.Clear(); if (ticketDto.tags != null) { foreach (var ticketTagDto in ticketDto.tags) { ListOfTagTitles.Add(ticketTagDto.title); } } ListOfUsers.Clear(); if (ticketDto.users != null) { foreach (var userTicketDto in ticketDto.users) { ListOfUsers.Add(new UserTicket().UpdateFromDto(userTicketDto)); } } return(this); }
// метод приема сообщений private void ReceiveMessages() { alive = true; try { while (alive) { IPEndPoint remoteIp = null; byte[] data = client.Receive(ref remoteIp); string message = Encoding.Unicode.GetString(data); if (message[0] == '0') { message = message.Substring(message.IndexOf("\n") + 1); string time = DateTime.Now.ToShortTimeString(); context.Post(delegate(object state) { ChatMessages.AppendText(time + " " + message + "\r\n"); }, null); } else if (message[0] == '1') { //context.Post(delegate (object state) { ListOfUsers.Clear(); }, null); message = message.Substring(message.IndexOf("\n")); ListOfUsers.Clear(); context.Post(delegate(object state) { ListOfUsers.AppendText(message + "\r\n"); }, null); } else if (message[0] == '@') { ExitChat(); } } } catch (ObjectDisposedException) { if (!alive) { return; } throw; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
// метод приема сообщений private void ReceiveMessages() { alive = true; try { while (alive) { IPEndPoint remoteIp = null; byte[] data = client.Receive(ref remoteIp); string message = Encoding.Unicode.GetString(data); if (message[0] == '0') { message = message.Substring(message.IndexOf("\n") + 1); string time = DateTime.Now.ToShortTimeString(); context.Post(delegate(object state) { ChatMessages.AppendText(time + " " + message + "\r\n"); }, null); string message_from_server = "0 \n"; message_from_server += ChatMessages; foreach (int port in ports) { data = Encoding.Unicode.GetBytes(message_from_server); client.Send(data, data.Length, HOST, port); } } else if (message[0] == '1') { message = message.Substring(message.IndexOf("\n")); users_in_room.Add(message); ListOfUsers.Clear(); context.Post(delegate(object state) { ListOfUsers.AppendText(message + "\r\n"); }, null); string message_from_server1 = "1 \n"; foreach (string name in users_in_room) { message_from_server1 += name + "\r\n"; } foreach (int port in ports) { data = Encoding.Unicode.GetBytes(message_from_server1); client.Send(data, data.Length, HOST, port); } } else if (message[0] == 'p') { message = message.Substring(message.IndexOf("\n") + 1); ports.Add(int.Parse(message)); } else if (message[0] == 'e') { message = message.Substring(message.IndexOf("\n") + 1); ports.Remove(int.Parse(message)); } else if (message[0] == 'o') { message = message.Substring(message.IndexOf("\n") + 1); users_in_room.Remove(message); ListOfUsers.Clear(); context.Post(delegate(object state) { ListOfUsers.AppendText(message + "\r\n"); }, null); string message_from_server1 = "1 \n"; foreach (string name in users_in_room) { message_from_server1 += name + "\r\n"; } foreach (int port in ports) { data = Encoding.Unicode.GetBytes(message_from_server1); client.Send(data, data.Length, HOST, port); } } } } catch (ObjectDisposedException) { if (!alive) { return; } throw; } catch (Exception ex) { MessageBox.Show(ex.Message); } }