public async Task <Document> AddAsync(Document entity)
        {
            var createdEntity = await _DocumentRepository.AddAsync(entity);

            //  await _BaseRepository.Sav();
            return(createdEntity);
        }
        public async Task <Document> TrainDocument(Document document)
        {
            ProcessedDocument processedDocument = _iPreProcessTextService.PreProcessDocument(document);

            _iLearningService.Train(processedDocument);
            return(await _documentRepository.AddAsync(document));
        }
Пример #3
0
        public async Task <int> CreateAsync(Guid id, Guid templateId, Guid templateVersionId, Guid currentVersion, string name, string userId, string content)
        {
            var document = new Document(id, templateId, templateVersionId, currentVersion, name, userId, content);
            await _documentRepository.AddAsync(document);

            return(0);
        }
Пример #4
0
        public async Task <DocumentView> ProcessAsync(Subject subject, DocumentProcessingAction[] documentProcessingActions)
        {
            if (subject is AddDocumentSubject newDocument)
            {
                var document = new Document
                {
                    Id      = newDocument.Id,
                    Content = newDocument.Content
                };
                await _documentRepository.AddAsync(document);

                var archivist = _archivistFactory.CreateArchivistChain(documentProcessingActions);
                var result    = archivist.Rethink(document);
                await _documentRepository.UpdateAsync(result);

                return(new DocumentView <DocumentProcessingResultContent>
                {
                    Type = DocumentViewType.Ok,
                    Content = new DocumentProcessingResultContent {
                        ProcessingResultType = DocumentProcessingResultType.Added
                    }
                });
            }
            throw new DocumentProcessingStrategyException($"Invalid subject type - {subject.GetType()}. It should be {typeof(AddDocumentSubject)}.");
        }
Пример #5
0
        public async Task HandleAsync(AddDocument command, ICorrelationContext context)
        {
            _logger.LogInformation($"Adding a document: name = {command.FileName}' documentId = '{command.Id}'");
            var document = new Document(command.Id, command.FileName, command.FileArray, command.ExternalId);
            await _documentRepository.AddAsync(document);

            _logger.LogInformation($"Added a document: name = {command.FileName}' documentId = '{command.Id}'");
            await _busPublisher.PublishAsync(new DocumentAdded(command.Id, command.FileName, command.FileArray, command.ExternalId), context);
        }
        public async Task addasync_invoke_once_time()
        {
            //Arrange
            _mockMongoRepository.Setup(s => s.AddAsync(_document)).Returns(Task.CompletedTask);

            //Act
            await _repository.AddAsync(_document);

            //Assert
            _mockMongoRepository.Verify(r => r.AddAsync(_document), Times.Once);
        }
        public async Task <ActionResult> CreateAsync([Bind("Id,Name,Description,Completed")] Item item)
        {
            if (ModelState.IsValid)
            {
                await _repository.AddAsync(item);

                return(RedirectToAction("Index"));
            }

            return(View(item));
        }
Пример #8
0
        public async Task <Document> AddAsync(string userId)
        {
            var document = new DocumentEntity
            {
                Created = DateTime.UtcNow,
                Id      = Guid.NewGuid().ToString("N"),
                Name    = NewDocumentName,
                UserId  = userId
            };

            await _documentsRepository.AddAsync(document);

            return(_mapper.Map <Document>(document));
        }
Пример #9
0
        public async Task <Document> Add(Document entity)
        {
            var document = new Document()
            {
                CreatedDate = DateTime.Now,
                Ip          = httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString(),
                Length      = entity.Length,
                LocalName   = entity.LocalName,
                ObjectId    = entity.ObjectId,
                ServerName  = entity.ServerName,
                UpdateDate  = DateTime.Now,
                UploadBy    = entity.UploadBy,
            };

            await documentRepository.AddAsync(document);

            return(document);
        }
Пример #10
0
        public async Task <bool> Handle(CreateOrUpdateDocumentCommand request, CancellationToken cancellationToken = default)
        {
            var path = request.Path;

            if (await _documentRepository.IsContainerPath(path.ToString()))
            {
                throw new InvalidOperationException();
            }

            // ドキュメントの存在チェック
            var document = await _documentRepository.GetAsync(path.ToString());

            // ファイル情報の取得
            try
            {
                if (!ContentTypeProvider.TryGetContentType(path.Extension, out var contentType))
                {
                    contentType = "application/octet-stream";
                }
                if (document == null)
                {
                    var utcNow = DateTime.UtcNow;
                    document = new Document(
                        new DocumentPath(path.ToString()),
                        contentType,
                        request.Data,
                        request.Created ?? utcNow,
                        request.LastModified ?? request.Created ?? utcNow);
                    await _documentRepository.AddAsync(document).ConfigureAwait(false);
                }
                else if (request.ForceCreate)
                {
                    var retryCount = 0;
                    var dirPath    = path.DirectoryPath;
                    var fnwoe      = path.FileNameWithoutExtension;
                    var ext        = path.Extension;
                    var filename   = path;
                    while (document != null)
                    {
                        retryCount++;
                        filename = dirPath.Combine(fnwoe + $"({retryCount})" + ext);
                        document = await _documentRepository.GetAsync(filename.ToString());
                    }

                    var utcNow = DateTime.UtcNow;
                    document = new Document(
                        new DocumentPath(filename.ToString()),
                        contentType,
                        request.Data,
                        request.Created ?? utcNow,
                        request.LastModified ?? request.Created ?? utcNow);
                    await _documentRepository.AddAsync(document).ConfigureAwait(false);
                }
                else
                {
                    var utcNow = DateTime.UtcNow;

                    if (request.Data.Hash == document.Hash)
                    {
                        await _dataStore.DeleteAsync(request.Data.StorageKey).ConfigureAwait(false);

                        if (request.Created != document.Created ||
                            request.LastModified != document.LastModified ||
                            contentType != document.ContentType)
                        {
                            var oldData = await _dataStore.FindAsync(document.StorageKey);

                            if (oldData == null)
                            {
                                document.Update(
                                    contentType,
                                    request.Data,
                                    request.Created ?? document.Created,
                                    request.LastModified ?? utcNow);
                            }
                            else
                            {
                                document.Update(
                                    contentType,
                                    oldData,
                                    request.Created ?? document.Created,
                                    request.LastModified ?? utcNow);
                            }
                        }
                    }
                    else
                    {
                        document.Update(
                            contentType,
                            request.Data,
                            request.Created ?? document.Created,
                            request.LastModified ?? utcNow);
                    }
                    await _documentRepository.UpdateAsync(document);
                }
                await _documentRepository.UnitOfWork.SaveEntitiesAsync().ConfigureAwait(false);

                return(true);
            }
            catch
            {
                await _dataStore.DeleteAsync(request.Data.StorageKey).ConfigureAwait(false);

                throw;
            }
        }