Esempio n. 1
0
        private void RemoveFile(CleanupWorkItem item)
        {
            //File names are never embedded into the first item, they are provided on-demand by a LazyProvider
            LazyTaskProvider provider = item.LazyProvider;

            item = provider();
            if (item == null)
            {
                return;                   //The provider is out of possible items
            }
            item.LazyProvider = provider; //So if this item fails, we can queue 'item' again and the next task run will get the next alternative.

            bool removedFile = false;

            cache.Locks.TryExecuteSynchronous(item.RelativePath.ToUpperInvariant(), 10, CancellationToken.None, delegate
            {
                //If the file is already gone, consider the mission a success.
                if (!File.Exists(item.PhysicalPath))
                {
                    cache.Index.SetCachedFileInfo(item.RelativePath, null);
                    removedFile = true;
                    return;
                }
                //Cool, we got a lock on the file.
                //Remove it from the cache. Better a miss than an invalidation.
                cache.Index.SetCachedFileInfo(item.RelativePath, null);
                try {
                    File.Delete(item.PhysicalPath);
                } catch (IOException) {
                    return; //The file is in use, or has an open handle. - try the next file.
                } catch (UnauthorizedAccessException) {
                    return; //Invalid NTFS permissions or readonly file.  - try the next file
                }

                cache.Index.SetCachedFileInfo(item.RelativePath, null); //In case it crossed paths.
                removedFile = true;
            });

            //If we didn't remove a file, insert the task back in the queue for the next iteration.
            if (!removedFile)
            {
                queue.Insert(item);
            }
        }
Esempio n. 2
0
 public CleanupWorkItem(Kind task, LazyTaskProvider callback)
 {
     this.Task         = task;
     this.LazyProvider = callback;
 }
Esempio n. 3
0
 public CleanupWorkItem(Kind task, LazyTaskProvider callback)
 {
     this.task = task;
     this.lazyProvider = callback;
 }