コード例 #1
0
        public async Task <PagedData <Product> > HandleAsync(Requests.GetAllProductsPagedRequest request, CancellationToken cancellationToken = default(CancellationToken))
        {
            var allProductsPaged = _allProductsPaged.FetchAsync(new Queries.AllProductsPagedQry
            {
                Offset   = request.Offset,
                PageSize = request.PageSize
            });

            var productsCount = _productsCount.FetchAsync(new Queries.ProductsCountQry());

            Task.WaitAll(allProductsPaged, productsCount);

            return(new PagedData <Product>
            {
                Offset = request.Offset,
                PageSize = request.PageSize,
                Data = await allProductsPaged,
                TotalRecords = await productsCount
            });
        }
コード例 #2
0
        public async Task <IQueryResult <TDto> > FetchAsync(TQuery query)
        {
            _logger.LogTrace($"Query handling started {typeof(TQuery).Name} at [{_session.Clock.UtcNow}] by [{_session.User}]");
            IQueryResult <TDto> result;
            var sw = Stopwatch.StartNew();

            try
            {
                result = await _handler.FetchAsync(query);
            }
            catch (Exception e)
            {
                sw.Stop();
                var message =
                    $"Query handling completed with error {typeof(TQuery).Name} at [{_session.Clock.UtcNow}] by [{_session.User}] in {sw.ElapsedMilliseconds}ms";
                _logger.LogTrace(message);
                _logger.LogError(e, message);
                throw;
            }

            sw.Stop();
            _logger.LogTrace($"Query handling completed {typeof(TQuery).Name} at [{_session.Clock.UtcNow}] by [{_session.User}] in {sw.ElapsedMilliseconds}ms");
            return(result);
        }