Пример #1
0
        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);
        }
Пример #2
0
        public void InitBasicPolicies()
        {
            _errorHandlingPolicies = new List <WatcherErrorHandlingPolicy>();

            WatcherErrorHandlingPolicy 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);

            WatcherErrorHandlingPolicy 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);
        }
Пример #3
0
 /// <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 Boolean RemovePolicy(WatcherErrorHandlingPolicy pol)
 {
     return(_errorHandlingPolicies.Remove(pol));
 }
Пример #4
0
 /// <summary>
 /// Adds an error handling policy
 /// </summary>
 /// <param name="pol"></param>
 public void AddPolicy(WatcherErrorHandlingPolicy pol)
 {
     _errorHandlingPolicies.Add(pol);
 }