Exemple #1
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            //延迟启动,加快软件第一屏出现速度
            Task.Run(() =>
            {
                this.Dispatcher.Invoke(new Action(delegate {
                    //接收到、发送数据成功回调
                    Tools.Global.uart.UartDataRecived += Uart_UartDataRecived;
                    Tools.Global.uart.UartDataSent    += Uart_UartDataSent;

                    //初始化所有数据
                    Tools.Global.Initial();//cost 299ms

                    //重写关闭窗口代码
                    this.Closing += MainWindow_Closing;

                    //窗口置顶事件
                    Tools.Global.setting.MainWindowTop += new EventHandler(topEvent);

                    //usb刷新时触发
                    usbDeviceNotifier.Enabled         = true;
                    usbDeviceNotifier.OnDeviceNotify += UsbDeviceNotifier_OnDeviceNotify;;

                    //收发数据显示页面
                    dataShowFrame.Navigate(new Uri("Pages/DataShowPage.xaml", UriKind.Relative));

                    //加载初始波特率
                    baudRateComboBox.Text = Tools.Global.setting.baudRate.ToString();

                    //刷新设备列表
                    refreshPortList();

                    //绑定数据
                    this.toSendDataTextBox.DataContext      = Tools.Global.setting;
                    toSendList.ItemsSource                  = toSendListItems;
                    this.sentCountTextBlock.DataContext     = Tools.Global.setting;
                    this.receivedCountTextBlock.DataContext = Tools.Global.setting;

                    //初始化快捷发送栏的数据
                    this.QuickListPage.DataContext = Tools.Global.setting;
                    canSaveSendList = false;
                    if (Global.setting.quickSendSelect == -1)
                    {
                        Global.setting.quickSendSelect = 0;
                    }
                    ToSendData.DataChanged += SaveSendList;
                    LoadQuickSendList();
                    canSaveSendList = true;


                    //快速搜索
                    SearchPanel.Install(textEditor.TextArea);
                    string name = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name + ".Lua.xshd";
                    System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
                    using (System.IO.Stream s = assembly.GetManifestResourceStream(name))
                    {
                        using (XmlTextReader reader = new XmlTextReader(s))
                        {
                            var xshd = HighlightingLoader.LoadXshd(reader);
                            textEditor.SyntaxHighlighting = HighlightingLoader.Load(xshd, HighlightingManager.Instance);
                        }
                    }

                    //加载上次打开的文件
                    loadLuaFile(Tools.Global.setting.runScript);

                    //加载lua日志打印事件
                    LuaEnv.LuaApis.PrintLuaLog += LuaApis_PrintLuaLog;
                    //lua代码出错/结束运行事件
                    LuaEnv.LuaRunEnv.LuaRunError += LuaRunEnv_LuaRunError;

                    //关于页面
                    aboutFrame.Navigate(new Uri("Pages/AboutPage.xaml", UriKind.Relative));

                    //tcp测试页面
                    tcpTestFrame.Navigate(new Uri("Pages/tcpTest.xaml", UriKind.Relative));

                    //mqtt测试页面
                    MqttTestFrame.Navigate(new Uri("Pages/MqttTestPage.xaml", UriKind.Relative));

                    //编码转换工具页面
                    EncodingToolsFrame.Navigate(new Uri("Pages/ConvertPage.xaml", UriKind.Relative));

                    //乱码修复
                    EncodingFixFrame.Navigate(new Uri("Pages/EncodingFixPage.xaml", UriKind.Relative));

                    this.Title += $" - {System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()}";

                    //检查更新
                    if (!Tools.Global.IsMSIX() && Tools.Global.setting.autoUpdate)
                    {
                        Task.Run(() => {
                            bool runed = false;
                            AutoUpdaterDotNET.AutoUpdater.CheckForUpdateEvent += (args) =>
                            {
                                if (runed)
                                {
                                    return;
                                }
                                runed = true;
                                if (args.IsUpdateAvailable)
                                {
                                    this.Dispatcher.Invoke(new Action(delegate
                                    {
                                        AutoUpdaterDotNET.AutoUpdater.ShowUpdateForm(args);
                                    }));
                                }
                            };
                            Random r = new Random();//加上随机参数,确保获取的是最新数据
                            try
                            {
                                AutoUpdaterDotNET.AutoUpdater.Start("https://llcom.papapoi.com/autoUpdate.xml?" + r);
                            }
                            catch
                            {
                                runed = true;
                            }
                        });
                    }
                }));
            });
        }
Exemple #2
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            //接收到、发送数据成功回调
            Tools.Global.uart.UartDataRecived += Uart_UartDataRecived;
            Tools.Global.uart.UartDataSent    += Uart_UartDataSent;

            //初始化所有数据
            Tools.Global.Initial();

            //重写关闭窗口代码
            this.Closing += MainWindow_Closing;

            //窗口置顶事件
            Tools.Global.setting.MainWindowTop += new EventHandler(topEvent);

            //usb刷新时触发
            usbDeviceNotifier.Enabled         = true;
            usbDeviceNotifier.OnDeviceNotify += UsbDeviceNotifier_OnDeviceNotify;;

            //收发数据显示页面
            dataShowFrame.Navigate(new Uri("Pages/DataShowPage.xaml", UriKind.Relative));

            //加载初始波特率
            baudRateComboBox.Text = Tools.Global.setting.baudRate.ToString();

            //刷新设备列表
            refreshPortList();

            //绑定数据
            this.toSendDataTextBox.DataContext      = Tools.Global.setting;
            toSendList.ItemsSource                  = toSendListItems;
            this.sentCountTextBlock.DataContext     = Tools.Global.setting;
            this.receivedCountTextBlock.DataContext = Tools.Global.setting;

            //初始化快捷发送栏的数据
            canSaveSendList         = false;
            ToSendData.DataChanged += SaveSendList;
            try
            {
                JObject jo = (JObject)JsonConvert.DeserializeObject(Tools.Global.setting.quickData);
                foreach (var i in jo["data"])
                {
                    if (i["commit"] == null)
                    {
                        i["commit"] = FindResource("QuickSendButton") as string;
                    }
                    toSendListItems.Add(new ToSendData()
                    {
                        id     = (int)i["id"],
                        text   = (string)i["text"],
                        hex    = (bool)i["hex"],
                        commit = (string)i["commit"]
                    });
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show($"{FindResource("QuickSendLoadError") as string}\r\n" + ex.ToString() + "\r\n" + Tools.Global.setting.quickData);
                Tools.Global.setting.quickData = "{\"data\":[{\"id\":1,\"text\":\"example string\",\"hex\":false},{\"id\":2,\"text\":\"lua可通过接口获取此处数据\",\"hex\":false},{\"id\":3,\"text\":\"aa 01 02 0d 0a\",\"hex\":true},{\"id\":4,\"text\":\"此处数据会被lua处理\",\"hex\":false}]}";
            }
            canSaveSendList = true;

            //快速搜索
            SearchPanel.Install(textEditor.TextArea);
            string name = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name + ".Lua.xshd";

            System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
            using (System.IO.Stream s = assembly.GetManifestResourceStream(name))
            {
                using (XmlTextReader reader = new XmlTextReader(s))
                {
                    var xshd = HighlightingLoader.LoadXshd(reader);
                    textEditor.SyntaxHighlighting = HighlightingLoader.Load(xshd, HighlightingManager.Instance);
                }
            }

            //加载上次打开的文件
            loadLuaFile(Tools.Global.setting.runScript);

            //加载lua日志打印事件
            LuaEnv.LuaApis.PrintLuaLog += LuaApis_PrintLuaLog;
            //lua代码出错/结束运行事件
            LuaEnv.LuaRunEnv.LuaRunError += LuaRunEnv_LuaRunError;

            //关于页面
            aboutFrame.Navigate(new Uri("Pages/AboutPage.xaml", UriKind.Relative));

            //tcp测试页面
            tcpTestFrame.Navigate(new Uri("Pages/tcpTest.xaml", UriKind.Relative));

            //mqtt测试页面
            MqttTestFrame.Navigate(new Uri("Pages/MqttTestPage.xaml", UriKind.Relative));

            //编码转换工具页面
            EncodingToolsFrame.Navigate(new Uri("Pages/ConvertPage.xaml", UriKind.Relative));

            //乱码修复
            EncodingFixFrame.Navigate(new Uri("Pages/EncodingFixPage.xaml", UriKind.Relative));

            this.Title += $" - {System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()}";
        }