public void Start() { Task.Factory.StartNew(async() => { var bus = _messageCommunicationFactory.Create(); do { if (!PingHost(_config.AddressCheck)) { bus.Publish <ConnectionLost>(); _logger.Warn($"Connection lost to {_config.AddressCheck}"); if (_config.ResetIfLost) { if (_config.RestoreTool != null) { bus.Execute <StartProcess, ICommunicationBase>(new StartProcess { Process = _config.RestoreTool }); } else { DisableAdapters(_config.AdapterList); await Task.Delay(_config.ResetDelay); EnableAdapters(_config.AdapterList); } } } await Task.Delay(_config.IntervalCheck); } while (!_token.IsCancellationRequested); }, _token.Token); }
public void Handle(CheckProcess checkProcess) { var result = CheckPrcessStatus(checkProcess); var messanger = _messageCommunicationFactory.Create(); messanger.Publish(result); }
public void Handle(CheckProcess checkProcess) { var result = CheckPrcessStatus(checkProcess); var messanger = _messageCommunicationFactory.Create(); result.InitModule = checkProcess.IsInitModule; messanger.Handle(result); }
public void Handle(object x) { var bus = _messageCommunicationFactory.Create(); bus.Handle(new HistoryCardMessages { }); }
public void Start() { var messageBus = _messageBusFactory.Create(); _logger.Info("AutobernerController started"); var result = messageBus.Execute <ProcessStatus, CheckProcess>(new CheckProcess { Name = _config.DependencyProcess.Name }, "process"); if (!result.Ready) { messageBus.Execute(new StartProcess { Process = _config.DependencyProcess }); } CardsMonitoring(); }
internal Core(Configuration configuration, IWebApiBootstraper webapiBootstrap, ISocketServer socketServer, IEnumerable <IBaseController> baseControllers, MessageCommunicationFactory communicationFactory) { _configuration = configuration; _webapiBootstrap = webapiBootstrap; _socketServer = socketServer; _baseControllers = baseControllers; _communication = communicationFactory.Create(); }
public ModeratorResultStatus Execute(ModeratorChangeCardActive resetAdapter) { var tryRestartCount = 5; var tryExecuteMessage = 5; var message = _messageCommunicationFactory.Create(); ModeratorResultStatus result; do { result = message.Execute <ModeratorResultStatus, CardChangeStatus>(new CardChangeStatus { IdCard = resetAdapter.IdCard, State = resetAdapter.Enable ? CardChangeStatus.StateGpu.MainOnly : CardChangeStatus.StateGpu.Disable }, "miner"); if (ModeratorResultStatus.IsOk(result)) { return(result); } do { var process = message.Execute <ProcessStatus, RestartProcess>(new RestartProcess { Process = _configure.DependencyProcess }); if (process.Ready) { break; } tryRestartCount--; } while (tryRestartCount != 0); tryExecuteMessage--; } while (!ModeratorResultStatus.IsOk(result) || tryExecuteMessage != 0); return(result); }
private void CardsMonitoring(CardParam[] configCards) { var messageBus = _messageBusFactory.Create(); Task.Factory.StartNew(async() => { do { _lockEvent.WaitOne(); try { var ctrlGpu = new ControlMemory(); ctrlGpu.Connect(); ctrlGpu.ReloadAll(); ctrlGpu.Reinitialize(); var actualList = FindCards(ctrlGpu); ctrlGpu.Disconnect(); if (_config.WatchDog) { WatchDog(configCards, actualList); } } catch (Exception ex) { _logger.Error($"CardsMonitoring error: {ex.Message}"); } await Task.Delay(_config.MonitoringInterval, _token.Token); } while (!_token.IsCancellationRequested); }, _token.Token, TaskCreationOptions.LongRunning, TaskScheduler.Default) .ContinueWith((x) => { messageBus.Publish <AutobernerStopWatchingMessage>(); }, TaskContinuationOptions.OnlyOnFaulted); }
private async Task <NetworkStream> ConnectApiMiner() { var messageBus = _messageCommunicationFactory.Create(); try { var clientApiMiner = new TcpClient(); await clientApiMiner.ConnectAsync(_config.IP, _config.Port); var stream = clientApiMiner.GetStream(); messageBus.Handle(new MinerApiStatus { Avaible = true }); return(stream); } catch (Exception ex) { messageBus.Handle(new MinerApiStatus { Avaible = false }); _logger.Error("can't connect to api minerController"); throw new FarmException(ex, ErrorCode.ConnectionError); } }
public void Start() => Task.Factory.StartNew(async(obj) => { var bus = _messageCommunicationFactory.Create(); do { if (_currentState != null) { foreach (var condition in _configure.Condtitions.Where(x => !x.IsLock()).AsParallel()) { condition.Lock(bus, TimeSpan.FromMinutes(1)); var listResult = new List <string>(0); var resultAggregate = true; foreach (var model in condition.Model) { var resut = _visitor.Validate(model, _currentState); listResult.AddRange(resut.AdditionInfo); resultAggregate &= resut.IsValid; } if (resultAggregate) { foreach (var exec in condition.PositiveExec) { bus.Execute(exec); } } else { foreach (var exec in condition.NegativeExec) { bus.Execute(exec); } } condition.UnLock(); if (listResult.Any()) { listResult.ForEach(_logger.Warn); } } } await Task.Delay(_configure.CheckInterval); } while (_ctx.IsCancellationRequested); }, _ctx, TaskCreationOptions.LongRunning);
public MinerController(MinerConfigure configuration, MessageCommunicationFactory messageCommunicationFactory) { _messageBus = messageCommunicationFactory.Create(); _config = configuration; }