static void Main() { VirtualRoot.StartTimer(); try { Console.Title = "NTMinerServices"; bool mutexCreated; try { _sMutexApp = new Mutex(true, "NTMinerServicesMutex", out mutexCreated); } catch { mutexCreated = false; } if (mutexCreated) { if (!EnableInnerIp) { NTMinerRegistry.SetAutoBoot("NTMinerServices", true); } Type thisType = typeof(HostRoot); Run(); } } catch (Exception e) { Logger.ErrorDebugLine(e); } }
static void Main(string[] args) { VirtualRoot.StartTimer(); try { Console.Title = "NTMinerServices"; bool mutexCreated; try { _sMutexApp = new Mutex(true, "NTMinerServicesMutex", out mutexCreated); } catch { mutexCreated = false; } if (mutexCreated) { if (!EnableInnerIp) { NTMinerRegistry.SetAutoBoot("NTMinerServices", true); } Type thisType = typeof(HostRoot); NotifyIcon = ExtendedNotifyIcon.Create(new System.Drawing.Icon(thisType.Assembly.GetManifestResourceStream(thisType, "logo.ico")), "群控服务", isShowNotifyIcon: true); Run(); } } catch (Exception e) { Logger.ErrorDebugLine(e); } }
static void Main() { VirtualRoot.SetOut(new ConsoleOut()); NTMinerConsole.MainUiOk(); NTMinerConsole.DisbleQuickEditMode(); try { VirtualRoot.StartTimer(); // 将服务器地址设为localhost从而使用内网ip访问免于验证用户名密码 RpcRoot.SetOfficialServerAddress(NTKeyword.Localhost); NTMinerRegistry.SetAutoBoot("NTMiner.CalcConfigUpdater", true); VirtualRoot.BuildEventPath <Per10MinuteEvent>("每10分钟更新收益计算器", LogEnum.DevConsole, location: typeof(Program), PathPriority.Normal, path: message => { UpdateAsync(); }); UpdateAsync(); NTMinerConsole.UserInfo("输入exit并回车可以停止服务!"); while (Console.ReadLine() != "exit") { } NTMinerConsole.UserOk($"服务停止成功: {DateTime.Now.ToString()}."); } catch (Exception e) { Logger.ErrorDebugLine(e); } System.Threading.Thread.Sleep(1000); }
static void Main() { HomePath.SetHomeDirFullName(AppDomain.CurrentDomain.BaseDirectory); NTMinerConsole.DisbleQuickEditMode(); try { VirtualRoot.StartTimer(); // 将服务器地址设为localhost从而使用内网ip访问免于验证用户名密码 RpcRoot.SetOfficialServerAddress(NTKeyword.Localhost); NTMinerRegistry.SetAutoBoot("NTMiner.CalcConfigUpdater", true); VirtualRoot.AddEventPath <Per10MinuteEvent>("每10分钟更新收益计算器", LogEnum.DevConsole, action: message => { UpdateAsync(); }, location: typeof(Program)); UpdateAsync(); Write.UserInfo("输入exit并回车可以停止服务!"); while (Console.ReadLine() != "exit") { } Write.UserOk($"服务停止成功: {DateTime.Now.ToString()}."); } catch (Exception e) { Logger.ErrorDebugLine(e); } System.Threading.Thread.Sleep(1000); }
static void Main(string[] args) { VirtualRoot.StartTimer(); try { // 将服务器地址设为localhost从而使用内网ip访问免于验证用户名密码 AssemblyInfo.OfficialServerHost = "localhost"; NTMinerRegistry.SetAutoBoot("NTMiner.CalcConfigUpdater", true); VirtualRoot.On <Per10MinuteEvent>("每10分钟更新收益计算器", LogEnum.DevConsole, action: message => { UpdateAsync(); }); UpdateAsync(); Write.UserInfo("输入exit并回车可以停止服务!"); while (Console.ReadLine() != "exit") { } Write.UserOk($"服务停止成功: {DateTime.Now}."); } catch (Exception e) { Logger.ErrorDebugLine(e); } System.Threading.Thread.Sleep(1000); }
static void Main() { NTMinerConsole.SetIsMainUiOk(true); NTMinerConsole.DisbleQuickEditMode(); DevMode.SetDevMode(); Windows.ConsoleHandler.Register(Exit); string thisServerAddress = ServerRoot.HostConfig.ThisServerAddress; Console.Title = $"{ServerAppType.WsServer.GetName()}_{thisServerAddress}"; // 通过WsServer的网络缓解对WebApiServer的外网流量的压力。WsServer调用WebApiServer的时候走内网调用节省外网带宽 RpcRoot.SetOfficialServerAddress(ServerRoot.HostConfig.RpcServerLocalAddress); // 用本节点的地址作为队列名,消费消息时根据路由键区分消息类型 string queue = $"{ServerAppType.WsServer.GetName()}.{thisServerAddress}"; string durableQueue = queue + MqKeyword.DurableQueueEndsWith; AbstractMqMessagePath[] mqMessagePaths = new AbstractMqMessagePath[] { new ReadOnlyUserMqMessagePath(durableQueue), new MinerSignMqMessagePath(durableQueue), new WsServerNodeMqMessagePath(queue), new OperationMqMessagePath(queue), new MinerClientMqMessagePath(queue, thisServerAddress) }; if (!MqRedis.Create(ServerAppType.WsServer, mqMessagePaths, out IMqRedis mqRedis)) { NTMinerConsole.UserError("启动失败,无法继续,因为服务器上下文创建失败"); return; } MinerClientMqSender = new MinerClientMqSender(mqRedis); SpeedDataRedis = new SpeedDataRedis(mqRedis); WsServerNodeRedis = new WsServerNodeRedis(mqRedis); OperationMqSender = new OperationMqSender(mqRedis); UserMqSender = new UserMqSender(mqRedis); _wsServerNodeMqSender = new WsServerNodeMqSender(mqRedis); WsServerNodeAddressSet = new WsServerNodeAddressSet(WsServerNodeRedis, _wsServerNodeMqSender); var minerRedis = new ReadOnlyMinerRedis(mqRedis); var userRedis = new ReadOnlyUserRedis(mqRedis); VirtualRoot.StartTimer(); RpcRoot.SetRpcUser(new RpcUser(ServerRoot.HostConfig.RpcLoginName, HashUtil.Sha1(ServerRoot.HostConfig.RpcPassword))); RpcRoot.SetIsOuterNet(false); // 构造函数中异步访问redis初始化用户列表,因为是异步的所以提前构造 UserSet = new ReadOnlyUserSet(userRedis); MinerSignSet = new MinerSignSet(minerRedis); _wsServer = new SharpWsServerAdapter(ServerRoot.HostConfig); MinerClientSessionSet = new MinerClientSessionSet(_wsServer.MinerClientWsSessions); MinerStudioSessionSet = new MinerStudioSessionSet(_wsServer.MinerStudioWsSessions); _started = _wsServer.Start(); if (!_started) { NTMinerConsole.UserError("启动失败,无法继续,因为_wsServer启动失败"); return; } VirtualRoot.RaiseEvent(new WebSocketServerStatedEvent()); Console.ReadKey(true); Exit(); }
protected override void OnStartup(StartupEventArgs e) { NotiCenterWindow.Instance.ShowWindow(); MainWindow = new MainWindow(); MainWindow.Show(); VirtualRoot.StartTimer(new WpfTimer()); base.OnStartup(e); }
static void Main() { VirtualRoot.SetOut(new ConsoleOut()); NTMinerConsole.MainUiOk(); NTMinerConsole.DisbleQuickEditMode(); DevMode.SetDevMode(); Windows.ConsoleHandler.Register(Exit); string thisServerAddress = ServerRoot.HostConfig.ThisServerAddress; Console.Title = $"{nameof(ServerAppType.WsServer)}_{thisServerAddress}"; // 用本节点的地址作为队列名,消费消息时根据路由键区分消息类型 string queue = $"{nameof(ServerAppType.WsServer)}.{thisServerAddress}"; string durableQueue = queue + MqKeyword.DurableQueueEndsWith; AbstractMqMessagePath[] mqMessagePaths = new AbstractMqMessagePath[] { new ReadOnlyUserMqMessagePath(durableQueue), new MinerSignMqMessagePath(queue), new WsServerNodeMqMessagePath(queue), new OperationMqMessagePath(queue), new MinerClientMqMessagePath(queue, thisServerAddress), new ClientTestIdMqMessagePath(queue) }; if (!MqRedis.Create(ServerAppType.WsServer, mqMessagePaths, out IMqRedis mqRedis)) { NTMinerConsole.UserError("启动失败,无法继续,因为服务器上下文创建失败"); return; } MinerClientMqSender = new MinerClientMqSender(mqRedis); SpeedDataRedis = new SpeedDataRedis(mqRedis); WsServerNodeRedis = new WsServerNodeRedis(mqRedis); OperationMqSender = new OperationMqSender(mqRedis); UserMqSender = new UserMqSender(mqRedis); _wsServerNodeMqSender = new WsServerNodeMqSender(mqRedis); WsServerNodeAddressSet = new WsServerNodeAddressSet(WsServerNodeRedis, _wsServerNodeMqSender); var minerRedis = new MinerDataRedis(mqRedis); var userRedis = new ReadOnlyUserDataRedis(mqRedis); VirtualRoot.StartTimer(); // 构造函数中异步访问redis初始化用户列表,因为是异步的所以提前构造 UserSet = new ReadOnlyUserSet(userRedis); MinerSignSet = new MinerSignSet(minerRedis); _wsServer = new SharpWsServerAdapter(ServerRoot.HostConfig); MinerClientSessionSet = new MinerClientSessionSet(_wsServer.MinerClientWsSessions); MinerStudioSessionSet = new MinerStudioSessionSet(_wsServer.MinerStudioWsSessions); _started = _wsServer.Start(); if (!_started) { NTMinerConsole.UserError("启动失败,无法继续,因为_wsServer启动失败"); return; } VirtualRoot.RaiseEvent(new WebSocketServerStatedEvent()); Console.ReadKey(true); Exit(); }
static void Main() { DevMode.SetDevMode(); var wssv = new WebSocketServer("ws://0.0.0.0:8088"); wssv.Log.Level = WebSocketSharp.LogLevel.Trace; wssv.AddWebSocketService <AllInOneBehavior>("/"); wssv.Start(); VirtualRoot.StartTimer(); Windows.ConsoleHandler.Register(wssv.Stop); Console.ReadKey(true); wssv.Stop(); }
protected override void OnStartup(StartupEventArgs e) { RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly; // 之所以提前到这里是因为升级之前可能需要下载升级器,下载升级器时需要下载器 VirtualRoot.AddCmdPath <ShowFileDownloaderCommand>(action: message => { FileDownloader.ShowWindow(message.DownloadFileUrl, message.FileTitle, message.DownloadComplete); }, location: this.GetType()); VirtualRoot.AddCmdPath <UpgradeCommand>(action: message => { AppStatic.Upgrade(message.FileName, message.Callback); }, location: this.GetType()); createdNew = AppUtil.GetMutex(NTKeyword.MinerStudioAppMutex); if (createdNew) { this.ShutdownMode = ShutdownMode.OnExplicitShutdown; // 因为登录窗口会用到VirtualRoot.Out,而Out的延迟自动关闭消息会用到倒计时 VirtualRoot.StartTimer(new WpfTimer()); NotiCenterWindow.Instance.ShowWindow(); LoginWindow.Login(() => { bool isInnerIp = Net.IpUtil.IsInnerIp(NTMinerRegistry.GetControlCenterHost()); if (isInnerIp) { NTMinerServices.NTMinerServicesUtil.RunNTMinerServices(() => { Init(); }); } else { Init(); } }); } 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); }
private void Init() { NTMinerRoot.Instance.Init(() => { _appViewFactory.Link(); UIThread.Execute(() => { VirtualRoot.Execute(new ShowMinerClientsWindowCommand()); AppContext.NotifyIcon = ExtendedNotifyIcon.Create("群控客户端", isMinerStudio: true); }); #region 处理显示主界面命令 VirtualRoot.AddCmdPath <ShowMainWindowCommand>(action: message => { VirtualRoot.Execute(new ShowMinerClientsWindowCommand()); }, location: this.GetType()); #endregion HttpServer.Start($"http://localhost:{NTKeyword.MinerStudioPort.ToString()}"); Rdp.RemoteDesktop = MsRdpRemoteDesktop.OpenRemoteDesktop; VirtualRoot.StartTimer(new WpfTimer()); }); }
protected override void OnStartup(StartupEventArgs e) { BuildCommonPaths(); // 升级挖矿端 if (!string.IsNullOrEmpty(CommandLineArgs.Upgrade)) { // 启动计时器以放置后续的逻辑中用到计时器 VirtualRoot.StartTimer(new WpfTimingEventProducer()); VirtualRoot.Execute(new UpgradeCommand(CommandLineArgs.Upgrade, () => { UIThread.Execute(() => { Environment.Exit(0); }); })); } else { DoRun(); } base.OnStartup(e); }
public App() { VirtualRoot.SetOut(NotiCenterWindowViewModel.Instance); AppDomain.CurrentDomain.UnhandledException += (object sender, UnhandledExceptionEventArgs e) => { if (e.ExceptionObject is Exception exception) { Handle(exception); } }; DispatcherUnhandledException += (object sender, DispatcherUnhandledExceptionEventArgs e) => { Handle(e.Exception); e.Handled = true; }; Write.UIThreadId = Dispatcher.Thread.ManagedThreadId; UIThread.InitializeWithDispatcher(); VirtualRoot.StartTimer(new WpfTimer()); Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("zh-CN"); InitializeComponent(); }
protected override void OnStartup(StartupEventArgs e) { RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly; if (AppUtil.GetMutex(NTKeyword.MinerUpdaterAppMutex)) { NotiCenterWindow.Instance.ShowWindow(); this.MainWindow = new MainWindow(); this.MainWindow.Show(); VirtualRoot.StartTimer(new WpfTimer()); } else { Process thatProcess = null; Process currentProcess = Process.GetCurrentProcess(); Process[] Processes = Process.GetProcessesByName(currentProcess.ProcessName); foreach (Process process in Processes) { if (process.Id != currentProcess.Id) { // 因为挖矿端和群控端的升级器是同一份程序所以区分一下 if (typeof(App).Assembly.Location.Equals(currentProcess.MainModule.FileName, StringComparison.OrdinalIgnoreCase)) { thatProcess = process; } } } if (thatProcess != null) { AppUtil.Show(thatProcess); } else { MessageBox.Show("另一个升级器已在运行", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Warning); } Environment.Exit(0); return; } base.OnStartup(e); }
protected override void OnStartup(StartupEventArgs e) { RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly; if (AppUtil.GetMutex(NTKeyword.MinerClientFinderAppMutex)) { NotiCenterWindow.Instance.ShowWindow(); MainWindow = new MainWindow(); MainWindow.Show(); VirtualRoot.StartTimer(new WpfTimer()); } else { Process thatProcess = null; Process currentProcess = Process.GetCurrentProcess(); Process[] Processes = Process.GetProcessesByName(currentProcess.ProcessName); foreach (Process process in Processes) { if (process.Id != currentProcess.Id) { thatProcess = process; break; } } if (thatProcess != null) { AppUtil.Show(thatProcess); } else { MessageBox.Show("另一个矿机雷达已在运行", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Warning); } Environment.Exit(0); return; } base.OnStartup(e); }
static void Main() { NTMinerConsole.DisbleQuickEditMode(); HomePath.SetHomeDirFullName(AppDomain.CurrentDomain.BaseDirectory); try { bool mutexCreated; try { // 锁名称上带上本节点的端口号,从而允许一个服务器上运行多个WebApiServer节点,这在软升级服务端程序时有用。 // 升级WebApiServer程序的时候步骤是: // 1,在另一个端口启动新版本的程序; // 2,让Widnows将来自旧端口的所有tcp请求转发到新端口; // 3,退出旧版本的程序并更新到新版本; // 4,删除第2步添加的Windows的端口转发; // 5,退出第1步运行的节点; // TODO:实现软升级策略 _sMutexApp = new Mutex(true, $"NTMinerServicesMutex{ServerRoot.HostConfig.GetServerPort().ToString()}", out mutexCreated); } catch { mutexCreated = false; } if (mutexCreated) { try { // 用本节点的地址作为队列名,消费消息时根据路由键区分消息类型 string queue = $"{ServerAppType.WebApiServer.GetName()}.{ServerRoot.HostConfig.ThisServerAddress}"; string durableQueue = queue + MqKeyword.DurableQueueEndsWith; AbstractMqMessagePath[] mqMessagePaths = new AbstractMqMessagePath[] { new UserMqMessagePath(durableQueue), new MinerClientMqMessagePath(queue) }; _serverContext = ServerContext.Create(mqClientTypeName: ServerAppType.WebApiServer.GetName(), mqMessagePaths); if (_serverContext == null) { Write.UserError("启动失败,无法继续,因为服务器上下文创建失败"); return; } Console.Title = $"{ServerAppType.WebApiServer.GetName()}_{ServerRoot.HostConfig.ThisServerAddress}"; _ossClient = new OssClient(ServerRoot.HostConfig.OssEndpoint, ServerRoot.HostConfig.OssAccessKeyId, ServerRoot.HostConfig.OssAccessKeySecret); var minerClientMqSender = new MinerClientMqSender(_serverContext.Channel); var userMqSender = new UserMqSender(_serverContext.Channel); var wsServerNodeMqSender = new WsServerNodeMqSender(_serverContext.Channel); var minerRedis = new MinerRedis(_serverContext.RedisConn); var speedDataRedis = new SpeedDataRedis(_serverContext.RedisConn); var userRedis = new UserRedis(_serverContext.RedisConn); var captchaRedis = new CaptchaRedis(_serverContext.RedisConn); WsServerNodeSet = new WsServerNodeSet(wsServerNodeMqSender); UserSet = new UserSet(userRedis, userMqSender); UserAppSettingSet = new UserAppSettingSet(); CaptchaSet = new CaptchaSet(captchaRedis); CalcConfigSet = new CalcConfigSet(); NTMinerWalletSet = new NTMinerWalletSet(); ClientDataSet clientDataSet = new ClientDataSet(minerRedis, speedDataRedis, minerClientMqSender); ClientDataSet = clientDataSet; CoinSnapshotSet = new CoinSnapshotSet(clientDataSet); MineWorkSet = new UserMineWorkSet(); MinerGroupSet = new UserMinerGroupSet(); NTMinerFileSet = new NTMinerFileSet(); OverClockDataSet = new OverClockDataSet(); KernelOutputKeywordSet = new KernelOutputKeywordSet(SpecialPath.LocalDbFileFullName, isServer: true); ServerMessageSet = new ServerMessageSet(SpecialPath.LocalDbFileFullName, isServer: true); UpdateServerMessageTimestamp(); if (VirtualRoot.LocalAppSettingSet.TryGetAppSetting(nameof(KernelOutputKeywordTimestamp), out IAppSetting appSetting) && appSetting.Value is DateTime value) { KernelOutputKeywordTimestamp = value; } else { KernelOutputKeywordTimestamp = Timestamp.UnixBaseTime; } } catch (Exception e) { Write.UserError(e.Message); Write.UserError(e.StackTrace); Write.UserInfo("按任意键退出"); Console.ReadKey(); return; } VirtualRoot.StartTimer(); NTMinerRegistry.SetAutoBoot("NTMinerServices", true); Type thisType = typeof(WebApiRoot); Run(); } } catch (Exception e) { Logger.ErrorDebugLine(e); } }
static void Main(string[] args) { if (args.Length != 0) { if (args.Contains("--sha1")) { File.WriteAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "sha1"), Sha1); return; } } try { VirtualRoot.StartTimer(); _waitHandle = new AutoResetEvent(false); bool mutexCreated; try { _sMutexApp = new Mutex(true, "NTMinerDaemonAppMutex", out mutexCreated); } catch { mutexCreated = false; } if (mutexCreated) { NTMinerRegistry.SetDaemonVersion(Sha1); NTMinerRegistry.SetAutoBoot("NTMinerDaemon", true); bool isAutoBoot = MinerProfileUtil.GetIsAutoBoot(); if (isAutoBoot) { string location = NTMinerRegistry.GetLocation(); if (!string.IsNullOrEmpty(location) && File.Exists(location)) { string processName = Path.GetFileName(location); Process[] processes = Process.GetProcessesByName(processName); if (processes.Length == 0) { string arguments = NTMinerRegistry.GetArguments(); if (NTMinerRegistry.GetIsLastIsWork()) { arguments = "--work " + arguments; } try { Process.Start(location, arguments); Write.DevOk($"启动挖矿端 {location} {arguments}"); } catch (Exception e) { Logger.ErrorDebugLine($"启动挖矿端失败因为异常 {location} {arguments}", e); } } else { Write.DevDebug($"挖矿端已经在运行中无需启动"); } } } else { Write.DevDebug($"挖矿端未设置为自动启动"); } Run(); } } catch (Exception e) { Logger.ErrorDebugLine(e); } }
protected override void OnStartup(StartupEventArgs e) { RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly; // 之所以提前到这里是因为升级之前可能需要下载升级器,下载升级器时需要下载器 VirtualRoot.AddCmdPath <ShowFileDownloaderCommand>(action: message => { FileDownloader.ShowWindow(message.DownloadFileUrl, message.FileTitle, message.DownloadComplete); }, location: this.GetType()); VirtualRoot.AddCmdPath <UpgradeCommand>(action: message => { AppStatic.Upgrade(message.FileName, message.Callback); }, location: this.GetType()); if (!string.IsNullOrEmpty(CommandLineArgs.Upgrade)) { VirtualRoot.Execute(new UpgradeCommand(CommandLineArgs.Upgrade, () => { UIThread.Execute(() => () => { Environment.Exit(0); }); })); } else { if (AppUtil.GetMutex(NTKeyword.MinerClientAppMutex)) { Logger.InfoDebugLine($"==================NTMiner.exe {EntryAssemblyInfo.CurrentVersion.ToString()}=================="); NotiCenterWindowViewModel.IsHotKeyEnabled = true; // 在另一个UI线程运行欢迎界面以确保欢迎界面的响应不被耗时的主界面初始化过程阻塞 // 注意:必须确保SplashWindow没有用到任何其它界面用到的依赖对象 SplashWindow splashWindow = null; SplashWindow.ShowWindowAsync(window => { splashWindow = window; }); NotiCenterWindow.Instance.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(); } 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.ServerContext.CoinSet.Count == 0) { VirtualRoot.ThisLocalError(nameof(App), "访问阿里云失败,请尝试更换本机dns解决此问题。", toConsole: true); } UIThread.Execute(() => () => { Window mainWindow = null; AppContext.NotifyIcon = ExtendedNotifyIcon.Create("开源矿工", isMinerStudio: false); if (NTMinerRoot.Instance.MinerProfile.IsNoUi && NTMinerRoot.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 WpfTimer()); }); Task.Factory.StartNew(() => { if (NTMinerRoot.Instance.MinerProfile.IsAutoDisableWindowsFirewall) { Firewall.DisableFirewall(); } if (!Firewall.IsMinerClientRuleExists()) { Firewall.AddMinerClientRule(); } try { HttpServer.Start($"http://localhost:{NTKeyword.MinerClientPort.ToString()}"); Daemon.DaemonUtil.RunNTMinerDaemon(); } 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); }
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); }
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)); } }); 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); } } }
static void Main() { VirtualRoot.SetOut(new ConsoleOut()); NTMinerConsole.MainUiOk(); NTMinerConsole.DisbleQuickEditMode(); DevMode.SetDevMode(); Windows.ConsoleHandler.Register(Exit); try { bool mutexCreated; try { // 锁名称上带上本节点的端口号,从而允许一个服务器上运行多个WebApiServer节点,这在软升级服务端程序时有用。 // 升级WebApiServer程序的时候步骤是: // 1,在另一个端口启动新版本的程序; // 2,让Widnows将来自旧端口的所有tcp请求转发到新端口; // 3,退出旧版本的程序并更新到新版本; // 4,删除第2步添加的Windows的端口转发; // 5,退出第1步运行的节点; // TODO:实现软升级策略 _sMutexApp = new Mutex(true, $"NTMinerServicesMutex{ServerRoot.HostConfig.GetServerPort().ToString()}", out mutexCreated); } catch { mutexCreated = false; } if (mutexCreated) { try { // 用本节点的地址作为队列名,消费消息时根据路由键区分消息类型 string queue = $"{nameof(ServerAppType.WebApiServer)}.{ServerRoot.HostConfig.ThisServerAddress}"; string durableQueue = queue + MqKeyword.DurableQueueEndsWith; string wsBreathQueue = queue + MqKeyword.WsBreathQueueEndsWith; AbstractMqMessagePath[] mqMessagePaths = new AbstractMqMessagePath[] { new UserMqMessagePath(durableQueue), new CalcConfigMqMessagePath(queue), new MinerClientMqMessagePath(queue), new WsBreathMqMessagePath(wsBreathQueue), new OperationMqMessagePath(queue), new MqCountMqMessagePath(queue), new ClientTestIdMqMessagePath(queue) }; if (!MqRedis.Create(ServerAppType.WebApiServer, mqMessagePaths, out IMqRedis mqRedis)) { NTMinerConsole.UserError("启动失败,无法继续,因为服务器上下文创建失败"); return; } Console.Title = $"{nameof(ServerAppType.WebApiServer)}_{ServerRoot.HostConfig.ThisServerAddress}"; // 阿里云OSS坑爹比七牛Kodo贵一半 CloudFileUrlGenerater = new AliCloudOSSFileUrlGenerater(); IRedis redis = mqRedis; IMq mq = mqRedis; AdminMqSender = new AdminMqSender(mq); ClientTestIdDataRedis = new ClientTestIdDataRedis(redis); var minerClientMqSender = new MinerClientMqSender(mq); var userMqSender = new UserMqSender(mq); var calcConfigMqSender = new CalcConfigMqSender(mq); var minerRedis = new MinerDataRedis(redis); var clientActiveOnRedis = new ClientActiveOnRedis(redis); var speedDataRedis = new SpeedDataRedis(redis); var userRedis = new UserDataRedis(redis); var captchaRedis = new CaptchaDataRedis(redis); var calcConfigRedis = new CalcConfigDataRedis(redis); MqCountSet = new MqCountSet(); WsServerNodeRedis = new WsServerNodeRedis(redis); WsServerNodeAddressSet = new WsServerNodeAddressSet(WsServerNodeRedis); UserSet = new UserSet(userRedis, userMqSender); UserAppSettingSet = new UserAppSettingSet(); CaptchaSet = new CaptchaSet(captchaRedis); CalcConfigSet = new CalcConfigSet(calcConfigRedis, calcConfigMqSender); NTMinerWalletSet = new NTMinerWalletSet(); GpuNameSet = new GpuNameSet(); ClientDataSet clientDataSet = new ClientDataSet(minerRedis, clientActiveOnRedis, speedDataRedis, minerClientMqSender); ClientDataSet = clientDataSet; var operationMqSender = new OperationMqSender(mq); MineWorkSet = new UserMineWorkSet(operationMqSender); MinerGroupSet = new UserMinerGroupSet(); NTMinerFileSet = new NTMinerFileSet(); OverClockDataSet = new OverClockDataSet(); KernelOutputKeywordSet = new KernelOutputKeywordSet(SpecialPath.LocalDbFileFullName); ServerMessageSet = new ServerMessageSet(SpecialPath.LocalDbFileFullName); if (VirtualRoot.LocalAppSettingSet.TryGetAppSetting(nameof(KernelOutputKeywordTimestamp), out IAppSetting appSetting) && appSetting.Value is DateTime value) { KernelOutputKeywordTimestamp = value; } else { KernelOutputKeywordTimestamp = Timestamp.UnixBaseTime; } } catch (Exception e) { NTMinerConsole.UserError(e.Message); NTMinerConsole.UserError(e.StackTrace); NTMinerConsole.UserInfo("按任意键退出"); Console.ReadKey(); return; } VirtualRoot.StartTimer(); NTMinerRegistry.SetAutoBoot("NTMinerServices", true); Type thisType = typeof(AppRoot); Run(); } } catch (Exception e) { Logger.ErrorDebugLine(e); } }