コード例 #1
0
ファイル: PopMessage.cs プロジェクト: FreakLign/Goodsig
 public PopMessage(MessageHall Hall)
 {
     this.Hall = Hall;
     MQTTEventTrigger.SetCallBackAction(new PubSubClient.ReceiveMessage(((string Topic, string Message) =>
     {
         if (Message != "" && Topic != "")
         {
             Task.Factory.StartNew(() =>
             {
                 Hall.Dispatcher.Invoke(() =>
                 {
                     TextBlock Content = new TextBlock();
                     MQTTEventTrigger.StatusMessage status = MQTTEventTrigger.MQTTMessageDecode(Topic, Message);
                     Content.Text = status.Message;
                     TextBlock Description = new TextBlock();
                     Description.Opacity = 0.68;
                     Description.Text = status.Description;
                     StackPanel panel = new StackPanel();
                     panel.Margin = new Thickness(24, 8, 24, 16);
                     panel.Orientation = Orientation.Vertical;
                     panel.Children.Add(Content);
                     panel.Children.Add(Description);
                     Expander expander = new Expander();
                     expander.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
                     expander.Header = status.Topic;
                     expander.Content = panel;
                     Hall.MessageList.Children.Insert(0, expander);
                     Hall.Ondoing.Text = status.Topic + "...";
                 });
             });
         }
     })));
 }
コード例 #2
0
        public static void StartConnection()
        {
            loginForm.ProgressLine.Visibility      = System.Windows.Visibility.Visible;
            loginForm.ProgressLine.IsIndeterminate = true;
            var MessageQueue = loginForm.SnackbarThree.MessageQueue;

            Task.Factory.StartNew(() =>
            {
                if (Middle.ConnectWithServer())
                {
                    Middle.client.SubScribe(new string [] { "Arduino/#", "Console/#" });
                    loginForm.Dispatcher.Invoke(() =>
                    {
                        home = new GUI.HomeWindow();
                        MQTTEventTrigger.Transfer(home, Middle.client);
                        home.Show();
                        home.Activate();
                        loginForm.Close();
                    });
                }
                else
                {
                    Task.Factory.StartNew(() =>
                    {
                        MessageQueue.Enqueue("未能连接到服务器,请检查服务器地址和端口以及用户名密码是否正确");
                        loginForm.Dispatcher.Invoke(() =>
                        {
                            loginForm.ProgressLine.IsIndeterminate = false;
                            loginForm.ProgressLine.Visibility      = System.Windows.Visibility.Hidden;
                        });
                    });
                }
            });
        }