Exemplo n.º 1
0
        /// <summary>
        /// Processes a single file in an input directory
        /// </summary>
        /// <param name="inputFile">File to process</param>
        /// <param name="outputDirectory">Directory to put processed file to</param>
        private void ProcessSingleFile(FileInfo inputFile, string outputDirectory)
        {
            FileKind fileKind        = ClassifyFile(inputFile.Extension.ToLower());
            string   subDirectory    = fileKind.GetAttributeOfType <DescriptionAttribute>().Description;
            string   destinationPath = string.Empty;

            try
            {
                destinationPath = m_FileProcessorFactory.ProvideProcessorForFile(fileKind).Process(inputFile, fileKind, outputDirectory);
            }
            catch (FileProcessorException)
            {
                destinationPath = m_FileProcessorFactory.ProvideProcessorForFile(FileKind.Unrecognized).Process(inputFile, FileKind.Unrecognized, outputDirectory);
            }
            catch (Exception e)
            {
                OnFileFailed(new FileEventArgs(inputFile.Name, subDirectory, e.Message));
            }

            if (File.Exists(destinationPath))
            {
                OnFileFailed(new FileEventArgs(inputFile.Name, subDirectory, $"{inputFile.Name} already exists in {subDirectory}"));
            }
            else
            {
                File.Copy(inputFile.FullName, destinationPath, false);
                OnFileCopied(new FileEventArgs(inputFile.Name, subDirectory));
            }
        }
        public void ProvideFileProcessorTest(FileKind fileKind, Type expectedFileProcessor)
        {
            var fileProcessor = m_FileProcessorFactory.ProvideProcessorForFile(fileKind);

            Assert.IsInstanceOf(expectedFileProcessor, fileProcessor);
        }