예제 #1
0
        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);
            }
        }
예제 #2
0
        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);
        }
예제 #3
0
 static App()
 {
     if (!Debugger.IsAttached && !Design.IsInDesignMode && DevMode.IsDevMode)
     {
         Write.Init();
     }
     AppType = Environment.CommandLine.IndexOf("--minerstudio", StringComparison.OrdinalIgnoreCase) != -1 ? NTMinerAppType.MinerStudio : NTMinerAppType.MinerClient;
 }
예제 #4
0
파일: App.xaml.cs 프로젝트: ayxcjqx/ntminer
 static App()
 {
     AppType = Environment.CommandLine.IndexOf("--minerstudio", StringComparison.OrdinalIgnoreCase) != -1 ? NTMinerAppType.MinerStudio : NTMinerAppType.MinerClient;
     // 读取注册表中的Location的时候会根据VirtualRoot.IsMinerStudio而变化所以需要赋值
     if (AppType == NTMinerAppType.MinerStudio)
     {
         VirtualRoot.SetIsMinerStudio(true);
     }
 }
예제 #5
0
 // 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);
     });
 }
예제 #6
0
 // 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);
     });
 }
예제 #7
0
        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);
        }
예제 #8
0
 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();
 }
예제 #9
0
        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);
        }
예제 #10
0
        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);
        }
예제 #11
0
 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);
     }
 }
예제 #12
0
 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);
 }
예제 #13
0
 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);
     }
 }
예제 #14
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);
     });
 }
예제 #15
0
        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);
        }
예제 #16
0
        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);
        }
예제 #17
0
 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();
 }
예제 #18
0
        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);
        }
예제 #19
0
        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);
        }
예제 #20
0
        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);
            }
        }
예제 #21
0
        public static void SetCurrentVersionTag(NTMinerAppType appType, string versionTag)
        {
            string valueName = GetValueName(appType, NTKeyword.CurrentVersionTagRegistryKey);

            Windows.WinRegistry.SetValue(Registry.Users, NTMinerRegistrySubKey, valueName, versionTag);
        }
예제 #22
0
 public static void ShowMainWindow(Application app, NTMinerAppType appType)
 {
     InnerFactory.ShowMainWindow(app, appType);
 }
예제 #23
0
 public ClientAppType(NTMinerAppType ntminerAppType)
 {
     this.NTMinerAppType = ntminerAppType;
 }
예제 #24
0
 protected SharpWsSessionAdapterBase(NTMinerAppType sessionType)
 {
     this.EmitOnPing  = true;
     this.SessionType = sessionType;
 }
예제 #25
0
 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();
         }
     });
 }
예제 #26
0
        public static void ReClientId(NTMinerAppType appType)
        {
            string valueName = GetValueName(appType, NTKeyword.ClientIdRegistryKey);

            Windows.WinRegistry.DeleteValue(Registry.Users, NTMinerRegistrySubKey, valueName);
        }
예제 #27
0
        public static void SetArguments(NTMinerAppType appType, string arguments)
        {
            string valueName = GetValueName(appType, NTKeyword.ArgumentsRegistryKey);

            Windows.WinRegistry.SetValue(Registry.Users, NTMinerRegistrySubKey, valueName, arguments);
        }
예제 #28
0
        public static void SetLocation(NTMinerAppType appType, string location)
        {
            string valueName = GetValueName(appType, NTKeyword.LocationRegistryKey);

            Windows.WinRegistry.SetValue(Registry.Users, NTMinerRegistrySubKey, valueName, location);
        }