private void additionalInstructions(DirectoryPair dirSettings, string source) { var bulkType = Path.GetFileName(source).Substring(1, 4); var instructions = dirSettings.AdditionalInstructionList.Where(i => i.BulkType == bulkType); foreach (var instr in instructions) { executeInstruction(source, instr); } }
private void capyToAArchive(DirectoryPair dirSettings, string source) { var archivePath = Path.Combine(dirSettings.ArchivePath, DateTime.Today.ToString("yyyy-MM-dd")); if (!Directory.Exists(archivePath)) { this.log.Write(Severity.Info, "Creating directory: {0}.", archivePath); Directory.CreateDirectory(archivePath); } var destination = Path.Combine(archivePath, Path.GetFileName(source)); this.log.Write(Severity.Info, "Archiving {0} to {1}.", source, destination); copy(source, destination); }
private void processDirectoryPair(DirectoryPair dirSettings) { DirectoryInfo di = new DirectoryInfo(dirSettings.SourcePath); FileInfo[] files = di.GetFiles(); string dest; if (files.Length == 0) // If directory is empty, exit. { return; } foreach (FileInfo fi in files) { this.log.Write(Severity.Debug, "Examining: {0}.", fi.Name); if (dirSettings.SourcePath.ToLower().Contains("incoming")) { dest = processIncomingFile(fi, dirSettings); } else { dest = processOutgoingFile(fi, dirSettings); } if (dest == null) { continue; } this.log.Write(Severity.Info, "Moving {0} to {1}, Size: {2:N0} bytes.", fi.FullName, dest, fi.Length); if (!move(fi.FullName, dest)) // Skip file if unavailable { continue; } capyToAArchive(dirSettings, dest); additionalInstructions(dirSettings, dest); } }
private string processIncomingFile(FileInfo fi, DirectoryPair dirSettings) { var nodes = fi.Name.Split(new char[] { '.' }); if (fi.Name.Length != 43) // Skip files that don't match the expected pattern. { this.log.Write(Severity.Info, "Skipping: {0} because it doesn't match the expected length.", fi.Name); return(null); } if (nodes.Length != 8) // Skip files that don't match the expected pattern. { this.log.Write(Severity.Info, "Skipping: {0} because it doesn't have 8 nodes.", fi.Name); return(null); } if (!dirSettings.ExpectedBulkTypeList.Contains(nodes[2])) { this.log.Write(Severity.Info, "Skipping: {0} because it is not an expected bulk type.", fi.Name); return(null); } return(Rename(dirSettings.DestinationPath, fi.FullName)); }
private string processOutgoingFile(FileInfo fi, DirectoryPair dirSettings) { var nodes = fi.Name.Split(new char[] { '.' }); if (fi.Name.Length != 24) // Skip files that don't match the expected pattern. { this.log.Write(Severity.Info, "Skipping: {0} because it doesn't match the expected length.", fi.Name); return(null); } if (nodes.Length != 2) // Skip files that don't match the expected pattern. { this.log.Write(Severity.Info, "Skipping: {0} because it doesn't have 2 nodes.", fi.Name); return(null); } if (!fi.Name.ToLower().StartsWith("ipm_")) { this.log.Write(Severity.Info, "Skipping: {0} because it doesn't have the correct filename", fi.Name); return(null); } return(Rename(dirSettings.DestinationPath, fi.FullName)); }