public void SetCoinKernelProfileProperty(Guid workId, Guid coinKernelId, string propertyName, object value, Action <ResponseBase> callback) { Task.Factory.StartNew(() => { Guid messageId = Guid.NewGuid(); try { SetCoinKernelProfilePropertyRequest request = new SetCoinKernelProfilePropertyRequest { MessageId = messageId, LoginName = LoginName, CoinKernelId = coinKernelId, PropertyName = propertyName, Value = value, Timestamp = DateTime.Now, WorkId = workId }; request.SignIt(Password); using (var service = CreateService()) { ResponseBase response = service.SetCoinKernelProfileProperty(request); callback?.Invoke(response); } } catch (CommunicationException e) { Global.DebugLine(e.Message, ConsoleColor.Red); callback?.Invoke(ResponseBase.ClientError(messageId, e.Message)); } catch (Exception e) { Global.Logger.Error(e.Message, e); callback?.Invoke(ResponseBase.ClientError(messageId, e.Message)); } }); }
public void SetMinerProfileProperty(string host, string pubKey, string propertyName, object value, Action <bool> callback) { Task.Factory.StartNew(() => { try { string desKey; string data = EncryptSerialize(new Dictionary <string, object> { { "propertyName", propertyName }, { "value", value }, { "time", DateTime.Now } }, out desKey); using (var service = CreateService(host)) { service.SetMinerProfileProperty(desKey, data); } callback?.Invoke(true); } catch (CommunicationException e) { Global.DebugLine(e.Message, ConsoleColor.Red); callback?.Invoke(false); } catch (Exception e) { Global.Logger.Error(e.Message, e); callback?.Invoke(false); } }); }
public void LoadClients(List <Guid> clientIds, Action <LoadClientsResponse> callback) { Guid messageId = Guid.NewGuid(); Task.Factory.StartNew(() => { try { using (var service = CreateService()) { LoadClientsRequest request = new LoadClientsRequest { MessageId = messageId, LoginName = LoginName, ClientIds = clientIds, Timestamp = DateTime.Now }; request.SignIt(Password); LoadClientsResponse response = service.LoadClients(request); callback?.Invoke(response); } } catch (CommunicationException e) { Global.DebugLine(e.Message, ConsoleColor.Red); callback?.Invoke(LoadClientsResponse.ClientError(messageId, e.Message)); } catch (Exception e) { Global.Logger.Error(e.Message, e); callback?.Invoke(LoadClientsResponse.ClientError(messageId, e.Message)); } }); }
public void AddOrUpdateWallet(WalletData entity, Action <ResponseBase> callback) { Task.Factory.StartNew(() => { Guid messageId = Guid.NewGuid(); try { entity.ModifiedOn = DateTime.Now; AddOrUpdateWalletRequest request = new AddOrUpdateWalletRequest { LoginName = LoginName, MessageId = messageId, Timestamp = DateTime.Now, Data = entity }; request.SignIt(Password); using (var service = CreateService()) { ResponseBase response = service.AddOrUpdateWallet(request); callback?.Invoke(response); } } catch (CommunicationException e) { Global.DebugLine(e.Message, ConsoleColor.Red); callback?.Invoke(ResponseBase.ClientError(messageId, e.Message)); } catch (Exception e) { Global.Logger.Error(e.Message, e); callback?.Invoke(ResponseBase.ClientError(messageId, e.Message)); } }); }
public void SaveCalcConfigs(List <CalcConfigData> configs) { Task.Factory.StartNew(() => { Guid messageId = Guid.NewGuid(); try { if (configs == null || configs.Count == 0) { return; } SaveCalcConfigsRequest request = new SaveCalcConfigsRequest { Data = configs, LoginName = LoginName, MessageId = messageId, Timestamp = DateTime.Now }; request.SignIt(Password); using (var service = CreateService()) { service.SaveCalcConfigs(request); } } catch (CommunicationException e) { Global.DebugLine(e.Message, ConsoleColor.Red); } catch (Exception e) { Global.Logger.Error(e.Message, e); } }); }
public void Login(string loginName, string password, Action <ResponseBase> callback) { Guid messageId = Guid.NewGuid(); Task.Factory.StartNew(() => { try { using (var service = CreateService()) { LoginControlCenterRequest request = new LoginControlCenterRequest { MessageId = messageId, LoginName = loginName, Timestamp = DateTime.Now }; request.SignIt(password); ResponseBase response = service.LoginControlCenter(request); callback?.Invoke(response); } } catch (CommunicationException e) { Global.DebugLine(e.Message, ConsoleColor.Red); callback?.Invoke(ResponseBase.ClientError(messageId, e.Message)); } catch (Exception e) { Global.Logger.Error(e.Message, e); callback?.Invoke(ResponseBase.ClientError(messageId, e.Message)); } }); }
public static void CreateProcess(IMineContext mineContext) { Global.DebugLine("解压内核包"); // 解压内核包 mineContext.Kernel.ExtractPackage(); string kernelExeFileFullName; string arguments; Global.DebugLine("组装命令"); // 组装命令 BuildCmdLine(mineContext, out kernelExeFileFullName, out arguments); bool isLogFile = arguments.Contains("{logfile}"); // 这是不应该发生的,如果发生很可能是填写命令的时候拼写错误了 if (!File.Exists(kernelExeFileFullName)) { Global.WriteLine(kernelExeFileFullName + "文件不存在,请检查是否有拼写错误", ConsoleColor.Red); } if (isLogFile) { Global.DebugLine("创建日志文件型进程"); // 如果内核支持日志文件 // 推迟打印cmdLine,因为{logfile}变量尚未求值 CreateLogfileProcess(mineContext, kernelExeFileFullName, arguments); } else { Global.DebugLine("创建管道型进程"); // 如果内核不支持日志文件 string cmdLine = $"\"{kernelExeFileFullName}\" {arguments}"; Global.DebugLine(cmdLine, ConsoleColor.Yellow); CreatePipProcess(mineContext, cmdLine); } }
public void GetLatestSnapshots( int limit, List <string> coinCodes, Action <GetCoinSnapshotsResponse> callback) { Task.Factory.StartNew(() => { Guid messageId = Guid.NewGuid(); try { using (var service = CreateService()) { GetCoinSnapshotsRequest request = new GetCoinSnapshotsRequest { MessageId = messageId, LoginName = LoginName, Limit = limit, CoinCodes = coinCodes, Timestamp = DateTime.Now }; request.SignIt(Password); GetCoinSnapshotsResponse response = service.GetLatestSnapshots(request); callback?.Invoke(response); } } catch (CommunicationException e) { Global.DebugLine(e.Message, ConsoleColor.Red); callback?.Invoke(GetCoinSnapshotsResponse.ClientError(messageId, e.Message)); } catch (Exception e) { Global.Logger.Error(e.Message, e); callback?.Invoke(GetCoinSnapshotsResponse.ClientError(messageId, e.Message)); } }); }
public void RemoveWallet(Guid id, Action <ResponseBase> callback) { Task.Factory.StartNew(() => { Guid messageId = Guid.NewGuid(); try { RemoveWalletRequest request = new RemoveWalletRequest { MessageId = messageId, LoginName = LoginName, Timestamp = DateTime.Now, WalletId = id }; request.SignIt(Password); using (var service = CreateService()) { ResponseBase response = service.RemoveWallet(request); callback?.Invoke(response); } } catch (CommunicationException e) { Global.DebugLine(e.Message, ConsoleColor.Red); callback?.Invoke(ResponseBase.ClientError(messageId, e.Message)); } catch (Exception e) { Global.Logger.Error(e.Message, e); callback?.Invoke(ResponseBase.ClientError(messageId, e.Message)); } }); }
private static void ReportState(INTMinerRoot root) { try { Server.ReportService.ReportState(ClientId.Id, root.IsMining); } catch (Exception e) { Global.DebugLine(e.Message, ConsoleColor.Red); Global.DebugLine(e.StackTrace, ConsoleColor.Red); } }
public void Start() { string baseUrl = $"http://localhost:{Global.ClientPort}/"; ServiceHost timeServiceHost = new ServiceHost(typeof(TimeServiceImpl)); timeServiceHost.AddServiceEndpoint(typeof(ITimeService), ChannelFactory.BasicHttpBinding, new Uri(new Uri(baseUrl), nameof(ITimeService))); ServiceHost minerServerServiceHost = new ServiceHost(typeof(ControlCenterServiceImpl)); minerServerServiceHost.AddServiceEndpoint(typeof(IControlCenterService), ChannelFactory.BasicHttpBinding, new Uri(new Uri(baseUrl), nameof(IControlCenterService))); ServiceHost mineServerServiceHost = new ServiceHost(typeof(ProfileServiceImpl)); mineServerServiceHost.AddServiceEndpoint(typeof(IProfileService), ChannelFactory.BasicHttpBinding, new Uri(new Uri(baseUrl), nameof(IProfileService))); ServiceHost reportServerServiceHost = new ServiceHost(typeof(ReportServiceImpl)); reportServerServiceHost.AddServiceEndpoint(typeof(IReportService), ChannelFactory.BasicHttpBinding, new Uri(new Uri(baseUrl), nameof(IReportService))); ServiceHost versionServerServiceHost = new ServiceHost(typeof(FileUrlServiceImpl)); versionServerServiceHost.AddServiceEndpoint(typeof(IFileUrlService), ChannelFactory.BasicHttpBinding, new Uri(new Uri(baseUrl), nameof(IFileUrlService))); _serviceHosts = new List <ServiceHost> { timeServiceHost, minerServerServiceHost, mineServerServiceHost, reportServerServiceHost, versionServerServiceHost }; foreach (var serviceHost in _serviceHosts) { ServiceMetadataBehavior serviceMetadata = serviceHost.Description.Behaviors.Find <ServiceMetadataBehavior>(); if (serviceMetadata == null) { serviceMetadata = new ServiceMetadataBehavior(); serviceHost.Description.Behaviors.Add(serviceMetadata); } serviceMetadata.HttpGetEnabled = false; serviceHost.Open(); } Global.DebugLine($"服务启动成功: {DateTime.Now}."); Global.DebugLine("服务列表:"); foreach (var serviceHost in _serviceHosts) { foreach (var endpoint in serviceHost.Description.Endpoints) { Global.DebugLine(endpoint.Address.Uri.ToString()); } } StartedOn = DateTime.Now; }
public void QueryClients( int pageIndex, int pageSize, Guid?mineWorkId, string minerIp, string minerName, MineStatus mineState, string mainCoin, string mainCoinPool, string mainCoinWallet, string dualCoin, string dualCoinPool, string dualCoinWallet, Action <QueryClientsResponse> callback) { Task.Factory.StartNew(() => { Guid messageId = Guid.NewGuid(); try { using (var service = CreateService()) { var request = new QueryClientsRequest { LoginName = LoginName, PageIndex = pageIndex, PageSize = pageSize, MineWorkId = mineWorkId, MinerIp = minerIp, MinerName = minerName, MineState = mineState, MainCoin = mainCoin, MainCoinPool = mainCoinPool, MainCoinWallet = mainCoinWallet, DualCoin = dualCoin, DualCoinPool = dualCoinPool, DualCoinWallet = dualCoinWallet, Timestamp = DateTime.Now }; request.SignIt(Password); QueryClientsResponse response = service.QueryClients(request); callback?.Invoke(response); } } catch (CommunicationException e) { Global.DebugLine(e.Message, ConsoleColor.Red); callback?.Invoke(QueryClientsResponse.ClientError(messageId, e.Message)); } catch (Exception e) { Global.Logger.Error(e.Message, e); callback?.Invoke(QueryClientsResponse.ClientError(messageId, e.Message)); } }); }
public CoinKernelProfileData GetCoinKernelProfile(Guid workId, Guid coinKernelId) { try { using (var service = CreateService()) { return(service.GetCoinKernelProfile(workId, coinKernelId)); } } catch (CommunicationException e) { Global.DebugLine(e.Message, ConsoleColor.Red); return(null); } catch (Exception e) { Global.Logger.ErrorDebugLine(e.Message, e); return(null); } }
public List <MineWorkData> GetMineWorks() { try { using (var service = CreateService()) { return(service.GetMineWorks()); } } catch (CommunicationException e) { Global.DebugLine(e.Message, ConsoleColor.Red); return(new List <MineWorkData>()); } catch (Exception e) { Global.Logger.ErrorDebugLine(e.Message, e); return(new List <MineWorkData>()); } }
public void ReportSpeed(SpeedData message) { Task.Factory.StartNew(() => { try { using (var service = CreateService()) { service.ReportSpeed(message); } } catch (CommunicationException e) { Global.DebugLine(e.Message, ConsoleColor.Red); } catch (Exception e) { Global.Logger.Error(e.Message, e); } }); }
public void ReportState(Guid clientId, bool isMining) { Task.Factory.StartNew(() => { try { using (var service = CreateService()) { service.ReportState(clientId, isMining); } } catch (CommunicationException e) { Global.DebugLine(e.Message, ConsoleColor.Red); } catch (Exception e) { Global.Logger.Error(e.Message, e); } }); }
public GetMinerGroupsResponse GetMinerGroups(Guid messageId) { try { using (var service = CreateService()) { return(service.GetMinerGroups(messageId)); } } catch (CommunicationException e) { Global.DebugLine(e.Message, ConsoleColor.Red); return(GetMinerGroupsResponse.ClientError(messageId, e.Message)); } catch (Exception e) { Global.Logger.Error(e.Message, e); return(GetMinerGroupsResponse.ClientError(messageId, e.Message)); } }
public GetCalcConfigsResponse GetCalcConfigs() { Guid messageId = Guid.NewGuid(); try { using (var service = CreateService()) { return(service.GetCalcConfigs(messageId)); } } catch (CommunicationException e) { Global.DebugLine(e.Message, ConsoleColor.Red); return(GetCalcConfigsResponse.ClientError(messageId, e.Message)); } catch (Exception e) { Global.Logger.ErrorDebugLine(e.Message, e); return(GetCalcConfigsResponse.ClientError(messageId, e.Message)); } }
public void GetPackageUrl(string package, Action <string> callback) { Task.Factory.StartNew(() => { try { using (var service = CreateService()) { callback?.Invoke(service.GetPackageUrl(package)); } } catch (CommunicationException e) { Global.DebugLine(e.Message, ConsoleColor.Red); callback?.Invoke(string.Empty); } catch (Exception e) { Global.Logger.Error(e.Message, e); callback?.Invoke(string.Empty); } }); }
public void GetTime(Action <DateTime> callback) { Task.Factory.StartNew(() => { try { using (var service = CreateService()) { callback?.Invoke(service.GetTime()); } } catch (CommunicationException e) { Global.DebugLine(e.Message, ConsoleColor.Red); callback?.Invoke(DateTime.Now); } catch (Exception e) { Global.Logger.Error(e.Message, e); callback?.Invoke(DateTime.Now); } }); }
public void GetMineWork(Guid workId, Action <MineWorkData> callback) { Task.Factory.StartNew(() => { try { using (var service = CreateService()) { callback?.Invoke(service.GetMineWork(workId)); } } catch (CommunicationException e) { Global.DebugLine(e.Message, ConsoleColor.Red); callback?.Invoke(null); } catch (Exception e) { Global.Logger.ErrorDebugLine(e.Message, e); callback?.Invoke(null); } }); }
public void GetNTMinerUrl(string fileName, Action <string> callback) { Task.Factory.StartNew(() => { try { using (var client = CreateService()) { string url = client.GetNTMinerUrl(fileName); callback?.Invoke(url); } } catch (CommunicationException e) { Global.DebugLine(e.Message, ConsoleColor.Red); callback?.Invoke(string.Empty); } catch (Exception e) { Global.Logger.Error(e.Message, e); callback?.Invoke(string.Empty); } }); }
public void GetNTMinerFiles(Action <List <NTMinerFileData> > callback) { Task.Factory.StartNew(() => { try { using (var client = CreateService()) { List <NTMinerFileData> list = client.GetNTMinerFiles() ?? new List <NTMinerFileData>(); callback?.Invoke(list); } } catch (CommunicationException e) { Global.DebugLine(e.Message, ConsoleColor.Red); callback?.Invoke(new List <NTMinerFileData>()); } catch (Exception e) { Global.Logger.Error(e.Message, e); callback?.Invoke(new List <NTMinerFileData>()); } }); }
private static void CreateLogfileProcess(IMineContext mineContext, string kernelExeFileFullName, string arguments) { string logFile = Path.Combine(SpecialPath.LogsDirFullName, "logfile_" + DateTime.Now.Ticks.ToString() + ".log"); arguments = arguments.Replace("{logfile}", logFile); string cmdLine = $"\"{kernelExeFileFullName}\" {arguments}"; Global.DebugLine(cmdLine, ConsoleColor.Yellow); ProcessStartInfo startInfo = new ProcessStartInfo(kernelExeFileFullName, arguments) { UseShellExecute = false, CreateNoWindow = true, WorkingDirectory = Path.Combine(SpecialPath.KernelsDirFullName, Path.GetFileNameWithoutExtension(mineContext.Kernel.Package)) }; Process process = new Process(); process.StartInfo = startInfo; process.Start(); Task.Factory.StartNew(() => { ReadPrintLoopLogFile(mineContext, logFile); }); Daemon(mineContext, null); }
private NTMinerRoot() { Task.Factory.StartNew(() => { object locker = new object(); bool isDownloaded = false; Global.Access <HasBoot5SecondEvent>( Guid.Parse("5746e92f-8c79-4f91-a54d-90aa83d2bd1e"), "检查server.json是否下载成功", LogEnum.Log, action: (message) => { lock (locker) { if (!isDownloaded) { Init(); } else { Global.Logger.Info("下载成功了"); } } }); using (WebClient webClient = new WebClient()) { string serverJsonUrl = "https://minerjson.oss-cn-beijing.aliyuncs.com/server.json"; Global.DebugLine("下载:" + serverJsonUrl); webClient.DownloadFileCompleted += (object sender, System.ComponentModel.AsyncCompletedEventArgs e) => { if (!e.Cancelled && e.Error == null) { lock (locker) { isDownloaded = true; } Init(); } }; webClient.DownloadFileAsync(new Uri(serverJsonUrl), SpecialPath.NTMinerJsonFileFullName); } }); }
public void Start() { BootLog.Log("开始启动Wcf服务"); string baseUrl = $"http://{MinerClientHost}:{Global.ClientPort}/"; ServiceHost minerClientServiceHost = new ServiceHost(typeof(Core.Impl.MinerClientService)); minerClientServiceHost.AddServiceEndpoint(typeof(IMinerClientService), ChannelFactory.BasicHttpBinding, new Uri(new Uri(baseUrl), nameof(IMinerClientService))); _serviceHosts = new List <ServiceHost> { minerClientServiceHost }; foreach (var serviceHost in _serviceHosts) { ServiceMetadataBehavior serviceMetadata = serviceHost.Description.Behaviors.Find <ServiceMetadataBehavior>(); if (serviceMetadata == null) { serviceMetadata = new ServiceMetadataBehavior(); serviceHost.Description.Behaviors.Add(serviceMetadata); } serviceMetadata.HttpGetEnabled = false; serviceHost.Open(); } Global.DebugLine($"服务启动成功: {DateTime.Now}."); Global.DebugLine("服务列表:"); foreach (var serviceHost in _serviceHosts) { foreach (var endpoint in serviceHost.Description.Endpoints) { Global.DebugLine(endpoint.Address.Uri.ToString()); } } BootLog.Log("Wcf服务启动完成"); Server.TimeService.GetTime((remoteTime) => { if (Math.Abs((DateTime.Now - remoteTime).TotalSeconds) < Global.DesyncSeconds) { Global.DebugLine("时间同步"); } else { Global.WriteLine($"本机时间和服务器时间不同步,请调整,本地:{DateTime.Now},服务器:{remoteTime}", ConsoleColor.Red); } }); Windows.Registry.SetValue(Registry.Users, ClientId.NTMinerRegistrySubKey, "Location", ClientId.AppFileFullName); Windows.Registry.SetValue(Registry.Users, ClientId.NTMinerRegistrySubKey, "Arguments", string.Join(" ", CommandLineArgs.Args)); Windows.Registry.SetValue(Registry.Users, ClientId.NTMinerRegistrySubKey, "CurrentVersion", CurrentVersion.ToString()); Windows.Registry.SetValue(Registry.Users, ClientId.NTMinerRegistrySubKey, "CurrentVersionTag", CurrentVersionTag); Report.Init(this); int shareCount = 0; DateTime shareOn = DateTime.Now; #region 挖矿开始时将无份额内核重启份额计数置0 Global.Access <MineStartedEvent>( Guid.Parse("e69e8729-868b-4b5d-b120-2914fffddf90"), "挖矿开始时将无份额内核重启份额计数置0", LogEnum.None, action: message => { shareCount = 0; shareOn = DateTime.Now; }); #endregion #region 每10秒钟检查是否需要重启 Global.Access <Per10SecondEvent>( Guid.Parse("16b3b7b4-5e6c-46b0-97a4-90e085614b78"), "每10秒钟检查是否需要重启", LogEnum.None, action: message => { #region 重启电脑 try { if (MinerProfile.IsPeriodicRestartComputer) { if ((DateTime.Now - shareOn).TotalHours > MinerProfile.PeriodicRestartComputerHours) { Global.WriteLine($"每运行{MinerProfile.PeriodicRestartKernelHours}小时重启电脑", ConsoleColor.Red); Windows.Power.Restart(); return; // 退出 } } } catch (Exception e) { Global.Logger.Error(e.Message, e); } #endregion #region 周期重启内核 try { if (IsMining && MinerProfile.IsPeriodicRestartKernel) { if ((DateTime.Now - shareOn).TotalHours > MinerProfile.PeriodicRestartKernelHours) { Global.WriteLine($"每运行{MinerProfile.PeriodicRestartKernelHours}小时重启内核", ConsoleColor.Red); RestartMine(); return; // 退出 } } } catch (Exception e) { Global.Logger.Error(e.Message, e); } #endregion #region 收益没有增加重启内核 try { if (IsMining && MinerProfile.IsNoShareRestartKernel) { if ((DateTime.Now - shareOn).TotalMinutes > MinerProfile.NoShareRestartKernelMinutes) { if (this.CurrentMineContext.MainCoin != null) { ICoinShare mainCoinShare = this.CoinShareSet.GetOrCreate(this.CurrentMineContext.MainCoin.GetId()); int totalShare = mainCoinShare.TotalShareCount; if ((this.CurrentMineContext is IDualMineContext dualMineContext) && dualMineContext.DualCoin != null) { ICoinShare dualCoinShare = this.CoinShareSet.GetOrCreate(dualMineContext.DualCoin.GetId()); totalShare += dualCoinShare.TotalShareCount; } if (shareCount == totalShare) { Global.WriteLine($"{MinerProfile.NoShareRestartKernelMinutes}分钟收益没有增加重启内核", ConsoleColor.Red); RestartMine(); } else { shareCount = totalShare; shareOn = DateTime.Now; } }
private static void ReportSpeed(INTMinerRoot root) { try { SpeedData data = new SpeedData { MessageId = Guid.NewGuid(), MinerName = root.MinerProfile.MinerName, ClientId = ClientId.Id, Timestamp = DateTime.Now, MainCoinCode = string.Empty, MainCoinShareDelta = 0, MainCoinSpeed = 0, DualCoinCode = string.Empty, DualCoinShareDelta = 0, DualCoinSpeed = 0, IsMining = root.IsMining, DualCoinPool = string.Empty, DualCoinWallet = string.Empty, IsDualCoinEnabled = false, Kernel = string.Empty, MainCoinPool = string.Empty, MainCoinWallet = string.Empty }; ICoin mainCoin; if (root.CoinSet.TryGetCoin(root.MinerProfile.CoinId, out mainCoin)) { data.MainCoinCode = mainCoin.Code; ICoinProfile coinProfile = root.CoinProfileSet.GetCoinProfile(mainCoin.GetId()); IPool mainCoinPool; if (root.PoolSet.TryGetPool(coinProfile.PoolId, out mainCoinPool)) { data.MainCoinPool = mainCoinPool.Server; } else { data.MainCoinPool = string.Empty; } data.MainCoinWallet = coinProfile.Wallet; ICoinKernel coinKernel; if (root.CoinKernelSet.TryGetKernel(coinProfile.CoinKernelId, out coinKernel)) { IKernel kernel; if (root.KernelSet.TryGetKernel(coinKernel.KernelId, out kernel)) { data.Kernel = kernel.FullName; ICoinKernelProfile coinKernelProfile = root.CoinKernelProfileSet.GetCoinKernelProfile(coinProfile.CoinKernelId); data.IsDualCoinEnabled = coinKernelProfile.IsDualCoinEnabled; if (coinKernelProfile.IsDualCoinEnabled) { ICoin dualCoin; if (root.CoinSet.TryGetCoin(coinKernelProfile.DualCoinId, out dualCoin)) { data.DualCoinCode = dualCoin.Code; ICoinProfile dualCoinProfile = root.CoinProfileSet.GetCoinProfile(dualCoin.GetId()); data.DualCoinWallet = dualCoinProfile.DualCoinWallet; IPool dualCoinPool; if (root.PoolSet.TryGetPool(dualCoinProfile.DualCoinPoolId, out dualCoinPool)) { data.DualCoinPool = dualCoinPool.Server; } else { data.DualCoinPool = string.Empty; } } } } } } // 如果正在挖矿则报告算力,否则默认报告0算力 if (root.IsMining) { CoinShareData preCoinShare; Guid coinId = root.CurrentMineContext.MainCoin.GetId(); IGpusSpeed gpuSpeeds = NTMinerRoot.Current.GpusSpeed; IGpuSpeed totalSpeed = gpuSpeeds.CurrentSpeed(root.GpuAllId); data.MainCoinSpeed = (int)totalSpeed.MainCoinSpeed.Value; ICoinShare share = root.CoinShareSet.GetOrCreate(coinId); if (!_coinShareDic.TryGetValue(coinId, out preCoinShare)) { preCoinShare = new CoinShareData() { TotalShareCount = share.TotalShareCount }; _coinShareDic.Add(coinId, preCoinShare); data.MainCoinShareDelta = share.TotalShareCount; } else { data.MainCoinShareDelta = share.TotalShareCount - preCoinShare.TotalShareCount; } if (root.CurrentMineContext is IDualMineContext dualMineContext) { if (root.IsMining) { coinId = dualMineContext.DualCoin.GetId(); gpuSpeeds = NTMinerRoot.Current.GpusSpeed; totalSpeed = gpuSpeeds.CurrentSpeed(root.GpuAllId); data.DualCoinSpeed = (int)totalSpeed.DualCoinSpeed.Value; share = root.CoinShareSet.GetOrCreate(coinId); if (!_coinShareDic.TryGetValue(coinId, out preCoinShare)) { preCoinShare = new CoinShareData() { TotalShareCount = share.TotalShareCount }; _coinShareDic.Add(coinId, preCoinShare); data.DualCoinShareDelta = share.TotalShareCount; } else { data.DualCoinShareDelta = share.TotalShareCount - preCoinShare.TotalShareCount; } } } } Server.ReportService.ReportSpeed(data); } catch (Exception e) { Global.DebugLine(e.Message, ConsoleColor.Red); Global.DebugLine(e.StackTrace, ConsoleColor.Red); } }
private void OnNTMinerRootInited() { NTMinerRoot.KernelDownloader = new KernelDownloader(); Execute.OnUIThread(() => { BootLog.Log("new MainWindow"); Window splashWindow = MainWindow; MainWindow window = new MainWindow(); IMainWindow mainWindow = window; this.MainWindow = window; this.MainWindow.Show(); this.MainWindow.Activate(); BootLog.Log("MainWindow showed"); notifyIcon = new ExtendedNotifyIcon("pack://application:,,,/NTMiner;component/logo.ico"); notifyIcon.Init(); #region 处理显示主界面命令 Global.Access <ShowMainWindowCommand>( Guid.Parse("01f3c467-f494-42b8-bcb5-848050df59f3"), "处理显示主界面命令", LogEnum.None, action: message => { Execute.OnUIThread(() => { Dispatcher.Invoke((ThreadStart)mainWindow.ShowThisWindow); AppHelper.MainWindowShowed(); }); }); #endregion #region 处理重启NTMiner命令 Global.Access <RestartNTMinerCommand>( Guid.Parse("d1712c1f-507c-496f-9da2-870cbd9fc57f"), "处理重启NTMiner命令", LogEnum.None, action: message => { List <string> args = CommandLineArgs.Args; if (message.IsWorkEdit) { if (CommandLineArgs.IsWorkEdit && CommandLineArgs.WorkId == message.MineWorkId) { Execute.OnUIThread(() => { Dispatcher.Invoke((ThreadStart)mainWindow.ShowThisWindow); }); return; } if (!CommandLineArgs.IsControlCenter) { args.Add("--controlCenter"); } } if (message.MineWorkId != Guid.Empty) { if (!CommandLineArgs.IsWorker) { args.Add("--workid=" + message.MineWorkId.ToString()); } else { for (int i = 0; i < args.Count; i++) { if (args[i].StartsWith("--workid=", StringComparison.OrdinalIgnoreCase)) { args[i] = "--workid=" + message.MineWorkId.ToString(); break; } } } } else { if (CommandLineArgs.IsWorker) { int workIdIndex = -1; for (int i = 0; i < args.Count; i++) { if (args[i].ToLower().Contains("--workid=")) { workIdIndex = i; break; } } if (workIdIndex != -1) { args.RemoveAt(workIdIndex); } } } NTMiner.Windows.Cmd.RunClose(ClientId.AppFileFullName, string.Join(" ", args)); Current.MainWindow.Close(); }); #endregion Task.Factory.StartNew(() => { AppHelper.RunPipeServer(this, _appPipName); }); try { NTMinerRoot.Current.Start(); } catch (Exception ex) { Global.Logger.Error(ex.Message, ex); } splashWindow?.Close(); if (NTMinerRoot.Current.MinerProfile.IsAutoStart || CommandLineArgs.IsAutoStart) { Global.DebugLine("自动开始挖矿倒计时", ConsoleColor.Yellow); Views.Ucs.AutoStartCountdown.ShowDialog(); } BootLog.SyncToDisk(); }); }