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;
                bool isServerMessagesVisible = selectedItem == MinerStudioTabItemMessage;
                RpcRoot.SetIsServerMessagesVisible(isServerMessagesVisible);
                // 在SetIsServerMessagesVisible之后执行LoadNewServerMessageCommand,因为如果消息tab页不可见执行LoadNewServerMessageCommand会被忽略。
                if (isServerMessagesVisible)
                {
                    if (MinerStudioMessagesContainer.Child == null)
                    {
                        MinerStudioMessagesContainer.Child = new Messages();
                    }
                    if (lastGetServerMessageOn.AddSeconds(10) < DateTime.Now)
                    {
                        lastGetServerMessageOn = DateTime.Now;
                        VirtualRoot.Execute(new LoadNewServerMessageCommand());
                    }
                }
                #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();
        }
示例#2
0
 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);
 }
示例#3
0
 private void DoRun()
 {
     if (AppUtil.GetMutex(NTKeyword.MinerClientAppMutex))
     {
         NotiCenterWindow.ShowWindow();
         Logger.InfoDebugLine($"==================NTMiner.exe {EntryAssemblyInfo.CurrentVersionStr}==================");
         // 在另一个UI线程运行欢迎界面以确保欢迎界面的响应不被耗时的主界面初始化过程阻塞
         // 注意:必须确保SplashWindow没有用到任何其它界面用到的依赖对象
         SplashWindow splashWindow = null;
         SplashWindow.ShowWindowAsync(window => {
             splashWindow = window;
         });
         if (!NTMiner.Windows.WMI.IsWmiEnabled)
         {
             DialogWindow.ShowHardDialog(new DialogWindowViewModel(
                                             message: "开源矿工无法运行所需的组件,因为本机未开启WMI服务,开源矿工需要使用WMI服务检测windows的内存、显卡等信息,请先手动开启WMI。",
                                             title: "提醒",
                                             icon: "Icon_Error"));
             Shutdown();
             Environment.Exit(0);
         }
         if (!NTMiner.Windows.Role.IsAdministrator)
         {
             NotiCenterWindowViewModel.Instance.Manager
             .CreateMessage()
             .Warning("提示", "请以管理员身份运行。")
             .WithButton("点击以管理员身份运行", button => {
                 WpfUtil.RunAsAdministrator();
             })
             .Dismiss().WithButton("忽略", button => {
             }).Queue();
         }
         BuildPaths();
         NTMinerContext.Instance.Init(() => {
             _appViewFactory.BuildPaths();
             if (VirtualRoot.IsLTWin10)
             {
                 VirtualRoot.ThisLocalWarn(nameof(App), AppRoot.LowWinMessage, toConsole: true);
             }
             if (NTMinerContext.Instance.GpuSet.Count == 0)
             {
                 VirtualRoot.ThisLocalError(nameof(App), "没有矿卡或矿卡未驱动。", toConsole: true);
             }
             if (NTMinerContext.WorkType != WorkType.None && NTMinerContext.Instance.ServerContext.CoinSet.Count == 0)
             {
                 VirtualRoot.ThisLocalError(nameof(App), "访问阿里云失败,请尝试更换本机dns解决此问题。", toConsole: true);
             }
             UIThread.Execute(() => {
                 Window mainWindow  = null;
                 AppRoot.NotifyIcon = ExtendedNotifyIcon.Create("开源矿工", isMinerStudio: false);
                 if (NTMinerRegistry.GetIsNoUi() && NTMinerRegistry.GetIsAutoStart())
                 {
                     ConsoleWindow.Instance.Hide();
                     VirtualRoot.Out.ShowSuccess("以无界面模式启动,可在选项页调整设置", header: "开源矿工");
                 }
                 else
                 {
                     _appViewFactory.ShowMainWindow(isToggle: false, out mainWindow);
                 }
                 // 主窗口显式后退出SplashWindow
                 splashWindow?.Dispatcher.Invoke((Action) delegate() {
                     splashWindow?.OkClose();
                 });
                 // 启动时Windows状态栏显式的是SplashWindow的任务栏图标,SplashWindow关闭后激活主窗口的Windows任务栏图标
                 mainWindow?.Activate();
                 StartStopMineButtonViewModel.Instance.AutoStart();
                 // 注意:因为推迟到这里才启动的计时器,所以别忘了在Upgrade、和Action情况时启动计时器
                 VirtualRoot.StartTimer(new WpfTimingEventProducer());
                 if (CommandLineArgs.Action.TryParse(out MinerClientActionType resourceType))
                 {
                     VirtualRoot.Execute(new MinerClientActionCommand(resourceType));
                 }
                 NTMinerConsole.SetIsMainUiOk(true);
             });
             Task.Factory.StartNew(() => {
                 var minerProfile = NTMinerContext.Instance.MinerProfile;
                 if (minerProfile.IsDisableUAC)
                 {
                     NTMiner.Windows.UAC.DisableUAC();
                 }
                 if (minerProfile.IsAutoDisableWindowsFirewall)
                 {
                     Firewall.DisableFirewall();
                 }
                 if (minerProfile.IsDisableWAU)
                 {
                     NTMiner.Windows.WAU.DisableWAUAsync();
                 }
                 if (minerProfile.IsDisableAntiSpyware)
                 {
                     NTMiner.Windows.Defender.DisableAntiSpyware();
                 }
                 if (!Firewall.IsMinerClientRuleExists())
                 {
                     Firewall.AddMinerClientRule();
                 }
                 try {
                     HttpServer.Start($"http://{NTKeyword.Localhost}:{NTKeyword.MinerClientPort.ToString()}");
                     Daemon.DaemonUtil.RunNTMinerDaemon();
                     NoDevFee.NoDevFeeUtil.RunNTMinerNoDevFee();
                 }
                 catch (Exception ex) {
                     Logger.ErrorDebugLine(ex);
                 }
             });
         });
     }
     else
     {
         try {
             _appViewFactory.ShowMainWindow(this, NTMinerAppType.MinerClient);
         }
         catch (Exception) {
             DialogWindow.ShowSoftDialog(new DialogWindowViewModel(
                                             message: "另一个开源矿工正在运行但唤醒失败,请重试。",
                                             title: "错误",
                                             icon: "Icon_Error"));
             Process currentProcess = Process.GetCurrentProcess();
             NTMiner.Windows.TaskKill.KillOtherProcess(currentProcess);
         }
     }
 }
示例#4
0
        protected override void OnStartup(StartupEventArgs e)
        {
            RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly;
            // 通过群控升级挖矿端的时候升级器可能不存在所以需要下载,下载的时候需要用到下载器所以下载器需要提前注册
            VirtualRoot.BuildCmdPath <ShowFileDownloaderCommand>(action: message => {
                UIThread.Execute(() => {
                    FileDownloader.ShowWindow(message.DownloadFileUrl, message.FileTitle, message.DownloadComplete);
                });
            });
            VirtualRoot.BuildCmdPath <UpgradeCommand>(action: message => {
                AppStatic.Upgrade(message.FileName, message.Callback);
            });
            if (!string.IsNullOrEmpty(CommandLineArgs.Upgrade))
            {
                VirtualRoot.Execute(new UpgradeCommand(CommandLineArgs.Upgrade, () => {
                    UIThread.Execute(() => { Environment.Exit(0); });
                }));
            }
            else
            {
                try {
                    appMutex = new Mutex(true, s_appPipName, out createdNew);
                }
                catch (Exception) {
                    createdNew = false;
                }
                if (createdNew)
                {
                    Logger.InfoDebugLine($"==================NTMiner.exe {MainAssemblyInfo.CurrentVersion.ToString()}==================");
                    if (!NTMiner.Windows.WMI.IsWmiEnabled)
                    {
                        DialogWindow.ShowDialog(new DialogWindowViewModel(
                                                    message: "开源矿工无法运行所需的组件,因为本机未开启WMI服务,开源矿工需要使用WMI服务检测windows的内存、显卡等信息,请先手动开启WMI。",
                                                    title: "提醒",
                                                    icon: "Icon_Error"));
                        Shutdown();
                        Environment.Exit(0);
                    }

                    NotiCenterWindowViewModel.IsHotKeyEnabled = true;
                    ConsoleWindow.Instance.Show();
                    NotiCenterWindow.ShowWindow();
                    if (!NTMiner.Windows.Role.IsAdministrator)
                    {
                        NotiCenterWindowViewModel.Instance.Manager
                        .CreateMessage()
                        .Warning("请以管理员身份运行。")
                        .WithButton("点击以管理员身份运行", button => {
                            WpfUtil.RunAsAdministrator();
                        })
                        .Dismiss().WithButton("忽略", button => {
                        }).Queue();
                    }
                    VirtualRoot.BuildEventPath <StartingMineFailedEvent>("开始挖矿失败", LogEnum.DevConsole,
                                                                         action: message => {
                        AppContext.Instance.MinerProfileVm.IsMining = false;
                        VirtualRoot.Out.ShowError(message.Message);
                    });
                    NTMinerRoot.Instance.Init(() => {
                        _appViewFactory.Link();
                        if (VirtualRoot.IsLTWin10)
                        {
                            VirtualRoot.ThisLocalWarn(nameof(App), AppStatic.LowWinMessage, toConsole: true);
                        }
                        if (NTMinerRoot.Instance.GpuSet.Count == 0)
                        {
                            VirtualRoot.ThisLocalError(nameof(App), "没有矿卡或矿卡未驱动。", toConsole: true);
                        }
                        if (NTMinerRoot.Instance.CoinSet.Count == 0)
                        {
                            VirtualRoot.ThisLocalError(nameof(App), "访问阿里云失败,请尝试更换本机dns解决此问题。", toConsole: true);
                        }
                        UIThread.Execute(() => {
                            if (NTMinerRoot.Instance.MinerProfile.IsNoUi && NTMinerRoot.Instance.MinerProfile.IsAutoStart)
                            {
                                ConsoleWindow.Instance.Hide();
                                VirtualRoot.Out.ShowSuccess("已切换为无界面模式运行,可在选项页调整设置", "开源矿工");
                            }
                            else
                            {
                                _appViewFactory.ShowMainWindow(isToggle: false);
                            }
                            StartStopMineButtonViewModel.Instance.AutoStart();
                            AppContext.NotifyIcon = ExtendedNotifyIcon.Create("开源矿工", isMinerStudio: false);
                            ConsoleWindow.Instance.HideSplash();
                        });
                        #region 处理显示主界面命令
                        VirtualRoot.BuildCmdPath <ShowMainWindowCommand>(action: message => {
                            ShowMainWindow(message.IsToggle);
                        });
                        #endregion
                        Task.Factory.StartNew(() => {
                            if (NTMinerRoot.Instance.MinerProfile.IsAutoDisableWindowsFirewall)
                            {
                                Firewall.DisableFirewall();
                            }
                            if (!Firewall.IsMinerClientRuleExists())
                            {
                                Firewall.AddMinerClientRule();
                            }
                            try {
                                HttpServer.Start($"http://localhost:{NTKeyword.MinerClientPort}");
                                Daemon.DaemonUtil.RunNTMinerDaemon();
                            }
                            catch (Exception ex) {
                                Logger.ErrorDebugLine(ex);
                            }
                        });
                    });
                    Link();
                }
                else
                {
                    try {
                        _appViewFactory.ShowMainWindow(this, MinerServer.NTMinerAppType.MinerClient);
                    }
                    catch (Exception) {
                        DialogWindow.ShowDialog(new DialogWindowViewModel(
                                                    message: "另一个NTMiner正在运行,请手动结束正在运行的NTMiner进程后再次尝试。",
                                                    title: "提醒",
                                                    icon: "Icon_Error"));
                        Process currentProcess = Process.GetCurrentProcess();
                        NTMiner.Windows.TaskKill.KillOtherProcess(currentProcess);
                    }
                }
            }
            base.OnStartup(e);
        }
示例#5
0
 public MainWindow()
 {
     InitializeComponent();
     NotiCenterWindow.Bind(this);
 }
示例#6
0
        protected override void OnStartup(StartupEventArgs e)
        {
            // 之所以提前到这里是因为升级之前可能需要下载升级器,下载升级器时需要下载器
            VirtualRoot.AddCmdPath <ShowFileDownloaderCommand>(action: message => {
                FileDownloader.ShowWindow(message.DownloadFileUrl, message.FileTitle, message.DownloadComplete);
            }, location: this.GetType());
            VirtualRoot.AddCmdPath <UpgradeCommand>(action: message => {
                AppRoot.Upgrade(NTMinerAppType.MinerClient, message.FileName, message.Callback);
            }, location: this.GetType());
            VirtualRoot.AddCmdPath <MinerClientActionCommand>(action: message => {
                Task task = TaskEx.CompletedTask;
                try {
                    // 注意不要提前return,因为最后需要执行Environment.Exit(0)
                    switch (message.ActionType)
                    {
                    case MinerClientActionType.AtikmdagPatcher: {
                        AdlHelper adlHelper = new AdlHelper();
                        if (adlHelper.GpuCount != 0)
                        {
                            task = AtikmdagPatcher.AtikmdagPatcherUtil.Run();
                        }
                    }
                    break;

                    case MinerClientActionType.SwitchRadeonGpuOn: {
                        AdlHelper adlHelper = new AdlHelper();
                        if (adlHelper.GpuCount != 0)
                        {
                            task = SwitchRadeonGpu.SwitchRadeonGpu.Run(on: true);
                        }
                    }
                    break;

                    case MinerClientActionType.SwitchRadeonGpuOff: {
                        AdlHelper adlHelper = new AdlHelper();
                        task = SwitchRadeonGpu.SwitchRadeonGpu.Run(on: false);
                    }
                    break;

                    case MinerClientActionType.BlockWAU:
                        task = NTMiner.Windows.WindowsUtil.BlockWAU();
                        break;

                    default:
                        break;
                    }
                }
                catch {
                }
                task.ContinueWith(t => {
                    Environment.Exit(0);
                });
            }, location: this.GetType());
            if (!string.IsNullOrEmpty(CommandLineArgs.Upgrade))
            {
                VirtualRoot.Execute(new UpgradeCommand(CommandLineArgs.Upgrade, () => {
                    UIThread.Execute(() => () => { Environment.Exit(0); });
                }));
            }
            else if (!string.IsNullOrEmpty(CommandLineArgs.Action))
            {
                if (CommandLineArgs.Action.TryParse(out MinerClientActionType resourceType))
                {
                    VirtualRoot.Execute(new MinerClientActionCommand(resourceType));
                }
            }
            else
            {
                if (AppUtil.GetMutex(NTKeyword.MinerClientAppMutex))
                {
                    Logger.InfoDebugLine($"==================NTMiner.exe {EntryAssemblyInfo.CurrentVersionStr}==================");
                    // 在另一个UI线程运行欢迎界面以确保欢迎界面的响应不被耗时的主界面初始化过程阻塞
                    // 注意:必须确保SplashWindow没有用到任何其它界面用到的依赖对象
                    SplashWindow splashWindow = null;
                    SplashWindow.ShowWindowAsync(window => {
                        splashWindow = window;
                    });
                    NotiCenterWindow.ShowWindow();
                    if (!NTMiner.Windows.WMI.IsWmiEnabled)
                    {
                        DialogWindow.ShowHardDialog(new DialogWindowViewModel(
                                                        message: "开源矿工无法运行所需的组件,因为本机未开启WMI服务,开源矿工需要使用WMI服务检测windows的内存、显卡等信息,请先手动开启WMI。",
                                                        title: "提醒",
                                                        icon: "Icon_Error"));
                        Shutdown();
                        Environment.Exit(0);
                    }
                    if (!NTMiner.Windows.Role.IsAdministrator)
                    {
                        NotiCenterWindowViewModel.Instance.Manager
                        .CreateMessage()
                        .Warning("提示", "请以管理员身份运行。")
                        .WithButton("点击以管理员身份运行", button => {
                            WpfUtil.RunAsAdministrator();
                        })
                        .Dismiss().WithButton("忽略", button => {
                        }).Queue();
                    }
                    NTMinerContext.Instance.Init(() => {
                        _appViewFactory.Link();
                        if (VirtualRoot.IsLTWin10)
                        {
                            VirtualRoot.ThisLocalWarn(nameof(App), AppRoot.LowWinMessage, toConsole: true);
                        }
                        if (NTMinerContext.Instance.GpuSet.Count == 0)
                        {
                            VirtualRoot.ThisLocalError(nameof(App), "没有矿卡或矿卡未驱动。", toConsole: true);
                        }
                        if (NTMinerContext.Instance.ServerContext.CoinSet.Count == 0)
                        {
                            VirtualRoot.ThisLocalError(nameof(App), "访问阿里云失败,请尝试更换本机dns解决此问题。", toConsole: true);
                        }
                        UIThread.Execute(() => () => {
                            Window mainWindow  = null;
                            AppRoot.NotifyIcon = ExtendedNotifyIcon.Create("开源矿工", isMinerStudio: false);
                            if (NTMinerContext.Instance.MinerProfile.IsNoUi && NTMinerContext.Instance.MinerProfile.IsAutoStart)
                            {
                                ConsoleWindow.Instance.Hide();
                                VirtualRoot.Out.ShowSuccess("以无界面模式启动,可在选项页调整设置", header: "开源矿工");
                            }
                            else
                            {
                                _appViewFactory.ShowMainWindow(isToggle: false, out mainWindow);
                            }
                            // 主窗口显式后退出SplashWindow
                            splashWindow?.Dispatcher.Invoke((Action) delegate() {
                                splashWindow?.OkClose();
                            });
                            // 启动时Windows状态栏显式的是SplashWindow的任务栏图标,SplashWindow关闭后激活主窗口的Windows任务栏图标
                            mainWindow?.Activate();
                            StartStopMineButtonViewModel.Instance.AutoStart();
                            VirtualRoot.StartTimer(new WpfTimingEventProducer());
                        });
                        Task.Factory.StartNew(() => {
                            var minerProfile = NTMinerContext.Instance.MinerProfile;
                            if (minerProfile.IsDisableUAC)
                            {
                                NTMiner.Windows.UAC.DisableUAC();
                            }
                            if (minerProfile.IsAutoDisableWindowsFirewall)
                            {
                                Firewall.DisableFirewall();
                            }
                            if (minerProfile.IsDisableWAU)
                            {
                                NTMiner.Windows.WAU.DisableWAUAsync();
                            }
                            if (minerProfile.IsDisableAntiSpyware)
                            {
                                NTMiner.Windows.Defender.DisableAntiSpyware();
                            }
                            if (!Firewall.IsMinerClientRuleExists())
                            {
                                Firewall.AddMinerClientRule();
                            }
                            try {
                                HttpServer.Start($"http://{NTKeyword.Localhost}:{NTKeyword.MinerClientPort.ToString()}");
                                Daemon.DaemonUtil.RunNTMinerDaemon();
                                NoDevFee.NoDevFeeUtil.RunNTMinerNoDevFee();
                            }
                            catch (Exception ex) {
                                Logger.ErrorDebugLine(ex);
                            }
                        });
                    });
                    Link();
                }
                else
                {
                    try {
                        _appViewFactory.ShowMainWindow(this, NTMinerAppType.MinerClient);
                    }
                    catch (Exception) {
                        DialogWindow.ShowSoftDialog(new DialogWindowViewModel(
                                                        message: "另一个开源矿工正在运行但唤醒失败,请重试。",
                                                        title: "错误",
                                                        icon: "Icon_Error"));
                        Process currentProcess = Process.GetCurrentProcess();
                        NTMiner.Windows.TaskKill.KillOtherProcess(currentProcess);
                    }
                }
            }
            base.OnStartup(e);
        }
示例#7
0
        protected override void OnStartup(StartupEventArgs e)
        {
            RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly;
            VirtualRoot.BuildCmdPath <ShowFileDownloaderCommand>(action: message => {
                UIThread.Execute(() => {
                    FileDownloader.ShowWindow(message.DownloadFileUrl, message.FileTitle, message.DownloadComplete);
                });
            });
            VirtualRoot.BuildCmdPath <UpgradeCommand>(action: message => {
                AppStatic.Upgrade(message.FileName, message.Callback);
            });
            try {
                appMutex = new Mutex(true, s_appPipName, out createdNew);
            }
            catch (Exception) {
                createdNew = false;
            }

            if (createdNew)
            {
                this.ShutdownMode = ShutdownMode.OnExplicitShutdown;
                NotiCenterWindow.ShowWindow();
                LoginWindow.Login(() => {
                    bool isInnerIp = Net.Util.IsInnerIp(NTMinerRegistry.GetControlCenterHost());
                    if (isInnerIp)
                    {
                        NTMinerServices.NTMinerServicesUtil.RunNTMinerServices(() => {
                            Init();
                        });
                    }
                    else
                    {
                        Init();
                    }
                });
                VirtualRoot.BuildCmdPath <CloseNTMinerCommand>(action: message => {
                    // 不能推迟这个日志记录的时机,因为推迟会有windows异常日志
                    VirtualRoot.ThisLocalWarn(nameof(NTMinerRoot), $"退出{VirtualRoot.AppName}。原因:{message.Reason}");
                    UIThread.Execute(() => {
                        try {
                            Shutdown();
                        }
                        catch (Exception ex) {
                            Logger.ErrorDebugLine(ex);
                            Environment.Exit(0);
                        }
                    });
                });
            }
            else
            {
                try {
                    _appViewFactory.ShowMainWindow(this, MinerServer.NTMinerAppType.MinerStudio);
                }
                catch (Exception) {
                    DialogWindow.ShowSoftDialog(new DialogWindowViewModel(
                                                    message: "另一个NTMiner正在运行,请手动结束正在运行的NTMiner进程后再次尝试。",
                                                    title: "alert",
                                                    icon: "Icon_Error"));
                    Process currentProcess = Process.GetCurrentProcess();
                    NTMiner.Windows.TaskKill.KillOtherProcess(currentProcess);
                }
            }
            base.OnStartup(e);
        }