コード例 #1
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);
        }
コード例 #2
0
ファイル: AbstractWsClient.cs プロジェクト: SZP1206/NtMiner
        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);
            }
        }