예제 #1
0
 private void ReceiveMessage(string text)
 {
     Application.Current.Dispatcher.BeginInvoke(
         DispatcherPriority.Background,
         new Action(() =>
     {
         try
         {
             if (text.Contains(logCode))
             {
                 UserBubble bubble = new UserBubble();
                 text             = text.Replace(logCode, "");
                 bubble.name.Text = text;
                 sp_user.Children.Add(bubble);
                 sv_user.ScrollToBottom();
             }
             else if (text.Contains(logApperanceChanged))
             {
                 sp_user.Children.Clear();
                 chatHubProxy.Invoke("Broadcast", logCode + name).Wait();
             }
             else
             {
                 MessageBubble bubble = new MessageBubble();
                 var cut             = text.Split('§');
                 bubble.name.Text    = cut[0];
                 bubble.message.Text = cut[1];
                 bubble.date.Text    = cut[2];
                 sp_messages.Children.Add(bubble);
                 sv_messages.ScrollToBottom();
             }
         }
         catch (System.IndexOutOfRangeException)
         {
         }
     }
                    ));
 }
예제 #2
0
        private void btn_senden_Click(object sender, RoutedEventArgs e)
        {
            hubConnection.Start().Wait();

            if (sender != null)
            {
                string message = tb_senden.Text;
                tb_senden.Text = "";

                chatHubProxy.Invoke("Broadcast", name + "§" + message + "§" + DateTime.Now.Hour.ToString() + ":" + DateTime.Now.Minute.ToString()).Wait();

                MessageBubble bubble = new MessageBubble();
                bubble.HorizontalAlignment = HorizontalAlignment.Right;
                Thickness margin = bubble.grid_bubble.Margin;
                margin.Left                  = 100;
                margin.Right                 = 5;
                margin.Top                   = 2;
                margin.Bottom                = 2;
                bubble.grid_bubble.Margin    = margin;
                bubble.name.Text             = name;
                bubble.message.Text          = message;
                bubble.message.TextAlignment = TextAlignment.Right;
                bubble.date.Text             = DateTime.Now.Hour.ToString() + ":" + DateTime.Now.Minute.ToString();
                sp_messages.Children.Add(bubble);
                sv_messages.ScrollToBottom();
            }
            else
            {
                chatHubProxy.Invoke("Broadcast", logApperanceChanged).Wait();
                Application.Current.Dispatcher.BeginInvoke(
                    DispatcherPriority.Background,
                    new Action(() =>
                {
                    chatHubProxy.Invoke("Broadcast", logCode + name).Wait();
                }));
            }
        }