Пример #1
0
        private static async Task <QueryContext> CreateAsyncCore(IDbConnectionFactory connectionFactory, QueryLoggingContext loggingContext, CancellationToken cancellationToken)
        {
            if (SemaphoreLookup.TryGetValue(connectionFactory, out var semaphore))
            {
                await semaphore.WaitAsync(cancellationToken).ConfigureAwait(false);

                try
                {
                    loggingContext.Start();
                    return(new QueryContext(semaphore, loggingContext));
                }
                finally
                {
                    semaphore.Release();
                }
            }
            else
            {
                loggingContext.Start();
                return(new QueryContext(loggingContext));
            }
        }
Пример #2
0
 private QueryContext(AsyncSemaphore semaphore, QueryLoggingContext loggingContext)
 {
     _semaphore      = semaphore ?? throw new ArgumentNullException(nameof(semaphore));
     _loggingContext = loggingContext ?? throw new ArgumentNullException(nameof(loggingContext));
 }
Пример #3
0
        public static Task <QueryContext> CreateAsync(IDbConnectionFactory connectionFactory, QueryLoggingContext loggingContext, CancellationToken cancellationToken = default)
        {
            if (connectionFactory == null)
            {
                throw new ArgumentNullException(nameof(connectionFactory));
            }
            if (loggingContext == null)
            {
                throw new ArgumentNullException(nameof(loggingContext));
            }

            return(CreateAsyncCore(connectionFactory, loggingContext, cancellationToken));
        }
Пример #4
0
 private QueryContext(QueryLoggingContext loggingContext)
 {
     _loggingContext = loggingContext ?? throw new ArgumentNullException(nameof(loggingContext));
 }