public SynchronizerData(string firstPath, string fileFilter, string secondPath, bool includeSubdirectories = true, IEnumerable <string> excludeSubDirectories = null, IEnumerable <string> excludeFileExtensions = null, int sysnchronizeDelayInMin = 60) { if (string.IsNullOrWhiteSpace(firstPath)) { throw new ArgumentException(nameof(firstPath)); } if (string.IsNullOrWhiteSpace(fileFilter)) { throw new ArgumentException(nameof(fileFilter)); } if (string.IsNullOrWhiteSpace(secondPath)) { throw new ArgumentException(nameof(secondPath)); } FirstPath = firstPath; FileFilter = fileFilter; SecondPath = secondPath; IncludeSubdirectories = includeSubdirectories; ExcludeSubDirectories.AddRange(excludeSubDirectories ?? new string[0]); ExcludeFileExtensions.AddRange(excludeFileExtensions ?? new string[0]); SynchronizeDelay = sysnchronizeDelayInMin * 1000; }
private bool IsHandleFile(string filePath) { string ext = Path.GetExtension(filePath); return(File.Exists(filePath) && ExcludeSubDirectories.Any(e => filePath.ToLower().Contains($"\\{e.ToLower()}")) == false && ExcludeFileExtensions.Any(i => i.Equals(ext, StringComparison.CurrentCultureIgnoreCase)) == false); }
protected DateTime SyncSourcePathToTargetPath() { var sourceFiles = IncludeSubdirectories ? Directory.GetFiles(SourcePath, FileFilter, SearchOption.AllDirectories) : Directory.GetFiles(SourcePath, FileFilter); var syncFiles = sourceFiles.Where(f => ExcludeSubDirectories.Any(e => f.ToLower().Contains($"\\{e.ToLower()}\\")) == false); foreach (var item in syncFiles) { SynchronizeSourceFile(item); } return(DateTime.Now); }
private DateTime SyncWatchPathToTargetPath() { var watchFiles = IncludeSubdirectories == true?Directory.GetFiles(WatchPath, WatchFilter, SearchOption.AllDirectories) : Directory.GetFiles(WatchPath, WatchFilter); var syncFiles = watchFiles.Where(f => ExcludeSubDirectories.Any(e => f.ToLower().Contains($"\\{e.ToLower()}\\")) == false); foreach (var item in syncFiles) { SynchronizeWatchFile(item); } return(DateTime.Now); }