public void StopMiner() { if (!_process.IsRunning()) { _process = null; return; } LogActivity(_donationMiningMode == MiningModeEnum.Donation ? "DonationStop" : "Stop"); WriteConsole(string.Format("Stopping {0} {1}", _currentRunning.ServicePrint, _currentRunning.AlgoName), true); RecordMiningTime(); if (MinerKillMode == 0) { ProcessUtil.KillProcess(_process); } else { ProcessUtil.KillProcessAndChildren(_process.Id); } _process = null; _donationMiningMode = MiningModeEnum.Stopped; if (_currentRunning != null) { var entry = PriceEntries.Where(o => o.Id == _currentRunning.Id).Single(); entry.UpdateStatus(); } _currentRunning = null; }
public void RunBestAlgo(bool isMinimizedToTray) { try { // Check for dead process if (!_process.IsRunning() && _currentRunning != null) { lock (this) { _currentRunning.DeadTime = DateTime.Now; LogActivity(_donationMiningMode == MiningModeEnum.Donation ? "DonationDead" : "Dead"); WriteConsole(string.Format("Dead {0} {1}", _currentRunning.ServicePrint, _currentRunning.Name), true); RecordMiningTime(); } } // Clear information if process not running if (!_process.IsRunning()) { _currentRunning = null; _startMining = null; _nextRun = null; _nextRunFromTime = null; } // Donation mining if (DoDonationMinging) { if (_donationMiningMode == MiningModeEnum.Automatic && TimeUntilDonation == TimeSpan.Zero) { StopMiner(); _donationMiningMode = MiningModeEnum.Donation; MiningMode = _donationMiningMode; _autoMiningTime = TimeSpan.Zero; } else if (_donationMiningMode == MiningModeEnum.Donation && TimeDuringDonation == TimeSpan.Zero) { StopMiner(); _donationMiningMode = MiningModeEnum.Automatic; MiningMode = _donationMiningMode; _donationMiningTime = TimeSpan.Zero; } } // Restart miner if max time reached if (RestartTime.HasValue && RestartTime.Value <= TimeSpan.Zero) { StopMiner(); } foreach (PriceEntryBase entry in _priceEntries) { entry.BelowMinPrice = entry.NetEarn < _minPrice; } // Find the best, live entry PriceEntryBase best = _priceEntries .Where(o => !IsBadEntry(o)) .Where(o => !string.IsNullOrWhiteSpace(_donationMiningMode == MiningModeEnum.Donation ? o.DonationCommand : o.Command)) .OrderByDescending(o => _mineByAverage? o.NetAverage: o.NetEarn) .FirstOrDefault(); // If none is found, because they're all banned, dead, below minprice // All should quit if (best == null && _currentRunning != null) { StopMiner(); return; } // If the current pool is banned, it should directly start the best one if (_currentRunning != null && _currentRunning.Banned && best.Id != _currentRunning.Id) { StopMiner(); StartMiner(best, isMinimizedToTray); return; } decimal highestMinProfit = 1M; // Handle minimum time for better algorithm before switching if (_switchTime > TimeSpan.Zero && _currentRunning != null) { if (!_nextRun.HasValue && _currentRunning.Id != best.Id) { _nextRun = best.Id; _nextRunFromTime = DateTime.Now; } else if (_nextRun.HasValue && _currentRunning.Id == best.Id) { _nextRun = null; _nextRunFromTime = null; } _profitBestOverRunning = _mineByAverage? best.NetAverage / _currentRunning.NetAverage : best.NetEarn / _currentRunning.NetEarn; highestMinProfit = best.ServiceEntry.ServiceEnum != _currentRunning.ServiceEntry.ServiceEnum ? Math.Max(best.MinProfit, _minProfit) : _minProfit; if (NextRunTime.HasValue && NextRunTime > TimeSpan.Zero) { best = _priceEntries.First(o => o.Id == _currentRunning.Id); } } // Update undead entries IEnumerable <PriceEntryBase> entries = PriceEntries.Where(o => !o.IsDead && o.DeadTime != DateTime.MinValue); foreach (PriceEntryBase entry in entries) { entry.DeadTime = DateTime.MinValue; } if (_currentRunning != null // Guarantees a minimum profit before switching && (_profitBestOverRunning < highestMinProfit // Keeps outliers pending/ignores them if requested and not mining by average || (!_mineByAverage && _ignoreOutliers && best.Outlier) // Just update time if we are already running the right entry || _currentRunning.Id == best.Id // Honor minimum time to run in auto mode || (MiningTime.HasValue && MiningTime.Value < _minTime))) { _currentRunning.UpdateStatus(); return; } StopMiner(); if (_stoppedMining == null || _stoppedMining + _delay <= DateTime.Now) { StartMiner(best, isMinimizedToTray); } } catch (Exception ex) { ErrorLogger.Log(ex); } }
public void RunBestAlgo(bool isMinimizedToTray) { try { // Check for dead process if (!_process.IsRunning() && _currentRunning != null) { lock (this) { _currentRunning.DeadTime = DateTime.Now; LogActivity(_donationMiningMode == MiningModeEnum.Donation ? "DonationDead" : "Dead"); WriteConsole(string.Format("Dead {0} {1}", _currentRunning.ServicePrint, _currentRunning.Name), true); RecordMiningTime(); } } // Clear information if process not running if (_process == null || _process.HasExited) { _currentRunning = null; _startMining = null; _nextRun = null; _nextRunFromTime = null; } // Donation mining if (DoDonationMinging) { if (_donationMiningMode == MiningModeEnum.Automatic && TimeUntilDonation == TimeSpan.Zero) { StopMiner(); _donationMiningMode = MiningModeEnum.Donation; MiningMode = _donationMiningMode; _autoMiningTime = TimeSpan.Zero; } else if (_donationMiningMode == MiningModeEnum.Donation && TimeDuringDonation == TimeSpan.Zero) { StopMiner(); _donationMiningMode = MiningModeEnum.Automatic; MiningMode = _donationMiningMode; _donationMiningTime = TimeSpan.Zero; } } // Restart miner if max time reached if (RestartTime.HasValue && RestartTime.Value <= TimeSpan.Zero) { StopMiner(); } // Find the best, live entry var best = _donationMiningMode == MiningModeEnum.Donation ? _priceEntries .Where(o => !o.IsDead) .Where(o => !string.IsNullOrWhiteSpace(o.DonationCommand)) .OrderByDescending(o => o.NetEarn) .First() : _priceEntries .Where(o => !o.IsDead) .Where(o => !string.IsNullOrWhiteSpace(o.Command)) .OrderByDescending(o => o.NetEarn) .First(); // Handle minimum time for better algorithm before switching if (_switchTime > TimeSpan.Zero && _currentRunning != null) { if (!_nextRun.HasValue && _currentRunning.Id != best.Id) { _nextRun = best.Id; _nextRunFromTime = DateTime.Now; } else if (_nextRun.HasValue && _currentRunning.Id == best.Id) { _nextRun = null; _nextRunFromTime = null; } if (NextRunTime.HasValue && NextRunTime > TimeSpan.Zero) { best = _priceEntries.First(o => o.Id == _currentRunning.Id); } } // Update undead entries var entries = PriceEntries.Where(o => !o.IsDead && o.DeadTime != DateTime.MinValue); foreach (var entry in entries) { entry.DeadTime = DateTime.MinValue; } // Just update time if we are already running the right entry if (_currentRunning != null && _currentRunning.Id == best.Id) { _currentRunning.UpdateStatus(); return; } // Honor minimum time to run in auto mode if (MiningTime.HasValue && MiningTime.Value < _minTime) { _currentRunning.UpdateStatus(); return; } StopMiner(); StartMiner(best, isMinimizedToTray); } catch (Exception ex) { ErrorLogger.Log(ex); } }