public Application(IRenderer renderer, ICancellationSource cancellationSource, IInitializer initializer, IGenerationProcessor generationProcessor) { _cancellationToken = cancellationSource.GetCancellationToken(); _renderer = renderer; _initializer = initializer; _generationProcessor = generationProcessor; }
/// <summary> /// Configures the cancellation source. /// </summary> /// <param name="cancellationToken">The cancellation token to use for cancellation requests.</param> protected virtual void ConfigureCancellationSource(CancellationToken cancellationToken) { cancellationSource?.Dispose(); cancellationSource = cancellationSourceFactory.Create(cancellationToken); if (cancellationSource == null) { throw new InvalidOperationException("The cancellation source factory did not create a cancellation source."); } }
private void InitializeCancellationSource() { cancellationSource?.Dispose(); cancellationSource = cancellationSourceFactory.Create(CancellationToken.None); if (cancellationSource == null) { throw new InvalidOperationException("The cancellation source factory did not produce a cancellation source."); } }
internal static async Task <TReturn> ExecAsync <TReturn>( Func <Task <TReturn> > operation, IJobExceptionState jobExceptionState, ICancellationSource cancellationSource, ILogger logger) { try { logger.Verbose("Before try operation"); var result = await operation().ConfigureAwait(false); logger.Verbose("After try operation"); return(result); } catch (OperationCanceledException operationCanceledException) { logger.Verbose("Caught OperationCanceledException"); if (!cancellationSource.IsCancellationRequested) { logger.Verbose("Before log OperationCanceledException"); HandleException(jobExceptionState, operationCanceledException, logger.Warning); logger.Verbose("After log OperationCanceledException"); } } catch (AggregateException aggregateException) { logger.Verbose("Caught AggregateException"); aggregateException.Handle((e) => { if (e is OperationCanceledException) { if (!cancellationSource.IsCancellationRequested) { logger.Verbose("Before log aggregate's OperationCanceledException"); HandleException(jobExceptionState, e, logger.Warning); logger.Verbose("After log aggregate's OperationCanceledException"); } return(true); } logger.Verbose("Before log aggregate's other inner exception"); HandleException(jobExceptionState, e, logger.Error); logger.Verbose("After log aggregate's other inner exception"); return(false); }); } catch (Exception exception) { logger.Verbose("Before log Exception"); HandleException(jobExceptionState, exception, logger.Error); logger.Verbose("After log Exception"); } return(default(TReturn)); }
internal static async Task ExecAsync( Func <Task> operation, IJobExceptionState jobExceptionState, ICancellationSource cancellationSource, ILogger logger) { await ExecAsync(async() => { await operation().ConfigureAwait(false); return(0); }, jobExceptionState, cancellationSource, logger); }