Esempio n. 1
0
        public async override Task MarkFilesAsUsedAsync(MarkFilesAsUsedCommand command)
        {
            this.Logger.LogInformation("[Start] {0} received.", command.GetType().Name);

            if (command != null)
            {
                this.Logger.LogInformation("[Start] Processing {0} with id = '{1}' and correlationId = '{2}'. Marking files in the upload session as in use.",
                                           command.GetType().Name, command.CommandId, command.CorrelationId);
            }

            await base.MarkFilesAsUsedAsync(command);

            if (command != null)
            {
                this.Logger.LogInformation("[Finish] Processing {0} with id = '{1}' and correlationId = '{2}'. Marking files in the upload session as in use.",
                                           command.GetType().Name, command.CommandId, command.CorrelationId);
            }

            this.Logger.LogInformation("[Finish] {0} received.", command.GetType().Name);
        }
        public async Task MarkFilesAsUsed_GivenValidArgsAndSessionEnded_DoesNotThrowException()
        {
            // Arrange
            string        sessionId = "273fbe3c-5e1d-47ea-bef3-d37783e10dd1";
            string        file01Id  = "939be7f6-33ef-412b-850f-c27f240a7787";
            string        file02Id  = "2c10700b-6779-4621-9117-eb4c9c41fa72";
            List <string> fileIds   = new List <string>()
            {
                file01Id,
                file02Id
            };

            MarkFilesAsUsedCommand command = new MarkFilesAsUsedCommand(Guid.NewGuid().ToString(),
                                                                        Guid.NewGuid().ToString(),
                                                                        new CommandIssuer(Guid.NewGuid().ToString(), Guid.NewGuid().ToString()),
                                                                        fileIds);
            var applicationService             = this.Fixture.Kernel.Get <IFileStorageCommandApplicationService>();
            var uploadSessionRepository        = this.Fixture.Kernel.Get <IUploadSessionRepository>();
            var fileInformationIndexRepository = this.Fixture.Kernel.Get <IFileInformationIndexRepository>();

            // Act
            await applicationService.MarkFilesAsUsedAsync(command);

            // Assert
            UploadSession session = await uploadSessionRepository.GetByIdAsync(new Guid(sessionId));

            FileInformationIndex index01 = await fileInformationIndexRepository.GetByIdAsync(new Guid(file01Id));

            FileInformationIndex index02 = await fileInformationIndexRepository.GetByIdAsync(new Guid(file02Id));

            Assert.NotNull(session);
            Assert.Equal(sessionId, session.Id.ToString());
            Assert.True(session.AreAllFilesInUse);
            Assert.NotNull(index01);
            Assert.NotNull(index02);
        }
        public async Task MarkFilesAsUsedAsync(MarkFilesAsUsedCommand command)
        {
            // VALIDATION
            AssertionHelper.AssertNotNull(command, "command");
            //TODO: Validate that file id's specified are valid guid's.
            if (command.FileIds == null || command.FileIds.Count() < 1)
            {
                //TODO: Throw exception
            }

            // Load session based on the identifier of the first file.
            UploadSession session = await this.UploadSessionRepository.GetByFileIdAsync(new Guid(command.FileIds.ElementAt(0)));

            if (session == null)
            {
                //TODO: Localize message
                throw new UploadSessionNotStartedException(string.Format("No upload session containing some of the specified files has been previously started. Please, make sure that the file identifiers have been properly uploaded correctly."));
            }

            // Mark file description in upload session as used
            session.MarkFilesAsUsed(Mapper.Map <IEnumerable <Guid> >(command.FileIds));

            // Index file information
            foreach (var id in command.FileIds)
            {
                FileUploadDescription fileDescription = session.GetFileUploadDescription(new Guid(id));
                FileInformationIndex  index           = FileInformationIndex.Create(fileDescription.Id, session.OwnerId, fileDescription.FileName, fileDescription.ContentType,
                                                                                    fileDescription.ContentLength, fileDescription.AssignedUri, session.UploadAsPublic);

                // Save index
                this.FileInformationIndexRepository.Add(index);
            }

            // Commit changes
            await this.UnitOfWork.CommitChangesAsync();
        }
Esempio n. 4
0
 public async virtual Task MarkFilesAsUsedAsync(MarkFilesAsUsedCommand command)
 {
     await this.ApplicationService.MarkFilesAsUsedAsync(command);
 }
 public async override Task MarkFilesAsUsedAsync(MarkFilesAsUsedCommand command)
 {
     await base.MarkFilesAsUsedAsync(command);
 }