Exemplo n.º 1
0
 static void Main(string[] args)
 {
     try {
         bool mutexCreated;
         try {
             _sMutexApp = new Mutex(true, "NTMinerDaemonAppMutex", out mutexCreated);
         }
         catch {
             mutexCreated = false;
         }
         if (mutexCreated)
         {
             NTMinerRegistry.SetAutoBoot("NTMinerDaemon", true);
             bool isAutoBoot = NTMinerRegistry.GetIsAutoBoot();
             if (isAutoBoot)
             {
                 string location = NTMinerRegistry.GetLocation();
                 if (!string.IsNullOrEmpty(location))
                 {
                     string arguments = NTMinerRegistry.GetArguments();
                     try {
                         Process.Start(location, arguments);
                     }
                     catch (Exception e) {
                         Logger.ErrorDebugLine(e.Message, e);
                     }
                 }
             }
             Run();
         }
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e.Message, e);
     }
 }
Exemplo n.º 2
0
 static void Main(string[] args)
 {
     try {
         Console.Title = "NTMinerDaemon";
         bool mutexCreated;
         try {
             s_mutexApp = new Mutex(true, "NTMinerDaemonAppMutex", out mutexCreated);
         }
         catch {
             mutexCreated = false;
         }
         if (mutexCreated)
         {
             NTMinerRegistry.SetAutoBoot("NTMinerDaemon", true);
             Type thisType = typeof(HostRoot);
             NotifyIcon = ExtendedNotifyIcon.Create(new System.Drawing.Icon(thisType.Assembly.GetManifestResourceStream(thisType, "logo.ico")), "挖矿端守护进程", isShowNotifyIcon: DevMode.IsDebugMode);
             bool isAutoBoot = NTMinerRegistry.GetIsAutoBoot();
             if (isAutoBoot)
             {
                 string location = NTMinerRegistry.GetLocation();
                 if (!string.IsNullOrEmpty(location))
                 {
                     string arguments = NTMinerRegistry.GetArguments();
                     try {
                         Process.Start(location, arguments);
                     }
                     catch (Exception e) {
                         Logger.ErrorDebugLine(e.Message, e);
                     }
                 }
             }
             Run();
         }
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e.Message, e);
     }
 }
Exemplo n.º 3
0
        public static SpeedData CreateSpeedData()
        {
            INTMinerRoot root = NTMinerRoot.Instance;
            SpeedData    data = new SpeedData {
                KernelSelfRestartCount = 0,
                IsAutoBoot             = NTMinerRegistry.GetIsAutoBoot(),
                IsAutoStart            = NTMinerRegistry.GetIsAutoStart(),
                Version       = NTMinerRoot.CurrentVersion.ToString(4),
                BootOn        = root.CreatedOn,
                MineStartedOn = null,
                IsMining      = root.IsMining,
                MineWorkId    = root.MinerProfile.MineWork != null?root.MinerProfile.MineWork.GetId() : Guid.Empty,
                                    MinerName           = root.MinerProfile.MinerName,
                                    GpuInfo             = root.GpuSetInfo,
                                    ClientId            = VirtualRoot.Id,
                                    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                    = root.GpuSet.DriverVersion,
                                    GpuType                      = root.GpuSet.GpuType,
                                    OSVirtualMemoryMb            = NTMinerRoot.OSVirtualMemoryMb,
                                    KernelCommandLine            = NTMinerRoot.UserKernelCommandLine,
                                    DiskSpace                    = NTMinerRoot.DiskSpace,
                                    IsAutoRestartKernel          = root.MinerProfile.IsAutoRestartKernel,
                                    IsNoShareRestartKernel       = root.MinerProfile.IsNoShareRestartKernel,
                                    IsPeriodicRestartComputer    = root.MinerProfile.IsPeriodicRestartComputer,
                                    IsPeriodicRestartKernel      = root.MinerProfile.IsPeriodicRestartKernel,
                                    NoShareRestartKernelMinutes  = root.MinerProfile.NoShareRestartKernelMinutes,
                                    PeriodicRestartComputerHours = root.MinerProfile.PeriodicRestartComputerHours,
                                    PeriodicRestartKernelHours   = root.MinerProfile.PeriodicRestartKernelHours,
                                    GpuTable                     = root.GpusSpeed.Where(a => a.Gpu.Index != NTMinerRoot.GpuAllId).Select(a => new GpuSpeedData {
                    Index            = a.Gpu.Index,
                    Name             = a.Gpu.Name,
                    TotalMemory      = a.Gpu.TotalMemory,
                    MainCoinSpeed    = a.MainCoinSpeed.Value,
                    DualCoinSpeed    = a.DualCoinSpeed.Value,
                    FanSpeed         = a.Gpu.FanSpeed,
                    Temperature      = a.Gpu.Temperature,
                    PowerUsage       = a.Gpu.PowerUsage,
                    Cool             = a.Gpu.Cool,
                    PowerCapacity    = a.Gpu.PowerCapacity,
                    CoreClockDelta   = a.Gpu.CoreClockDelta,
                    MemoryClockDelta = a.Gpu.MemoryClockDelta,
                    TempLimit        = a.Gpu.TempLimit
                }).ToArray()
            };

            #region 当前选中的币种是什么
            if (root.CoinSet.TryGetCoin(root.MinerProfile.CoinId, out ICoin mainCoin))
            {
                data.MainCoinCode = mainCoin.Code;
                ICoinProfile coinProfile = root.MinerProfile.GetCoinProfile(mainCoin.GetId());
                data.MainCoinWallet = coinProfile.Wallet;
                if (root.PoolSet.TryGetPool(coinProfile.PoolId, out IPool mainCoinPool))
                {
                    data.MainCoinPool = mainCoinPool.Server;
                    if (mainCoinPool.IsUserMode)
                    {
                        IPoolProfile mainCoinPoolProfile = root.MinerProfile.GetPoolProfile(coinProfile.PoolId);
                        data.MainCoinWallet = mainCoinPoolProfile.UserName;
                    }
                }
                else
                {
                    data.MainCoinPool = string.Empty;
                }
                if (root.CoinKernelSet.TryGetCoinKernel(coinProfile.CoinKernelId, out ICoinKernel coinKernel))
                {
                    if (root.KernelSet.TryGetKernel(coinKernel.KernelId, out IKernel kernel))
                    {
                        data.Kernel = kernel.GetFullName();
                        ICoinKernelProfile coinKernelProfile = root.MinerProfile.GetCoinKernelProfile(coinProfile.CoinKernelId);
                        data.IsDualCoinEnabled = coinKernelProfile.IsDualCoinEnabled;
                        if (coinKernelProfile.IsDualCoinEnabled)
                        {
                            if (root.CoinSet.TryGetCoin(coinKernelProfile.DualCoinId, out ICoin dualCoin))
                            {
                                data.DualCoinCode = dualCoin.Code;
                                ICoinProfile dualCoinProfile = root.MinerProfile.GetCoinProfile(dualCoin.GetId());
                                data.DualCoinWallet = dualCoinProfile.DualCoinWallet;
                                if (root.PoolSet.TryGetPool(dualCoinProfile.DualCoinPoolId, out IPool dualCoinPool))
                                {
                                    data.DualCoinPool = dualCoinPool.Server;
                                    if (dualCoinPool.IsUserMode)
                                    {
                                        IPoolProfile dualCoinPoolProfile = root.MinerProfile.GetPoolProfile(dualCoinProfile.DualCoinPoolId);
                                        data.DualCoinWallet = dualCoinPoolProfile.UserName;
                                    }
                                }
                                else
                                {
                                    data.DualCoinPool = string.Empty;
                                }
                            }
                        }
                    }
                }
            }
            #endregion

            if (root.IsMining)
            {
                var mineContext = root.CurrentMineContext;
                if (mineContext != null)
                {
                    data.KernelSelfRestartCount = mineContext.KernelSelfRestartCount;
                    data.MineStartedOn          = mineContext.CreatedOn;
                    data.KernelCommandLine      = mineContext.CommandLine;
                }
                // 判断上次报告的算力币种和本次报告的是否相同,否则说明刚刚切换了币种默认第一次报告0算力
                if (_sLastSpeedMainCoin == null || _sLastSpeedMainCoin == root.CurrentMineContext.MainCoin)
                {
                    _sLastSpeedMainCoin = root.CurrentMineContext.MainCoin;
                    Guid       coinId     = root.CurrentMineContext.MainCoin.GetId();
                    IGpusSpeed gpuSpeeds  = NTMinerRoot.Instance.GpusSpeed;
                    IGpuSpeed  totalSpeed = gpuSpeeds.CurrentSpeed(NTMinerRoot.GpuAllId);
                    data.MainCoinSpeed = totalSpeed.MainCoinSpeed.Value;
                    ICoinShare share = root.CoinShareSet.GetOrCreate(coinId);
                    data.MainCoinTotalShare  = share.TotalShareCount;
                    data.MainCoinRejectShare = share.RejectShareCount;
                }
                else
                {
                    _sLastSpeedMainCoin = root.CurrentMineContext.MainCoin;
                }
                if (root.CurrentMineContext is IDualMineContext dualMineContext)
                {
                    // 判断上次报告的算力币种和本次报告的是否相同,否则说明刚刚切换了币种默认第一次报告0算力
                    if (_sLastSpeedDualCoin == null || _sLastSpeedDualCoin == dualMineContext.DualCoin)
                    {
                        _sLastSpeedDualCoin = dualMineContext.DualCoin;
                        Guid       coinId     = dualMineContext.DualCoin.GetId();
                        IGpusSpeed gpuSpeeds  = NTMinerRoot.Instance.GpusSpeed;
                        IGpuSpeed  totalSpeed = gpuSpeeds.CurrentSpeed(NTMinerRoot.GpuAllId);
                        data.DualCoinSpeed = totalSpeed.DualCoinSpeed.Value;
                        ICoinShare share = root.CoinShareSet.GetOrCreate(coinId);
                        data.DualCoinTotalShare  = share.TotalShareCount;
                        data.DualCoinRejectShare = share.RejectShareCount;
                    }
                    else
                    {
                        _sLastSpeedDualCoin = dualMineContext.DualCoin;
                    }
                }
            }
            return(data);
        }
Exemplo n.º 4
0
        private void Link()
        {
            VirtualRoot.Window <RegCmdHereCommand>("处理注册右键打开windows命令行菜单命令", LogEnum.DevConsole,
                                                   action: message => {
                try {
                    RegCmdHere();
                    VirtualRoot.Happened(new RegCmdHereEvent(true, "windows右键命令行添加成功"));
                }
                catch (Exception e) {
                    Logger.ErrorDebugLine(e);
                    VirtualRoot.Happened(new RegCmdHereEvent(false, "windows右键命令行添加失败"));
                }
            });
            #region 挖矿开始时将无份额内核重启份额计数置0
            int      shareCount = 0;
            DateTime shareOn    = DateTime.Now;
            VirtualRoot.On <MineStartedEvent>("挖矿开始后将无份额内核重启份额计数置0", LogEnum.DevConsole,
                                              action: message => {
                // 将无份额内核重启份额计数置0
                shareCount = 0;
                if (!message.MineContext.IsRestart)
                {
                    shareOn = DateTime.Now;
                }
            });
            #endregion
            #region 每20秒钟检查是否需要重启
            VirtualRoot.On <Per20SecondEvent>("每20秒钟检查是否需要重启", LogEnum.None,
                                              action: message => {
                #region 重启电脑
                try {
                    if (MinerProfile.IsPeriodicRestartComputer)
                    {
                        if ((DateTime.Now - this.CreatedOn).TotalMinutes > 60 * MinerProfile.PeriodicRestartComputerHours + MinerProfile.PeriodicRestartComputerMinutes)
                        {
                            Logger.WarnWriteLine($"每运行{MinerProfile.PeriodicRestartKernelHours}小时{MinerProfile.PeriodicRestartComputerMinutes}分钟重启电脑");
                            Windows.Power.Restart(60);
                            VirtualRoot.Execute(new CloseNTMinerCommand());
                            return;    // 退出
                        }
                    }
                }
                catch (Exception e) {
                    Logger.ErrorDebugLine(e);
                }
                #endregion

                #region 周期重启内核
                try {
                    if (IsMining && MinerProfile.IsPeriodicRestartKernel)
                    {
                        if ((DateTime.Now - CurrentMineContext.CreatedOn).TotalMinutes > 60 * MinerProfile.PeriodicRestartKernelHours + MinerProfile.PeriodicRestartKernelMinutes)
                        {
                            Logger.WarnWriteLine($"每运行{MinerProfile.PeriodicRestartKernelHours}小时{MinerProfile.PeriodicRestartKernelMinutes}分钟重启内核");
                            RestartMine();
                            return;    // 退出
                        }
                    }
                }
                catch (Exception e) {
                    Logger.ErrorDebugLine(e);
                }
                #endregion

                #region 收益没有增加重启内核
                try {
                    if (IsMining && this.CurrentMineContext.MainCoin != null)
                    {
                        int totalShare       = 0;
                        bool restartComputer = MinerProfile.IsNoShareRestartComputer && (DateTime.Now - shareOn).TotalMinutes > MinerProfile.NoShareRestartComputerMinutes;
                        bool restartKernel   = MinerProfile.IsNoShareRestartKernel && (DateTime.Now - shareOn).TotalMinutes > MinerProfile.NoShareRestartKernelMinutes;
                        if (restartComputer || restartKernel)
                        {
                            ICoinShare mainCoinShare = this.CoinShareSet.GetOrCreate(this.CurrentMineContext.MainCoin.GetId());
                            totalShare = mainCoinShare.TotalShareCount;
                            if ((this.CurrentMineContext is IDualMineContext dualMineContext) && dualMineContext.DualCoin != null)
                            {
                                ICoinShare dualCoinShare = this.CoinShareSet.GetOrCreate(dualMineContext.DualCoin.GetId());
                                totalShare += dualCoinShare.TotalShareCount;
                            }
                            // 如果份额没有增加
                            if (shareCount == totalShare)
                            {
                                if (restartComputer)
                                {
                                    if (!NTMinerRegistry.GetIsAutoBoot())
                                    {
                                        NTMinerRegistry.SetIsAutoBoot(true);
                                    }
                                    if (!NTMinerRegistry.GetIsAutoStart())
                                    {
                                        NTMinerRegistry.SetIsAutoStart(true);
                                    }
                                    Logger.WarnWriteLine($"{MinerProfile.NoShareRestartComputerMinutes}分钟收益没有增加重启电脑");
                                    Windows.Power.Restart(60);
                                    VirtualRoot.Execute(new CloseNTMinerCommand());
                                    return;    // 退出
                                }
                                // 产生过份额或者已经两倍重启内核时间了
                                if (restartKernel && (totalShare > 0 || (DateTime.Now - shareOn).TotalMinutes > 2 * MinerProfile.NoShareRestartKernelMinutes))
                                {
                                    Logger.WarnWriteLine($"{MinerProfile.NoShareRestartKernelMinutes}分钟收益没有增加重启内核");
                                    RestartMine();
                                    return;    // 退出
                                }
                            }
                            if (totalShare > shareCount)
                            {
                                shareCount = totalShare;
                                shareOn    = DateTime.Now;
                            }
                        }
Exemplo n.º 5
0
 static void Main(string[] args)
 {
     if (args.Length != 0)
     {
         if (args.Contains("--sha1"))
         {
             File.WriteAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "sha1"), Sha1);
             return;
         }
     }
     try {
         VirtualRoot.StartTimer();
         if (!Debugger.IsAttached)
         {
             Write.Init();
         }
         _waitHandle = new AutoResetEvent(false);
         bool mutexCreated;
         try {
             _sMutexApp = new Mutex(true, "NTMinerDaemonAppMutex", out mutexCreated);
         }
         catch {
             mutexCreated = false;
         }
         if (mutexCreated)
         {
             NTMinerRegistry.SetDaemonVersion(Sha1);
             NTMinerRegistry.SetAutoBoot("NTMinerDaemon", true);
             bool isAutoBoot = NTMinerRegistry.GetIsAutoBoot();
             if (isAutoBoot)
             {
                 string location = NTMinerRegistry.GetLocation();
                 if (!string.IsNullOrEmpty(location) && File.Exists(location))
                 {
                     string    processName = Path.GetFileName(location);
                     Process[] processes   = Process.GetProcessesByName(processName);
                     if (processes.Length == 0)
                     {
                         string arguments = NTMinerRegistry.GetArguments();
                         if (NTMinerRegistry.GetIsLastIsWork())
                         {
                             arguments = "--work " + arguments;
                         }
                         try {
                             Process.Start(location, arguments);
                             Write.DevOk($"启动挖矿端 {location} {arguments}");
                         }
                         catch (Exception e) {
                             Logger.ErrorDebugLine($"启动挖矿端失败因为异常 {location} {arguments}", e);
                         }
                     }
                     else
                     {
                         Write.DevDebug($"挖矿端已经在运行中无需启动");
                     }
                 }
             }
             else
             {
                 Write.DevDebug($"挖矿端未设置为自动启动");
             }
             Run();
         }
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e);
     }
 }