Ejemplo n.º 1
0
 public TemplateFinder(IFileScanner fileScanner, IEnumerable <IPackageInfo> packages)
 {
     _fileScanner   = fileScanner;
     _packages      = packages;
     _requestConfig = new CompositeAction <ScanRequest>();
     _hostExcludes  = new CompositeAction <ScanRequest>();
 }
Ejemplo n.º 2
0
 public FileSystemTemplateFinder(IFileScanner fileScanner, IRootPathProvider rootPathProvider, IFindModelFromViewCollection findModelFromViewCollection)
 {
     this.fileScanner = fileScanner;
     this.rootPathProvider = rootPathProvider;
     this.findModelFromViewCollection = findModelFromViewCollection;
     requestConfig = new CompositeAction<ScanRequest>();
 }
Ejemplo n.º 3
0
 public TemplateFinder(IFileScanner fileScanner, IEnumerable<IPackageInfo> packages)
 {
     _fileScanner = fileScanner;
     _packages = packages;
     _requestConfig = new CompositeAction<ScanRequest>();
     _hostExcludes = new CompositeAction<ScanRequest>();
 }
        public static void DetectFile(string filePath, string projectFileName)
        {
            var builder = new ContainerBuilder();

            builder.RegisterModule(new FrameworkModule());
            builder.RegisterModule(new DataContractSerializerModule());

            using (var container = builder.Build())
            {
                string           detectorPath    = ConfigurationManager.AppSettings.Get("Defraser.DetectorPath") ?? AppDomain.CurrentDomain.BaseDirectory;
                IDetectorFactory detectorFactory = container.Resolve <IDetectorFactory>();
                detectorFactory.Initialize(detectorPath);

                File.Delete(projectFileName);
                ProjectManager projectManager = container.Resolve <ProjectManager>();
                IProject       project        = projectManager.CreateProject(projectFileName, "Console", DateTime.Now, "Batch process");

                IInputFile   inputFile   = project.AddFile(filePath, detectorFactory.ContainerDetectors.Union(detectorFactory.CodecDetectors));
                IFileScanner fileScanner = container.Resolve <IFileScanner>();
                fileScanner.ContainerDetectors = detectorFactory.ContainerDetectors;
                fileScanner.CodecDetectors     = detectorFactory.CodecDetectors;
                fileScanner.DataBlockDetected += (s, e) => project.AddDataBlock(e.DataBlock);
                fileScanner.Scan(inputFile, container.Resolve <IProgressReporter>());

                projectManager.SaveProject(project);
                projectManager.CloseProject(project);
            }
        }
Ejemplo n.º 5
0
 public UtilityCommand(IFileScanner fileScanner,
                       ILogger <UtilityCommand> logger,
                       IMusicDecryptor musicDecryptor)
 {
     _fileScanner    = fileScanner;
     _logger         = logger;
     _musicDecryptor = musicDecryptor;
 }
Ejemplo n.º 6
0
        public DiffBuilder(IDiffInfoBuilder diffInfoBuilder, IFileScanner fileScanner, IFolderDiffer folderDiffer)
        {
            IsNotNull(fileScanner);
            IsNotNull(folderDiffer);

            _diffInfoBuilder = diffInfoBuilder;
            _fileScanner     = fileScanner;
            _folderDiffer    = folderDiffer;
        }
        public async Task<UploadSaveResult[]> SaveInCabinet(HandleExistingMethod handleExisting = HandleExistingMethod.Throw, IFileScanner fileScanner = null) {
            var saveTasks = this.FileData.Select(async (fd) => {
                string uploadFileName = fd.Headers.ContentDisposition.FileName?.Trim('"')?.Trim('\\');
                string uploadExtension = Path.GetExtension(uploadFileName)?.TrimStart('.');
                string uploadMediaType = fd.Headers.ContentType?.MediaType;

                if(!this.fileValidator.IsFileTypeWhitelisted(uploadExtension, uploadMediaType)) {
                    return new UploadSaveResult(uploadFileName, uploadMediaType, "The file type is not allowed");
                }

                string fileName = fd.LocalFileName;
                var uploadedFileInfo = new FileInfo(fileName);

                if(this.fileValidator.IsFileTooLarge(uploadedFileInfo.Length)) {
                    return new UploadSaveResult(uploadFileName, uploadMediaType, "The file is too large");
                }

                if(this.fileValidator.IsFileTooSmall(uploadedFileInfo.Length)) {
                    return new UploadSaveResult(uploadFileName, uploadMediaType, "The file is too small");
                }

                string delimiter = this.fileCabinet.GetKeyDelimiter();
                string key = this.keyProvider.GetKey(uploadFileName, uploadMediaType, delimiter);

                if(String.IsNullOrWhiteSpace(key)) {
                    return new UploadSaveResult(uploadFileName, uploadMediaType, "No key was provided");
                }
                
                if(!File.Exists(fileName)) {
                    return new UploadSaveResult(uploadFileName, uploadMediaType, "Could not find uploaded file.");
                }

                // File scanner to optionally check the file an remove if it's unsafe
                // note the c# 6 fileScanner?.ScanFileAsync syntax doesn't seem to work
                if(fileScanner != null) {
                    await fileScanner.ScanFileAsync(fileName);
                }

                if(!File.Exists(fileName)) {
                    return new UploadSaveResult(uploadFileName, uploadMediaType, "File has been removed as it is unsafe.");
                }

                var cabinetResult = await this.fileCabinet.SaveFileAsync(key, fileName, handleExisting, this.CabinetFileSaveProgress);

                return new UploadSaveResult(uploadFileName, uploadMediaType, cabinetResult);
            });

            var saveResults = await Task.WhenAll(saveTasks);

            // cleanup temp files
            foreach(var file in this.FileData) {
                File.Delete(file.LocalFileName);
            }

            return saveResults;
        }
Ejemplo n.º 8
0
        public void SetUp()
        {
            fileScanner = new FileScanner(new FileSystem(new DefaultJsonParser()));
            rootPathProvider = A.Fake<IRootPathProvider>();
            findModelFromViewCollection = A.Fake<IFindModelFromViewCollection>();

            templateFinder = new FileSystemTemplateFinder(fileScanner, rootPathProvider, findModelFromViewCollection);

            A.CallTo(() => rootPathProvider.GetRoot()).Returns(GetRootPath());
        }
Ejemplo n.º 9
0
        public void Carve(string path, long position, long length, IDataBlockCallback callback)
        {
            IProject         project         = CreateProject("C:/folderDieNietBestaat");
            IInputFile       inputFile       = CreateInputFile(project, path);
            IFileScanner     fileScanner     = CreateFileScanner();
            IDetectorFactory detectorFactory = CreateDetectorFactory();

            fileScanner.CodecDetectors     = detectorFactory.CodecDetectors;
            fileScanner.ContainerDetectors = detectorFactory.ContainerDetectors;
            fileScanner.DataBlockDetected += (o, e) => { callback.DataBlockDetectedWithCodecs(e.DataBlock.StartOffset, e.DataBlock.EndOffset, GetCodecStreamsAndKeyFrames(e.DataBlock)); };

            (fileScanner as FileScanner).Scan(inputFile, CreateDataReaderPool().CreateDataReader(inputFile.CreateDataPacket().GetSubPacket(position, length)), new NullProgressReporter());
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Initialize new instance of <see cref="MoviebaseApp"/>.
        /// </summary>
        private MoviebaseApp()
        {
            _dal             = new MoviebaseDAL();
            _pathTransformer = new PathTransformer();

            _fileScanner   = new FileScanner();
            _fileAnalyzer  = new FileAnalyzer(new CompositeTitleProvider());
            _fileOrganizer = new FileOrganizer(new FolderCleaner(), _pathTransformer);

            _apiClient = new TMDbClient(GlobalSettings.Default.ApiKey);

            ReloadSettings();
        }
Ejemplo n.º 11
0
 public DownloadCommand(ILogger <DownloadCommand> logger,
                        IFileScanner fileScanner,
                        IOptions <ToolOptions> options,
                        ITagLoader tagLoader,
                        IEnumerable <ILyricDownloader> lyricDownloaderList,
                        IEnumerable <IAlbumDownloader> albumDownloaderList)
 {
     _logger              = logger;
     _fileScanner         = fileScanner;
     _tagLoader           = tagLoader;
     _lyricDownloaderList = lyricDownloaderList;
     _albumDownloaderList = albumDownloaderList;
     _options             = options.Value;
 }
Ejemplo n.º 12
0
        internal static IInputFile DetectData(IList <IDetector> containerDetectors, IList <IDetector> codecDetectors, IProject project, string fileName)
        {
            IFileScanner fileScanner = _container.Resolve <IFileScanner>();

            fileScanner.ContainerDetectors = containerDetectors;
            fileScanner.CodecDetectors     = codecDetectors;
            fileScanner.DataBlockDetected += (s, e) => project.AddDataBlock(e.DataBlock);
            List <IDetector> detectors = new List <IDetector>();

            detectors.AddRange(containerDetectors);
            detectors.AddRange(codecDetectors);
            IInputFile inputFile = project.AddFile(fileName, detectors);

            fileScanner.Scan(inputFile, new NullProgressReporter());
            return(inputFile);
        }
        /// <summary>
        /// Creates a new background file scanner.
        /// </summary>
        /// <param name="createSubProgressReporter">
        /// The factory method for creating progress reporters for a sub-task,
        /// e.g. scanning a single file
        /// </param>
        /// <param name="fileScanner">The <see cref="IFileScanner"/> used for scanning input files</param>
        /// <param name="dataBlockScanner"></param>
        /// <param name="synchronizeInvoke">
        /// The <see cref="ISynchronizeInvoke"/> for executing code on the GUI-thread
        /// </param>
        public BackgroundFileScanner(Creator <IProgressReporter, IProgressReporter, long, long, long> createSubProgressReporter,
                                     IFileScanner fileScanner, DataBlockScanner dataBlockScanner, ISynchronizeInvoke synchronizeInvoke)
        {
            PreConditions.Argument("createSubProgressReporter").Value(createSubProgressReporter).IsNotNull();
            PreConditions.Argument("fileScanner").Value(fileScanner).IsNotNull();
            PreConditions.Argument("synchronizeInvoke").Value(synchronizeInvoke).IsNotNull();

            _createSubProgressReporter = createSubProgressReporter;
            _fileScanner       = fileScanner;
            _dataBlockScanner  = dataBlockScanner;
            _synchronizeInvoke = synchronizeInvoke;

            _fileScanner.DataBlockDetected += FileScanner_DataBlockDetected;

            InitializeComponent();
        }
Ejemplo n.º 14
0
        public TemplateFinder(IFileScanner fileScanner, IEnumerable<IPackageInfo> packages)
        {
            _fileScanner = fileScanner;
            _packages = packages;
            _requestConfig = new CompositeAction<ScanRequest>();
            _hostExcludes = new CompositeAction<ScanRequest>();

            // TODO: Preferably set this on the Finder from the SparkExtension (as a default convention).

            IncludeFile("*spark");
            // TODO: This is not automatically synched with what the attacher looks for.
            IncludeFile("bindings.xml");

            ExcludeHostDirectory(FubuMvcPackageFacility.FubuPackagesFolder);
            ExcludeHostDirectory(FubuMvcPackageFacility.FubuPackagesFolder, FubuMvcPackageFacility.FubuContentFolder);
            ExcludeHostDirectory(FubuMvcPackageFacility.FubuContentFolder);
        }
Ejemplo n.º 15
0
        public TemplateFinder(IFileScanner fileScanner, IEnumerable <IPackageInfo> packages)
        {
            _fileScanner   = fileScanner;
            _packages      = packages;
            _requestConfig = new CompositeAction <ScanRequest>();
            _hostExcludes  = new CompositeAction <ScanRequest>();

            // TODO: Preferably set this on the Finder from the SparkExtension (as a default convention).

            IncludeFile("*spark");
            // TODO: This is not automatically synched with what the attacher looks for.
            IncludeFile("bindings.xml");

            ExcludeHostDirectory(FubuMvcPackageFacility.FubuPackagesFolder);
            ExcludeHostDirectory(FubuMvcPackageFacility.FubuPackagesFolder, FubuMvcPackageFacility.FubuContentFolder);
            ExcludeHostDirectory(FubuMvcPackageFacility.FubuContentFolder);
        }
Ejemplo n.º 16
0
        public MovideoApp(IConfigReader configReader, IFileScanner fileScanner, IFileAnalyzer analyzer, IMovieDb db)
        {
            _fileScanner = fileScanner;
            _analyzer    = analyzer;
            _db          = db;

            ApiSettings apiSettings = configReader.GetApiSettings();

            if (apiSettings == null)
            {
                throw new ArgumentNullException("Impossibile proseguire. API non configurata.");
            }
            _apiClient = new TMDbClient(apiSettings.ApiKey)
            {
                DefaultCountry  = "IT",
                DefaultLanguage = "it"
            };
        }
Ejemplo n.º 17
0
        public void Carve(string path, long position, long length, StringList codecDetectors, StringList containerDetectors, IDataBlockCallback callback, IBaseProgressListener baseProgressListener)
        {
            IProject                  project          = CreateProject("C:/nonExistingFolder");
            IInputFile                inputFile        = CreateInputFile(project, path);
            IFileScanner              fileScanner      = CreateFileScanner();
            IDetectorFactory          detectorFactory  = CreateDetectorFactory();
            CancelableProgressAdapter progressReporter = new CancelableProgressAdapter(baseProgressListener);

            fileScanner.CodecDetectors     = detectorFactory.CodecDetectors.Where(detector => codecDetectors.Contains(detector.Name));
            fileScanner.ContainerDetectors = detectorFactory.ContainerDetectors.Where(detector => containerDetectors.Contains(detector.Name));
            fileScanner.DataBlockDetected += (o, e) => { callback.DataBlockDetectedWithCodecs(e.DataBlock.StartOffset, e.DataBlock.EndOffset, GetCodecStreamsAndKeyFrames(e.DataBlock)); };

            try
            {
                StartPolling(progressReporter);
                (fileScanner as FileScanner).Scan(inputFile, CreateDataReaderPool().CreateDataReader(inputFile.CreateDataPacket().GetSubPacket(position, length)), progressReporter);
            }
            finally
            {
                _polling = false;
            }
        }
 public void Setup()
 {
     this._fileScanner = A.Fake <IFileScanner>();
     this._logger      = new NullLogger <FileScannerScheduler>();
 }
Ejemplo n.º 19
0
 public FileScannerScheduler(IFileScanner fileScanner, ILogger <FileScannerScheduler> logger)
 {
     this._fileScanner = fileScanner ?? throw new ArgumentNullException(nameof(fileScanner));
     this._logger      = logger ?? throw new ArgumentNullException(nameof(logger));
 }
Ejemplo n.º 20
0
 public DirectoryScanner(IFileScanner fileScanner)
 {
     this.fileScanner = fileScanner;
 }
        public async Task <UploadSaveResult[]> SaveInCabinet(HandleExistingMethod handleExisting = HandleExistingMethod.Throw, IFileScanner fileScanner = null)
        {
            var saveTasks = this.FileData.Select(async(fd) => {
                string uploadFileName  = fd.Headers.ContentDisposition.FileName?.Trim('"')?.Trim('\\');
                string uploadExtension = Path.GetExtension(uploadFileName)?.TrimStart('.');
                string uploadMediaType = fd.Headers.ContentType?.MediaType;

                if (!this.fileValidator.IsFileTypeWhitelisted(uploadExtension))
                {
                    return(new UploadSaveResult(uploadFileName, uploadMediaType, "The file type is not allowed"));
                }

                string fileName      = fd.LocalFileName;
                var uploadedFileInfo = new FileInfo(fileName);

                if (this.fileValidator.IsFileTooLarge(uploadedFileInfo.Length))
                {
                    return(new UploadSaveResult(uploadFileName, uploadMediaType, "The file is too large"));
                }

                if (this.fileValidator.IsFileTooSmall(uploadedFileInfo.Length))
                {
                    return(new UploadSaveResult(uploadFileName, uploadMediaType, "The file is too small"));
                }

                string delimiter = this.fileCabinet.GetKeyDelimiter();
                string key       = this.keyProvider.GetKey(uploadFileName, uploadMediaType, delimiter);

                if (String.IsNullOrWhiteSpace(key))
                {
                    return(new UploadSaveResult(uploadFileName, uploadMediaType, "No key was provided"));
                }

                if (!File.Exists(fileName))
                {
                    return(new UploadSaveResult(uploadFileName, uploadMediaType, "Could not find uploaded file."));
                }

                // File scanner to optionally check the file an remove if it's unsafe
                // note the c# 6 fileScanner?.ScanFileAsync syntax doesn't seem to work
                if (fileScanner != null)
                {
                    await fileScanner.ScanFileAsync(fileName);
                }

                if (!File.Exists(fileName))
                {
                    return(new UploadSaveResult(uploadFileName, uploadMediaType, "File has been removed as it is unsafe."));
                }

                var cabinetResult = await this.fileCabinet.SaveFileAsync(key, fileName, handleExisting, this.CabinetFileSaveProgress);

                return(new UploadSaveResult(uploadFileName, uploadMediaType, cabinetResult));
            });

            var saveResults = await Task.WhenAll(saveTasks);

            // cleanup temp files
            foreach (var file in this.FileData)
            {
                File.Delete(file.LocalFileName);
            }

            return(saveResults);
        }