示例#1
0
 private void ws_webSocketMessage(object sender, WebSocketMessageEventArgs e)
 {
     Dispatcher.BeginInvoke(new Action(delegate
     {
         if (!e.Message.StartsWith("SYSTEM:") && !e.Message.StartsWith("Info:"))
         {
             var hextorgb = ColorTranslator.FromHtml("#" + e.Color);
             var userColor = Color.FromArgb(hextorgb.A, hextorgb.R, hextorgb.G, hextorgb.B);
             SolidColorBrush brush = new SolidColorBrush(userColor);
             chatTextBox.Foreground = brush;
             chatTextBox.Inlines.Add(e.UserName);
             chatTextBox.Foreground = Brushes.Black;
             chatTextBox.Inlines.Add(": ");
             chatTextBox.Inlines.Add(HttpUtility.HtmlDecode(e.Message));
         }
         else
         {
             chatTextBox.Inlines.Add(String.Format("{0}", e.Message));
         }
         chatTextBox.Inlines.Add(Environment.NewLine);
     }));
 }
 private void OnWebSocketMessageReceived(WebSocketMessageEventArgs e)
 {
     if (WebSocketMessage != null)
         WebSocketMessage(this, e);
 }
 public void GuiMessage(string username, string messasge, string color)
 {
     var wsMessage = new WebSocketMessageEventArgs {UserName = username, Message = messasge, Color = color};
     OnWebSocketMessageReceived(wsMessage);
 }