public void SetValue(ExecutionContext context, string value) { if (_scenario != null) { if (_scenario.GetInitializationState() == ScenarioInitializationValue.NotInitialized) { _scenario.FullInitialize().Wait(); } else { while (_scenario.GetInitializationState() == ScenarioInitializationValue.Initializing) { SystemUtils.Sleep(100, context.CancellationTokenSource); } } var executionId = string.Empty; if (Mode == RunExistingScenarioMode.Asynchronously) { _scenario?.ExecuteAsyncParallel(ScenarioActionSource, value, context); } else if (Mode == RunExistingScenarioMode.Synchronously) { _scenario?.Execute(ScenarioActionSource, value, out executionId, context); } else if (Mode == RunExistingScenarioMode.MainExecutionContext) { _scenario?.ExecuteAsync(ScenarioActionSource, value, out executionId, context); } } }
private void StartListen() { StopListen(); _isListening = true; _timerCancellationToken = new CancellationTokenSource(); TaskUtils.StartLongRunning( () => { var server = ClientFactory.GetServer(Credentials); while (!_timerCancellationToken.IsCancellationRequested && ServerScenariosInfos.Any()) { for (var i = 0; i < ServerScenariosInfos.Count; i++) { if (i >= ServerScenariosInfos.Count) { i = 0; } if (!ServerScenariosInfos.Any() || _timerCancellationToken.IsCancellationRequested) { break; } var info = ServerScenariosInfos[i]; var error = false; Log.DebugFormat("Remote scenario refresh iteration begin: [{0}]; remote id: [{1}]", info.Name, info.ScenarioId); HandleExceptions( () => { var newScenInfo = server.GetScenarioInfo(new Encrypted <string>(info.ScenarioId, Credentials.SecretKey)).Decrypt(Credentials.SecretKey); if (!info.Unregistered) { info.ValueChangedCallback(new RemoteScenarioValueChangedArgs(info, newScenInfo)); } }, () => { error = true; if (!info.Unregistered) { info.IsAvailableChangedCallback(new RemoteScenarioAvailabilityChangedArgs(info, false)); } }, info); Log.DebugFormat("Remote scenario refresh iteration end: [{0}]; remote id: [{1}]", info.Name, info.ScenarioId); if (!ServerScenariosInfos.Any() || _timerCancellationToken.IsCancellationRequested) { break; } var timeout = error ? CalculateTimeoutOnError() : CalculateTimeout(); SystemUtils.Sleep(timeout, _timerCancellationToken.Token); } } StopListen(); }, (e) => Log.Error("Ошибка во время выполнения прослушивания удаленных сценариев", e)); }
public void SetValue(ExecutionContext context, string value) { while (Checker.Evaluate(context)) { if (context.CancellationTokenSource.IsCancellationRequested) { break; } Action.SetValue(context, string.Empty); SystemUtils.Sleep(WhileIterationsInterval, context.CancellationTokenSource.Token); } }
public string GetValue(ExecutionContext context) { if (_scenario != null) { if (_scenario.GetInitializationState() == ScenarioInitializationValue.NotInitialized) { _scenario.FullInitialize().Wait(); } else { while (_scenario.GetInitializationState() == ScenarioInitializationValue.Initializing) { SystemUtils.Sleep(100, context.CancellationTokenSource); } } return(_scenario.CalculateCurrentValue(ScenarioActionSource, context)); } return(string.Empty); }
private void StartListen() { StopListen(); _isListening = true; _timerCancellationToken = new SafeCancellationToken(); TaskUtils.StartLongRunning( () => { while (!_timerCancellationToken.IsCancellationRequested && ServerScenariosInfos.Any()) { for (var i = 0; i < ServerScenariosInfos.Count; i++) { if (i >= ServerScenariosInfos.Count) { i = 0; } if (!ServerScenariosInfos.Any() || _timerCancellationToken.IsCancellationRequested) { break; } var info = ServerScenariosInfos[i]; var error = false; Log.Debug($"Remote scenario refresh iteration begin: [{info.Name}][{info.ScenarioId}]"); try { var client = ServiceClientFactory.Current.GetClient(Credentials); var newScenInfo = TaskUtils.Wait(client.GetScenarioInfo(info.ScenarioId)); if (!info.Unregistered) { info.ValueChangedCallback(new RemoteScenarioValueChangedArgs(info, newScenInfo)); } } catch (Exception e) { Log.Info($"Ошибка во время соединения с удаленным сценарием. {e.Message}. Сценарий: [{info.Name}]:[{info.ScenarioId}]"); error = true; if (!info.Unregistered) { info.IsAvailableChangedCallback(new RemoteScenarioAvailabilityChangedArgs(info, false)); } } Log.Debug($"Remote scenario refresh iteration end: [{info.Name}][{info.ScenarioId}]"); if (!ServerScenariosInfos.Any() || _timerCancellationToken.IsCancellationRequested) { break; } var timeout = error ? CalculateTimeoutOnError() : CalculateTimeout(); SystemUtils.Sleep(timeout, _timerCancellationToken); } } StopListen(); }, (e) => Log.Error("Ошибка во время прослушивания удаленных сценариев", e)); }