コード例 #1
0
        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);
                    }
                }
            }
        }
コード例 #2
0
        public override bool Equals(object obj)
        {
            ClientPart client = (ClientPart)obj;

            if ((client.nick == this.nick) && (client.color == this.color))
            {
                return(true);
            }
            return(false);
        }
コード例 #3
0
 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);
     }));
 }
コード例 #4
0
 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();
     }));
 }
コード例 #5
0
ファイル: MainWindow.xaml.cs プロジェクト: SvetaSliusar/Chat
        private void connect_Click(object sender, RoutedEventArgs e)
        {
            client = new ClientPart(ipBox.Text, Convert.ToInt32(portBox.Text));

            this.Close();
        }