예제 #1
0
        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;
            }
        }
예제 #2
0
        /// <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);
        }
예제 #3
0
 /// <summary>
 /// Cleans the given directory.
 /// </summary>
 public void Clean(FreshDirectory directory)
 {
     DoClean(directory);
     InvokeCleaningDone();
     cancel = false;
 }
예제 #4
0
 protected DirectoryScannedEventArgs(FreshDirectory result)
 {
     Directory = result;
 }
 public DirectorySkippedEventArgs(FreshDirectory result, Exception exception)
     : base(result)
 {
     Exception = exception;
 }