public void CreateXMLFile() { var parms = new CopyCommandParameters { CopySubdirectories = true, DeleteExistingDirectoriesFirst = true, DeleteExistingFilesFirst = true, WildCard = "*.*", FileName = "", RegExFilter = "", PostCopyAction = "" }; var cmd1 = new CopyFileCommand { CommandParameters = parms, SourceDirectory = @"D:\T001\TestFolder", TargetDirectory = @"D:\T002\TestFolder" }; var cmd2 = new CopyFileCommand { CommandParameters = parms, SourceDirectory = @"D:\T001", TargetDirectory = @"D:\T015" }; var cmd3 = new CopyFileCommand { CommandParameters = parms, SourceDirectory = @"D:\T001", TargetDirectory = @"D:\T003" }; var list = new List<CopyFileCommand> {cmd1,cmd2,cmd3}; var root = new CopyFileOperation { CopyFileCommands = list }; var u = new HelperUtility(); var serializer = new XmlSerializer(typeof (CopyFileOperation)); var output = Path.Combine(@"D:\CS_Test", u.XMLCommandFileName); var fs = new FileStream(output, FileMode.Create); serializer.Serialize(fs,root); fs.Close(); }
public string GetDefaultXMLPathAndFileName() { var u = new HelperUtility(); var xmlPathAndFileName = u.CombineHomeExePathWithFileName(xmlFileName); if(!File.Exists(xmlPathAndFileName)) { _log.LogAndDisplay("Missing XML Config File! Application Terminating!",LoggerMode.LogAndDisplayConsoleLine); return null; } return xmlPathAndFileName; }
public string ComputeTargetDirectoryFromSourceDirectory(string targetDir, string srcBaseDirectory, DirectoryInfo currDirectory) { var u = new HelperUtility(); var baseTarget = u.ConvertStringPathToInfo(u.RemoveTrailingDirectorySlash(targetDir)); if(baseTarget==null) { _log.LogAndDisplay(String.Format("Invalid Directory Info For: {0}",targetDir),LoggerMode.LogAndDisplayConsoleLine); return null; } var baseSource = u.ConvertStringPathToInfo(u.RemoveTrailingDirectorySlash(srcBaseDirectory)); if(baseSource==null) { throw new Exception(String.Format("Invalid Source Directory Info: {0}",srcBaseDirectory)); } var relDir = u.RemoveTrailingDirectorySlash(currDirectory.FullName.Remove(0, baseSource.FullName.Length)); return baseTarget.FullName + relDir; }
private void CreateLogFileName() { var uH = new HelperUtility(); var homePath = uH.AddTrailingDirectorySlash(uH.GetExecutableDirectory()); var sb = new StringBuilder(); DateTime now = DateTime.Now; sb.Append(homePath); sb.Append(now.Year.ToString("0000")); sb.Append(now.Month.ToString("00")); sb.Append(now.Day.ToString("00_")); sb.Append(now.Hour.ToString("00")); sb.Append(now.Minute.ToString("00")); sb.Append(now.Second.ToString("00")); sb.Append("_CopyLog.txt"); _logFilePathAndName = sb.ToString(); }
private void DoCopyCommand(CopyFileCommand cmd, string currSourceDir) { var uF = new FileUtility(_log); var uH = new HelperUtility(); var currSrcInfo = uH.ConvertStringPathToInfo(currSourceDir); if(currSrcInfo==null) { throw new Exception(String.Format("Invalid Srouce Directory Info: {0}", currSourceDir)); } var newTargetDir = uF.ComputeTargetDirectoryFromSourceDirectory(cmd.TargetDirectory,cmd.SourceDirectory, currSrcInfo); if(newTargetDir == null) { return; } if(!Directory.Exists(newTargetDir)) { try { Directory.CreateDirectory(newTargetDir); } catch(Exception e) { _log.LogAndDisplay(String.Format("Error Creating Target Directory: {0}",newTargetDir),e,LoggerMode.LogAndDisplayConsoleLine); return; } } var newTargInfo = uH.ConvertStringPathToInfo(newTargetDir); if(newTargInfo==null) { _log.LogAndDisplay(String.Format("Invalid Target Directory Info: {0}", newTargetDir),LoggerMode.LogAndDisplayConsoleLine); return; } _log.DisplayCopyDirectoryStatus(currSrcInfo.FullName, newTargInfo.FullName); AssignCopyOperationByCopyMode(cmd, currSrcInfo, newTargInfo); if(!cmd.CommandParameters.CopySubdirectories) { return; } var dirs = currSrcInfo.GetDirectories(); if(dirs.Length < 1) { return; } foreach (var dir in dirs) { DoCopyCommand(cmd, uH.RemoveTrailingDirectorySlash(dir.FullName)); } }
internal string ComputeTargetFileNameFromSourceFileName(DirectoryInfo targetDirInfo, FileInfo srcFileInfo) { var uH = new HelperUtility(); var targetDir = uH.AddTrailingDirectorySlash(targetDirInfo.FullName); return targetDir + srcFileInfo.Name; }
public IList<DirectoryInfo> GetAllDirectoriesInTree(string topDirectory) { var u = new HelperUtility(); if(string.IsNullOrEmpty(topDirectory)) { _log.DisplayToConsole(string.Format("Top Directory is NULL/Empty: {0}", topDirectory), LoggerMode.LogAndDisplayConsoleLine); return null; } var dInfo = u.ConvertStringPathToInfo(topDirectory); if(dInfo==null) { _log.DisplayToConsole(string.Format("Top Directory Info Object is Invalid: {0}", topDirectory), LoggerMode.LogAndDisplayConsoleLine); return null; } IList<DirectoryInfo> dirInfoTree = new List<DirectoryInfo>(); GetAllDirectoriesInTree(dInfo, dirInfoTree); return dirInfoTree; }
public void DeleteAllFilesInDirectoryTree(string dirTree) { var u = new HelperUtility(); var dInfoTopdir = u.ConvertStringPathToInfo(dirTree); if(dInfoTopdir==null) { return; } DeleteAllFilesInDirectoryTree(dInfoTopdir); }