private static void AssertCorrectReturnType <T>(IResultProcessor processor) { if (processor == null && typeof(T) != typeof(int)) { throw new ArgumentException($"Attempted to run a non-query command with the return type '{typeof(T).FullName}'. Non-query commands must return the type 'int'.", "T"); } }
public BacklogItem(IRedisCommand redisCommand, CancellationToken cancellationToken, TaskCompletionSource <T> taskCompletionSource, IResultProcessor <T> resultProcessor) { RedisCommand = redisCommand; CancellationToken = cancellationToken; TaskCompletionSource = taskCompletionSource; ResultProcessor = resultProcessor; }
public ResultController(IResultProcessor resultProcessor, ITokenProvider tokenProvider, IValidator <ResultRequestDto> resultRequestValidator, IValidator <EmptyResultRequestDto> emptyResultRequestValidator) { _resultProcessor = resultProcessor; _tokenProvider = tokenProvider; _resultRequestValidator = resultRequestValidator; _emptyResultRequestValidator = emptyResultRequestValidator; }
public AwsScoreProcessor(IS3EventNotificationMessageParser s3EventNotificationMessageParser, IS3DataProvider s3DataProvider, ISqsMessageDeleter sqsMessageDeleter, IResultProcessor resultProcessor) { _s3DataProvider = s3DataProvider; _sqsMessageDeleter = sqsMessageDeleter; _resultProcessor = resultProcessor; _s3EventNotificationMessageParser = s3EventNotificationMessageParser; }
public ResultsController( IResultProcessor resultProcessor, ILogger <ResultsController> logger, FileProcessingChannel fileProcessingChannel) { _resultProcessor = resultProcessor; _logger = logger; _fileProcessingChannel = fileProcessingChannel; }
/// <summary> /// Queues a command and returns a deferred reference to the result. /// </summary> /// <typeparam name="T">Result type.</typeparam> /// <param name="context">The SQL context.</param> /// <param name="processor">The processor.</param> /// <returns>Deferred<T>.</returns> private Deferred <T> DeferCommand <T>(IContext context, IResultProcessor processor) { _context.Append(context); var deferredResult = new Deferred <T>(this); _processors.Add(new ProcessorContext { Processer = processor, Deferred = deferredResult }); return(deferredResult); }
public ResultsController( IResultProcessor resultProcessor, ILogger <ResultsController> logger, FileProcessingChannel fileProcessingChannel, IAmazonS3 amazonS3, IOptions <ScoreProcesingConfiguration> options) { _resultProcessor = resultProcessor; _logger = logger; _fileProcessingChannel = fileProcessingChannel; _amazonS3 = amazonS3; _s3BucketName = options.Value.S3BucketName; }
internal async ValueTask <T> SendAndReceive_Impl <T>(IRedisCommand command, IResultProcessor <T> resultProcessor, CancellationToken cancellationToken, bool isReconnectionAttempt) { IsBusy = true; Log.Debug($"Executing Command: {command}"); LastCommand = command; Interlocked.Increment(ref _operationsPerformed); try { if (!isReconnectionAttempt) { await _sendAndReceiveSemaphoreSlim.WaitAsync(cancellationToken).ConfigureAwait(false); if (!IsConnected) { await TryConnectAsync(cancellationToken).ConfigureAwait(false); } } await Write(command); LastAction = "Reading Bytes Async"; return(await resultProcessor.Start(this, _pipe)); } catch (Exception innerException) { if (innerException.IsSameOrSubclassOf(typeof(RedisException)) || innerException.IsSameOrSubclassOf(typeof(OperationCanceledException))) { throw; } DisposeNetwork(); IsConnected = false; throw new RedisConnectionException(innerException); } finally { Interlocked.Decrement(ref _outStandingOperations); if (!isReconnectionAttempt) { _sendAndReceiveSemaphoreSlim.Release(); } IsBusy = false; } }
public static void Start(IResultProcessor resultProcessor, int listeningPort) { var host = new WebHostBuilder() .UseUrls($"http://*:{listeningPort}") .UseKestrel() .UseContentRoot(Directory.GetCurrentDirectory()) .ConfigureServices((c, s) => { s.AddSingleton <IResultProcessor>(resultProcessor); }) .UseStartup <WebApiStartup>() .Build(); host.Start(); }
private ValueTask <T> QueueToBacklog <T>(IRedisCommand command, IResultProcessor <T> resultProcessor, CancellationToken cancellationToken) { var taskCompletionSource = new TaskCompletionSource <T>(); var backlogQueueCount = _backlog.Count; _backlog.Enqueue(new BacklogItem <T>(command, cancellationToken, taskCompletionSource, resultProcessor)); if (backlogQueueCount == 0) { StartBacklogProcessor(); } return(new ValueTask <T>(taskCompletionSource.Task)); }
/// <summary> /// Run the specified SQL command as an asynchronous operation. /// </summary> /// <typeparam name="T">The expected result type.</typeparam> /// <param name="context">The SQL context to run.</param> /// <param name="processor"> /// The query processor. If this value is null, a non-query type command /// is assumed and the integer type will be assumed. /// </param> /// <param name="cancel">A token to monitor for cancellation requests.</param> /// <returns>An asynchronous task for the query result.</returns> private async Task <T> RunCommandAsync <T>(IContext context, IResultProcessor processor = null, CancellationToken cancel = default) { AssertCorrectReturnType <T>(processor); using (var connection = await CreateConnectionAsync()) { using (var command = connection.CreateCommand()) { // initialize command command.Connection = connection; command.CommandText = context.CommandText; AddParametersToCommand(command, context); object result; using (var scope = CreateScope(context)) { try { await connection.OpenAsync(cancel); if (processor == null) { result = await command.ExecuteNonQueryAsync(cancel); } else { using (var reader = await command.ExecuteReaderAsync(cancel)) { result = processor.Process(reader); } } connection.Close(); } catch { scope.Span.SetTag(Tags.Error, true); throw; } } return((T)result); } } }
/// <summary> /// Run the specified SQL command as an normal, thread-blocking operation. /// </summary> /// <typeparam name="T">The expected result type.</typeparam> /// <param name="context">The SQL context to run.</param> /// <param name="processor"> /// The query processor. If this value is null, a non-query type command /// is assumed and the integer type will be assumed. /// </param> /// <returns>An asynchronous task for the query result.</returns> private T RunCommand <T>(IContext context, IResultProcessor processor = null) { AssertCorrectReturnType <T>(processor); using (var connection = AsyncHelper.RunSync(() => CreateConnectionAsync())) { using (var command = connection.CreateCommand()) { // initialize command command.Connection = connection; command.CommandText = context.CommandText; AddParametersToCommand(command, context); object result; using (var scope = CreateScope(context)) { try { connection.Open(); if (processor == null) { result = command.ExecuteNonQuery(); } else { using (var reader = command.ExecuteReader()) { result = processor.Process(reader); } } connection.Close(); } catch { scope.Span.SetTag(Tags.Error, true); throw; } } return((T)result); } } }
//[MethodImpl(MethodImplOptions.AggressiveInlining)] internal ValueTask <T> SendAndReceiveAsync <T>(IRedisCommand command, IResultProcessor <T> resultProcessor, CancellationToken cancellationToken, bool isReconnectionAttempt = false) { LastUsed = DateTime.Now; LastAction = "Throwing Cancelled Exception due to Cancelled Token"; cancellationToken.ThrowIfCancellationRequested(); Interlocked.Increment(ref _outStandingOperations); if (!isReconnectionAttempt && CanQueueToBacklog && IsBusy) { return(QueueToBacklog(command, resultProcessor, cancellationToken)); } return(SendAndReceive_Impl(command, resultProcessor, cancellationToken, isReconnectionAttempt)); }
public ResultProcessingFunction(IResultProcessor service, IDateTimeProvider dateTimeProvider) { this.service = service; this.dateTimeProvider = dateTimeProvider; }
public McsResultController(IResultProcessor processor) { this.processor = processor; }
public ProcessRunner(IDictionaryProvider dictionaryProvider, IShortestPathCalculator shortestPathCalculator, IResultProcessor resultProcessor) { _dictionaryProvider = dictionaryProvider; _shortestPathCalculator = shortestPathCalculator; _resultProcessor = resultProcessor; }
protected QueryBase(IResultProcessor <T> resultProcessor = null) { _resultProcessor = resultProcessor ?? new DefaultResultProcessor <T>(); }
public ResultController(IResultProcessor resultProcessor) { _resultProcessor = resultProcessor; }
public ResultFileWriter(string directory, object consoleLock, IResultProcessor nextProcessor = null) { this.directory = directory; this.consoleLock = consoleLock; this.nextProcessor = nextProcessor; }
private void InjectionInitialize( ICharacterService characterService, IComicService comicService, ICreatorService creatorService, ISeriesService seriesService, IEventService eventService, ILoadingManager loadingManager, IScreenManager screenManager, IEventManager eventManager, IResultProcessor resultProcessor, IPlanetSystemSpawner planetSystemSpawner, SearchViewModel searchViewModel) { this.characterService = characterService; this.comicService = comicService; this.creatorService = creatorService; this.seriesService = seriesService; this.eventService = eventService; this.loadingManager = loadingManager; this.screenManager = screenManager; this.eventManager = eventManager; this.resultProcessor = resultProcessor; this.planetSystemSpawner = planetSystemSpawner; this.searchViewModel = searchViewModel; this.eventManager.GetEvent<LoadingEvent>().AddListener(this.OnLoading); }
public ConsoleResultPrinter(object consoleLock, IResultProcessor nextProcessor = null) { this.consoleLock = consoleLock; this.nextProcessor = nextProcessor; }
public ResultsController(IResultProcessor resultProcessor, ILogger <ResultsController> logger) { _resultProcessor = resultProcessor; _logger = logger; }
public ResultInvoker(IResultProcessor <TActionMethodResult, TExecutedCommandResult> resultProcessor, IGenericMapper mapper, IErrorAspect errorAspect) { _resultProcessor = resultProcessor; _errorAspect = errorAspect; _mapper = mapper; }