public static void StartRefreshDeviceListViewTimer()
 {
     if (_refreshDeviceListViewTimer?.IsActive ?? false)
     {
         return;
     }
     _refreshDeviceListViewTimer = new AppTimer((object sender, ElapsedEventArgs e) => {
         RefreshDeviceListView?.Invoke(sender, EventArgs.Empty);
     },
                                                2000);
     _refreshDeviceListViewTimer.Start();
 }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        // TODO add check for any enabled algorithms
        public static (bool started, string failReason) StartAllAvailableDevices(bool isRpcCall = false)
        {
            var allDevs        = AvailableDevices.Devices;
            var devicesToStart = allDevs.Where(dev => dev.State == DeviceState.Stopped);

            if (devicesToStart.Count() == 0)
            {
                return(false, "there are no new devices to start");
            }
            // TODO for now no partial success so if one fails send back that everything fails
            var started    = true;
            var failReason = "";

            // TODO we have a BUG HERE if device enabled with all disabled algorithms
            var devicesToBenchmark   = devicesToStart.Where(dev => dev.AllEnabledAlgorithmsWithoutBenchmarks() && dev.AnyAlgorithmEnabled());
            var devicesToReBenchmark = devicesToStart.Where(dev => dev.HasEnabledAlgorithmsWithReBenchmark() && !devicesToBenchmark.Contains(dev));

            foreach (var dev in devicesToBenchmark)
            {
                dev.State = DeviceState.Benchmarking;
                BenchmarkManager.StartBenchmarForDevice(dev, new BenchmarkStartSettings
                {
                    StartMiningAfterBenchmark = true,
                    BenchmarkPerformanceType  = BenchmarkPerformanceType.Standard,
                    BenchmarkOption           = BenchmarkOption.ZeroOrReBenchOnly
                });
            }
            foreach (var dev in devicesToReBenchmark)
            {
                dev.State = DeviceState.Benchmarking;
                BenchmarkManager.StartBenchmarForDevice(dev, new BenchmarkStartSettings
                {
                    StartMiningAfterBenchmark = true,
                    BenchmarkPerformanceType  = BenchmarkPerformanceType.Standard,
                    BenchmarkOption           = BenchmarkOption.ReBecnhOnly
                });
            }

            var devicesInErrorState      = devicesToStart.Where(dev => !dev.AnyAlgorithmEnabled() || dev.AllEnabledAlgorithmsZeroPaying()).ToList();
            var devicesInErrorStateUUIDs = devicesInErrorState.Select(dev => dev.Uuid);

            foreach (var dev in devicesInErrorState)
            {
                dev.State = DeviceState.Error;
            }

            // TODO check count
            var devicesToMine = devicesToStart.Where(dev => !dev.AllEnabledAlgorithmsWithoutBenchmarks() && !devicesInErrorStateUUIDs.Contains(dev.Uuid)).ToList();

            foreach (var dev in devicesToMine)
            {
                dev.State = DeviceState.Mining;
            }
            UpdateDevicesToMine();
            if (!isRpcCall)
            {
                NiceHashStats.StateChanged();
            }
            RefreshDeviceListView?.Invoke(null, null);

            return(started, "");
        }
Ejemplo n.º 4
0
 // TODO this thing should be dropped when we have bindable properties
 public static void UpdateDevicesStatesAndStartDeviceRefreshTimer()
 {
     MiningState.Instance.CalculateDevicesStateChange();
     RefreshDeviceListView?.Invoke(null, null);
     StartRefreshDeviceListViewTimer();
 }