コード例 #1
0
        /// <inheritdoc />
        public Task <Unit> Handle(DeleteRangeRequest <T> request, CancellationToken cancellationToken, RequestHandlerDelegate <Unit> next)
        {
            if (request == default)
            {
                throw new ArgumentNullException(nameof(request));
            }

            if (next == default)
            {
                throw new ArgumentNullException(nameof(next));
            }

            if (!_options.UseScopedLogging)
            {
                return(Handle());
            }

            using (request.Scope)
            {
                return(Handle());
            }

            async Task <Unit> Handle()
            {
                var start = new DeleteRangeNotification <T>(request.Expressions, request.Logger);
                await _mediator.Publish(start, cancellationToken).ConfigureAwait(false);

                var response = await next().ConfigureAwait(false);

                var finish = new DeleteRangeNotification(request.Logger);
                await _mediator.Publish(finish, cancellationToken).ConfigureAwait(false);

                return(response);
            }
        }
コード例 #2
0
        public Task Handle(DeleteRangeNotification <TId> notification, CancellationToken cancellationToken)
        {
            if (notification == default)
            {
                throw new ArgumentNullException(nameof(notification));
            }

            foreach (var key in notification.Keys)
            {
                _cache.Remove(key);
            }

            return(_database.KeyDeleteAsync(notification.Keys.Select <TId, RedisKey>(x => x.ToString()).ToArray(), FireAndForget));
        }
コード例 #3
0
        public async Task <IActionResult> DeleteAssets(
            [SwaggerParameter("The Asset Ids", Required = true), FromQuery, Required] Guid[] ids,
            CancellationToken cancellationToken)
        {
            if (ids == default || ids.Length == 0)
            {
                ModelState.AddModelError(nameof(ids), "Ids are required");
                return(BadRequest(ModelState));
            }

            var expressions = ids.Select(id => (Expression <Func <Asset, bool> >)(asset => asset.Id == id));
            var request     = new DeleteRangeRequest <Asset>(nameof(MongoDB), expressions.ToArray(), _logger);
            await _mediator.Send(request, cancellationToken).ConfigureAwait(false);

            var notification = new DeleteRangeNotification <Guid>(ids);
            await _mediator.Publish(notification, cancellationToken).ConfigureAwait(false);

            return(NoContent());
        }