コード例 #1
0
 private MainWindowViewModel()
 {
     if (App.IsInDesignMode)
     {
         return;
     }
     this.Refresh();
     this.CancelDownload = new DelegateCommand(() => {
         this.cancel?.Invoke();
         this.IsDownloading = false;
     });
     this.Install = new DelegateCommand(() => {
         if (this.IsDownloading)
         {
             return;
         }
         this.IsDownloading = true;
         string ntMinerFile = string.Empty;
         string version     = string.Empty;
         if (IsHistoryVisible == Visibility.Collapsed)
         {
             if (ServerLatestVm != null)
             {
                 ntMinerFile = ServerLatestVm.FileName;
                 version     = ServerLatestVm.Version;
             }
         }
         else
         {
             ntMinerFile = SelectedNTMinerFile.FileName;
             version     = SelectedNTMinerFile.Version;
         }
         Download(ntMinerFile, version, progressChanged: (percent) => {
             this.DownloadMessage = percent + "%";
             this.DownloadPercent = (double)percent / 100;
         }, downloadComplete: (isSuccess, message, saveFileFullName) => {
             this.DownloadMessage  = message;
             this.DownloadPercent  = 0;
             this.BtnCancelVisible = Visibility.Collapsed;
             if (isSuccess)
             {
                 this.DownloadMessage = "更新成功,正在重启";
                 if (VirtualRoot.IsMinerStudio)
                 {
                     Client.MinerStudioService.CloseMinerStudio();
                 }
                 else
                 {
                     Client.MinerClientService.CloseNTMiner();
                 }
                 TimeSpan.FromSeconds(2).Delay().ContinueWith((t) => {
                     string location = NTMinerRegistry.GetLocation();
                     if (string.IsNullOrEmpty(location) || !File.Exists(location))
                     {
                         location = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ntMinerFile);
                     }
                     File.Copy(saveFileFullName, location, overwrite: true);
                     File.Delete(saveFileFullName);
                     string arguments = NTMinerRegistry.GetArguments();
                     Process.Start(location, arguments);
                     this.IsDownloading = false;
                     UIThread.Execute(() => {
                         Application.Current.MainWindow.Close();
                     });
                 });
             }
             else
             {
                 TimeSpan.FromSeconds(2).Delay().ContinueWith((t) => {
                     this.IsDownloading = false;
                 });
             }
         }, cancel: out cancel);
     });
     this.ShowHistory = new DelegateCommand(() => {
         if (IsHistoryVisible == Visibility.Visible)
         {
             IsHistoryVisible = Visibility.Collapsed;
         }
         else
         {
             IsHistoryVisible = Visibility.Visible;
         }
     });
     this.AddNTMinerFile = new DelegateCommand(() => {
         NTMinerFileEdit window = new NTMinerFileEdit("添加", "Icon_Add", new NTMinerFileViewModel()
         {
             AppType = App.AppType
         });
         window.ShowDialogEx();
     });
 }
コード例 #2
0
        public void OpenOrCloseWs(bool isResetFailCount = false)
        {
            try {
                if (isResetFailCount)
                {
                    ResetFailCount();
                }
                switch (_appType)
                {
                case NTMinerAppType.MinerClient:
                    _isOuterUserEnabled = NTMinerRegistry.GetIsOuterUserEnabled();
                    break;

                case NTMinerAppType.MinerStudio:
                    _isOuterUserEnabled = true;
                    break;

                default:
                    _isOuterUserEnabled = false;
                    break;
                }
                string outerUserId;
                switch (_appType)
                {
                case NTMinerAppType.MinerClient:
                    outerUserId = NTMinerRegistry.GetOuterUserId();
                    break;

                case NTMinerAppType.MinerStudio:
                    outerUserId = RpcRoot.RpcUser.LoginName;
                    break;

                default:
                    outerUserId = string.Empty;
                    break;
                }
                if (!_isOuterUserEnabled)
                {
                    ResetFailCount();
                    if (_ws != null && _ws.ReadyState == WebSocketState.Open)
                    {
                        _ws.CloseAsync(CloseStatusCode.Normal, "外网群控已禁用");
                    }
                    return;
                }
                if (string.IsNullOrEmpty(outerUserId))
                {
                    ResetFailCount();
                    _ws?.CloseAsync(CloseStatusCode.Normal, "未填写用户");
                    return;
                }
                bool isUserIdChanged = _outerUserId != outerUserId;
                if (isUserIdChanged)
                {
                    _outerUserId = outerUserId;
                }
                // 1,进程启动后第一次连接时
                if (_ws == null)
                {
                    NewWebSocket(webSocket => _ws = webSocket);
                }
                else if (isUserIdChanged)
                {
                    ResetFailCount();
                    if (_ws.ReadyState == WebSocketState.Open)
                    {
                        // 因为旧的用户名密码成连接过且用户名或密码变更了,那么关闭连接即可,无需立即再次连接因为一定连接不成功因为用户名密码不再正确。
                        string why = string.Empty;
                        if (isUserIdChanged)
                        {
                            why = ",因为用户变更";
                        }
                        _ws.CloseAsync(CloseStatusCode.Normal, $"关闭连接{why}");
                    }
                    else
                    {
                        // 因为旧用户名密码没有成功连接过,说明旧用户名密码不正确,而现在用户名密码变更了,有可能变更正确了所以尝试连接一次。
                        ConnectAsync(_ws);
                    }
                }
                else if (_ws.ReadyState != WebSocketState.Open)
                {
                    ConnectAsync(_ws);
                }
            }
            catch (Exception e) {
                Logger.ErrorDebugLine(e);
            }
        }
コード例 #3
0
        public SpeedDto CreateSpeedDto()
        {
            INTMinerContext ntminerContext = NTMinerContext.Instance;
            IWorkProfile    workProfile    = ntminerContext.MinerProfile;
            string          localIps       = VirtualRoot.FormatLocalIps(out string macAddress);
            Guid            mineContextId  = Guid.Empty;

            if (ntminerContext.CurrentMineContext != null)
            {
                mineContextId = ntminerContext.CurrentMineContext.Id;
            }
            SpeedDto speedDto = new SpeedDto {
                MineContextId   = mineContextId,
                MainCoinSpeedOn = DateTime.MinValue,
                DualCoinSpeedOn = DateTime.MinValue,
                IsAutoDisableWindowsFirewall = workProfile.IsAutoDisableWindowsFirewall,
                IsDisableAntiSpyware         = workProfile.IsDisableAntiSpyware,
                IsDisableUAC                = workProfile.IsDisableUAC,
                IsDisableWAU                = workProfile.IsDisableWAU,
                Is1080PillEnabled           = workProfile.Is1080PillEnabled,
                IsPreventDisplaySleep       = workProfile.IsPreventDisplaySleep,
                IsAutoReboot                = workProfile.IsAutoReboot,
                LocalServerMessageTimestamp = VirtualRoot.LocalServerMessageSetTimestamp,
                KernelSelfRestartCount      = 0,
                IsAutoBoot            = workProfile.IsAutoBoot,
                IsAutoStart           = workProfile.IsAutoStart,
                AutoStartDelaySeconds = workProfile.AutoStartDelaySeconds,
                Version                        = EntryAssemblyInfo.CurrentVersionStr,
                BootOn                         = ntminerContext.CreatedOn,
                MineStartedOn                  = null,
                IsMining                       = ntminerContext.IsMining,
                MineWorkId                     = Guid.Empty,
                MineWorkName                   = string.Empty,
                MinerName                      = workProfile.MinerName,
                GpuInfo                        = ntminerContext.GpuSetInfo,
                ClientId                       = NTMinerContext.Id,
                MACAddress                     = macAddress,
                LocalIp                        = localIps,
                MainCoinCode                   = string.Empty,
                MainCoinWallet                 = string.Empty,
                MainCoinTotalShare             = 0,
                MainCoinRejectShare            = 0,
                MainCoinSpeed                  = 0,
                DualCoinCode                   = string.Empty,
                DualCoinTotalShare             = 0,
                DualCoinRejectShare            = 0,
                DualCoinSpeed                  = 0,
                DualCoinPool                   = string.Empty,
                DualCoinWallet                 = string.Empty,
                IsDualCoinEnabled              = false,
                Kernel                         = string.Empty,
                MainCoinPool                   = string.Empty,
                OSName                         = Windows.OS.Instance.WindowsEdition,
                GpuDriver                      = ntminerContext.GpuSet.DriverVersion,
                GpuType                        = ntminerContext.GpuSet.GpuType,
                OSVirtualMemoryMb              = VirtualRoot.DriveSet.OSVirtualMemoryMb,
                TotalPhysicalMemoryMb          = (int)(Windows.Ram.Instance.TotalPhysicalMemory / NTKeyword.IntM),
                KernelCommandLine              = string.Empty,
                DiskSpace                      = VirtualRoot.DriveSet.ToDiskSpaceString(),
                IsAutoRestartKernel            = workProfile.IsAutoRestartKernel,
                AutoRestartKernelTimes         = workProfile.AutoRestartKernelTimes,
                IsNoShareRestartKernel         = workProfile.IsNoShareRestartKernel,
                NoShareRestartKernelMinutes    = workProfile.NoShareRestartKernelMinutes,
                IsNoShareRestartComputer       = workProfile.IsNoShareRestartComputer,
                NoShareRestartComputerMinutes  = workProfile.NoShareRestartComputerMinutes,
                IsPeriodicRestartComputer      = workProfile.IsPeriodicRestartComputer,
                PeriodicRestartComputerHours   = workProfile.PeriodicRestartComputerHours,
                IsPeriodicRestartKernel        = workProfile.IsPeriodicRestartKernel,
                PeriodicRestartKernelHours     = workProfile.PeriodicRestartKernelHours,
                PeriodicRestartComputerMinutes = workProfile.PeriodicRestartComputerMinutes,
                PeriodicRestartKernelMinutes   = workProfile.PeriodicRestartKernelMinutes,
                IsAutoStartByCpu               = workProfile.IsAutoStartByCpu,
                IsAutoStopByCpu                = workProfile.IsAutoStopByCpu,
                CpuGETemperatureSeconds        = workProfile.CpuGETemperatureSeconds,
                CpuLETemperatureSeconds        = workProfile.CpuLETemperatureSeconds,
                CpuStartTemperature            = workProfile.CpuStartTemperature,
                CpuStopTemperature             = workProfile.CpuStopTemperature,
                MainCoinPoolDelay              = string.Empty,
                DualCoinPoolDelay              = string.Empty,
                MinerIp                        = string.Empty,
                IsFoundOneGpuShare             = false,
                IsGotOneIncorrectGpuShare      = false,
                IsRejectOneGpuShare            = false,
                CpuPerformance                 = ntminerContext.CpuPackage.Performance,
                CpuTemperature                 = ntminerContext.CpuPackage.Temperature,
                IsRaiseHighCpuEvent            = workProfile.IsRaiseHighCpuEvent,
                HighCpuPercent                 = workProfile.HighCpuBaseline,
                HighCpuSeconds                 = workProfile.HighCpuSeconds,
                IsOuterUserEnabled             = workProfile.IsOuterUserEnabled,
                ReportOuterUserId              = NTMinerRegistry.GetOuterUserId(),
                IsLowSpeedRestartComputer      = false,
                LowSpeedRestartComputerMinutes = 0,
                LowSpeed                       = 0,
                IsLowSpeedReOverClock          = false,
                LowSpeedReOverClockMinutes     = 0,
                OverClockLowSpeed              = 0,
                GpuTable                       = ntminerContext.GpusSpeed.AsEnumerable().Where(a => a.Gpu.Index != NTMinerContext.GpuAllId).Select(a => a.ToGpuSpeedData()).ToArray()
            };

            if (workProfile.MineWork != null)
            {
                speedDto.MineWorkId   = workProfile.MineWork.GetId();
                speedDto.MineWorkName = workProfile.MineWork.Name;
            }
            #region 当前选中的币种是什么
            if (ntminerContext.ServerContext.CoinSet.TryGetCoin(workProfile.CoinId, out ICoin mainCoin))
            {
                speedDto.MainCoinCode = mainCoin.Code;
                ICoinProfile coinProfile = workProfile.GetCoinProfile(mainCoin.GetId());
                speedDto.MainCoinWallet            = coinProfile.Wallet;
                speedDto.IsLowSpeedRestartComputer = coinProfile.IsLowSpeedRestartComputer;
                speedDto.LowSpeed = coinProfile.LowSpeed;
                speedDto.LowSpeedRestartComputerMinutes = coinProfile.LowSpeedRestartComputerMinutes;
                speedDto.IsLowSpeedReOverClock          = coinProfile.IsLowSpeedReOverClock;
                speedDto.LowSpeedReOverClockMinutes     = coinProfile.LowSpeedReOverClockMinutes;
                speedDto.OverClockLowSpeed = coinProfile.OverClockLowSpeed;
                if (ntminerContext.ServerContext.PoolSet.TryGetPool(coinProfile.PoolId, out IPool mainCoinPool))
                {
                    speedDto.MainCoinPool = mainCoinPool.Server;
                    if (ntminerContext.IsMining)
                    {
                        speedDto.MainCoinPoolDelay = ntminerContext.ServerContext.PoolSet.GetPoolDelayText(mainCoinPool.GetId(), isDual: false);
                    }
                    if (mainCoinPool.IsUserMode)
                    {
                        IPoolProfile mainCoinPoolProfile = workProfile.GetPoolProfile(coinProfile.PoolId);
                        speedDto.MainCoinWallet = mainCoinPoolProfile.UserName;
                    }
                }
                else
                {
                    speedDto.MainCoinPool = string.Empty;
                }
                if (ntminerContext.ServerContext.CoinKernelSet.TryGetCoinKernel(coinProfile.CoinKernelId, out ICoinKernel coinKernel))
                {
                    if (ntminerContext.ServerContext.KernelSet.TryGetKernel(coinKernel.KernelId, out IKernel kernel))
                    {
                        speedDto.Kernel = kernel.GetFullName();
                        if (ntminerContext.ServerContext.KernelOutputSet.TryGetKernelOutput(kernel.KernelOutputId, out IKernelOutput kernelOutput))
                        {
                            speedDto.IsFoundOneGpuShare        = !string.IsNullOrEmpty(kernelOutput.FoundOneShare);
                            speedDto.IsGotOneIncorrectGpuShare = !string.IsNullOrEmpty(kernelOutput.GpuGotOneIncorrectShare);
                            speedDto.IsRejectOneGpuShare       = !string.IsNullOrEmpty(kernelOutput.RejectOneShare);
                        }
                        ICoinKernelProfile coinKernelProfile = workProfile.GetCoinKernelProfile(coinProfile.CoinKernelId);
                        speedDto.IsDualCoinEnabled = coinKernelProfile.IsDualCoinEnabled;
                        if (coinKernelProfile.IsDualCoinEnabled)
                        {
                            if (ntminerContext.ServerContext.CoinSet.TryGetCoin(coinKernelProfile.DualCoinId, out ICoin dualCoin))
                            {
                                speedDto.DualCoinCode = dualCoin.Code;
                                ICoinProfile dualCoinProfile = workProfile.GetCoinProfile(dualCoin.GetId());
                                speedDto.DualCoinWallet = dualCoinProfile.DualCoinWallet;
                                if (ntminerContext.ServerContext.PoolSet.TryGetPool(dualCoinProfile.DualCoinPoolId, out IPool dualCoinPool))
                                {
                                    speedDto.DualCoinPool = dualCoinPool.Server;
                                    if (ntminerContext.IsMining)
                                    {
                                        speedDto.DualCoinPoolDelay = ntminerContext.ServerContext.PoolSet.GetPoolDelayText(dualCoinPool.GetId(), isDual: true);
                                    }
                                    if (dualCoinPool.IsUserMode)
                                    {
                                        IPoolProfile dualCoinPoolProfile = workProfile.GetPoolProfile(dualCoinProfile.DualCoinPoolId);
                                        speedDto.DualCoinWallet = dualCoinPoolProfile.UserName;
                                    }
                                }
                                else
                                {
                                    speedDto.DualCoinPool = string.Empty;
                                }
                            }
                        }
                    }
                }
            }
            #endregion

            if (ntminerContext.IsMining)
            {
                var mineContext = ntminerContext.LockedMineContext;
                if (mineContext != null)
                {
                    speedDto.KernelSelfRestartCount = mineContext.KernelSelfRestartCount;
                    if (mineContext.MineStartedOn != DateTime.MinValue)
                    {
                        speedDto.MineStartedOn = mineContext.MineStartedOn;
                    }
                    speedDto.KernelCommandLine = mineContext.CommandLine;
                }
                // 判断上次报告的算力币种和本次报告的是否相同,否则说明刚刚切换了币种默认第一次报告0算力
                if (_sLastSpeedMainCoin == null || _sLastSpeedMainCoin == ntminerContext.LockedMineContext.MainCoin)
                {
                    _sLastSpeedMainCoin = ntminerContext.LockedMineContext.MainCoin;
                    Guid       coinId     = ntminerContext.LockedMineContext.MainCoin.GetId();
                    IGpusSpeed gpuSpeeds  = ntminerContext.GpusSpeed;
                    IGpuSpeed  totalSpeed = gpuSpeeds.CurrentSpeed(NTMinerContext.GpuAllId);
                    speedDto.MainCoinSpeed   = totalSpeed.MainCoinSpeed.Value;
                    speedDto.MainCoinSpeedOn = totalSpeed.MainCoinSpeed.SpeedOn;
                    ICoinShare share = ntminerContext.CoinShareSet.GetOrCreate(coinId);
                    speedDto.MainCoinTotalShare  = share.TotalShareCount;
                    speedDto.MainCoinRejectShare = share.RejectShareCount;
                }
                else
                {
                    _sLastSpeedMainCoin = ntminerContext.LockedMineContext.MainCoin;
                }
                if (ntminerContext.LockedMineContext is IDualMineContext dualMineContext)
                {
                    // 判断上次报告的算力币种和本次报告的是否相同,否则说明刚刚切换了币种默认第一次报告0算力
                    if (_sLastSpeedDualCoin == null || _sLastSpeedDualCoin == dualMineContext.DualCoin)
                    {
                        _sLastSpeedDualCoin = dualMineContext.DualCoin;
                        Guid       coinId     = dualMineContext.DualCoin.GetId();
                        IGpusSpeed gpuSpeeds  = ntminerContext.GpusSpeed;
                        IGpuSpeed  totalSpeed = gpuSpeeds.CurrentSpeed(NTMinerContext.GpuAllId);
                        speedDto.DualCoinSpeed   = totalSpeed.DualCoinSpeed.Value;
                        speedDto.DualCoinSpeedOn = totalSpeed.DualCoinSpeed.SpeedOn;
                        ICoinShare share = ntminerContext.CoinShareSet.GetOrCreate(coinId);
                        speedDto.DualCoinTotalShare  = share.TotalShareCount;
                        speedDto.DualCoinRejectShare = share.RejectShareCount;
                    }
                    else
                    {
                        _sLastSpeedDualCoin = dualMineContext.DualCoin;
                    }
                }
            }
            return(speedDto);
        }
コード例 #4
0
 /// <summary>
 /// 同步方法
 /// </summary>
 /// <param name="clientId"></param>
 /// <returns></returns>
 private static List <UserData> GetUsers()
 {
     try {
         DataRequest <Guid?> request = new DataRequest <Guid?> {
             Data = NTMinerRegistry.GetClientId()
         };
         using (HttpClient client = new HttpClient()) {
             client.Timeout = TimeSpan.FromMilliseconds(2000);
             Task <HttpResponseMessage>      getHttpResponse = client.PostAsJsonAsync($"http://{NTMinerRegistry.GetControlCenterHost()}:{NTKeyword.ControlCenterPort.ToString()}/api/ControlCenter/Users", request);
             DataResponse <List <UserData> > response        = getHttpResponse.Result.Content.ReadAsAsync <DataResponse <List <UserData> > >().Result;
             if (response != null && response.Data != null)
             {
                 return(response.Data);
             }
         }
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e);
     }
     return(new List <UserData>());
 }
コード例 #5
0
 // TODO:异步化
 /// <summary>
 /// 同步方法
 /// </summary>
 /// <param name="clientId"></param>
 /// <returns></returns>
 public List <UserData> GetUsers(Guid?clientId)
 {
     try {
         DataRequest <Guid?> request = new DataRequest <Guid?> {
             Data = clientId
         };
         DataResponse <List <UserData> > response = RpcRoot.Post <DataResponse <List <UserData> > >(NTMinerRegistry.GetControlCenterHost(), NTKeyword.ControlCenterPort, _controllerName, nameof(IUserController.Users), request, request, timeout: 2000);
         if (response != null && response.Data != null)
         {
             return(response.Data);
         }
         return(new List <UserData>());
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e);
         return(new List <UserData>());
     }
 }
コード例 #6
0
 public List <AppSettingData> GetAppSettings()
 {
     try {
         AppSettingsRequest request = new AppSettingsRequest {
         };
         DataResponse <List <AppSettingData> > response = RpcRoot.Post <DataResponse <List <AppSettingData> > >(NTMinerRegistry.GetControlCenterHost(), NTKeyword.ControlCenterPort, _controllerName, nameof(IAppSettingController.AppSettings), request);
         if (response.IsSuccess())
         {
             return(response.Data);
         }
         return(new List <AppSettingData>());
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e);
         return(new List <AppSettingData>());
     }
 }
コード例 #7
0
ファイル: MinerProfile.cs プロジェクト: skyplaying/NtMiner
        private void Init(INTMinerContext ntminerContext)
        {
            var minerProfileRepository = ntminerContext.ServerContext.CreateLocalRepository <MinerProfileData>();

            _data = minerProfileRepository.GetAll().FirstOrDefault();
            var mineWorkRepository = ntminerContext.ServerContext.CreateLocalRepository <MineWorkData>();

            MineWork = mineWorkRepository.GetAll().FirstOrDefault();
            if (_data == null)
            {
                Guid  coinId = Guid.Empty;
                ICoin coin   = ntminerContext.ServerContext.CoinSet.AsEnumerable().OrderBy(a => a.Code).FirstOrDefault();
                if (coin != null)
                {
                    coinId = coin.GetId();
                }
                _data = MinerProfileData.CreateDefaultData(coinId);
            }
            else
            {
                // 交换到注册表以供守护进程访问
                if (ClientAppType.IsMinerClient && !NTMinerContext.IsJsonLocal)
                {
                    SetIsOuterUserEnabled(_data.IsOuterUserEnabled);
                    SetOuterUserId(_data.OuterUserId);
                }
            }
            if (!_data.IsAutoStart && NTMinerRegistry.GetIsAutoStart())
            {
                _data.IsAutoStart = true;
                minerProfileRepository.Update(_data);
            }
            if (_coinProfileSet == null)
            {
                _coinProfileSet = new CoinProfileSet(ntminerContext);
            }
            else
            {
                _coinProfileSet.Refresh();
            }
            if (_coinKernelProfileSet == null)
            {
                _coinKernelProfileSet = new CoinKernelProfileSet(ntminerContext);
            }
            else
            {
                _coinKernelProfileSet.Refresh();
            }
            if (_poolProfileSet == null)
            {
                _poolProfileSet = new PoolProfileSet(ntminerContext);
            }
            else
            {
                _poolProfileSet.Refresh();
            }
            if (_walletSet == null)
            {
                _walletSet = new WalletSet(ntminerContext);
            }
            else
            {
                _walletSet.Refresh();
            }
        }
コード例 #8
0
 // TODO:异步化
 /// <summary>
 /// 同步方法
 /// </summary>
 /// <returns></returns>
 public List <MineWorkData> GetMineWorks()
 {
     try {
         SignRequest request = new SignRequest {
         };
         DataResponse <List <MineWorkData> > response = RpcRoot.Post <DataResponse <List <MineWorkData> > >(NTMinerRegistry.GetControlCenterHost(), NTKeyword.ControlCenterPort, _controllerName, nameof(IMineWorkController.MineWorks), request, request, timeout: 2000);
         if (response != null && response.Data != null)
         {
             return(response.Data);
         }
         return(new List <MineWorkData>());
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e);
         return(new List <MineWorkData>());
     }
 }
コード例 #9
0
 /// <summary>
 /// 同步方法
 /// </summary>
 /// <param name="clientId"></param>
 /// <returns></returns>
 private static List <UserData> GetUsers()
 {
     try {
         DataRequest <Guid?> request = new DataRequest <Guid?> {
             LoginName = string.Empty,
             Data      = NTMinerRegistry.GetClientId()
         };
         using (HttpClient client = new HttpClient()) {
             Task <HttpResponseMessage>      message  = client.PostAsJsonAsync($"http://{NTMinerRegistry.GetControlCenterHost()}:{WebApiConst.ControlCenterPort}/api/ControlCenter/Users", request);
             DataResponse <List <UserData> > response = message.Result.Content.ReadAsAsync <DataResponse <List <UserData> > >().Result;
             if (response != null && response.Data != null)
             {
                 return(response.Data);
             }
         }
     }
     catch (Exception e) {
         e = e.GetInnerException();
         Logger.ErrorDebugLine(e.Message, e);
     }
     return(new List <UserData>());
 }
コード例 #10
0
        private void BtnLogin_OnClick(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(Vm.ServerHost))
            {
                Vm.ShowMessage("服务器地址不能为空");
                return;
            }
            string passwordSha1 = HashUtil.Sha1(Vm.Password);

            NTMinerRegistry.SetControlCenterAddress(Vm.ServerHost);
            var list = NTMinerRegistry.GetControlCenterAddresses();

            if (!list.Contains(Vm.ServerHost))
            {
                list.Insert(0, Vm.ServerHost);
            }
            NTMinerRegistry.SetControlCenterAddresses(list);
            // 内网免登录
            if (Net.IpUtil.IsInnerIp(Vm.ServerHost))
            {
                RpcRoot.SetRpcUser(RpcUser.Empty);
                RpcRoot.SetIsOuterNet(false);
                _isLogined = true;
                this.Close();
                // 回调可能弹窗,弹窗可能有父窗口,父窗口是顶层窗口,如果在this.Close()之前回调
                // 则会导致弹窗的父窗口是本窗口,而本窗口随后立即关闭导致作为子窗口的弹窗也会被关闭。
                _onLoginSuccess?.Invoke();
                return;
            }
            else if (string.IsNullOrEmpty(Vm.LoginName))
            {
                Vm.ShowMessage("没有填写用户名");
                return;
            }
            else if (string.IsNullOrEmpty(Vm.Password))
            {
                Vm.ShowMessage("没有填写密码");
                return;
            }
            RpcRoot.OfficialServer.UserService.LoginAsync(Vm.LoginName, passwordSha1, (response, exception) => {
                if (response == null)
                {
                    Vm.ShowMessage("服务器忙");
                    return;
                }
                if (response.IsSuccess())
                {
                    RpcRoot.SetRpcUser(new RpcUser(response.Data, passwordSha1));
                    RpcRoot.SetIsOuterNet(true);
                    _isLogined = true;
                    UIThread.Execute(() => {
                        this.Close();
                    });
                    // 回调可能弹窗,弹窗可能有父窗口,父窗口是顶层窗口,如果在this.Close()之前回调
                    // 则会导致弹窗的父窗口是本窗口,而本窗口随后立即关闭导致作为子窗口的弹窗也会被关闭。
                    _onLoginSuccess?.Invoke();
                }
                else
                {
                    Vm.ShowMessage(response.ReadMessage(exception));
                }
            });
        }
コード例 #11
0
ファイル: AppStatic.cs プロジェクト: zheng9980419/ntminer
 public static void Upgrade(string ntminerFileName, Action callback)
 {
     try {
         string updaterDirFullName = Path.Combine(VirtualRoot.GlobalDirFullName, "Updater");
         if (!Directory.Exists(updaterDirFullName))
         {
             Directory.CreateDirectory(updaterDirFullName);
         }
         OfficialServer.FileUrlService.GetNTMinerUpdaterUrlAsync((downloadFileUrl, e) => {
             try {
                 if (string.IsNullOrEmpty(downloadFileUrl))
                 {
                     callback?.Invoke();
                     return;
                 }
                 string argument = string.Empty;
                 if (!string.IsNullOrEmpty(ntminerFileName))
                 {
                     argument = "ntminerFileName=" + ntminerFileName;
                 }
                 if (VirtualRoot.IsMinerStudio)
                 {
                     argument += " --minerstudio";
                 }
                 string ntMinerUpdaterFileFullName = Path.Combine(updaterDirFullName, "NTMinerUpdater.exe");
                 Uri uri = new Uri(downloadFileUrl);
                 string updaterVersion = NTMinerRegistry.GetUpdaterVersion();
                 if (string.IsNullOrEmpty(updaterVersion) || !File.Exists(ntMinerUpdaterFileFullName) || uri.AbsolutePath != updaterVersion)
                 {
                     FileDownloader.ShowWindow(downloadFileUrl, "开源矿工更新器", (window, isSuccess, message, saveFileFullName) => {
                         try {
                             if (isSuccess)
                             {
                                 File.Copy(saveFileFullName, ntMinerUpdaterFileFullName, overwrite: true);
                                 File.Delete(saveFileFullName);
                                 NTMinerRegistry.SetUpdaterVersion(uri.AbsolutePath);
                                 window?.Close();
                                 Windows.Cmd.RunClose(ntMinerUpdaterFileFullName, argument);
                                 callback?.Invoke();
                             }
                             else
                             {
                                 NotiCenterWindowViewModel.Current.Manager.ShowErrorMessage(message);
                                 callback?.Invoke();
                             }
                         }
                         catch {
                             callback?.Invoke();
                         }
                     });
                 }
                 else
                 {
                     Windows.Cmd.RunClose(ntMinerUpdaterFileFullName, argument);
                     callback?.Invoke();
                 }
             }
             catch {
                 callback?.Invoke();
             }
         });
     }
     catch {
         callback?.Invoke();
     }
 }
コード例 #12
0
        /// <summary>
        /// 这是一次彻底的重连,重新获取服务器地址的重连,以下情况下才会调用该方法:
        /// 1,进程启动后第一次连接时;
        /// 2,连不上服务器时;
        /// 3,收到服务器的WsMessage.ReGetServerAddress类型的消息时;
        /// </summary>
        /// <returns></returns>
        private void NewWebSocket()
        {
            if (_ws != null)
            {
                return;
            }
            RpcRoot.OfficialServer.WsServerNodeService.GetNodeAddressAsync(NTMinerRegistry.GetClientId(_appType), _preOuterUserId, (response, ex) => {
                if (_ws == null)
                {
                    lock (_wsLocker) {
                        if (_ws == null)
                        {
                            LastTryOn   = DateTime.Now;
                            _wsServerIp = string.Empty;

                            #region 网络错误或没有获取到WsServer节点时退出
                            if (!response.IsSuccess())
                            {
                                // 没有获取到该矿机的WsServer分片节点,递增失败次数以增大重试延迟周期
                                IncreaseFailCount();
                                UpdateNextTrySecondsDelay();
                                string description;
                                if (response == null || response.ReasonPhrase == null)
                                {
                                    description = "网络错误";
                                }
                                else
                                {
                                    description = response.ReadMessage(ex);
                                }
                                UpdateWsStateAsync(description, toOut: false);
                                // 退出
                                return;
                            }
                            string server = response.Data;
                            if (string.IsNullOrEmpty(server))
                            {
                                // 没有获取到该矿机的WsServer分片节点,递增失败次数以增大重试延迟周期
                                IncreaseFailCount();
                                UpdateNextTrySecondsDelay();
                                UpdateWsStateAsync("服务器不在线", toOut: false);
                                // 退出
                                return;
                            }
                            _wsServerIp = server;
                            #endregion

                            var ws = new WebSocket($"ws://{server}/{_appType.GetName()}")
                            {
                                Compression = CompressionMethod.Deflate
                            };
                            ws.Log.File   = System.IO.Path.Combine(TempPath.TempLogsDirFullName, NTKeyword.WebSocketSharpMinerClientLogFileName);
                            ws.Log.Output = WebSocketSharpOutput;
                            ws.OnOpen    += new EventHandler(Ws_OnOpen);
                            ws.OnMessage += new EventHandler <MessageEventArgs>(Ws_OnMessage);
                            ws.OnError   += new EventHandler <ErrorEventArgs>(Ws_OnError);
                            ws.OnClose   += new EventHandler <CloseEventArgs>(Ws_OnClose);

                            ConnectAsync(ws);
                            _ws = ws;
                        }
                    }
                }
            });
        }
コード例 #13
0
 private MainWindowViewModel()
 {
     if (WpfUtil.IsInDesignMode)
     {
         return;
     }
     this.ShowServerLatestDescription = new DelegateCommand(() => {
         VirtualRoot.Out.ShowInfo(ServerLatestVm.Description, header: $"{ServerLatestVm.Version}({ServerLatestVm.VersionTag})", autoHideSeconds: 0);
     });
     this.CancelDownload = new DelegateCommand(() => {
         this._cancel?.Invoke();
     });
     this.Install = new DelegateCommand(() => {
         this.IsDownloading = true;
         string ntminerFile = string.Empty;
         string version     = string.Empty;
         if (IsHistoryVisible == Visibility.Collapsed)
         {
             if (ServerLatestVm != null)
             {
                 ntminerFile = ServerLatestVm.FileName;
                 version     = ServerLatestVm.Version;
             }
         }
         else
         {
             ntminerFile = SelectedNTMinerFile.FileName;
             version     = SelectedNTMinerFile.Version;
         }
         Download(ntminerFile, version,
                  progressChanged: (percent) => {
             this.DownloadMessage = percent + "%";
             this.DownloadPercent = (double)percent / 100;
         },
                  downloadComplete: (isSuccess, message, saveFileFullName) => {
             this.DownloadMessage = message;
             this.DownloadPercent = 0;
             if (isSuccess)
             {
                 this.DownloadMessage = "更新成功,正在重启";
                 void callback()
                 {
                     3.SecondsDelay().ContinueWith((t) => {
                         string location = NTMinerRegistry.GetLocation(App.AppType);
                         if (string.IsNullOrEmpty(location) || !File.Exists(location))
                         {
                             location = Path.Combine(HomePath.AppDomainBaseDirectory, ntminerFile);
                         }
                         try {
                             Process process = Process.GetProcessesByName(Path.GetFileName(location)).FirstOrDefault();
                             if (process != null)
                             {
                                 process.Kill();
                             }
                         }
                         catch (Exception e) {
                             Logger.ErrorDebugLine(e);
                         }
                         try {
                             if (File.Exists(location))
                             {
                                 Guid kernelBrandId = VirtualRoot.GetBrandId(location, NTKeyword.KernelBrandId);
                                 if (kernelBrandId != Guid.Empty)
                                 {
                                     VirtualRoot.TagBrandId(NTKeyword.KernelBrandId, kernelBrandId, saveFileFullName, saveFileFullName);
                                 }
                                 Guid poolBrandId = VirtualRoot.GetBrandId(location, NTKeyword.PoolBrandId);
                                 if (poolBrandId != Guid.Empty)
                                 {
                                     VirtualRoot.TagBrandId(NTKeyword.PoolBrandId, poolBrandId, saveFileFullName, saveFileFullName);
                                 }
                             }
                         }
                         catch (Exception e) {
                             Logger.ErrorDebugLine(e);
                         }
                         int failCount = 0;
                         while (true)
                         {
                             try {
                                 File.Copy(saveFileFullName, location, overwrite: true);
                                 break;
                             }
                             catch (Exception e) {
                                 failCount++;
                                 if (failCount == 3)
                                 {
                                     VirtualRoot.Out.ShowError(e.Message);
                                     break;
                                 }
                                 else
                                 {
                                     System.Threading.Thread.Sleep(3000);
                                 }
                             }
                         }
                         try {
                             File.Delete(saveFileFullName);
                         }
                         catch (Exception e) {
                             Logger.ErrorDebugLine(e);
                         }
                         string arguments = NTMinerRegistry.GetMinerClientArguments(App.AppType);
                         Process.Start(location, arguments);
                         this.IsDownloading = false;
                         2.SecondsDelay().ContinueWith(_ => {
                             UIThread.Execute(() => {
                                 Application.Current.MainWindow?.Close();
                             });
                         });
                     });
                 }
                 if (AppStatic.IsMinerStudio)
                 {
                     RpcRoot.Client.MinerStudioService.CloseMinerStudioAsync(callback);
                 }
                 else
                 {
                     RpcRoot.Client.MinerClientService.CloseNTMinerAsync(callback);
                 }
             }
             else
             {
                 2.SecondsDelay().ContinueWith((t) => {
                     this.IsDownloading = false;
                 });
             }
         }, cancel: out _cancel);
     }, () => !IsDownloading);
     this.ShowHistory = new DelegateCommand(() => {
         if (IsHistoryVisible == Visibility.Visible)
         {
             IsHistoryVisible = Visibility.Collapsed;
         }
         else
         {
             IsHistoryVisible = Visibility.Visible;
         }
     });
     this.AddNTMinerFile = new DelegateCommand(() => {
         NTMinerFileEdit window = new NTMinerFileEdit("Icon_Add", new NTMinerFileViewModel()
         {
             AppType = App.AppType
         });
         window.ShowSoftDialog();
     });
     VirtualRoot.BuildEventPath <NTMinerFileSetInitedEvent>("开源矿工程序版本文件集初始化后刷新Vm内存", LogEnum.DevConsole, path: message => {
         var ntminerFiles  = _readOnlyNTMinerFileSet.AsEnumerable().Where(a => a.AppType == App.AppType);
         this.NTMinerFiles = ntminerFiles.Select(a => new NTMinerFileViewModel(a)).OrderByDescending(a => a.VersionData).ToList();
         if (this.NTMinerFiles == null || this.NTMinerFiles.Count == 0)
         {
             LocalIsLatest = true;
         }
         else
         {
             ServerLatestVm = this.NTMinerFiles.OrderByDescending(a => a.VersionData).FirstOrDefault();
             if (ServerLatestVm.VersionData > LocalNTMinerVersion)
             {
                 this.SelectedNTMinerFile = ServerLatestVm;
                 LocalIsLatest            = false;
             }
             else
             {
                 LocalIsLatest = true;
             }
         }
         OnPropertyChanged(nameof(IsBtnInstallVisible));
         IsReady = true;
         if (!string.IsNullOrEmpty(CommandLineArgs.NTMinerFileName))
         {
             NTMinerFileViewModel ntminerFileVm = this.NTMinerFiles.FirstOrDefault(a => a.FileName == CommandLineArgs.NTMinerFileName);
             if (ntminerFileVm != null)
             {
                 IsHistoryVisible         = Visibility.Visible;
                 this.SelectedNTMinerFile = ntminerFileVm;
                 Install.Execute(null);
             }
         }
     }, this.GetType());
     this.Refresh();
 }
コード例 #14
0
        /// <summary>
        /// 这是一次彻底的重连,重新获取服务器地址的重连,以下情况下才会调用该方法:
        /// 1,进程启动后第一次连接时;
        /// 2,连不上服务器时;
        /// 3,收到服务器的WsMessage.ReGetServerAddress类型的消息时;
        /// </summary>
        /// <returns></returns>
        private void NewWebSocket(Action <WebSocket> callback)
        {
            RpcRoot.OfficialServer.WsServerNodeService.GetNodeAddressAsync(NTMinerRegistry.GetClientId(_appType), _outerUserId, (response, ex) => {
                LastTryOn = DateTime.Now;
                if (!response.IsSuccess())
                {
                    IncreaseFailCount();
                    UpdateNextTrySecondsDelay();
                    string description;
                    if (response == null || response.ReasonPhrase == null)
                    {
                        description = "网络错误";
                    }
                    else
                    {
                        description = response.ReadMessage(ex);
                    }
                    UpdateWsStateAsync(description, toOut: false);
                    callback?.Invoke(null);
                    // 退出
                    return;
                }
                string server = response.Data;
                if (string.IsNullOrEmpty(server))
                {
                    IncreaseFailCount();
                    UpdateNextTrySecondsDelay();
                    UpdateWsStateAsync("服务器不在线", toOut: false);
                    callback?.Invoke(null);
                    // 退出
                    return;
                }

                var ws     = new WebSocket($"ws://{server}/{_appType.GetName()}");
                ws.OnOpen += (sender, e) => {
                    ResetFailCount();
                    UpdateWsStateAsync("连接服务器成功", toOut: false);
                };
                ws.OnMessage += (sender, e) => {
                    if (_ws != ws)
                    {
                        return;
                    }
                    #region
                    if (e.IsPing)
                    {
                        return;
                    }
                    WsMessage message = null;
                    if (e.IsBinary)
                    {
                        message = VirtualRoot.BinarySerializer.Deserialize <WsMessage>(e.RawData);
                    }
                    else  // 此时一定IsText,因为取值只有IsBinary、IsPing、IsText这三种
                    {
                        if (string.IsNullOrEmpty(e.Data) || e.Data[0] != '{' || e.Data[e.Data.Length - 1] != '}')
                        {
                            return;
                        }
                        message = VirtualRoot.JsonSerializer.Deserialize <WsMessage>(e.Data);
                    }
                    if (message == null)
                    {
                        return;
                    }
                    switch (_appType)
                    {
                    case NTMinerAppType.MinerClient:
                        if (message.Type == WsMessage.UpdateAESPassword)
                        {
                            if (message.TryGetData(out AESPassword aesPassword))
                            {
                                aesPassword.Password = Cryptography.RSAUtil.DecryptString(aesPassword.Password, aesPassword.PublicKey);
                                _aesPassword         = aesPassword;
                            }
                            return;
                        }
                        if (_aesPassword == null)
                        {
                            return;
                        }
                        if (message.Sign != message.CalcSign(_aesPassword.Password))
                        {
                            UpdateWsStateAsync(description: "来自群控的消息签名错误", toOut: true);
                            return;
                        }
                        break;
コード例 #15
0
 private MainWindowViewModel()
 {
     if (WpfUtil.IsInDesignMode)
     {
         return;
     }
     this.Refresh();
     this.ShowServerLatestDescription = new DelegateCommand(() => {
         VirtualRoot.Out.ShowInfo(ServerLatestVm.Description, header: $"{ServerLatestVm.Version}({ServerLatestVm.VersionTag})", autoHideSeconds: 0);
     });
     this.CancelDownload = new DelegateCommand(() => {
         this._cancel?.Invoke();
     });
     this.Install = new DelegateCommand(() => {
         this.IsDownloading = true;
         string ntMinerFile = string.Empty;
         string version     = string.Empty;
         if (IsHistoryVisible == Visibility.Collapsed)
         {
             if (ServerLatestVm != null)
             {
                 ntMinerFile = ServerLatestVm.FileName;
                 version     = ServerLatestVm.Version;
             }
         }
         else
         {
             ntMinerFile = SelectedNTMinerFile.FileName;
             version     = SelectedNTMinerFile.Version;
         }
         Download(ntMinerFile, version,
                  progressChanged: (percent) => {
             this.DownloadMessage = percent + "%";
             this.DownloadPercent = (double)percent / 100;
         },
                  downloadComplete: (isSuccess, message, saveFileFullName) => {
             this.DownloadMessage = message;
             this.DownloadPercent = 0;
             if (isSuccess)
             {
                 this.DownloadMessage = "更新成功,正在重启";
                 if (VirtualRoot.IsMinerStudio)
                 {
                     RpcRoot.Client.MinerStudioService.CloseMinerStudio();
                 }
                 else
                 {
                     RpcRoot.Client.MinerClientService.CloseNTMiner();
                 }
                 3.SecondsDelay().ContinueWith((t) => {
                     string location = NTMinerRegistry.GetLocation();
                     if (string.IsNullOrEmpty(location) || !File.Exists(location))
                     {
                         location = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ntMinerFile);
                     }
                     try {
                         if (File.Exists(location))
                         {
                             Guid kernelBrandId = VirtualRoot.GetBrandId(location, NTKeyword.KernelBrandId);
                             if (kernelBrandId != Guid.Empty)
                             {
                                 VirtualRoot.TagBrandId(NTKeyword.KernelBrandId, kernelBrandId, saveFileFullName, saveFileFullName);
                             }
                             Guid poolBrandId = VirtualRoot.GetBrandId(location, NTKeyword.PoolBrandId);
                             if (poolBrandId != Guid.Empty)
                             {
                                 VirtualRoot.TagBrandId(NTKeyword.PoolBrandId, poolBrandId, saveFileFullName, saveFileFullName);
                             }
                         }
                     }
                     catch (Exception e) {
                         Logger.ErrorDebugLine(e);
                     }
                     int failCount = 0;
                     while (true)
                     {
                         try {
                             File.Copy(saveFileFullName, location, overwrite: true);
                             break;
                         }
                         catch (Exception e) {
                             failCount++;
                             if (failCount == 3)
                             {
                                 VirtualRoot.Out.ShowError(e.Message);
                                 break;
                             }
                             else
                             {
                                 System.Threading.Thread.Sleep(3000);
                             }
                         }
                     }
                     try {
                         File.Delete(saveFileFullName);
                     }
                     catch (Exception e) {
                         Logger.ErrorDebugLine(e);
                     }
                     string arguments = NTMinerRegistry.GetArguments();
                     Process.Start(location, arguments);
                     this.IsDownloading = false;
                     2.SecondsDelay().ContinueWith(_ => {
                         UIThread.Execute(() => () => {
                             Application.Current.MainWindow?.Close();
                         });
                     });
                 });
             }
             else
             {
                 2.SecondsDelay().ContinueWith((t) => {
                     this.IsDownloading = false;
                 });
             }
         }, cancel: out _cancel);
     }, () => !IsDownloading);
     this.ShowHistory = new DelegateCommand(() => {
         if (IsHistoryVisible == Visibility.Visible)
         {
             IsHistoryVisible = Visibility.Collapsed;
         }
         else
         {
             IsHistoryVisible = Visibility.Visible;
         }
     });
     this.AddNTMinerFile = new DelegateCommand(() => {
         NTMinerFileEdit window = new NTMinerFileEdit("Icon_Add", new NTMinerFileViewModel()
         {
             AppType = App.AppType
         });
         window.ShowSoftDialog();
     });
 }
コード例 #16
0
ファイル: DaemonOperation.cs プロジェクト: zylx0532/NtMiner
 private static bool TryGetMinerClientLocation(out string location)
 {
     location = NTMinerRegistry.GetLocation(NTMinerAppType.MinerClient);
     return(!string.IsNullOrEmpty(location) && File.Exists(location));
 }
コード例 #17
0
 private MainWindowViewModel()
 {
     if (App.IsInDesignMode)
     {
         return;
     }
     this.Refresh();
     this.ShowOrHideServerLatestDescription = new DelegateCommand(() => {
         if (ServerLatestDescriptionVisible == Visibility.Visible)
         {
             ServerLatestDescriptionVisible = Visibility.Collapsed;
         }
         else
         {
             ServerLatestDescriptionVisible = Visibility.Visible;
         }
     });
     this.CancelDownload = new DelegateCommand(() => {
         this._cancel?.Invoke();
     });
     this.Install = new DelegateCommand(() => {
         this.IsDownloading = true;
         string ntMinerFile = string.Empty;
         string version     = string.Empty;
         if (IsHistoryVisible == Visibility.Collapsed)
         {
             if (ServerLatestVm != null)
             {
                 ntMinerFile = ServerLatestVm.FileName;
                 version     = ServerLatestVm.Version;
             }
         }
         else
         {
             ntMinerFile = SelectedNTMinerFile.FileName;
             version     = SelectedNTMinerFile.Version;
         }
         Download(ntMinerFile, version, progressChanged: (percent) => {
             this.DownloadMessage = percent + "%";
             this.DownloadPercent = (double)percent / 100;
         }, downloadComplete: (isSuccess, message, saveFileFullName) => {
             this.DownloadMessage = message;
             this.DownloadPercent = 0;
             if (isSuccess)
             {
                 this.DownloadMessage = "更新成功,正在重启";
                 if (VirtualRoot.IsMinerStudio)
                 {
                     Client.MinerStudioService.CloseMinerStudio();
                 }
                 else
                 {
                     Client.MinerClientService.CloseNTMiner();
                 }
                 TimeSpan.FromSeconds(3).Delay().ContinueWith((t) => {
                     string location = NTMinerRegistry.GetLocation();
                     if (string.IsNullOrEmpty(location) || !File.Exists(location))
                     {
                         location = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ntMinerFile);
                     }
                     try {
                         if (File.Exists(location))
                         {
                             Guid kernelBrandId = VirtualRoot.GetBrandId(location, Consts.KernelBrandId);
                             if (kernelBrandId != Guid.Empty)
                             {
                                 Logger.InfoDebugLine("内核品牌打码开始");
                                 VirtualRoot.TagBrandId(Consts.KernelBrandId, kernelBrandId, saveFileFullName, saveFileFullName);
                                 Logger.OkDebugLine("内核品牌打码成功");
                             }
                             Guid poolBrandId = VirtualRoot.GetBrandId(location, Consts.PoolBrandId);
                             if (poolBrandId != Guid.Empty)
                             {
                                 Logger.InfoDebugLine("矿池打码开始");
                                 VirtualRoot.TagBrandId(Consts.PoolBrandId, poolBrandId, saveFileFullName, saveFileFullName);
                                 Logger.OkDebugLine("矿池打码成功");
                             }
                         }
                     }
                     catch (Exception e) {
                         Logger.ErrorDebugLine(e);
                     }
                     Logger.InfoDebugLine("复制开始");
                     File.Copy(saveFileFullName, location, overwrite: true);
                     File.Delete(saveFileFullName);
                     Logger.InfoDebugLine("复制完成,删除旧文件");
                     string arguments = NTMinerRegistry.GetArguments();
                     Logger.InfoDebugLine("启动新程序");
                     Process.Start(location, arguments);
                     this.IsDownloading = false;
                     UIThread.Execute(() => {
                         Logger.InfoDebugLine("退出升级器");
                         Application.Current.MainWindow?.Close();
                     });
                 });
             }
             else
             {
                 TimeSpan.FromSeconds(2).Delay().ContinueWith((t) => {
                     this.IsDownloading = false;
                 });
             }
         }, cancel: out _cancel);
     }, () => !IsDownloading);
     this.ShowHistory = new DelegateCommand(() => {
         if (IsHistoryVisible == Visibility.Visible)
         {
             IsHistoryVisible = Visibility.Collapsed;
         }
         else
         {
             IsHistoryVisible = Visibility.Visible;
         }
     });
     this.AddNTMinerFile = new DelegateCommand(() => {
         NTMinerFileEdit window = new NTMinerFileEdit("Icon_Add", new NTMinerFileViewModel()
         {
             AppType = App.AppType
         });
         window.ShowDialogEx();
     });
 }
コード例 #18
0
 public void RefreshIcon()
 {
     _targetNotifyIcon.Visible = _isMinerStudio || NTMinerRegistry.GetIsShowNotifyIcon();
 }
コード例 #19
0
 // TODO:异步化
 /// <summary>
 /// 同步方法
 /// </summary>
 /// <returns></returns>
 public DataResponse <List <WalletData> > GetWallets()
 {
     try {
         SignRequest request = new SignRequest {
         };
         DataResponse <List <WalletData> > response = RpcRoot.Post <DataResponse <List <WalletData> > >(NTMinerRegistry.GetControlCenterHost(), NTKeyword.ControlCenterPort, _controllerName, nameof(IWalletController.Wallets), request, request, timeout: 2000);
         return(response);
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e);
         return(null);
     }
 }