Beispiel #1
0
        public void MarkFilesAsUsed(IEnumerable <Guid> fileIds)
        {
            AssertionHelper.AssertNotNull(fileIds, "fileIds");

            try
            {
                foreach (Guid id in fileIds)
                {
                    this.MarkFileAsUsed(id);
                }
            }
            catch (UploadSessionFileNotRegisteredException e)
            {
                throw new UploadSessionFileNotRegisteredException(string.Format(Resources.Messages.Error_UploadSession_MarkFilesAsUsedMethod_FileIsNotRegistered, this.Id), e);
            }
        }
        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();
        }
Beispiel #3
0
 private void SetFileDescriptions(List <FileUploadDescription> fileDescriptions)
 {
     AssertionHelper.AssertNotNull(fileDescriptions, "fileDescriptions", Resources.Messages.Error_UploadSession_FileDescriptions_IsNullOrEmpty);
     AssertionHelper.AssertNotEmpty(fileDescriptions, "fileDescriptions", Resources.Messages.Error_UploadSession_FileDescriptions_IsNullOrEmpty);
     this.InnerFileDescriptions = fileDescriptions;
 }