Ejemplo n.º 1
0
        private static void Main(string[] args)
        {
            var result =
                Parser.Default.ParseArguments<Options>(args).WithNotParsed(ArgumentsNotParsed);

            Options options = ((Parsed<Options>)result).Value;

            var folders = options.Folders;
            var regExInfoPath = options.RegExInfoPath;

            var regexInfo = new RegexInfo(regExInfoPath);

            log4net.Config.XmlConfigurator.Configure();
            ILog logger = LogManager.GetLogger("textLogger");

            var fileProcessor = new FileProcessor(logger);
            fileProcessor.ProcessFiles(folders, regexInfo);
        }
Ejemplo n.º 2
0
        public void Constructor_WithValidPath_ReturnsInstanceWithPropertiesPopulated()
        {
            // Arrange
            const string path = @".\Resources\RegexInfo.xml";
            const string expectedDateRegexPattern =
                @"\d{1,2}(?:st|nd|rd|th)\s[A-Z,a-z]{3}\s20\d{2}\sto\s(?<day>\d{1,2})(?:st|nd|rd|th)\s(?<month>[A-Z,a-z]{3})\s(?<year>20\d{2})";
            const string scannerDateRegex = @"^(?<year>20[\d]{2})[_ ]*(?<month>[0-1][0-9])([_ ](?<day>[0-3][0-9]))*(_(?<time>[\d]{2}_[\d]{2}_[\d]{2}))*[_ ](?<name>[\w -]+)(?<extension>.[a-z]+)";

            // Act
            var regexInfo = new RegexInfo(path);
            // Assert
            Assert.That(regexInfo.PdfInfos.Count, Is.EqualTo(2), "regexInfo.PdfInfos.Count");
            Assert.That(regexInfo.ScannerDateRegex, Is.EqualTo(scannerDateRegex), "regexInfo.ScannerDateRegex");
            Assert.That(regexInfo.PdfInfos[0].FilePrefix, Is.EqualTo("My Bank"), "regexInfo.PdfInfos[0].FilePrefix");
            Assert.That(regexInfo.PdfInfos[0].Folder, Is.EqualTo(@"C:\Temp"), "regexInfo.PdfInfos[0].Folder");
            Assert.That(regexInfo.PdfInfos[0].TextRegexPattern, Is.EqualTo("mybank.com"), "regexInfo.PdfInfos[0].TextRegexPattern");
            Assert.That(regexInfo.PdfInfos[0].DateRegexPattern, Is.EqualTo(expectedDateRegexPattern), "regexInfo.PdfInfos[0].DateRegexPattern");
        }
Ejemplo n.º 3
0
        public void ProcessFiles(IEnumerable<string> folders, RegexInfo regexInfo)
        {
            var fileNames = GetFileNames(folders, SearchOption.TopDirectoryOnly);
            var fileMetaDatas = PdfParser.GetFilesToRename(fileNames, regexInfo.PdfInfos);

            // Set dates on files that are not recognised or do not containing a recognised date
            var filesMetaDatasWithoutDates = fileMetaDatas.Where(x => x.Date == null);
            FileNameDateHelper.UpdateDateInfosUsingFileName(filesMetaDatasWithoutDates, regexInfo.ScannerDateRegex);

            try
            {
                var pdfUpdater = new PdfUpdater(_logger);
                pdfUpdater.UpdateFiles(fileMetaDatas);
            }
            catch (Exception e)
            {
                _logger.Error(e);
                throw;
            }
        }