예제 #1
0
        protected async Task <File> Handle(IFileCommand request, CancellationToken cancellationToken)
        {
            await this.Authorize();

            using (var lockResult = await _lockService.GetFileLock(request.Id).LockAsync(0))
            {
                if (!lockResult.AcquiredLock)
                {
                    throw new FileConflictException();
                }

                var file = await _db.Files.FindAsync(request.Id);

                if (file == null)
                {
                    throw new EntityNotFoundException <File>();
                }

                await this.PerformOperation(file);

                await _db.SaveChangesAsync(cancellationToken);
            }

            return(await _fileQuery.ExecuteAsync(request.Id));
        }
예제 #2
0
        /// <summary>
        /// Constructs a new instance of the <see cref="FileService"/>.
        /// </summary>
        /// <param name="fileCommand">Instance of <see cref="IFileCommand"/>.</param>
        /// <param name="fileRepository">Instance of <see cref="IFileRepository"/>.</param>
        public FileService(IFileCommand fileCommand, IFileRepository fileRepository,
                           IFileUploadValidationService fileUploadValidationService,
                           IConfigurationProvider configurationProvider, IMemoryCache memoryCache)
        {
            if (fileCommand is null)
            {
                throw new ArgumentNullException(nameof(fileCommand));
            }
            if (fileRepository is null)
            {
                throw new ArgumentNullException(nameof(fileRepository));
            }
            if (fileUploadValidationService is null)
            {
                throw new ArgumentNullException(nameof(fileUploadValidationService));
            }
            if (configurationProvider is null)
            {
                throw new ArgumentNullException(nameof(configurationProvider));
            }
            if (memoryCache is null)
            {
                throw new ArgumentNullException(nameof(memoryCache));
            }

            _fileCommand    = fileCommand;
            _fileRepository = fileRepository;
            _fileUploadValidationService = fileUploadValidationService;
            _configurationProvider       = configurationProvider;
            _memoryCache = memoryCache;
        }
예제 #3
0
 public FileService(ISystemClock systemClock, ILogger <DiscussionService> logger, IPermissionsService permissionsService, IFileCommand fileCommand, IFileBlobStorageProvider blobStorageProvider, IFileTypeValidator fileTypeValidator, IGroupCommand groupCommand)
 {
     _systemClock         = systemClock;
     _fileCommand         = fileCommand;
     _blobStorageProvider = blobStorageProvider;
     _permissionsService  = permissionsService;
     _fileTypeValidator   = fileTypeValidator;
     _groupCommand        = groupCommand;
     _logger = logger;
 }
예제 #4
0
 private void Consume()
 {
     while (true)
     {
         IFileCommand command = null;
         if (this.queue.TryDequeue(out command))
         {
             command.Execute();
             Thread.Sleep(500);
         }
     }
 }
        public string GetCommandDetails(string fileType)
        {
            IFileCommand cmd = null;
            FileTypes    ft;

            Enum.TryParse <FileTypes>(fileType, out ft);
            if (ft != null)
            {
                cmd = ConvertorJson.FileFactory(ft);
            }

            return(cmd.getFileDataInJson());
        }
예제 #6
0
        private const long MaxFileSizeBytes          = 5242880; // 5MB

        public GroupService(ISystemClock systemClock,
                            ILogger <DiscussionService> logger,
                            IPermissionsService permissionsService,
                            IFileCommand fileCommand,
                            IImageBlobStorageProvider blobStorageProvider,
                            IFileTypeValidator fileTypeValidator,
                            IGroupImageService imageService,
                            IGroupCommand groupCommand,
                            IHtmlSanitizer htmlSanitizer,
                            IGroupDataProvider groupDataProvider,
                            IContentService contentService)
        {
            _systemClock         = systemClock ?? throw new ArgumentNullException(nameof(systemClock));
            _blobStorageProvider = blobStorageProvider ?? throw new ArgumentNullException(nameof(blobStorageProvider));
            _permissionsService  = permissionsService ?? throw new ArgumentNullException(nameof(permissionsService));
            _fileTypeValidator   = fileTypeValidator ?? throw new ArgumentNullException(nameof(fileTypeValidator));
            _groupCommand        = groupCommand ?? throw new ArgumentNullException(nameof(groupCommand));
            _groupDataProvider   = groupDataProvider ?? throw new ArgumentNullException(nameof(groupDataProvider));
            _logger         = logger ?? throw new ArgumentNullException(nameof(logger));
            _imageService   = imageService ?? throw new ArgumentNullException(nameof(imageService));
            _htmlSanitizer  = htmlSanitizer ?? throw new ArgumentNullException(nameof(htmlSanitizer));
            _contentService = contentService ?? throw new ArgumentNullException(nameof(contentService));
        }
예제 #7
0
 public AddWithFileCommand(IFileCommand <T> fileCommand)
 {
     controlFileCommand = fileCommand;
 }