public void Processing() { string info = readData(); List <ClientPart> clients = JsonConvert.DeserializeObject <List <ClientPart> >(info); AddUsersToListBox(clients); while (client.Connected) { info = readData(); if (info != "") { ClientPart client = JsonConvert.DeserializeObject <ClientPart>(info); if (client.message == "connected") { clients.Add(client); AddUserToListBox(client); } else if (client.message == "disconnected") { RemoveAtListBox(clients.IndexOf(client)); clients.Remove(client); } else { showMessageFromClient(client); } } } }
public override bool Equals(object obj) { ClientPart client = (ClientPart)obj; if ((client.nick == this.nick) && (client.color == this.color)) { return(true); } return(false); }
public void AddUserToListBox(ClientPart client) { chat.Dispatcher.BeginInvoke( (Action)(() => { ListBoxItem item = new ListBoxItem(); item.Content = client.nick + " online"; item.Foreground = (Brush) new BrushConverter().ConvertFromString(client.color); chat.users.Items.Add(item); })); }
void showMessageFromClient(ClientPart client) { chat.Dispatcher.BeginInvoke( (Action)(() => { Brush brush = brushFromString(client.color); TextPointer previewTextEnd = chat.chatText.Document.ContentEnd; TextRange nickRange = new TextRange(previewTextEnd, previewTextEnd); nickRange.Text = client.nick + " "; nickRange.ApplyPropertyValue(RichTextBox.ForegroundProperty, brush); TextPointer nickRangeEnd = chat.chatText.Document.ContentEnd; TextRange messageRange = new TextRange(nickRangeEnd, nickRangeEnd); messageRange.Text = client.message + "\r"; messageRange.ClearAllProperties(); chat.chatText.ScrollToEnd(); })); }
private void connect_Click(object sender, RoutedEventArgs e) { client = new ClientPart(ipBox.Text, Convert.ToInt32(portBox.Text)); this.Close(); }