예제 #1
0
        public void Tag_AppendsTimeStamp_ToEndOfFileName()
        {
            DateFileTagger fileTagger = new DateFileTagger();
            FileInfo       inputFile  = new FileInfo("../../../Utilities/TestData/TestFileToArchive.txt");
            DateTime       timestamp  = DateTime.Now;
            //Match String such as /Utilities/TestData/TestFileToArchive_20002021-142245.txt
            Regex pattern = new Regex("^.+_[\\d-]+\\..*");

            FileInfo result         = fileTagger.Tag(inputFile, timestamp);
            String   resultFullName = result.FullName;

            Assert.Matches(pattern, resultFullName);
        }
        public void Run()
        {
            try
            {
                if (!VerifyImportFiles())
                {
                    logger.Error("Required Files do not exist. Exiting the application.");
                    Environment.Exit(0);
                }

                IEnumerable <EverfiUser> userList = GetEverfiUsersFromCSV();

                logger.Information("Loading Template at: {0}", templateFile.FullName);
                using (EverfiExcelTemplate template = new EverfiExcelTemplate(this.templateFile, this.logger))
                {
                    logger.Information("Importing CSV File from: {0}", csvFile.FullName);
                    template.ImportDataFromList(userList.ToList());
                    DateFileTagger fileTagger      = new DateFileTagger();
                    FileInfo       saveDestination = new FileInfo(Environment.ExpandEnvironmentVariables(this.configuration.ReportSavePath));
                    saveDestination = fileTagger.Tag(saveDestination, this.timeStamp);

                    logger.Information("Saving report to: {0}", saveDestination.FullName);
                    bool saveSuccessful = template.SaveTemplateTo(saveDestination);
                    if (saveSuccessful)
                    {
                        logger.Information("Save successful | Path: {0}", saveDestination.FullName);
                        DirectoryInfo archiveDirectory = new DirectoryInfo(Environment.ExpandEnvironmentVariables(configuration.ArchiveDirectory));
                        FileInfo      archivedFile     = this.fileArchiver.Archive(csvFile, archiveDirectory);
                        if (!archivedFile.Exists)
                        {
                            logger.Warning("Could not archive the CSV File: {0}", archivedFile.FullName);
                        }
                        else
                        {
                            logger.Information("Archive successful: {0}", archivedFile.FullName);
                        }
                    }
                    else
                    {
                        logger.Error("Failed to save the exported excel sheet in the specified location: {0}", saveDestination.FullName);
                        Environment.Exit(0);
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error("Something unexpected happened | Reason: {0}", ex);
                Environment.Exit(0);
            }
        }
 public FileArchiver(DateTime timestamp, ILogger log)
 {
     this.timestamp  = timestamp;
     this.log        = log;
     this.fileTagger = new DateFileTagger();
 }