public void InitBasicPolicies() { _errorHandlingPolicies = new List<WatcherErrorHandlingPolicy>(); var accessDeniedPolicy = new WatcherErrorHandlingPolicy( typeof (Win32Exception), "When an 'access denied' win32 exception occures, refresh the wrapped watcher.", exception => (exception as Win32Exception)?.NativeErrorCode == 5 ? WatcherErrorHandlingType.RefreshAndSwallow : WatcherErrorHandlingType.Forward); var netNameDeletedPolicy = new WatcherErrorHandlingPolicy( typeof (Win32Exception), "When a 'net name deleted' win32 exception occures, refresh the wrapped watcher.", exception => (exception as Win32Exception)?.NativeErrorCode == 64 ? WatcherErrorHandlingType.RefreshAndSwallow : WatcherErrorHandlingType.Forward); _errorHandlingPolicies.Add(accessDeniedPolicy); _errorHandlingPolicies.Add(netNameDeletedPolicy); }
/// <summary> /// Tries to remove a specific error handling policy /// </summary> /// <param name="pol">The policy to remove</param> /// <returns> /// true if policy is successfully removed; otherwise, false. This method also returns /// false if policy was not found in the policies collection. /// </returns> public bool RemovePolicy(WatcherErrorHandlingPolicy pol) { return _errorHandlingPolicies.Remove(pol); }
/// <summary> /// Adds an error handling policy /// </summary> /// <param name="pol"></param> public void AddPolicy(WatcherErrorHandlingPolicy pol) { _errorHandlingPolicies.Add(pol); }
private void InitPollerErrorPolicies() { var dirNotFoundPolicy = new WatcherErrorHandlingPolicy(typeof(DirectoryNotFoundException), "When the poller indicates a 'directory not found' exception check if it's the main watched directory or sub-dir." + "If it's the main directory - refresh the watcher.", exception => (exception as DirectoryNotFoundException)?.Path() == Path ? WatcherErrorHandlingType.Refresh | WatcherErrorHandlingType.Swallow : WatcherErrorHandlingType.Forward); var unAuthPolicy = new WatcherErrorHandlingPolicy(typeof(UnauthorizedAccessException), "When the poller indicates an 'unauthorized access' exception check if it's access was denied to the main watched directory or file/sub-dir." + "If it's the main directory - refresh the watcher.", exception => (exception as UnauthorizedAccessException)?.Path() == Path ? WatcherErrorHandlingType.Refresh | WatcherErrorHandlingType.Swallow : WatcherErrorHandlingType.Forward); AddPolicy(dirNotFoundPolicy); AddPolicy(unAuthPolicy); }