private bool PostcheckIsDefinedAction(Watcher watcher) { bool isDefinedAction = false; foreach (WatcherAction watcherAction in (WatcherAction[])Enum.GetValues(typeof(WatcherAction))) { if (watcher.Action == watcherAction.ToString("g")) { isDefinedAction = true; } } if (!isDefinedAction) { NLogger.Info( "Invalid Watcher Action: {0} is not defined in MirrorFreezeCopy. This watcher will be skipped.", watcher.Action); } return(isDefinedAction); }
private bool PostcheckDestinationFolderCanBeCreated(Watcher watcher) { if (!Directory.Exists(watcher.Destination)) { try { Directory.CreateDirectory(watcher.Destination); } catch (NotSupportedException ex) { NLogger.Error(ex, "Error while creating Destination folder."); NLogger.Info( "Invalid Watcher:" + Environment.NewLine + "Action: {0}." + Environment.NewLine + "Source: {1}." + Environment.NewLine + "Destination: {2}." + Environment.NewLine + "Watcher Destination folder:" + Environment.NewLine + "{2}" + Environment.NewLine + "can not be created.", watcher.Action, watcher.Source, watcher.Destination); return(false); } return(true); } else { return(true); } }
private bool PostcheckWatcherIsRootFolder(Watcher watcher) { // Do not start WindowsFileSystemWatcher if the folder to be copied from is root. // More coding will be required for ROBOCOPY to mirror correctly from root. // Therefor MirrorFreezeCopy will skipp the config for root folder. if (watcher.Action == WatcherAction.Freeze.ToString("g")) { DirectoryInfo directoryInfoDestination = new DirectoryInfo(watcher.Destination); if (directoryInfoDestination.Parent == null) { NLogger.Info( "Invalid Watcher:" + Environment.NewLine + "Action: {0}." + Environment.NewLine + "Source: {1}." + Environment.NewLine + "Destination: {2}." + Environment.NewLine + "Watcher Destination folder:" + Environment.NewLine + "{2}" + Environment.NewLine + "is root folder." + Environment.NewLine + "MirrorFreezeCopy will not Freeze from this folder.", watcher.Action, watcher.Source, watcher.Destination); return(true); } else { return(false); } } else { DirectoryInfo directoryInfoSource = new DirectoryInfo(watcher.Source); if (directoryInfoSource.Parent == null) { NLogger.Info( "Invalid Watcher:" + Environment.NewLine + "Action: {0}." + Environment.NewLine + "Source: {1}." + Environment.NewLine + "Destination: {2}." + Environment.NewLine + "Watcher Source folder:" + Environment.NewLine + "{1}" + Environment.NewLine + "is root folder." + Environment.NewLine + "MirrorFreezeCopy will not Mirror or Copy from this folder.", watcher.Action, watcher.Source, watcher.Destination); return(true); } else { return(false); } } }