private MinerClientsWindow() { if (WpfUtil.IsInDesignMode) { return; } Width = SystemParameters.FullPrimaryScreenWidth * 0.95; Height = SystemParameters.FullPrimaryScreenHeight * 0.95; this.DataContext = Vm; ConsoleWindow.Instance.Show(); ConsoleWindow.Instance.MouseDown += (sender, e) => { MoveConsoleWindow(); }; this.Owner = ConsoleWindow.Instance; this.Loaded += (sender, e) => { MoveConsoleWindow(); hwndSource = PresentationSource.FromVisual((Visual)sender) as HwndSource; hwndSource.AddHook(new HwndSourceHook(Win32Proc.WindowProc)); this.WindowState = WindowState.Maximized; }; InitializeComponent(); // 这一行是为了看见设计视图 this.ResizeCursors.Visibility = Visibility.Visible; this.TbUcName.Text = nameof(MinerClientsWindow); DateTime lastGetServerMessageOn = DateTime.MinValue; this.MinerStudioTabControl.SelectionChanged += (sender, e) => { // 延迟创建,以加快主界面的启动 #region var selectedItem = MinerStudioTabControl.SelectedItem; if (selectedItem == MinerStudioTabItemMessage) { if (MinerStudioMessagesContainer.Child == null) { MinerStudioMessagesContainer.Child = new Messages(); } if (lastGetServerMessageOn.AddSeconds(10) < DateTime.Now) { lastGetServerMessageOn = DateTime.Now; VirtualRoot.Execute(new LoadNewServerMessageCommand()); } } RpcRoot.SetIsServerMessagesVisible(selectedItem == MinerStudioTabItemMessage); #endregion }; this.MinerClienTabControl.SelectionChanged += (sender, e) => { // 延迟创建,以加快主界面的启动 #region var selectedItem = MinerClienTabControl.SelectedItem; if (selectedItem == MinerClientTabItemMessage) { if (MinerClientMessagesContainer.Child == null) { MinerClientMessagesContainer.Child = new MinerClientMessages(); } MinerStudioRoot.SetIsMinerClientMessagesVisible(true); } else { MinerStudioRoot.SetIsMinerClientMessagesVisible(false); } #endregion }; this.ConsoleRectangle.IsVisibleChanged += (sender, e) => { MoveConsoleWindow(); }; this.ConsoleRectangle.SizeChanged += (s, e) => { MoveConsoleWindow(); }; this.StateChanged += (s, e) => { #region if (WindowState == WindowState.Maximized) { ResizeCursors.Visibility = Visibility.Collapsed; } else { ResizeCursors.Visibility = Visibility.Visible; } MoveConsoleWindow(); #endregion }; this.SizeChanged += (s, e) => { #region if (!this.ConsoleRectangle.IsVisible) { if (e.WidthChanged) { ConsoleWindow.Instance.Width = e.NewSize.Width; } if (e.HeightChanged) { ConsoleWindow.Instance.Height = e.NewSize.Height; } } #endregion }; this.LocationChanged += (sender, e) => { MoveConsoleWindow(); }; this.AddEventPath <Per1SecondEvent>("刷新倒计时秒表", LogEnum.None, action: message => { #region var minerClients = Vm.MinerClients.ToArray(); if (Vm.CountDown > 0) { Vm.CountDown = Vm.CountDown - 1; foreach (var item in minerClients) { item.OnPropertyChanged(nameof(item.LastActivedOnText)); } if (RpcRoot.IsOuterNet && Vm.CountDown == 5) { // 外网群控时在矿机列表页数据刷新前5秒通过Ws刷新矿机的算力数据 MinerStudioRoot.WsClient.SendAsync(new WsMessage(Guid.NewGuid(), WsMessage.GetSpeed) { Data = Vm.MinerClients.Select(a => a.ClientId).ToList() }); } } else if (Vm.CountDown == 0) { MinerStudioRoot.MinerClientsWindowVm.QueryMinerClients(isAuto: true); } #endregion }, location: this.GetType()); NotiCenterWindow.Bind(this, ownerIsTopMost: true); MinerStudioRoot.MinerClientsWindowVm.QueryMinerClients(); }
protected override void OnStartup(StartupEventArgs e) { // 之所以提前到这里是因为升级之前可能需要下载升级器,下载升级器时需要下载器 VirtualRoot.BuildCmdPath <ShowFileDownloaderCommand>(path: message => { FileDownloader.ShowWindow(message.DownloadFileUrl, message.FileTitle, message.DownloadComplete); }, location: this.GetType()); VirtualRoot.BuildCmdPath <UpgradeCommand>(path: message => { AppRoot.Upgrade(NTMinerAppType.MinerStudio, message.FileName, message.Callback); }, location: this.GetType()); if (AppUtil.GetMutex(NTKeyword.MinerStudioAppMutex)) { this.ShutdownMode = ShutdownMode.OnExplicitShutdown; // 因为登录窗口会用到VirtualRoot.Out,而Out的延迟自动关闭消息会用到倒计时 VirtualRoot.StartTimer(new WpfTimingEventProducer()); NotiCenterWindow.ShowWindow(); AppRoot.RemoteDesktop = MsRdpRemoteDesktop.OpenRemoteDesktop; MinerStudioRoot.Login(() => { MinerStudioRoot.Init(new MinerStudioWsClient()); _ = MinerStudioService.Instance;// 访问一下从而提前拉取本地服务数据 NTMinerContext.Instance.Init(() => { _appViewFactory.BuildPaths(); UIThread.Execute(() => { MinerStudioRoot.MinerClientsWindowVm.OnPropertyChanged(nameof(MinerStudioRoot.MinerClientsWindowVm.NetTypeText)); if (RpcRoot.IsOuterNet) { MinerStudioRoot.MinerClientsWindowVm.QueryMinerClients(); } else { VirtualRoot.BuildOnecePath <ClientSetInitedEvent>("矿工集合初始化完成后刷新矿机列表界面", LogEnum.DevConsole, path: message => { MinerStudioRoot.MinerClientsWindowVm.QueryMinerClients(); }, pathId: PathId.Empty, this.GetType()); } AppRoot.NotifyIcon = ExtendedNotifyIcon.Create("群控客户端", isMinerStudio: true); VirtualRoot.Execute(new ShowMinerClientsWindowCommand(isToggle: false)); }); }); }, btnCloseClick: () => { Shutdown(); }); #region 处理显示主界面命令 VirtualRoot.BuildCmdPath <ShowMainWindowCommand>(path: message => { VirtualRoot.Execute(new ShowMinerClientsWindowCommand(isToggle: message.IsToggle)); }, location: this.GetType()); #endregion HttpServer.Start($"http://{NTKeyword.Localhost}:{NTKeyword.MinerStudioPort.ToString()}"); } else { try { _appViewFactory.ShowMainWindow(this, NTMinerAppType.MinerStudio); } catch (Exception) { DialogWindow.ShowSoftDialog(new DialogWindowViewModel( message: "另一个群控客户端正在运行但唤醒失败,请重试。", title: "错误", icon: "Icon_Error")); Process currentProcess = Process.GetCurrentProcess(); NTMiner.Windows.TaskKill.KillOtherProcess(currentProcess); } } base.OnStartup(e); }