Beispiel #1
0
        public async Task <GetDocumentStreamQueryResult> RetrieveAsync(GetDocumentStreamQuery query, CancellationToken cancellationToken = default)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                _logger.LogInformation($"{nameof(GetDocumentStreamQueryHandler)}.{nameof(RetrieveAsync)} was cancelled before execution");
                cancellationToken.ThrowIfCancellationRequested();
            }

            using (var context = _projectionDbContextFactory.Create())
            {
                var document = await context.Set <Document>().FindAsync(new object[] { query.Subject }, cancellationToken);

                if (document is null)
                {
                    throw new ArgumentNullException(nameof(document));
                }

                if (!_contentTypeProvider.TryGetContentType(document.FileName, out var contentType))
                {
                    contentType = "application/octet-stream";
                }


                var result = new GetDocumentStreamQueryResult(new MemoryStream(), contentType, document.FileName);

                await _fileClient.DownloadAsync($"{query.Subject}{Path.GetExtension(document.FileName)}", query.Actor, result.Stream, cancellationToken);

                result.Stream.Position = 0;
                return(result);
            }
        }
Beispiel #2
0
        public async Task <TView> AddAsync(string subject, Func <TView> add, CancellationToken cancellationToken = default)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                _logger.LogInformation($"{nameof(EntityFrameworkCoreProjectionWriter<TView>)}.{nameof(AddAsync)} was cancelled before execution");
                cancellationToken.ThrowIfCancellationRequested();
            }

            var entity = add();

            using (var context = _projectionDbContextFactory.Create())
            {
                await context.Set <TView>().AddAsync(entity);

                await context.SaveChangesAsync(cancellationToken);
            }

            return(entity);
        }
Beispiel #3
0
        public async Task ResetAsync(CancellationToken cancellationToken = default)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                _logger.LogInformation($"{nameof(StoreProjector<TProjection>)}.{nameof(ResetAsync)} was cancelled before execution");
                cancellationToken.ThrowIfCancellationRequested();
            }

            using (var context = _projectionDbContextFactory.Create())
            {
                var state = await context.ProjectionStates.FindAsync(_name);

                if (state != null)
                {
                    state.Position         = 0;
                    state.LastModifiedDate = DateTimeOffset.UtcNow;

                    await context.SaveChangesAsync(cancellationToken);
                }

                await _projectionManager.ResetAsync(cancellationToken);
            }
        }
        public async Task <GetTranslationOptionsQueryResult> RetrieveAsync(GetTranslationOptionsQuery query, CancellationToken cancellationToken = default)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                _logger.LogInformation($"{nameof(GetTranslationOptionsQueryHandler)}.{nameof(RetrieveAsync)} was cancelled before execution");
                cancellationToken.ThrowIfCancellationRequested();
            }

            using (var context = _projectionDbContextFactory.Create())
            {
                var translationOptions = await context.Set <TranslationOption>()
                                         .AsNoTracking()
                                         .AsQueryable()
                                         .OrderBy(to => to.Subject)
                                         .ToArrayAsync(cancellationToken);

                return(new GetTranslationOptionsQueryResult(translationOptions));
            }
        }
Beispiel #5
0
        public async Task <GetDocumentsForUserQueryResult> RetrieveAsync(GetDocumentsForUserQuery query, CancellationToken cancellationToken = default)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                _logger.LogInformation($"{nameof(GetDocumentsForUserQueryHandler)}.{nameof(RetrieveAsync)} was cancelled before execution");
                cancellationToken.ThrowIfCancellationRequested();
            }

            using (var context = _projectionDbContextFactory.Create())
            {
                var documents = await context.Set <UserDocuments>().Where(ud => ud.UserId == query.Actor)
                                .AsNoTracking()
                                .AsQueryable()
                                .Include(ud => ud.Documents)
                                .SelectMany(ud => ud.Documents)
                                .Skip((query.Page - 1) * query.PageSize)
                                .Take(query.PageSize)
                                .ToArrayAsync(cancellationToken);

                return(new GetDocumentsForUserQueryResult(documents));
            }
        }