예제 #1
0
 public GetSortedFoldersQueryHandler(IFileProviderFactory fileProviderFactory, IMemoryCache memoryCache)
 {
     Guard.IsNotNull(fileProviderFactory, nameof(fileProviderFactory));
     Guard.IsNotNull(memoryCache, nameof(memoryCache));
     _fileProviderFactory = fileProviderFactory;
     _memoryCache         = memoryCache;
 }
예제 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FtpServer"/> class.
 /// The server uses custom file, data connection, and authentication provider.
 /// </summary>
 /// <param name="endPoint">The local end point to listen, usually 0.0.0.0:21.</param>
 /// <param name="fileProviderFactory">The <see cref="IFileProviderFactory"/> to use.</param>
 /// <param name="dataConnFactory">The <see cref="IDataConnectionFactory"/> to use.</param>
 /// <param name="authenticator">The <see cref="IAuthenticator"/> to use.</param>
 public FtpServer(
     IPEndPoint endPoint,
     IFileProviderFactory fileProviderFactory,
     IDataConnectionFactory dataConnFactory,
     IAuthenticator authenticator)
     : this(endPoint, fileProviderFactory, dataConnFactory, authenticator, null)
 {
 }
예제 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FtpServer"/> class
        /// with <see cref="SimpleFileProviderFactory"/>, <see cref="LocalDataConnectionFactory"/>,
        /// and <see cref="AnonymousAuthenticator"/>.
        /// </summary>
        /// <param name="endPoint">The local end point to listen, usually 0.0.0.0:21</param>
        /// <param name="baseDirectory">The directory to provide files</param>
        public FtpServer(IPEndPoint endPoint, string baseDirectory)
        {
            this.endPoint = endPoint;
            tcpListener   = new TcpListener(endPoint);

            fileProviderFactory = new SimpleFileProviderFactory(baseDirectory);
            dataConnFactory     = new LocalDataConnectionFactory();
            authenticator       = new AnonymousAuthenticator();
        }
        /// <summary>
        /// Creates a new <see cref="IFileProvider" /> from the file system.
        /// </summary>
        /// <param name="fileSystem">The file system.</param>
        /// <param name="fileProvider">When this method returns, contains an <see cref="IFileProvider"/> created from the file system.</param>
        /// <returns>
        /// <c>true</c> if the <see cref="IFileProvider" /> was successfully created; otherwise, <c>false</c>.
        /// </returns>
        public static bool TryCreateFileProvider(this IFileSystem fileSystem, [MaybeNullWhen(false)] out IFileProvider fileProvider)
        {
            fileProvider = fileSystem switch
            {
                IFileProviderFactory fileProviderFactory => fileProviderFactory.Create(),
                                     _ => null
            };

            return(fileProvider != null);
        }
    }
예제 #5
0
 private static void Validate(IFileProviderFactory fileProviderFactory, GetSortedFoldersDefinition parameters)
 {
     if (parameters.Limit < 0)
     {
         throw new ValidationPublicException("Negative value can't be used for a limit");
     }
     if (!fileProviderFactory.Exists(parameters.Path))
     {
         throw new ObjectNotFoundPublicException("Path not found");
     }
 }
예제 #6
0
 public FileService(
     IFileRepository repository,
     IFileProviderFactory fileProvider,
     IRepository <FieldEntity> fieldRepository,
     IMapper mapper,
     ITime time)
 {
     _repository       = repository;
     _fieldsRepository = fieldRepository;
     _fileProvider     = fileProvider;
     _time             = time;
     _mapper           = mapper;
 }
예제 #7
0
 public CFTReadAllProcess(
     IOptions <FileScanerOptions> options,
     IFileProviderFactory fileProviderFactory,
     IServiceProvider applicationServices,
     ICFTMiddlewareBuilder cftMiddlewareBuilder)
 {
     if (fileProviderFactory == null)
     {
         throw new ArgumentNullException(nameof(fileProviderFactory));
     }
     _options             = options?.Value ?? throw new ArgumentNullException(nameof(options));
     _applicationServices = applicationServices ?? throw new ArgumentNullException(nameof(applicationServices));
     _fileProvider        = fileProviderFactory.GetFileProvider(options.Value.FileProviderType, options.Value.FileProviderSettings);
     _semaphore           = new SemaphoreSlim(_options.NumberParallelFileWork, _options.NumberParallelFileWork);
 }
예제 #8
0
        public CommandsFactory(IMovieTheaterDbContext movieDbContext, IStaffDbContext staffDbContext, IShopDbContext shopDbContext,
                               IModelsFactory factory, IExporter exporter, IFileProviderFactory fileProviderFactory)
        {
            Guard.WhenArgument(movieDbContext, DbContextCheck).IsNull().Throw();
            Guard.WhenArgument(factory, ModelsFactoryCheck).IsNull().Throw();
            Guard.WhenArgument(exporter, ExporterCheck).IsNull().Throw();
            Guard.WhenArgument(fileProviderFactory, FileProviderFactoryCheck).IsNull().Throw();

            this.moviesDbContext     = movieDbContext;
            this.modelsFactory       = factory;
            this.staffDbContext      = staffDbContext;
            this.shopDbContext       = shopDbContext;
            this.exporter            = exporter;
            this.fileProviderFactory = fileProviderFactory;
        }
예제 #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FtpServer"/> class.
        /// The server uses custom file, data connection, and authentication provider.
        /// </summary>
        /// <param name="endPoint">The local end point to listen, usually 0.0.0.0:21</param>
        /// <param name="fileProviderFactory">The <see cref="IFileProviderFactory"/> to use</param>
        /// <param name="dataConnFactory">The <see cref="IDataConnectionFactory"/> to use</param>
        /// <param name="authenticator">The <see cref="IAuthenticator"/> to use</param>
        public FtpServer(
            IPEndPoint endPoint,
            IFileProviderFactory fileProviderFactory,
            IDataConnectionFactory dataConnFactory,
            IAuthenticator authenticator)
        {
            this.endPoint = endPoint;
            tcpListener   = new TcpListener(endPoint);

            this.fileProviderFactory = fileProviderFactory;
            this.dataConnFactory     = dataConnFactory;
            this.authenticator       = authenticator;

            tracer.CommandInvoked += Tracer_CommandInvoked;
            tracer.ReplyInvoked   += Tracer_ReplyInvoked;
        }
예제 #10
0
        public RemoveFileMiddleWare(
            MiddlewareDelegate <CFTFileContext> next,
            ILogger <RemoveFileMiddleWare> logger,
            IFileProviderFactory fileProviderFactory,
            RemoveFileOptions options)
            : base(next, logger)
        {
            try
            {
                options.ValidationParams();
                _fileProvider = fileProviderFactory.GetFileProvider(options.FileProviderType, options.FileProviderSettings);
            }
            catch (Exception e)
            {
                throw new CFTConfigurationException("Ошибка при конфигурации модуля проверки по XSD схеме.", e);
            }

            _option = options;
        }
예제 #11
0
        public ExportFileMiddleWare(
            MiddlewareDelegate <CFTFileContext> next,
            ILogger <ExportFileMiddleWare> logger,
            IFileProviderFactory fileProviderFactory,
            ExportFileOptions options)
            : base(next, logger)
        {
            try
            {
                options.ValidationParams();
                _fileProvider = fileProviderFactory.GetFileProvider(options.FileProviderType, options.FileProviderSettings);
                var exportFolder = _fileProvider.GetDirectoryContents(options.Path);
                if (!exportFolder.Exists)
                {
                    throw new ArgumentException($"Каталог '{options.Path}' не существует.", nameof(options.Path));
                }
            }
            catch (Exception e)
            {
                throw new CFTConfigurationException("Ошибка при конфигурации модуля экспорта файла.", e);
            }

            _option = options;
        }
예제 #12
0
        public FileScanerHostedService(
            ICFTReadAllProcess readAllProcess,
            IOptions <FileScanerOptions> options,
            IFileProviderFactory fileProviderFactory,
            ICFTMiddlewareBuilder cftMiddlewareBuilder)
        {
            if (fileProviderFactory == null)
            {
                throw new ArgumentNullException(nameof(fileProviderFactory));
            }
            _readAllProcess       = readAllProcess ?? throw new ArgumentNullException(nameof(readAllProcess));
            _options              = options?.Value ?? throw new ArgumentNullException(nameof(options));
            _cftMiddlewareBuilder = cftMiddlewareBuilder ?? throw new ArgumentNullException(nameof(cftMiddlewareBuilder));
            _fileProvider         = fileProviderFactory.GetFileProvider(options.Value.FileProviderType, options.Value.FileProviderSettings);

            try
            {
                options.Value.ValidateOptions();
            }
            catch (Exception e)
            {
                throw new CFTConfigurationException("Ошибка конфигурации службы.", e);
            }
        }
예제 #13
0
 public CreateJsonReaderCommand(IFileProviderFactory fileProviderFactory, IMovieTheaterDbContext dbContext, IModelsFactory modelsFactory)
     : base(dbContext, modelsFactory)
 {
     this.fileProviderFactory = fileProviderFactory;
 }
예제 #14
0
        private static FolderInfo[] GetFolderInfosInternal(GetSortedFoldersDefinition parameters, IFileProviderFactory fileProviderFactory, CancellationToken cancellationToken)
        {
            var fileProvider = fileProviderFactory.GetFileProvider(parameters.Path);

            var rootContents = fileProvider.GetDirectoryContents(string.Empty);
            var topDirs      = rootContents.Where(fi => fi.IsDirectory);

            var resultList = new List <FolderInfo>();

            foreach (var topDir in topDirs)
            {
                var size       = GetFolderSize(fileProvider, topDir, cancellationToken);
                var folderInfo = new FolderInfo {
                    Name = topDir.Name, Size = size
                };
                resultList.Add(folderInfo);
            }

            var orderedFolders = resultList.OrderByDescending(f => f.Size);
            var result         = parameters.Limit.HasValue ? orderedFolders.Take(parameters.Limit.Value) : orderedFolders;

            return(result.ToArray());
        }