예제 #1
0
        private MinerClientsWindow()
        {
            Width            = SystemParameters.FullPrimaryScreenWidth * 0.95;
            Height           = SystemParameters.FullPrimaryScreenHeight * 0.95;
            this.DataContext = Vm;
            this.DataContext = AppContext.Instance.MinerClientsWindowVm;
            InitializeComponent();
            this.TbUcName.Text = nameof(MinerClientsWindow);
            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.AddEventPath <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));
                    }
                }
            }, location: this.GetType());
            this.AddEventPath <Per10SecondEvent>("周期刷新在线客户端列表", LogEnum.DevConsole,
                                                 action: message => {
                AppContext.Instance.MinerClientsWindowVm.QueryMinerClients();
            }, location: this.GetType());
            NotiCenterWindow.Instance.Bind(this);
            AppContext.Instance.MinerClientsWindowVm.QueryMinerClients();
        }
예제 #2
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
        }
예제 #3
0
        public MainWindow()
        {
            if (WpfUtil.IsInDesignMode)
            {
                return;
            }

            this.MinHeight = 430;
            this.MinWidth  = 640;
            this.Width     = AppStatic.MainWindowWidth;
            this.Height    = AppStatic.MainWindowHeight;
#if DEBUG
            NTStopwatch.Start();
#endif
            ConsoleWindow.Instance.Show();
            ConsoleWindow.Instance.MouseDown += (sender, e) => {
                MoveConsoleWindow();
            };
            ConsoleWindow.Instance.Hide();
            this.Owner = ConsoleWindow.Instance;
            SystemEvents.SessionSwitch += SystemEvents_SessionSwitch;
            this.Loaded += (sender, e) => {
                MoveConsoleWindow();
                hwndSource = PresentationSource.FromVisual((Visual)sender) as HwndSource;
                hwndSource.AddHook(new HwndSourceHook(Win32Proc.WindowProc));
            };
            InitializeComponent();
            _leftDrawerGripWidth    = LeftDrawerGrip.Width;
            _btnLeftDrawerGripBrush = BtnLeftDrawerGrip.Background;
            NTMinerRoot.RefreshArgsAssembly.Invoke();
            // 下面几行是为了看见设计视图
            this.ResizeCursors.Visibility = Visibility.Visible;
            this.HideLeftDrawerGrid();
            // 上面几行是为了看见设计视图

            DateTime lastGetServerMessageOn = DateTime.MinValue;
            // 切换了主界面上的Tab时
            this.MainArea.SelectionChanged += (sender, e) => {
                // 延迟创建,以加快主界面的启动
                #region
                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());
                    }
                }
                #endregion
            };
            this.IsVisibleChanged += (sender, e) => {
                #region
                if (this.IsVisible)
                {
                    NTMinerRoot.IsUiVisible = true;
                }
                else
                {
                    NTMinerRoot.IsUiVisible = false;
                }
                MoveConsoleWindow();
                #endregion
            };
            this.ConsoleRectangle.IsVisibleChanged += (sender, e) => {
                MoveConsoleWindow();
            };
            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
            };
            this.ConsoleRectangle.SizeChanged += (s, e) => {
                MoveConsoleWindow();
            };
            this.SizeChanged += (s, e) => {
                #region
                if (this.Width < 860)
                {
                    this.CloseLeftDrawer();
                }
                else
                {
                    this.OpenLeftDrawer();
                }
                if (!this.ConsoleRectangle.IsVisible)
                {
                    if (e.WidthChanged)
                    {
                        ConsoleWindow.Instance.Width = e.NewSize.Width;
                    }
                    if (e.HeightChanged)
                    {
                        ConsoleWindow.Instance.Height = e.NewSize.Height;
                    }
                }
                #endregion
            };
            NotiCenterWindow.Instance.Bind(this, ownerIsTopMost: true);
            this.LocationChanged += (sender, e) => {
                MoveConsoleWindow();
            };
            VirtualRoot.AddCmdPath <CloseMainWindowCommand>(action: message => {
                UIThread.Execute(() => () => {
                    if (message.IsAutoNoUi)
                    {
                        SwitchToNoUi();
                    }
                    else
                    {
                        this.Close();
                    }
                });
            }, location: this.GetType());
            this.AddEventPath <PoolDelayPickedEvent>("从内核输出中提取了矿池延时时展示到界面", LogEnum.DevConsole,
                                                     action: message => {
                UIThread.Execute(() => () => {
                    if (message.IsDual)
                    {
                        Vm.StateBarVm.DualPoolDelayText = message.PoolDelayText;
                    }
                    else
                    {
                        Vm.StateBarVm.PoolDelayText = message.PoolDelayText;
                    }
                });
            }, location: this.GetType());
            this.AddEventPath <MineStartedEvent>("开始挖矿后将清空矿池延时", LogEnum.DevConsole,
                                                 action: message => {
                UIThread.Execute(() => () => {
                    Vm.StateBarVm.PoolDelayText     = string.Empty;
                    Vm.StateBarVm.DualPoolDelayText = string.Empty;
                });
            }, location: this.GetType());
            this.AddEventPath <MineStopedEvent>("停止挖矿后将清空矿池延时", LogEnum.DevConsole,
                                                action: message => {
                UIThread.Execute(() => () => {
                    Vm.StateBarVm.PoolDelayText     = string.Empty;
                    Vm.StateBarVm.DualPoolDelayText = string.Empty;
                });
            }, location: this.GetType());
            this.AddEventPath <Per1MinuteEvent>("挖矿中时自动切换为无界面模式", LogEnum.DevConsole,
                                                action: message => {
                if (NTMinerRoot.IsUiVisible && NTMinerRoot.Instance.MinerProfile.IsAutoNoUi && NTMinerRoot.Instance.IsMining)
                {
                    if (NTMinerRoot.MainWindowRendedOn.AddMinutes(NTMinerRoot.Instance.MinerProfile.AutoNoUiMinutes) < message.BornOn)
                    {
                        VirtualRoot.ThisLocalInfo(nameof(MainWindow), $"挖矿中界面展示{NTMinerRoot.Instance.MinerProfile.AutoNoUiMinutes}分钟后自动切换为无界面模式,可在选项页调整配置");
                        VirtualRoot.Execute(new CloseMainWindowCommand(isAutoNoUi: true));
                    }
                }
            }, location: this.GetType());
            this.AddEventPath <CpuPackageStateChangedEvent>("CPU包状态变更后刷新Vm内存", LogEnum.None,
                                                            action: message => {
                UpdateCpuView();
            }, location: this.GetType());
#if DEBUG
            var elapsedMilliseconds = NTStopwatch.Stop();
            if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds)
            {
                Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor");
            }
#endif
        }