public static Tuple <ComputeDevice, DeviceMiningStatus> getDeviceMiningStatus(ComputeDevice device) { DeviceMiningStatus status = DeviceMiningStatus.CanMine; if (device == null) // C# is null happy { status = DeviceMiningStatus.DeviceNull; } else if (device.Enabled == false) { status = DeviceMiningStatus.Disabled; } else { bool hasEnabledAlgo = false; foreach (Algorithm algo in device.GetAlgorithmSettings()) { hasEnabledAlgo |= IsAlgoMiningCapable(algo) && MinerPaths.IsValidMinerPath(algo.MinerBinaryPath); } if (hasEnabledAlgo == false) { status = DeviceMiningStatus.NoEnabledAlgorithms; } } return(new Tuple <ComputeDevice, DeviceMiningStatus>(device, status)); }
Tuple <ComputeDevice, DeviceMiningStatus> getDeviceMiningStatus(ComputeDevice device) { DeviceMiningStatus status = DeviceMiningStatus.CanMine; if (device == null) // C# is null happy { status = DeviceMiningStatus.DeviceNull; } else if (device.Enabled == false) { status = DeviceMiningStatus.Disabled; } else { bool hasEnabledAlgo = false; foreach (Algorithm algo in device.DeviceBenchmarkConfig.AlgorithmSettings.Values) { hasEnabledAlgo |= IsAlgoMiningCapable(algo); } if (hasEnabledAlgo == false) { status = DeviceMiningStatus.NoEnabledAlgorithms; } } return(new Tuple <ComputeDevice, DeviceMiningStatus>(device, status)); }
private static string GetDisabledDeviceStatusString(ComputeDevice dev, DeviceMiningStatus status) { return(status switch { DeviceMiningStatus.DeviceNull => "Passed Device is NULL", DeviceMiningStatus.Disabled => $"DISABLED: {dev.GetFullName()}", DeviceMiningStatus.NoEnabledAlgorithms => $"No Enabled Algorithms: {dev.GetFullName()}", _ => "Invalid status Passed", });
public MiningSession(List <ComputeDevice> devices, IMainFormRatesComunication mainFormRatesComunication, string miningLocation, string worker, string btcAdress) { // init fixed _mainFormRatesComunication = mainFormRatesComunication; _miningLocation = miningLocation; if (worker.Length > 0) { _workerBtcStringWorker = btcAdress + "." + worker; } else { _workerBtcStringWorker = btcAdress; } // initial settup { // used for logging List <Tuple <ComputeDevice, DeviceMiningStatus> > disabledDevicesStatuses = new List <Tuple <ComputeDevice, DeviceMiningStatus> >(); // logging and settup List <ComputeDevice> enabledDevices = new List <ComputeDevice>(); // get enabled devices { // check passed devices statuses List <Tuple <ComputeDevice, DeviceMiningStatus> > devicesStatuses = new List <Tuple <ComputeDevice, DeviceMiningStatus> >(); foreach (var device in devices) { devicesStatuses.Add(getDeviceMiningStatus(device)); } // sort device statuses foreach (var deviceStatus in devicesStatuses) { if (deviceStatus.Item2 == DeviceMiningStatus.CanMine) { enabledDevices.Add(deviceStatus.Item1); } else { disabledDevicesStatuses.Add(deviceStatus); } } } // print statuses if (disabledDevicesStatuses.Count > 0) { Helpers.ConsolePrint(TAG, "Disabled Devices:"); foreach (var deviceStatus in disabledDevicesStatuses) { ComputeDevice device = deviceStatus.Item1; DeviceMiningStatus status = deviceStatus.Item2; if (status == DeviceMiningStatus.DeviceNull) { Helpers.ConsolePrint(TAG, "Critical Device is NULL"); } else if (status == DeviceMiningStatus.Disabled) { Helpers.ConsolePrint(TAG, String.Format("DISABLED ({0})", device.GetFullName())); } else if (status == DeviceMiningStatus.NoEnabledAlgorithms) { Helpers.ConsolePrint(TAG, String.Format("No Enabled Algorithms ({0})", device.GetFullName())); } } } if (enabledDevices.Count > 0) { // print enabled Helpers.ConsolePrint(TAG, "Enabled Devices for Mining session:"); foreach (var device in enabledDevices) { Helpers.ConsolePrint(TAG, String.Format("ENABLED ({0})", device.GetFullName())); foreach (var algo in device.DeviceBenchmarkConfig.AlgorithmSettings.Values) { var isEnabled = IsAlgoMiningCapable(algo); Helpers.ConsolePrint(TAG, String.Format("\t\tALGORITHM {0} ({1})", isEnabled ? "ENABLED " : "DISABLED", // ENABLED/DISABLED AlgorithmNiceHashNames.GetName(algo.NiceHashID))); } } // settup mining devices foreach (var device in enabledDevices) { _miningDevices.Add(new MiningDevice(device)); } } } if (_miningDevices.Count > 0) { // calculate avarage speeds, to ensure mining stability // device name, algo key, algos refs list Dictionary <string, Dictionary <AlgorithmType, List <MiningAlgorithm> > > avarager = new Dictionary <string, Dictionary <AlgorithmType, List <MiningAlgorithm> > >(); // init empty avarager foreach (var device in _miningDevices) { string devName = device.Device.Name; avarager[devName] = new Dictionary <AlgorithmType, List <MiningAlgorithm> >(); foreach (var key in AlgorithmNiceHashNames.GetAllAvaliableTypes()) { avarager[devName][key] = new List <MiningAlgorithm>(); } } // fill avarager foreach (var device in _miningDevices) { string devName = device.Device.Name; foreach (var kvp in device.Algorithms) { var key = kvp.Key; MiningAlgorithm algo = kvp.Value; avarager[devName][key].Add(algo); } } // calculate avarages foreach (var devDict in avarager.Values) { foreach (List <MiningAlgorithm> miningAlgosList in devDict.Values) { // if list not empty calculate avarage if (miningAlgosList.Count > 0) { // calculate avarage double sum = 0; foreach (var algo in miningAlgosList) { sum += algo.AvaragedSpeed; } double avarageSpeed = sum / miningAlgosList.Count; // set avarage foreach (var algo in miningAlgosList) { algo.AvaragedSpeed = avarageSpeed; } } } } } // init timer stuff _preventSleepTimer = new Timer(); _preventSleepTimer.Elapsed += PreventSleepTimer_Tick; // sleep time is minimal 1 minute _preventSleepTimer.Interval = 20 * 1000; // leave this interval, it works // set internet checking _internetCheckTimer = new Timer(); _internetCheckTimer.Elapsed += InternetCheckTimer_Tick; _internetCheckTimer.Interval = 1000 * 30 * 1; // every minute or 5?? // 1000 * 60 * 1 _miningStatusCheckTimer = new Timer(); _miningStatusCheckTimer.Elapsed += MiningStatusCheckTimer_Tick; _miningStatusCheckTimer.Interval = 1000 * 30; // assume profitable IsProfitable = true; // assume we have internet IsConnectedToInternet = true; if (IsMiningEnabled) { _preventSleepTimer.Start(); _internetCheckTimer.Start(); _miningStatusCheckTimer.Start(); } IsMiningRegardlesOfProfit = ConfigManager.Instance.GeneralConfig.MinimumProfit == 0; }