Ejemplo n.º 1
0
 public KernelsWindow()
 {
     InitializeComponent();
     if (DevMode.IsDevMode)
     {
         this.Width += 600;
     }
     this.WindowContextEventPath <MineStopedEvent>("当内核宝库窗口开着时如果是本地手动停止的挖矿则引发UserActionEvent事件", LogEnum.DevConsole,
                                                   action: message => {
         if (message.StopReason == StopMineReason.LocalUserAction)
         {
             VirtualRoot.RaiseEvent(new UserActionEvent());
         }
     });
     this.WindowContextEventPath <ServerContextVmsReInitedEvent>("ServerContext的Vm集刷新后刷新内核宝库", LogEnum.DevConsole,
                                                                 action: message => {
         UIThread.Execute(() => {
             Vm.OnPropertyChanged(nameof(Vm.QueryResults));
         });
     });
     AppContext.Instance.KernelVms.PropertyChanged += Current_PropertyChanged;
     NotiCenterWindow.Bind(this);
     if (!Vm.MinerProfile.IsMining)
     {
         VirtualRoot.RaiseEvent(new UserActionEvent());
     }
 }
Ejemplo n.º 2
0
 public KernelsWindow()
 {
     // 为了使设计视图的宽高生效以下几个属性的赋值挪到这里
     Width     = AppRoot.MainWindowWidth;
     Height    = AppRoot.MainWindowHeight;
     MinHeight = 430;
     MinWidth  = 640;
     InitializeComponent();
     if (DevMode.IsDevMode)
     {
         this.Width += 600;
     }
     this.TbUcName.Text = nameof(KernelsWindow);
     this.AddEventPath <MineStopedEvent>("当内核宝库窗口开着时如果是本地手动停止的挖矿则引发UserActionEvent事件", LogEnum.DevConsole,
                                         action: message => {
         if (message.StopReason == StopMineReason.LocalUserAction)
         {
             VirtualRoot.RaiseEvent(new UserActionEvent());
         }
     }, location: this.GetType());
     this.AddEventPath <ServerContextVmsReInitedEvent>("ServerContext的Vm集刷新后刷新内核宝库", LogEnum.DevConsole,
                                                       action: message => {
         UIThread.Execute(() => () => {
             Vm.OnPropertyChanged(nameof(Vm.QueryResults));
         });
     }, location: this.GetType());
     AppRoot.KernelVms.PropertyChanged += Current_PropertyChanged;
     NotiCenterWindow.Bind(this);
     if (!Vm.MinerProfile.IsMining)
     {
         VirtualRoot.RaiseEvent(new UserActionEvent());
     }
 }
Ejemplo n.º 3
0
 private MinerClientsWindow()
 {
     Width            = SystemParameters.FullPrimaryScreenWidth * 0.95;
     Height           = SystemParameters.FullPrimaryScreenHeight * 0.95;
     this.DataContext = Vm;
     this.DataContext = AppContext.Instance.MinerClientsWindowVm;
     InitializeComponent();
     this.WindowContextEventPath <Per1SecondEvent>("刷新倒计时秒表", LogEnum.None,
                                                   action: message => {
         var minerClients = Vm.MinerClients.ToArray();
         if (Vm.CountDown > 0)
         {
             Vm.CountDown = Vm.CountDown - 1;
             foreach (var item in minerClients)
             {
                 item.OnPropertyChanged(nameof(item.LastActivedOnText));
             }
         }
     });
     this.WindowContextEventPath <Per10SecondEvent>("周期刷新在线客户端列表", LogEnum.DevConsole,
                                                    action: message => {
         AppContext.Instance.MinerClientsWindowVm.QueryMinerClients();
     });
     NotiCenterWindow.Bind(this);
     AppContext.Instance.MinerClientsWindowVm.QueryMinerClients();
     Write.UserLine("小提示:鼠标配合ctrl和shift可以多选矿机", ConsoleColor.Yellow);
 }
Ejemplo n.º 4
0
 private LoginWindow(Action onLoginSuccess)
 {
     _onLoginSuccess = onLoginSuccess;
     InitializeComponent();
     // 1个是通知窗口,1个是本窗口
     NotiCenterWindow.Bind(this, isNoOtherWindow: Application.Current.Windows.Count <= 2);
     PasswordFocus();
 }
Ejemplo n.º 5
0
 public MainWindow()
 {
     InitializeComponent();
     NotiCenterWindow.Bind(this);
     this.AddEventPath <LocalIpSetInitedEvent>("本机IP集刷新后刷新状态栏", LogEnum.DevConsole,
                                               action: message => {
         UIThread.Execute(() => Vm.RefreshLocalIps);
     }, location: this.GetType());
     this.AddCmdPath <ShowLocalIpsCommand>(LogEnum.DevConsole, action: message => {
         UIThread.Execute(() => LocalIpConfig.ShowWindow);
     }, location: this.GetType());
 }
Ejemplo n.º 6
0
 internal LoginWindow(Action onLoginSuccess, string serverHost, Action btnCloseClick)
 {
     _onLoginSuccess  = onLoginSuccess;
     _btnCloseClick   = btnCloseClick;
     this.Vm          = new LoginWindowViewModel(serverHost);
     this.DataContext = Vm;
     InitializeComponent();
     this.TbUcName.Text = nameof(LoginWindow);
     // 1个是通知窗口,1个是本窗口
     NotiCenterWindow.Bind(this);
     PasswordFocus();
 }
Ejemplo n.º 7
0
 public MainWindow()
 {
     if (WpfUtil.IsInDesignMode)
     {
         return;
     }
     this.Vm          = new MainWindowViewModel();
     this.DataContext = this.Vm;
     InitializeComponent();
     NotiCenterWindow.Bind(this);
     this.AddCmdPath <ShowLocalIpsCommand>(LogEnum.DevConsole, action: message => {
         UIThread.Execute(() => LocalIpConfig.ShowWindow());
     }, location: this.GetType());
 }
Ejemplo n.º 8
0
 private ChartsWindow()
 {
     Width  = SystemParameters.FullPrimaryScreenWidth * 0.95;
     Height = SystemParameters.FullPrimaryScreenHeight * 0.95;
     InitializeComponent();
     NotiCenterWindow.Bind(this);
     #region 总算力
     this.WindowContextEventPath <Per10SecondEvent>("周期刷新总算力图", LogEnum.DevConsole,
                                                    action: message => {
         RefreshTotalSpeedChart(limit: 1);
     });
     RefreshTotalSpeedChart(limit: 60);
     #endregion
 }
Ejemplo n.º 9
0
 private LoginWindow(Action onLoginSuccess, string serverHost, Action btnCloseClick)
 {
     _onLoginSuccess  = onLoginSuccess;
     _btnCloseClick   = btnCloseClick;
     this.Vm          = new LoginWindowViewModel(serverHost);
     this.DataContext = Vm;
     InitializeComponent();
     if (!string.IsNullOrEmpty(serverHost))
     {
         this.TextBoxServerHost.IsEnabled = false;
         this.ButtonServerHost.IsEnabled  = false;
     }
     this.TbUcName.Text = nameof(LoginWindow);
     // 1个是通知窗口,1个是本窗口
     NotiCenterWindow.Bind(this, isNoOtherWindow: Application.Current.Windows.Count <= 2);
     PasswordFocus();
 }
Ejemplo n.º 10
0
        private MinerClientsWindow()
        {
            Width            = SystemParameters.FullPrimaryScreenWidth * 0.95;
            Height           = SystemParameters.FullPrimaryScreenHeight * 0.95;
            this.DataContext = Vm;
            this.DataContext = AppContext.Instance.MinerClientsWindowVm;
            InitializeComponent();
            DateTime lastGetServerMessageOn = DateTime.MinValue;

            this.ServerMessagesUc.IsVisibleChanged += (sender, e) => {
                VirtualRoot.SetIsServerMessagesVisible(this.ServerMessagesUc.IsVisible);
                if (this.ServerMessagesUc.IsVisible)
                {
                    if (lastGetServerMessageOn.AddSeconds(10) < DateTime.Now)
                    {
                        lastGetServerMessageOn = DateTime.Now;
                        VirtualRoot.Execute(new LoadNewServerMessageCommand());
                    }
                }
            };
            this.BuildEventPath <Per1SecondEvent>("刷新倒计时秒表", LogEnum.None,
                                                  action: message => {
                var minerClients = Vm.MinerClients.ToArray();
                if (Vm.CountDown > 0)
                {
                    Vm.CountDown = Vm.CountDown - 1;
                    foreach (var item in minerClients)
                    {
                        item.OnPropertyChanged(nameof(item.LastActivedOnText));
                    }
                }
            });
            this.BuildEventPath <Per10SecondEvent>("周期刷新在线客户端列表", LogEnum.DevConsole,
                                                   action: message => {
                AppContext.Instance.MinerClientsWindowVm.QueryMinerClients();
            });
            NotiCenterWindow.Bind(this);
            AppContext.Instance.MinerClientsWindowVm.QueryMinerClients();
            Write.UserLine("小提示:鼠标配合ctrl和shift可以多选矿机", ConsoleColor.Yellow);
        }
Ejemplo n.º 11
0
 public KernelsWindow()
 {
     if (WpfUtil.IsInDesignMode)
     {
         return;
     }
     this.Vm          = new KernelsWindowViewModel();
     this.DataContext = this.Vm;
     // 为了使设计视图的宽高生效以下几个属性的赋值挪到这里
     Width     = AppRoot.MainWindowWidth;
     Height    = AppRoot.MainWindowHeight;
     MinHeight = 430;
     MinWidth  = 640;
     InitializeComponent();
     if (DevMode.IsDevMode)
     {
         this.Width += 600;
     }
     this.TbUcName.Text = nameof(KernelsWindow);
     this.BuildEventPath <MineStopedEvent>("当内核宝库窗口开着时如果是本地手动停止的挖矿则引发UserActionEvent事件", LogEnum.DevConsole,
                                           path: message => {
         if (message.StopReason == StopMineReason.LocalUserAction)
         {
             VirtualRoot.RaiseEvent(new UserActionEvent());
         }
     }, location: this.GetType());
     this.BuildEventPath <LocalContextReInitedEventHandledEvent>("ServerContext的Vm集刷新后刷新内核宝库", LogEnum.DevConsole,
                                                                 path: message => {
         Vm.OnPropertyChanged(nameof(Vm.QueryResults));
     }, location: this.GetType());
     AppRoot.KernelVms.PropertyChanged += Current_PropertyChanged;
     NotiCenterWindow.Bind(this);
     if (!Vm.MinerProfile.IsMining && ClientAppType.IsMinerClient)
     {
         VirtualRoot.RaiseEvent(new UserActionEvent());
     }
 }
Ejemplo n.º 12
0
        public MainWindow()
        {
            if (WpfUtil.IsInDesignMode)
            {
                return;
            }
            if (!NTMinerConsole.IsEnabled)
            {
                NTMinerConsole.Enable();
            }
            this.Vm          = new MainWindowViewModel();
            this.DataContext = Vm;
            this.MinHeight   = 430;
            this.MinWidth    = 640;
            this.Width       = AppRoot.MainWindowWidth;
            this.Height      = AppRoot.MainWindowHeight;
#if DEBUG
            NTStopwatch.Start();
#endif
            ConsoleWindow.Instance.MouseDown += (sender, e) => {
                MoveConsoleWindow();
            };
            SystemEvents.SessionSwitch += SystemEvents_SessionSwitch;
            this.Loaded += (sender, e) => {
                ConsoleTabItemTopBorder.Margin = new Thickness(0, ConsoleTabItem.ActualHeight - 1, 0, 0);
                MoveConsoleWindow();
                hwndSource = PresentationSource.FromVisual((Visual)sender) as HwndSource;
                hwndSource.AddHook(new HwndSourceHook(Win32Proc.WindowProc));
            };
            InitializeComponent();
            _leftDrawerGripWidth    = LeftDrawerGrip.Width;
            _btnOverClockBackground = BtnOverClock.Background;
            // 下面几行是为了看见设计视图
            this.ResizeCursors.Visibility = Visibility.Visible;
            this.HideLeftDrawerGrid();
            // 上面几行是为了看见设计视图

            DateTime lastGetServerMessageOn = DateTime.MinValue;
            // 切换了主界面上的Tab时
            this.MainTabControl.SelectionChanged += (sender, e) => {
                // 延迟创建,以加快主界面的启动
                #region
                var selectedItem = MainTabControl.SelectedItem;
                if (selectedItem == TabItemSpeedTable)
                {
                    if (SpeedTableContainer.Child == null)
                    {
                        SpeedTableContainer.Child = GetSpeedTable();
                    }
                }
                else if (selectedItem == TabItemMessage)
                {
                    if (MessagesContainer.Child == null)
                    {
                        MessagesContainer.Child = new Messages();
                    }
                }
                else if (selectedItem == TabItemToolbox)
                {
                    if (ToolboxContainer.Child == null)
                    {
                        ToolboxContainer.Child = new Toolbox();
                    }
                }
                else if (selectedItem == TabItemMinerProfileOption)
                {
                    if (MinerProfileOptionContainer.Child == null)
                    {
                        MinerProfileOptionContainer.Child = new MinerProfileOption();
                    }
                }
                RpcRoot.SetIsServerMessagesVisible(selectedItem == TabItemMessage);
                if (selectedItem == TabItemMessage)
                {
                    if (lastGetServerMessageOn.AddSeconds(10) < DateTime.Now)
                    {
                        lastGetServerMessageOn = DateTime.Now;
                        VirtualRoot.Execute(new LoadNewServerMessageCommand());
                    }
                }
                if (selectedItem == ConsoleTabItem)
                {
                    ConsoleTabItemTopBorder.Visibility = Visibility.Visible;
                }
                else
                {
                    ConsoleTabItemTopBorder.Visibility = Visibility.Collapsed;
                }
                #endregion
            };
            this.IsVisibleChanged += (sender, e) => {
                #region
                if (this.IsVisible)
                {
                    NTMinerContext.IsUiVisible = true;
                }
                else
                {
                    NTMinerContext.IsUiVisible = false;
                }
                MoveConsoleWindow();
                #endregion
            };
            this.StateChanged += (s, e) => {
                #region
                if (Vm.MinerProfile.IsShowInTaskbar)
                {
                    ShowInTaskbar = true;
                }
                else
                {
                    if (WindowState == WindowState.Minimized)
                    {
                        ShowInTaskbar = false;
                    }
                    else
                    {
                        ShowInTaskbar = true;
                    }
                }
                if (WindowState == WindowState.Maximized)
                {
                    ResizeCursors.Visibility = Visibility.Collapsed;
                }
                else
                {
                    ResizeCursors.Visibility = Visibility.Visible;
                }
                MoveConsoleWindow();
                #endregion
            };
            bool isLeftClosed = false;
            this.ConsoleRectangle.IsVisibleChanged += (sender, e) => {
                if (this.ConsoleRectangle.IsVisible)
                {
                    if (isLeftClosed != (LeftDrawerGrip.Width == _leftDrawerGripWidth))
                    {
                        ConsoleWindowFit();
                    }
                }
                else
                {
                    isLeftClosed = LeftDrawerGrip.Width == _leftDrawerGripWidth;
                }
            };
            this.ConsoleRectangle.SizeChanged += (s, e) => {
                MoveConsoleWindow();
            };
            if (this.Width < 860)
            {
                NTMinerConsole.UserWarn("左侧面板已折叠,可点击侧边的'开始挖矿'按钮展开。");
            }
            this.SizeChanged += (s, e) => {
                #region
                if (this.Width < 860)
                {
                    this.CloseLeftDrawer();
                    this.BtnAboutNTMiner.Visibility = Visibility.Collapsed;
                }
                else
                {
                    this.OpenLeftDrawer(isSizeChanged: true);
                    this.BtnAboutNTMiner.Visibility = Visibility.Visible;
                }
                if (!this.ConsoleRectangle.IsVisible)
                {
                    if (e.WidthChanged)
                    {
                        ConsoleWindow.Instance.Width = e.NewSize.Width;
                    }
                    if (e.HeightChanged)
                    {
                        ConsoleWindow.Instance.Height = e.NewSize.Height;
                    }
                }
                #endregion
            };
            NotiCenterWindow.Bind(this, ownerIsTopmost: true);
            this.LocationChanged += (sender, e) => {
                MoveConsoleWindow();
            };
            VirtualRoot.BuildCmdPath <TopmostCommand>(path: message => {
                UIThread.Execute(() => {
                    if (!this.Topmost)
                    {
                        this.Topmost = true;
                    }
                });
            }, this.GetType());
            VirtualRoot.BuildCmdPath <UnTopmostCommand>(path: message => {
                UIThread.Execute(() => {
                    if (this.Topmost)
                    {
                        this.Topmost = false;
                    }
                });
            }, this.GetType());
            VirtualRoot.BuildCmdPath <CloseMainWindowCommand>(path: message => {
                UIThread.Execute(() => {
                    if (message.IsAutoNoUi)
                    {
                        SwitchToNoUi();
                    }
                    else
                    {
                        this.Close();
                    }
                });
            }, location: this.GetType());
            this.BuildEventPath <Per1MinuteEvent>("挖矿中时自动切换为无界面模式", LogEnum.DevConsole,
                                                  path: message => {
                if (NTMinerContext.IsUiVisible && NTMinerContext.Instance.MinerProfile.IsAutoNoUi && NTMinerContext.Instance.IsMining)
                {
                    if (NTMinerContext.MainWindowRendedOn.AddMinutes(NTMinerContext.Instance.MinerProfile.AutoNoUiMinutes) < message.BornOn)
                    {
                        VirtualRoot.ThisLocalInfo(nameof(MainWindow), $"挖矿中界面展示{NTMinerContext.Instance.MinerProfile.AutoNoUiMinutes}分钟后自动切换为无界面模式,可在选项页调整配置");
                        VirtualRoot.Execute(new CloseMainWindowCommand(isAutoNoUi: true));
                    }
                }
            }, location: this.GetType());
#if DEBUG
            var elapsedMilliseconds = NTStopwatch.Stop();
            if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds)
            {
                NTMinerConsole.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor");
            }
#endif
        }
Ejemplo n.º 13
0
 public MainWindow()
 {
     InitializeComponent();
     NotiCenterWindow.Bind(this);
 }
Ejemplo n.º 14
0
 public LoginWindow()
 {
     InitializeComponent();
     NotiCenterWindow.Bind(this, isNoOtherWindow: true);
     this.PbPassword.Focus();
 }
Ejemplo n.º 15
0
        public MainWindow()
        {
            this.MinHeight = 430;
            this.MinWidth  = 640;
            this.Width     = AppStatic.MainWindowWidth;
            this.Height    = AppStatic.MainWindowHeight;
#if DEBUG
            Write.Stopwatch.Restart();
#endif
            this.Owner = ConsoleWindow.Instance;
            InitializeComponent();

            BtnMinerProfileGrip.Visibility = Visibility.Collapsed;
            if (WpfUtil.IsInDesignMode)
            {
                return;
            }

            UIThread.StartTimer();
            ConsoleWindow.Instance.OnSplashHided = MoveConsoleWindow;
            _borderBrush = this.BorderBrush;
            NTMinerRoot.RefreshArgsAssembly.Invoke();

            this.MainArea.SelectionChanged += (sender, e) => {
                var selectedItem = MainArea.SelectedItem;
                if (selectedItem == TabItemToolbox)
                {
                    if (ToolboxContainer.Child == null)
                    {
                        ToolboxContainer.Child = new Toolbox();
                    }
                }
                else if (selectedItem == TabItemMinerProfileOption)
                {
                    if (MinerProfileOptionContainer.Child == null)
                    {
                        MinerProfileOptionContainer.Child = new MinerProfileOption();
                    }
                }
            };
            this.IsVisibleChanged += (sender, e) => {
                if (this.IsVisible)
                {
                    NTMinerRoot.IsUiVisible        = true;
                    NTMinerRoot.MainWindowRendedOn = DateTime.Now;
                }
                else
                {
                    NTMinerRoot.IsUiVisible = false;
                }
                MoveConsoleWindow();
            };
            this.ConsoleRectangle.IsVisibleChanged += (sender, e) => {
                MoveConsoleWindow();
            };
            this.StateChanged += (s, e) => {
                if (Vm.MinerProfile.IsShowInTaskbar)
                {
                    ShowInTaskbar = true;
                }
                else
                {
                    if (WindowState == WindowState.Minimized)
                    {
                        ShowInTaskbar = false;
                    }
                    else
                    {
                        ShowInTaskbar = true;
                    }
                }
                if (WindowState == WindowState.Maximized)
                {
                    ResizeCursors.Visibility = Visibility.Collapsed;
                    this.BorderBrush         = WpfUtil.BlackBrush;
                }
                else
                {
                    ResizeCursors.Visibility = Visibility.Visible;
                    this.BorderBrush         = _borderBrush;
                }
                MoveConsoleWindow();
            };
            this.SizeChanged += (s, e) => {
                if (!ConsoleRectangle.IsVisible)
                {
                    ConsoleWindow.Instance.Hide();
                }
            };
            this.ConsoleRectangle.SizeChanged += (s, e) => {
                MoveConsoleWindow();
            };
            NotiCenterWindow.Bind(this, ownerIsTopMost: true);
            this.LocationChanged += (sender, e) => {
                MoveConsoleWindow();
            };
            VirtualRoot.BuildCmdPath <CloseMainWindowCommand>(action: message => {
                UIThread.Execute(() => {
                    if (NTMinerRoot.Instance.MinerProfile.IsCloseMeanExit)
                    {
                        VirtualRoot.Execute(new CloseNTMinerCommand());
                        return;
                    }
                    this.Close();
                    VirtualRoot.Out.ShowSuccess(message.Message, "开源矿工");
                });
            });
            this.WindowContextEventPath <PoolDelayPickedEvent>("从内核输出中提取了矿池延时时展示到界面", LogEnum.DevConsole,
                                                               action: message => {
                UIThread.Execute(() => {
                    if (message.IsDual)
                    {
                        Vm.StateBarVm.DualPoolDelayText = message.PoolDelayText;
                    }
                    else
                    {
                        Vm.StateBarVm.PoolDelayText = message.PoolDelayText;
                    }
                });
            });
            this.WindowContextEventPath <MineStartedEvent>("开始挖矿后将清空矿池延时", LogEnum.DevConsole,
                                                           action: message => {
                UIThread.Execute(() => {
                    Vm.StateBarVm.PoolDelayText     = string.Empty;
                    Vm.StateBarVm.DualPoolDelayText = string.Empty;
                });
            });
            this.WindowContextEventPath <MineStopedEvent>("停止挖矿后将清空矿池延时", LogEnum.DevConsole,
                                                          action: message => {
                UIThread.Execute(() => {
                    Vm.StateBarVm.PoolDelayText     = string.Empty;
                    Vm.StateBarVm.DualPoolDelayText = string.Empty;
                });
            });
            this.WindowContextEventPath <Per1MinuteEvent>("挖矿中时自动切换为无界面模式 和 守护进程状态显示", LogEnum.DevConsole,
                                                          action: message => {
                if (NTMinerRoot.IsUiVisible && NTMinerRoot.Instance.MinerProfile.IsAutoNoUi && NTMinerRoot.Instance.IsMining)
                {
                    if (NTMinerRoot.MainWindowRendedOn.AddMinutes(NTMinerRoot.Instance.MinerProfile.AutoNoUiMinutes) < message.Timestamp)
                    {
                        VirtualRoot.Execute(new CloseMainWindowCommand($"界面展示{NTMinerRoot.Instance.MinerProfile.AutoNoUiMinutes}分钟后自动切换为无界面模式,可在选项页调整配置"));
                    }
                }
                Vm.RefreshDaemonStateBrush();
            });
            RefreshCpu();
#if DEBUG
            Write.DevTimeSpan($"耗时{Write.Stopwatch.ElapsedMilliseconds}毫秒 {this.GetType().Name}.ctor");
#endif
        }
Ejemplo n.º 16
0
        public MainWindow()
        {
            this.MinHeight = 430;
            this.MinWidth  = 640;
            this.Width     = AppStatic.MainWindowWidth;
            this.Height    = AppStatic.MainWindowHeight;
#if DEBUG
            Write.Stopwatch.Start();
#endif
            this.Loaded += (sender, e) => {
                ConsoleWindow.Instance.Show();
                ConsoleWindow.Instance.MouseDown += (ss, ee) => {
                    MoveConsoleWindow();
                };
                this.Owner = ConsoleWindow.Instance;
                hwndSource = PresentationSource.FromVisual((Visual)sender) as HwndSource;
                hwndSource.AddHook(new HwndSourceHook(Win32MessageProc.WindowProc));
                MoveConsoleWindow();
            };
            InitializeComponent();

            BtnMinerProfileGrip.Visibility = Visibility.Collapsed;
            if (WpfUtil.IsInDesignMode)
            {
                return;
            }

            UIThread.StartTimer();
            _borderBrush = this.BorderBrush;
            DateTime lastGetServerMessageOn = DateTime.MinValue;
            NTMinerRoot.RefreshArgsAssembly.Invoke();
            // 切换了主界面上的Tab时
            this.MainArea.SelectionChanged += (sender, e) => {
                // 延迟创建,以加快主界面的启动
                var selectedItem = MainArea.SelectedItem;
                if (selectedItem == TabItemSpeedTable)
                {
                    if (SpeedTableContainer.Child == null)
                    {
                        SpeedTableContainer.Child = GetSpeedTable();
                    }
                }
                else if (selectedItem == TabItemMessage)
                {
                    if (MessagesContainer.Child == null)
                    {
                        MessagesContainer.Child = new Messages();
                    }
                }
                else if (selectedItem == TabItemToolbox)
                {
                    if (ToolboxContainer.Child == null)
                    {
                        ToolboxContainer.Child = new Toolbox();
                    }
                }
                else if (selectedItem == TabItemMinerProfileOption)
                {
                    if (MinerProfileOptionContainer.Child == null)
                    {
                        MinerProfileOptionContainer.Child = new MinerProfileOption();
                    }
                }
                VirtualRoot.SetIsServerMessagesVisible(selectedItem == TabItemMessage);
                if (selectedItem == TabItemMessage)
                {
                    if (lastGetServerMessageOn.AddSeconds(10) < DateTime.Now)
                    {
                        lastGetServerMessageOn = DateTime.Now;
                        VirtualRoot.Execute(new LoadNewServerMessageCommand());
                    }
                }
            };
            this.IsVisibleChanged += (sender, e) => {
                if (this.IsVisible)
                {
                    NTMinerRoot.IsUiVisible        = true;
                    NTMinerRoot.MainWindowRendedOn = DateTime.Now;
                }
                else
                {
                    NTMinerRoot.IsUiVisible = false;
                }
                MoveConsoleWindow();
            };
            this.ConsoleRectangle.IsVisibleChanged += (sender, e) => {
                MoveConsoleWindow();
            };
            this.StateChanged += (s, e) => {
                if (Vm.MinerProfile.IsShowInTaskbar)
                {
                    ShowInTaskbar = true;
                }
                else
                {
                    if (WindowState == WindowState.Minimized)
                    {
                        ShowInTaskbar = false;
                    }
                    else
                    {
                        ShowInTaskbar = true;
                    }
                }
                if (WindowState == WindowState.Maximized)
                {
                    ResizeCursors.Visibility = Visibility.Collapsed;
                    this.BorderBrush         = WpfUtil.BlackBrush;
                }
                else
                {
                    ResizeCursors.Visibility = Visibility.Visible;
                    this.BorderBrush         = _borderBrush;
                }
                MoveConsoleWindow();
            };
            this.ConsoleRectangle.SizeChanged += (s, e) => {
                MoveConsoleWindow();
            };
            NotiCenterWindow.Bind(this, ownerIsTopMost: true);
            this.LocationChanged += (sender, e) => {
                MoveConsoleWindow();
            };
            VirtualRoot.BuildCmdPath <CloseMainWindowCommand>(action: message => {
                UIThread.Execute(() => {
                    this.Close();
                });
            });
            this.BuildEventPath <PoolDelayPickedEvent>("从内核输出中提取了矿池延时时展示到界面", LogEnum.DevConsole,
                                                       action: message => {
                UIThread.Execute(() => {
                    if (message.IsDual)
                    {
                        Vm.StateBarVm.DualPoolDelayText = message.PoolDelayText;
                    }
                    else
                    {
                        Vm.StateBarVm.PoolDelayText = message.PoolDelayText;
                    }
                });
            });
            this.BuildEventPath <MineStartedEvent>("开始挖矿后将清空矿池延时", LogEnum.DevConsole,
                                                   action: message => {
                UIThread.Execute(() => {
                    Vm.StateBarVm.PoolDelayText     = string.Empty;
                    Vm.StateBarVm.DualPoolDelayText = string.Empty;
                });
            });
            this.BuildEventPath <MineStopedEvent>("停止挖矿后将清空矿池延时", LogEnum.DevConsole,
                                                  action: message => {
                UIThread.Execute(() => {
                    Vm.StateBarVm.PoolDelayText     = string.Empty;
                    Vm.StateBarVm.DualPoolDelayText = string.Empty;
                });
            });
            this.BuildEventPath <Per1MinuteEvent>("挖矿中时自动切换为无界面模式 和 守护进程状态显示", LogEnum.DevConsole,
                                                  action: message => {
                if (NTMinerRoot.IsUiVisible && NTMinerRoot.Instance.MinerProfile.IsAutoNoUi && NTMinerRoot.Instance.IsMining)
                {
                    if (NTMinerRoot.MainWindowRendedOn.AddMinutes(NTMinerRoot.Instance.MinerProfile.AutoNoUiMinutes) < message.Timestamp)
                    {
                        VirtualRoot.Out.ShowSuccess($"界面展示{NTMinerRoot.Instance.MinerProfile.AutoNoUiMinutes}分钟后自动切换为无界面模式,可在选项页调整配置", "开源矿工");
                        VirtualRoot.Execute(new CloseMainWindowCommand());
                    }
                }
            });
            this.BuildEventPath <CpuPackageStateChangedEvent>("CPU包状态变更后刷新Vm内存", LogEnum.None,
                                                              action: message => {
                UIThread.Execute(UpdateCpuView);
            });
#if DEBUG
            var elapsedMilliseconds = Write.Stopwatch.Stop();
            if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds)
            {
                Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor");
            }
#endif
        }