private void DoClean(FreshDirectory directory) { // Check for null if (directory == null) { throw new ArgumentNullException("directory"); } // Check for cancel if (cancel) { InvokeDirectoryScanned(new DirectorySkippedEventArgs(directory, new UserCancelledException())); return; } // Check that directory exists if (!directory.Exists) { InvokeDirectoryScanned(new DirectorySkippedEventArgs(directory, new DirectoryNotFoundException("Directory not found."))); return; } // Try to delete all sub directories try { foreach (var subDirectory in directory.GetSubDirectories()) { DoClean(subDirectory); } } catch (Exception e) { InvokeDirectoryScanned(new DirectorySkippedEventArgs(directory, e)); return; } // Check for cancel again if (cancel) { InvokeDirectoryScanned(new DirectorySkippedEventArgs(directory, new UserCancelledException())); return; } // Try to delete the directory try { directory.Delete(); InvokeDirectoryScanned(new DirectoryDeletedEventArgs(directory)); } catch (Exception e) { InvokeDirectoryScanned(new DirectorySkippedEventArgs(directory, e)); return; } }
/// <summary> /// Starts to clean the given directory. Returns immidiately. /// </summary> public void StartCleaning(FreshDirectory directory) { var thread = new Thread(Clean) { Name = "Cleaning: " + directory.FullName, IsBackground = false, }; thread.Start(directory); }
/// <summary> /// Cleans the given directory. /// </summary> public void Clean(FreshDirectory directory) { DoClean(directory); InvokeCleaningDone(); cancel = false; }
protected DirectoryScannedEventArgs(FreshDirectory result) { Directory = result; }
public DirectorySkippedEventArgs(FreshDirectory result, Exception exception) : base(result) { Exception = exception; }