Пример #1
0
        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)
            {
                PriceEntryBase entry = PriceEntries.Single(o => o.Id == _currentRunning.Id);
                entry.UpdateStatus();
            }

            if (_stoppedMining == null)
            {
                _stoppedMining = DateTime.Now;
            }
            _currentRunning = null;
        }
Пример #2
0
        private void Refresh(string CFile)
        {
            MiningModeEnum originalMode = _engine.MiningMode;
            string         service      = "Manual";
            string         algo         = string.Empty;
            int            id           = 0;

            MT = _engine.miningTime;
            if (_engine.CurrentPriceEntry != null)
            {
                service = _engine.CurrentPriceEntry.ServiceEntry.ServiceName;
                algo    = _engine.CurrentPriceEntry.AlgoName;
                id      = _engine.CurrentPriceEntry.Id;
            }

            _engine.RequestStop();
            _engine.Cleanup();

            _engine = new MiningEngine
            {
                WriteConsoleAction = WriteConsole,
                WriteRemoteAction  = WriteRemote
            };
            _appStartTime = DateTime.Now;

            if (!_engine.LoadConfig(CFile))
            {
                MessageBox.Show("Something went wrong with reloading your configuration file. Check for errors.",
                                "Error loading conf", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            dgServices.DataSource = new SortableBindingList <IService>(_engine.Services);
            dgPrices.DataSource   = new SortableBindingList <PriceEntryBase>(_engine.PriceEntries);

            _engine.MiningMode = originalMode;

            _engine.LoadExchangeRates();

            UpdateButtons();
            //RunCycle();
            _engine.CheckFees();
            _engine.CheckPrices();
            UpdateGrid();

            _engine._autoMiningTime = MT;

            InitHistoryChart();

            if (originalMode == MiningModeEnum.Manual)
            {
                //_engine.RequestStart(service, algo, IsMinimizedToTray);
                _engine.RequestStart(id, IsMinimizedToTray);
            }
        }
Пример #3
0
        private void btnReloadConfig_Click(object sender, EventArgs e)
        {
            MiningModeEnum originalMode = _engine.MiningMode;
            ServiceEnum    service      = ServiceEnum.Manual;
            string         algo         = string.Empty;

            if (_engine.CurrentPriceEntry != null)
            {
                service = _engine.CurrentPriceEntry.ServiceEntry.ServiceEnum;
                algo    = _engine.CurrentPriceEntry.AlgoName;
            }

            _engine.Cleanup();
            _engine = new MiningEngine
            {
                WriteConsoleAction = WriteConsole,
                WriteRemoteAction  = WriteRemote
            };

            if (!_engine.LoadConfig())
            {
                MessageBox.Show("Something went wrong with reloading your configuration file. Check for errors.",
                                "Error loading conf", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            dgServices.DataSource = new SortableBindingList <IService>(_engine.Services);
            dgPrices.DataSource   = new SortableBindingList <PriceEntryBase>(_engine.PriceEntries);

            _engine.MiningMode = originalMode;

            _engine.LoadExchangeRates();
            RunCycle();
            UpdateButtons();
            UpdateGrid();

            HistoryChart historyChart = tabHistory.Controls["historyChart"] as HistoryChart;

            if (historyChart != null)
            {
                historyChart.UpdateChart();
            }

            if (originalMode == MiningModeEnum.Manual)
            {
                _engine.RequestStart(service, algo, IsMinimizedToTray);
            }
        }
Пример #4
0
        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);
            }
        }
Пример #5
0
        private void StartMiner(PriceEntryBase entry, bool isMinimizedToTray = false)
        {
            _nextRun         = null;
            _nextRunFromTime = null;
            _currentRunning  = entry;
            _startMining     = DateTime.Now;
            _stoppedMining   = null;

            _process = new Process();
            if (_donationMiningMode == MiningModeEnum.Donation)
            {
                if (!string.IsNullOrWhiteSpace(entry.DonationFolder))
                {
                    _process.StartInfo.WorkingDirectory = entry.DonationFolder;
                }
                _process.StartInfo.FileName = string.IsNullOrWhiteSpace(entry.DonationFolder)
                    ? entry.DonationCommand
                    : string.Format(@"{0}\{1}", entry.DonationFolder, entry.DonationCommand);
                _process.StartInfo.Arguments = entry.DonationArguments;
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(entry.Folder))
                {
                    _process.StartInfo.WorkingDirectory = entry.Folder;
                }
                _process.StartInfo.FileName = string.IsNullOrWhiteSpace(entry.Folder)
                    ? entry.Command
                    : string.Format(@"{0}\{1}", entry.Folder, entry.Command);
                _process.StartInfo.Arguments = entry.Arguments;
            }

            WriteConsole(
                string.Format("Starting {0} {1} with {2} {3}", _currentRunning.ServicePrint, _currentRunning.Name,
                              _process.StartInfo.FileName, _process.StartInfo.Arguments), true);

            if (!string.IsNullOrWhiteSpace(_process.StartInfo.WorkingDirectory) &&
                !Directory.Exists(_process.StartInfo.WorkingDirectory))
            {
                entry.DeadTime = DateTime.Now;
                string message = string.Format("Path '{0}' does not exist.", _process.StartInfo.WorkingDirectory);
                _process = null;
                WriteConsole(message, true);
                throw new ArgumentException(message);
            }
            if (!string.IsNullOrWhiteSpace(_process.StartInfo.FileName) && !File.Exists(_process.StartInfo.FileName))
            {
                entry.DeadTime = DateTime.Now;
                string message = string.Format("File '{0}' does not exist.", _process.StartInfo.FileName);
                _process = null;
                WriteConsole(message, true);
                throw new ArgumentException(message);
            }

            if (entry.UseWindow)
            {
                _process.StartInfo.WindowStyle = (isMinimizedToTray && TrayMode == 2)
                    ? ProcessWindowStyle.Hidden
                    : ProcessWindowStyle.Minimized;
                _process.Start();

                Thread.Sleep(100);
                try
                {
                    ProcessUtil.SetWindowTitle(_process, string.Format("{0} {1} Miner", entry.ServicePrint, entry.Name));
                }
                catch (Exception ex)
                {
                    ErrorLogger.Log(ex);
                }

                if (isMinimizedToTray && TrayMode == 1)
                {
                    HideMinerWindow();
                }
            }
            else
            {
                _process.StartInfo.RedirectStandardOutput = true;
                _process.StartInfo.RedirectStandardError  = true;
                _process.EnableRaisingEvents       = true;
                _process.StartInfo.CreateNoWindow  = true;
                _process.StartInfo.UseShellExecute = false;

                _process.ErrorDataReceived  += ProcessConsoleOutput;
                _process.OutputDataReceived += ProcessConsoleOutput;

                _process.Start();

                _process.BeginOutputReadLine();
                _process.BeginErrorReadLine();
            }

            ProcessPriorityClass processPriority;

            if (entry.Priority != "Normal" && entry.Priority != string.Empty &&
                Enum.TryParse(entry.Priority, out processPriority))
            {
                // Defaults to Normal, other possible values are Idle, BelowNormal,
                // AboveNormal, High & RealTime. ccminer <3 RealTime
                // Note 1: Realtime by minercontrol is only possible when given administrator privileges to minercontrol
                // Note 2: --cpu-priority by ccminer overrides minercontrols priority
                // Note 3: When giving administrator privileges to minercontrol and setting the priority by minercontrol to
                // something DIFFERENT than what's used by --cpu-priority by ccminer, then your whole system locks up
                _process.PriorityClass = processPriority;
            }

            if (entry.Affinity > 0)
            {
                // Just like with start /affinity, you can use 1 for first core, 2 for second core, 4 for third core, etc
                _process.ProcessorAffinity = (IntPtr)entry.Affinity;
            }

            _startMining        = DateTime.Now;
            _donationMiningMode = MiningMode;

            entry.UpdateStatus();

            LogActivity(_donationMiningMode == MiningModeEnum.Donation ? "DonationStart" : "Start");
        }
Пример #6
0
        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);
            }
        }
Пример #7
0
        private void StartMiner(PriceEntryBase entry, bool isMinimizedToTray = false)
        {
            _nextRun         = null;
            _nextRunFromTime = null;
            _currentRunning  = entry;
            _startMining     = DateTime.Now;

            _process = new Process();
            if (_donationMiningMode == MiningModeEnum.Donation)
            {
                if (!string.IsNullOrWhiteSpace(entry.DonationFolder))
                {
                    _process.StartInfo.WorkingDirectory = entry.DonationFolder;
                }
                _process.StartInfo.FileName = string.IsNullOrWhiteSpace(entry.DonationFolder)
                    ? entry.DonationCommand
                    : string.Format(@"{0}\{1}", entry.DonationFolder, entry.DonationCommand);
                _process.StartInfo.Arguments = entry.DonationArguments;
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(entry.Folder))
                {
                    _process.StartInfo.WorkingDirectory = entry.Folder;
                }
                _process.StartInfo.FileName = string.IsNullOrWhiteSpace(entry.Folder)
                    ? entry.Command
                    : string.Format(@"{0}\{1}", entry.Folder, entry.Command);
                _process.StartInfo.Arguments = entry.Arguments;
            }

            WriteConsole(string.Format("Starting {0} {1} with {2} {3}", _currentRunning.ServicePrint, _currentRunning.Name, _process.StartInfo.FileName, _process.StartInfo.Arguments), true);

            if (!string.IsNullOrWhiteSpace(_process.StartInfo.WorkingDirectory) && !Directory.Exists(_process.StartInfo.WorkingDirectory))
            {
                entry.DeadTime = DateTime.Now;
                var message = string.Format("Path '{0}' does not exist.", _process.StartInfo.WorkingDirectory);
                _process = null;
                WriteConsole(message, true);
                throw new ArgumentException(message);
            }
            if (!string.IsNullOrWhiteSpace(_process.StartInfo.FileName) && !File.Exists(_process.StartInfo.FileName))
            {
                entry.DeadTime = DateTime.Now;
                var message = string.Format("File '{0}' does not exist.", _process.StartInfo.FileName);
                _process = null;
                WriteConsole(message, true);
                throw new ArgumentException(message);
            }

            if (entry.UseWindow)
            {
                _process.StartInfo.WindowStyle = (isMinimizedToTray && TrayMode == 2) ? ProcessWindowStyle.Hidden : ProcessWindowStyle.Minimized;
                _process.Start();

                Thread.Sleep(100);
                try
                {
                    ProcessUtil.SetWindowTitle(_process, string.Format("{0} {1} Miner", entry.ServicePrint, entry.Name));
                }
                catch (Exception ex)
                {
                    ErrorLogger.Log(ex);
                }

                if (isMinimizedToTray && TrayMode == 1)
                {
                    HideMinerWindow();
                }
            }
            else
            {
                _process.StartInfo.RedirectStandardOutput = true;
                _process.StartInfo.RedirectStandardError  = true;
                _process.EnableRaisingEvents       = true;
                _process.StartInfo.CreateNoWindow  = true;
                _process.StartInfo.UseShellExecute = false;

                _process.ErrorDataReceived  += ProcessConsoleOutput;
                _process.OutputDataReceived += ProcessConsoleOutput;

                _process.Start();

                _process.BeginOutputReadLine();
                _process.BeginErrorReadLine();
            }

            _startMining        = DateTime.Now;
            _donationMiningMode = MiningMode;

            entry.UpdateStatus();

            LogActivity(_donationMiningMode == MiningModeEnum.Donation ? "DonationStart" : "Start");
        }
Пример #8
0
        private void StartMiner(PriceEntryBase entry, bool isMinimizedToTray = false)
        {
            _nextRun = null;
            _nextRunFromTime = null;
            _currentRunning = entry;
            _startMining = DateTime.Now;
            _stoppedMining = null;

            _process = new Process();
            if (_donationMiningMode == MiningModeEnum.Donation)
            {
                if (!string.IsNullOrWhiteSpace(entry.DonationFolder))
                    _process.StartInfo.WorkingDirectory = entry.DonationFolder;
                _process.StartInfo.FileName = string.IsNullOrWhiteSpace(entry.DonationFolder)
                    ? entry.DonationCommand
                    : string.Format(@"{0}\{1}", entry.DonationFolder, entry.DonationCommand);
                _process.StartInfo.Arguments = DetectNiceHashStratum(entry) + entry.DonationArguments;
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(entry.Folder))
                    _process.StartInfo.WorkingDirectory = entry.Folder;
                _process.StartInfo.FileName = string.IsNullOrWhiteSpace(entry.Folder)
                    ? entry.Command
                    : string.Format(@"{0}\{1}", entry.Folder, entry.Command);
                _process.StartInfo.Arguments = DetectNiceHashStratum(entry) + entry.Arguments;
            }

            WriteConsole(
                string.Format("Starting {0} {1} with {2} {3}", _currentRunning.ServicePrint, _currentRunning.Name,
                    _process.StartInfo.FileName, _process.StartInfo.Arguments), true);

            if (!string.IsNullOrWhiteSpace(_process.StartInfo.WorkingDirectory) &&
                !Directory.Exists(_process.StartInfo.WorkingDirectory))
            {
                entry.DeadTime = DateTime.Now;
                string message = string.Format("Path '{0}' does not exist.", _process.StartInfo.WorkingDirectory);
                _process = null;
                WriteConsole(message, true);
                throw new ArgumentException(message);
            }
            if (!string.IsNullOrWhiteSpace(_process.StartInfo.FileName) && !File.Exists(_process.StartInfo.FileName))
            {
                entry.DeadTime = DateTime.Now;
                string message = string.Format("File '{0}' does not exist.", _process.StartInfo.FileName);
                _process = null;
                WriteConsole(message, true);
                throw new ArgumentException(message);
            }

            if (entry.UseWindow)
            {
                _process.StartInfo.WindowStyle = (isMinimizedToTray && TrayMode == 2)
                    ? ProcessWindowStyle.Hidden
                    : ProcessWindowStyle.Minimized;
                _process.Start();

                Thread.Sleep(100);
                try
                {
                    ProcessUtil.SetWindowTitle(_process, string.Format("{0} {1} Miner", entry.ServicePrint, entry.Name));
                }
                catch (Exception ex)
                {
                    ErrorLogger.Log(ex);
                }

                if (isMinimizedToTray && TrayMode == 1)
                    HideMinerWindow();
            }
            else
            {
                _process.StartInfo.RedirectStandardOutput = true;
                _process.StartInfo.RedirectStandardError = true;
                _process.EnableRaisingEvents = true;
                _process.StartInfo.CreateNoWindow = true;
                _process.StartInfo.UseShellExecute = false;

                _process.ErrorDataReceived += ProcessConsoleOutput;
                _process.OutputDataReceived += ProcessConsoleOutput;

                _process.Start();

                _process.BeginOutputReadLine();
                _process.BeginErrorReadLine();
            }

            ProcessPriorityClass processPriority;
            if (entry.Priority != "Normal" && entry.Priority != string.Empty
                && Enum.TryParse(entry.Priority, out processPriority))
            {
                // Defaults to Normal, other possible values are Idle, BelowNormal,
                // AboveNormal, High & RealTime. ccminer <3 RealTime
                // Note 1: Realtime by minercontrol is only possible when given administrator privileges to minercontrol
                // Note 2: --cpu-priority by ccminer overrides minercontrols priority
                // Note 3: When giving administrator privileges to minercontrol and setting the priority by minercontrol to
                // something DIFFERENT than what's used by --cpu-priority by ccminer, then your whole system locks up
                _process.PriorityClass = processPriority;
            }

            if (entry.Affinity > 0)
            {
                // Just like with start /affinity, you can use 1 for first core, 2 for second core, 4 for third core, etc
                _process.ProcessorAffinity = (IntPtr) entry.Affinity;
            }

            _startMining = DateTime.Now;
            _donationMiningMode = MiningMode;

            entry.UpdateStatus();

            LogActivity(_donationMiningMode == MiningModeEnum.Donation ? "DonationStart" : "Start");
        }
Пример #9
0
        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)
            {
                PriceEntryBase entry = PriceEntries.Single(o => o.Id == _currentRunning.Id);
                entry.UpdateStatus();
            }

            if(_stoppedMining == null) _stoppedMining = DateTime.Now;
            _currentRunning = null;
        }
Пример #10
0
        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.ServiceName != _currentRunning.ServiceEntry.ServiceName
                        ? 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);
            }
        }