public void FileFetchingService_FetchLogs_FetchToExistingDirectory() { DateTime currentTime = DateTime.Now; string sourceDirectory = @"C:\_LogFiles\TF1"; string targetDirectory = @"C:\_ArchiveFiles\" + currentTime.ToString("ddMMyy"); // If source directory doesn't exist create it. if (!Directory.Exists(sourceDirectory)) { Directory.CreateDirectory(sourceDirectory); } // If sourceDirectory doesn't contain any logs create them. if (Directory.GetFiles(sourceDirectory).Length == 0) { using (File.Create(sourceDirectory + @"\log1.csv")) { } } // Create target directory if it doesn't exists to test FetchToExistingDirectory. if (!Directory.Exists(targetDirectory)) { Directory.CreateDirectory(targetDirectory); } //act bool result = FileFetchingService.FetchLogs(sourceDirectory, targetDirectory, 0); //assert Assert.IsTrue(result); }
public void FileFetchingService_FetchLogs_InvalidDaysInput() { //arrage DateTime currentTime = DateTime.Now; string sourceDirectory = @"C:\_LogFiles\TF3"; string targetDirectory = @"C:\_ArchiveFiles\" + currentTime.ToString("ddMMyy"); bool result; //Pass a negative amount of days. int days = -1; // If source directory doesn't exist create it. if (!Directory.Exists(sourceDirectory)) { Directory.CreateDirectory(sourceDirectory); } // Act try { result = FileFetchingService.FetchLogs(sourceDirectory, targetDirectory, days); } catch { result = false; } // Assert Assert.IsFalse(result); }
public void FileFetchingService_FetchLogs_NoLogFilesinSourceDirectory() { // Arrange DateTime currentTime = DateTime.Now; string sourceDirectory = @"C:\ajdshfkjahds"; string targetDirectory = @"C:\_ArchiveFiles\" + currentTime.ToString("ddMMyy"); bool result; // If source Directory exists delete it and recreate so it has no logs files. if (Directory.Exists(sourceDirectory)) { Directory.Delete(sourceDirectory, true); Directory.CreateDirectory(sourceDirectory); } // If source Directory doesn't exist create it. else { Directory.CreateDirectory(sourceDirectory); } // Act try { result = FileFetchingService.FetchLogs(sourceDirectory, targetDirectory, 30); } catch { result = false; } // Assert Assert.IsFalse(result); }
public void FileFetchingService_FetchLogs_FetchExistingFilesToNewDirectory() { //arrage DateTime currentTime = DateTime.Now; string sourceDirectory = @"C:\_LogFiles\TF3"; string targetDirectory = @"C:\_ArchiveFiles\" + currentTime.ToString("ddMMyy"); int days = 0; // If source directory doesn't exist create it. if (!Directory.Exists(sourceDirectory)) { Directory.CreateDirectory(sourceDirectory); } // If sourceDirectory doesn't contain any logs create them. if (Directory.GetFiles(sourceDirectory).Length == 0) { using (File.Create(sourceDirectory + @"\log1.csv")) { }; } // Delete targetdirectory to test FetchExistingFilesToNewDirectory if (Directory.Exists(targetDirectory)) { Directory.Delete(targetDirectory, true); } //act bool result = FileFetchingService.FetchLogs(sourceDirectory, targetDirectory, days); //assert Assert.IsTrue(result); }
public static async Task Main(string[] args) { // Make sure only days, source Directory, and targetDirectory are entered into program if (args.Length != 4) { await SystemUtilityService.NotifySystemAdminAsync(Constants.InvalidArgs, Constants.SystemAdminEmailAddress).ConfigureAwait(false); return; } DateTime currentTime = DateTime.Now; int days; string targetDirectory = ""; try { days = Convert.ToInt32(args[1]); } catch { await SystemUtilityService.NotifySystemAdminAsync(Constants.FirstArgumentNotInt, Constants.SystemAdminEmailAddress).ConfigureAwait(false); return; } string sourceDir; if (Directory.Exists(args[2])) { sourceDir = args[2]; } else { await SystemUtilityService.NotifySystemAdminAsync(Constants.SourceDirectoryDNE, Constants.SystemAdminEmailAddress).ConfigureAwait(false); return; } if (Directory.Exists(args[3])) { targetDirectory = args[3]; } targetDirectory += currentTime.ToString(Constants.NamingFormatString); bool result = false; // FetchLogs will return true if files of the proper age are found in the source directory. if (FileFetchingService.FetchLogs(sourceDir, targetDirectory, days)) { if (CompressionService.Compress(Constants.SevenZipPath, sourceDir, targetDirectory)) { result = await FTPService.SendAsync(Constants.FTPUrl, "", targetDirectory, Constants.FTPUsername, Constants.FTPpassword).ConfigureAwait(false); } } // Notify system admin if Archiving fails to run successfully. if (result == false) { await SystemUtilityService.NotifySystemAdminAsync("Archiving failed on" + currentTime, Constants.SystemAdminEmailAddress).ConfigureAwait(false); } }