public void ShowMainWindow(Application app, NTMinerAppType appType) { try { switch (appType) { case NTMinerAppType.MinerClient: RpcRoot.Client.MinerClientService.ShowMainWindowAsync((isSuccess, exception) => { if (!isSuccess) { RestartNTMiner(); } UIThread.Execute(() => app.Shutdown()); }); break; case NTMinerAppType.MinerStudio: RpcRoot.Client.MinerStudioService.ShowMainWindowAsync((isSuccess, exception) => { if (!isSuccess) { RestartNTMiner(); } UIThread.Execute(() => app.Shutdown()); }); break; default: break; } } catch (Exception e) { RestartNTMiner(); Logger.ErrorDebugLine(e); } }
public static string GetMinerClientArguments(NTMinerAppType appType) { string arguments = GetArguments(appType); if (appType == NTMinerAppType.MinerClient) { switch (GetWorkType()) { case WorkType.None: break; case WorkType.SelfWork: arguments = "--selfWork " + arguments; break; case WorkType.MineWork: arguments = "--work " + arguments; break; default: break; } } return(arguments); }
static App() { if (!Debugger.IsAttached && !Design.IsInDesignMode && DevMode.IsDevMode) { Write.Init(); } AppType = Environment.CommandLine.IndexOf("--minerstudio", StringComparison.OrdinalIgnoreCase) != -1 ? NTMinerAppType.MinerStudio : NTMinerAppType.MinerClient; }
static App() { AppType = Environment.CommandLine.IndexOf("--minerstudio", StringComparison.OrdinalIgnoreCase) != -1 ? NTMinerAppType.MinerStudio : NTMinerAppType.MinerClient; // 读取注册表中的Location的时候会根据VirtualRoot.IsMinerStudio而变化所以需要赋值 if (AppType == NTMinerAppType.MinerStudio) { VirtualRoot.SetIsMinerStudio(true); } }
// ReSharper disable once InconsistentNaming public void GetNTMinerFilesAsync(NTMinerAppType appType, Action <List <NTMinerFileData>, Exception> callback) { RpcRoot.PostAsync(_host, _port, _controllerName, nameof(IFileUrlController.NTMinerFiles), callback: (List <NTMinerFileData> data, Exception e) => { if (data != null) { data = data.Where(a => a.AppType == appType).ToList(); } callback?.Invoke(data, e); }); }
// ReSharper disable once InconsistentNaming public void GetNTMinerFilesAsync(NTMinerAppType appType, Action <List <NTMinerFileData>, Exception> callback) { PostAsync <List <NTMinerFileData> >(SControllerName, nameof(IFileUrlController.NTMinerFiles), null, null, callback: (data, e) => { if (data != null) { data = data.Where(a => a.AppType == appType).ToList(); } callback?.Invoke(data, e); }); }
public static string GetArguments(NTMinerAppType appType) { string valueName = GetValueName(appType, NTKeyword.ArgumentsRegistryKey); object value = Windows.WinRegistry.GetValue(Registry.Users, NTMinerRegistrySubKey, valueName); if (value != null) { return((string)value); } return(string.Empty); }
public AbstractWsClient(NTMinerAppType appType) { _appType = appType; _clientId = NTMinerRegistry.GetClientId(appType); VirtualRoot.BuildEventPath <Per1SecondEvent>("重试Ws连接的秒表倒计时", LogEnum.None, typeof(VirtualRoot), PathPriority.Normal, path: message => { if (_nextTrySecondsDelay > 0) { _nextTrySecondsDelay--; } }); VirtualRoot.BuildEventPath <Per10SecondEvent>("周期检查Ws连接", LogEnum.None, typeof(VirtualRoot), PathPriority.Normal, path: message => { if (_ws == null || _ws.ReadyState != WebSocketState.Open) { if (_continueCount >= _failConnCount) { _continueCount = 0; OpenOrCloseWs(); } else { _continueCount++; } } }); // 20秒是个不错的值,即不太频繁,也不太少 VirtualRoot.BuildEventPath <Per20SecondEvent>("周期Ws Ping", LogEnum.None, typeof(VirtualRoot), PathPriority.Normal, path: message => { if (_ws != null && _ws.ReadyState == WebSocketState.Open) { // 或者_ws.IsAlive,因为_ws.IsAlive内部也是一个Ping,所以用Ping从而显式化这里有个网络请求 Task.Factory.StartNew(() => { if (!_ws.Ping()) { _ws.CloseAsync(CloseStatusCode.Away); } }); } }); VirtualRoot.BuildEventPath <AppExitEvent>("退出程序时关闭Ws连接", LogEnum.DevConsole, this.GetType(), PathPriority.Normal, path: message => { _ws?.CloseAsync(CloseStatusCode.Normal, "客户端程序退出"); }); NetworkChange.NetworkAvailabilityChanged += (object sender, NetworkAvailabilityEventArgs e) => { if (e.IsAvailable) { 1.SecondsDelay().ContinueWith(t => { OpenOrCloseWs(isResetFailCount: true); }); } }; /// 1,进程启动后第一次连接时; NeedReWebSocket(); OpenOrCloseWs(); }
public static Guid GetClientId(NTMinerAppType appType) { string valueName = GetValueName(appType, NTKeyword.ClientIdRegistryKey); object value = Windows.WinRegistry.GetValue(Registry.Users, NTMinerRegistrySubKey, valueName); if (value == null || !Guid.TryParse((string)value, out Guid id)) { id = Guid.NewGuid(); Windows.WinRegistry.SetValue(Registry.Users, NTMinerRegistrySubKey, valueName, id.ToString()); } return(id); }
public static string GetCurrentVersionTag(NTMinerAppType appType) { string valueName = GetValueName(appType, NTKeyword.CurrentVersionTagRegistryKey); string currentVersionTag = string.Empty; object value = Windows.WinRegistry.GetValue(Registry.Users, NTMinerRegistrySubKey, valueName); if (value != null) { currentVersionTag = (string)value; } return(currentVersionTag); }
static App() { if (!Debugger.IsAttached && !Design.IsInDesignMode) { Write.Init(); } AppType = Environment.CommandLine.IndexOf("--minerstudio", StringComparison.OrdinalIgnoreCase) != -1 ? NTMinerAppType.MinerStudio : NTMinerAppType.MinerClient; // 读取注册表中的Location的时候会根据VirtualRoot.IsMinerStudio而变化所以需要赋值 if (AppType == NTMinerAppType.MinerStudio) { VirtualRoot.SetIsMinerStudio(true); } }
public void ReClientIdAsync(NTMinerAppType appType) { RpcRoot.JsonRpc.FirePostAsync( NTKeyword.Localhost, NTKeyword.NTMinerDaemonPort, _controllerName, nameof(INTMinerDaemonController.ReClientId), new Dictionary <string, string> { ["newClientId"] = NTMinerRegistry.GetClientId(appType).ToString() }, data: null, timeountMilliseconds: 3000); }
public NTMinerFileViewModel(INTMinerFile data) : this() { _id = data.Id; _appType = data.AppType; _version = data.Version; _fileName = data.FileName; _versionTag = data.VersionTag; _createdOn = data.CreatedOn; _publishOn = data.PublishOn; if (!System.Version.TryParse(_version, out _versionData)) { _versionData = new Version(1, 0); } }
// ReSharper disable once InconsistentNaming public void GetNTMinerFilesAsync(NTMinerAppType appType, Action <List <NTMinerFileData> > callback) { JsonRpcRoot.PostAsync(RpcRoot.OfficialServerHost, RpcRoot.OfficialServerPort, _controllerName, nameof(IFileUrlController.NTMinerFiles), callback: (List <NTMinerFileData> data, Exception e) => { if (data != null) { data = data.Where(a => a.AppType == appType).ToList(); } else { data = new List <NTMinerFileData>(); } callback?.Invoke(data); }); }
public static string GetCurrentVersion(NTMinerAppType appType) { string valueName = GetValueName(appType, NTKeyword.CurrentVersionRegistryKey); string currentVersion = "1.0.0.0"; object value = Windows.WinRegistry.GetValue(Registry.Users, NTMinerRegistrySubKey, valueName); if (value != null) { currentVersion = (string)value; } if (string.IsNullOrEmpty(currentVersion)) { return("1.0.0.0"); } return(currentVersion); }
public static Guid GetClientId(NTMinerAppType appType) { string valueName = GetValueName(appType, NTKeyword.ClientIdRegistryKey); object value = Windows.WinRegistry.GetValue(Registry.Users, NTMinerRegistrySubKey, valueName); // 如果是通过克隆磁盘装的系统注册表会被克隆 string cpuId = GetCpuId(); string realCpuId = VirtualRoot.CpuId; if (cpuId != realCpuId) { SetCpuId(realCpuId); } if (value == null || !Guid.TryParse((string)value, out Guid id) || cpuId != realCpuId) { id = Guid.NewGuid(); Windows.WinRegistry.SetValue(Registry.Users, NTMinerRegistrySubKey, valueName, id.ToString()); } return(id); }
public AbstractWsClient(NTMinerAppType appType) { _appType = appType; VirtualRoot.AddEventPath <Per1SecondEvent>("重试Ws连接的秒表倒计时", LogEnum.None, action: message => { if (NextTrySecondsDelay > 0) { NextTrySecondsDelay--; } }, typeof(VirtualRoot)); VirtualRoot.AddEventPath <Per10SecondEvent>("周期检查Ws连接", LogEnum.None, action: message => { if (_continueCount >= _failConnCount) { _continueCount = 0; OpenOrCloseWs(); } else { _continueCount++; } }, typeof(VirtualRoot)); VirtualRoot.AddEventPath <Per20SecondEvent>("周期Ws Ping", LogEnum.None, action: message => { try { if (_ws != null && _ws.ReadyState == WebSocketState.Open) { // 或者_ws.IsAlive,因为_ws.IsAlive内部也是一个Ping,所以用Ping从而显式化这里有个网络请求 Task.Factory.StartNew(() => { if (!_ws.Ping()) { _ws.CloseAsync(CloseStatusCode.Away); } }); } } catch (Exception e) { Logger.ErrorDebugLine(e); } }, typeof(VirtualRoot)); VirtualRoot.AddEventPath <AppExitEvent>("退出程序时关闭Ws连接", LogEnum.DevConsole, action: message => { _ws?.CloseAsync(CloseStatusCode.Normal, "客户端程序退出"); }, this.GetType()); OpenOrCloseWs(); }
private static string GetValueName(NTMinerAppType appType, string baseValueName) { string valueName; switch (appType) { case NTMinerAppType.MinerClient: valueName = baseValueName; break; case NTMinerAppType.MinerStudio: valueName = MinerStudio + baseValueName; break; default: throw new InvalidProgramException(); } return(valueName); }
public void GetJsonFileVersionAsync(NTMinerAppType appType, string key, Action <ServerStateResponse> callback) { HashSet <string> macAddresses = new HashSet <string>(); foreach (var localIp in VirtualRoot.LocalIpSet.AsEnumerable().ToArray()) { macAddresses.Add(localIp.MACAddress); } JsonFileVersionRequest request = new JsonFileVersionRequest { Key = key, ClientId = NTMinerRegistry.GetClientId(appType), MACAddress = macAddresses.ToArray() }; RpcRoot.JsonRpc.PostAsync( RpcRoot.OfficialServerHost, RpcRoot.OfficialServerPort, _controllerName, nameof(IAppSettingController.GetServerState), request, callback: (ServerStateResponse response, Exception e) => { if (e != null) { Logger.ErrorDebugLine(e); } if (response == null) { response = ServerStateResponse.Empty; Logger.ErrorWriteLine("询问服务器状态失败,请检查网络。"); } if (response.NeedReClientId) { NTMinerRegistry.ReClientId(ClientAppType.AppType); RpcRoot.Client.NTMinerDaemonService.ReClientIdAsync(appType); Logger.InfoDebugLine("检测到本机标识存在重复,已重新生成"); } callback?.Invoke(response); }, timeountMilliseconds: 10 * 1000); }
public static void ShowMainWindow(Application app, NTMinerAppType appType) { try { switch (appType) { case NTMinerAppType.MinerClient: Client.MinerClientService.ShowMainWindowAsync(WebApiConst.MinerClientPort, (isSuccess, exception) => { if (!isSuccess) { RestartNTMiner(); } UIThread.Execute(() => { app.Shutdown(); }); }); break; case NTMinerAppType.MinerStudio: Client.MinerStudioService.ShowMainWindowAsync(WebApiConst.MinerStudioPort, (isSuccess, exception) => { if (!isSuccess) { RestartNTMiner(); } UIThread.Execute(() => { app.Shutdown(); }); }); break; default: break; } } catch (Exception ex) { RestartNTMiner(); Logger.ErrorDebugLine(ex.Message, ex); } }
public static void SetCurrentVersionTag(NTMinerAppType appType, string versionTag) { string valueName = GetValueName(appType, NTKeyword.CurrentVersionTagRegistryKey); Windows.WinRegistry.SetValue(Registry.Users, NTMinerRegistrySubKey, valueName, versionTag); }
public static void ShowMainWindow(Application app, NTMinerAppType appType) { InnerFactory.ShowMainWindow(app, appType); }
public ClientAppType(NTMinerAppType ntminerAppType) { this.NTMinerAppType = ntminerAppType; }
protected SharpWsSessionAdapterBase(NTMinerAppType sessionType) { this.EmitOnPing = true; this.SessionType = sessionType; }
public static void Upgrade(NTMinerAppType appType, string fileName, Action callback) { RpcRoot.OfficialServer.FileUrlService.GetNTMinerUpdaterUrlAsync((downloadFileUrl, e) => { try { string argument = string.Empty; if (!string.IsNullOrEmpty(fileName)) { argument = "ntminerFileName=" + fileName; } if (appType == NTMinerAppType.MinerStudio) { argument += " --minerstudio"; } if (string.IsNullOrEmpty(downloadFileUrl)) { if (File.Exists(HomePath.UpdaterFileFullName)) { Windows.Cmd.RunClose(HomePath.UpdaterFileFullName, argument); } callback?.Invoke(); return; } Uri uri = new Uri(downloadFileUrl); string localVersion = GetUpdaterVersion(); if (string.IsNullOrEmpty(localVersion) || !File.Exists(HomePath.UpdaterFileFullName) || uri.AbsolutePath != localVersion) { VirtualRoot.Execute(new ShowFileDownloaderCommand(downloadFileUrl, "开源矿工更新器", (window, isSuccess, message, saveFileFullName) => { try { if (isSuccess) { string updateDirFullName = Path.GetDirectoryName(HomePath.UpdaterFileFullName); if (!Directory.Exists(updateDirFullName)) { Directory.CreateDirectory(updateDirFullName); } File.Delete(HomePath.UpdaterFileFullName); File.Move(saveFileFullName, HomePath.UpdaterFileFullName); SetUpdaterVersion(uri.AbsolutePath); window?.Close(); Windows.Cmd.RunClose(HomePath.UpdaterFileFullName, argument); callback?.Invoke(); } else { VirtualRoot.ThisLocalError(nameof(AppRoot), "下载新版本:" + message, toConsole: true); callback?.Invoke(); } } catch (Exception ex) { Logger.ErrorDebugLine(ex); callback?.Invoke(); } })); } else { Windows.Cmd.RunClose(HomePath.UpdaterFileFullName, argument); callback?.Invoke(); } } catch (Exception ex) { Logger.ErrorDebugLine(ex); callback?.Invoke(); } }); }
public static void ReClientId(NTMinerAppType appType) { string valueName = GetValueName(appType, NTKeyword.ClientIdRegistryKey); Windows.WinRegistry.DeleteValue(Registry.Users, NTMinerRegistrySubKey, valueName); }
public static void SetArguments(NTMinerAppType appType, string arguments) { string valueName = GetValueName(appType, NTKeyword.ArgumentsRegistryKey); Windows.WinRegistry.SetValue(Registry.Users, NTMinerRegistrySubKey, valueName, arguments); }
public static void SetLocation(NTMinerAppType appType, string location) { string valueName = GetValueName(appType, NTKeyword.LocationRegistryKey); Windows.WinRegistry.SetValue(Registry.Users, NTMinerRegistrySubKey, valueName, location); }