Esempio n. 1
0
        public static (bool started, string failReason) StartDevice(ComputeDevice device, bool skipBenhcmakrk = false)
        {
            // we can only start a device it is already stopped
            if (device.State != DeviceState.Stopped && !skipBenhcmakrk)
            {
                return(false, "Device already started");
            }

            var started              = true;
            var failReason           = "";
            var isErrorState         = !device.AnyAlgorithmEnabled();
            var isAllZeroPayingState = device.AllEnabledAlgorithmsZeroPaying();
            // check if device has any benchmakrs
            var needsBenchmark   = device.AllEnabledAlgorithmsWithoutBenchmarks();
            var needsReBenchmark = device.HasEnabledAlgorithmsWithReBenchmark();

            if (isErrorState || isAllZeroPayingState)
            {
                device.State = DeviceState.Error;
                started      = false;
                failReason   = isAllZeroPayingState ? "No enabled algorithm is profitable" : "Cannot start a device with all disabled algoirhtms";
            }
            else if (needsBenchmark && !skipBenhcmakrk)
            {
                device.State = DeviceState.Benchmarking;
                BenchmarkManager.StartBenchmarForDevice(device, new BenchmarkStartSettings {
                    StartMiningAfterBenchmark = true,
                    BenchmarkPerformanceType  = BenchmarkPerformanceType.Standard,
                    BenchmarkOption           = BenchmarkOption.ZeroOnly
                });
            }
            else if (needsReBenchmark && !skipBenhcmakrk)
            {
                device.State = DeviceState.Benchmarking;
                BenchmarkManager.StartBenchmarForDevice(device, new BenchmarkStartSettings
                {
                    StartMiningAfterBenchmark = true,
                    BenchmarkPerformanceType  = BenchmarkPerformanceType.Standard,
                    BenchmarkOption           = BenchmarkOption.ReBecnhOnly
                });
            }
            else
            {
                device.State = DeviceState.Mining;
                UpdateDevicesToMine();
            }

            RefreshDeviceListView?.Invoke(null, null);
            NiceHashStats.StateChanged();

            return(started, failReason);
        }
Esempio n. 2
0
        internal static async Task <(bool started, string failReason)> StartDeviceTask(ComputeDevice device)
        {
            device.StartState = true;
            // we can only start a device it is already stopped
            if (device.State == DeviceState.Disabled)
            {
                return(false, "Device is disabled");
            }

            if (device.State != DeviceState.Stopped && device.State != DeviceState.Error)
            {
                return(false, "Device already started");
            }

            var started               = true;
            var failReason            = "";
            var allAlgorithmsDisabled = !device.AnyAlgorithmEnabled();
            var isAllZeroPayingState  = device.AllEnabledAlgorithmsZeroPaying();
            // check if device has any benchmakrs
            var needBenchmarkOrRebench = device.AnyEnabledAlgorithmsNeedBenchmarking();

            if (allAlgorithmsDisabled)
            {
                device.State = DeviceState.Error;
                started      = false;
                failReason   = "Cannot start a device with all disabled algoirhtms";
            }
            else if (isAllZeroPayingState && !needBenchmarkOrRebench)
            {
                device.State = DeviceState.Error;
                started      = false;
                failReason   = "No enabled algorithm is profitable";
            }
            else
            {
                await MiningManager.StartDevice(device);
            }

            return(started, failReason);
        }