예제 #1
0
        //private static async Task ResumeAllMiners()
        //{
        //    foreach (var groupMiner in _runningMiners.Values)
        //    {
        //        await groupMiner.StartMinerTask(stopMiningManager, _miningLocation, _username);
        //    }
        //    // TODO resume devices to Mining state
        //}

        private static async Task CheckGroupingAndUpdateMiners(MainCommand command)
        {
            // #1 parse the command
            var commandType = command.GetType().Name;

            Logger.Debug(Tag, $"Command type {commandType}");
            if (command is NormalizedProfitsUpdateCommand normalizedProfitsUpdateCommand)
            {
                _normalizedProfits = normalizedProfitsUpdateCommand.normalizedProfits;
            }
            else if (command is MiningLocationChangedCommand miningLocationChangedCommand)
            {
                var oldLocation = _miningLocation;
                _miningLocation = miningLocationChangedCommand.miningLocation;
                if (_miningLocation == oldLocation)
                {
                    return;
                }
            }
            else if (command is UsernameChangedCommand usernameChangedCommand)
            {
                _username = usernameChangedCommand.username;
            }


            // here we do the deciding
            // to mine we need to have the username mining location set and ofc device to mine with
            if (_username == null || _normalizedProfits == null || _miningLocation == null)
            {
                if (_username == null)
                {
                    Logger.Error(Tag, "_username is null");
                }
                if (_normalizedProfits == null)
                {
                    Logger.Error(Tag, "_normalizedProfits is null");
                }
                if (_miningLocation == null)
                {
                    Logger.Error(Tag, "_miningLocation is null");
                }
                await PauseAllMiners();
            }
            else if (command is MiningLocationChangedCommand || command is UsernameChangedCommand || command is RunEthlargementChangedCommand)
            {
                // TODO this is miner restarts on mining location and username change, you should take into account the mining location changed for benchmarking
                // RESTART-STOP-START
                // STOP
                foreach (var miner in _runningMiners.Values)
                {
                    await miner.StopTask();
                }
                // START
                foreach (var miner in _runningMiners.Values)
                {
                    await miner.StartMinerTask(stopMiningManager, _miningLocation, _username);
                }
            }
            else if (_miningDevices.Count == 0)
            {
                await StopAllMinersTask();

                ApplicationStateManager.StopMining();
            }
            else
            {
                ApplicationStateManager.StartMining();
                bool skipProfitsThreshold = command is MiningProfitSettingsChangedCommand || command is MinerRestartLoopNotifyCommand;
                await SwichMostProfitableGroupUpMethodTask(_normalizedProfits, skipProfitsThreshold);
            }
        }
예제 #2
0
        //private static async Task ResumeAllMiners()
        //{
        //    foreach (var groupMiner in _runningMiners.Values)
        //    {
        //        await groupMiner.StartMinerTask(stopMiningManager, _username);
        //    }
        //    // TODO resume devices to Mining state
        //}

        private static async Task CheckGroupingAndUpdateMiners(MainCommand command)
        {
            // #1 parse the command
            var commandType = command.GetType().Name;

            Logger.Debug(Tag, $"Command type {commandType}");
            if (command is NormalizedProfitsUpdateCommand normalizedProfitsUpdateCommand)
            {
                _normalizedProfits = normalizedProfitsUpdateCommand.normalizedProfits;
            }
            else if (command is UsernameChangedCommand usernameChangedCommand)
            {
                _username = usernameChangedCommand.username;
            }
            else if (command is PauseMiningWhenGamingModeSettingsChangedCommand pauseMiningWhenGamingModeSettingsChangedCommand)
            {
                _isPauseMiningWhenGamingEnabled = pauseMiningWhenGamingModeSettingsChangedCommand.isPauseMiningWhenGamingModeSettingEnabled;
                if (!_isPauseMiningWhenGamingEnabled)
                {
                    var dev = AvailableDevices.Devices.FirstOrDefault(d => d.IsGaming == true);
                    if (dev != null)
                    {
                        dev.IsGaming = false;
                    }
                }
            }
            else if (command is IsSteamGameRunningChangedCommand isSteamGameRunningChangedCommand)
            {
                _isGameRunning = isSteamGameRunningChangedCommand.isSteamGameRunning;
            }
            else if (command is GPUToPauseChangedCommand gpuToPauseChangedCommand)
            {
                _deviceToPauseUuid = gpuToPauseChangedCommand.gpuUuid;

                // unpause device if not mining and not selected
                var devToUnpause = AvailableDevices.Devices.FirstOrDefault(d => d.Uuid != _deviceToPauseUuid && d.IsGaming == true);
                if (devToUnpause != null)
                {
                    devToUnpause.IsGaming = false;
                }

                // set new selected gpu to true
                var newSelectedDev = AvailableDevices.GetDeviceWithUuid(_deviceToPauseUuid);
                if (newSelectedDev != null)
                {
                    newSelectedDev.PauseMiningWhenGamingMode = true;
                    ConfigManager.DeviceConfigFileCommit(newSelectedDev);
                }

                // set previous selected gpu to false
                var oldSelectedDev = AvailableDevices.Devices.FirstOrDefault(d => d.Uuid != _deviceToPauseUuid && d.PauseMiningWhenGamingMode);
                if (oldSelectedDev != null)
                {
                    oldSelectedDev.PauseMiningWhenGamingMode = false;
                    ConfigManager.DeviceConfigFileCommit(oldSelectedDev);
                }
            }

            bool isRestartMinersCommand(Command command) =>
            command switch
            {
                UsernameChangedCommand => true,
                UseOptimizationProfilesChangedCommand => true,
                DNSQChangedCommand => true,
                SSLMiningChangedCommand => true,
                _ => false,
            };
            // here we do the deciding
            // to mine we need to have the username mining location set and ofc device to mine with
            if (_username == null || _normalizedProfits == null)
            {
                if (_username == null)
                {
                    Logger.Error(Tag, "_username is null");
                }
                if (_normalizedProfits == null)
                {
                    Logger.Error(Tag, "_normalizedProfits is null");
                }
                await PauseAllMiners();
            }
            else if (isRestartMinersCommand(command))
            {
                // RESTART-STOP-START
                // STOP
                foreach (var miner in _runningMiners.Values)
                {
                    await miner.StopTask();
                }
                // START
                foreach (var miner in _runningMiners.Values)
                {
                    await miner.StartMinerTask(_stopMiningManager, _username);
                }
            }
            else if (_miningDevices.Count == 0)
            {
                await StopAllMinersTask();

                ApplicationStateManager.StopMining();
            }
            else if (_isGameRunning && _isPauseMiningWhenGamingEnabled && _deviceToPauseUuid != null)
            {
                AvailableNotifications.CreateGamingStarted();
                var dev = AvailableDevices.Devices.FirstOrDefault(d => d.Uuid == _deviceToPauseUuid);
                dev.IsGaming = true;
                bool skipProfitsThreshold = CheckIfShouldSkipProfitsThreshold(command);
                await SwichMostProfitableGroupUpMethodTask(_normalizedProfits, skipProfitsThreshold);
            }
            else if (!_isGameRunning && _isPauseMiningWhenGamingEnabled && command is IsSteamGameRunningChangedCommand)
            {
                AvailableNotifications.CreateGamingFinished();
                var dev = AvailableDevices.Devices.FirstOrDefault(d => d.Uuid == _deviceToPauseUuid);
                dev.IsGaming = false;
                bool skipProfitsThreshold = CheckIfShouldSkipProfitsThreshold(command);
                await SwichMostProfitableGroupUpMethodTask(_normalizedProfits, skipProfitsThreshold);
            }
            else
            {
                ApplicationStateManager.StartMining();
                bool skipProfitsThreshold = CheckIfShouldSkipProfitsThreshold(command);
                await SwichMostProfitableGroupUpMethodTask(_normalizedProfits, skipProfitsThreshold);
            }
        }