コード例 #1
0
 public void Perform_Fails_IfAllRetriesFail()
 {
     Assert.Throws <Exception>(() =>
     {
         ActionRetryer.Perform(() => { throw new Exception("Derp."); });
     });
 }
コード例 #2
0
        /// <summary>
        /// Removes an item but does not process any descendant items. You probably almost never want to use this, in favor of Remove() instead.
        /// This method is here for when a specific item needs to be removed, without messing with children. This occurs for example when
        /// you move an item which has loopback pathed children, who may preserve the same source and destination location.
        /// </summary>
        public virtual void RemoveWithoutChildren(IItemMetadata descendant)
        {
            lock (FileUtil.GetFileLock(descendant.SerializedItemId))
            {
                BeforeFilesystemDelete(descendant.SerializedItemId);
                try
                {
                    ActionRetryer.Perform(() =>
                    {
                        _treeWatcher.PushKnownUpdate(descendant.SerializedItemId, TreeWatcher.TreeWatcherChangeType.Delete);
                        File.Delete(descendant.SerializedItemId);
                    });
                }
                catch (Exception exception)
                {
                    throw new SfsDeleteException("Error deleting SFS item " + descendant.SerializedItemId, exception);
                }
                AfterFilesystemDelete(descendant.SerializedItemId);

                var childrenDirectory = Path.ChangeExtension(descendant.SerializedItemId, null);

                if (Directory.Exists(childrenDirectory))
                {
                    BeforeFilesystemDelete(childrenDirectory);
                    try
                    {
                        ActionRetryer.Perform(() =>
                        {
                            _treeWatcher.PushKnownUpdate(childrenDirectory, TreeWatcher.TreeWatcherChangeType.Delete);
                            Directory.Delete(childrenDirectory, true);
                        });
                    }
                    catch (Exception exception)
                    {
                        throw new SfsDeleteException("Error deleting SFS directory " + childrenDirectory, exception);
                    }
                    AfterFilesystemDelete(childrenDirectory);
                }

                var shortChildrenDirectory = new DirectoryInfo(Path.Combine(_physicalRootPath, descendant.Id.ToString()));
                if (shortChildrenDirectory.Exists && !shortChildrenDirectory.EnumerateFiles().Any())
                {
                    BeforeFilesystemDelete(shortChildrenDirectory.FullName);
                    try
                    {
                        ActionRetryer.Perform(() =>
                        {
                            _treeWatcher.PushKnownUpdate(shortChildrenDirectory.FullName, TreeWatcher.TreeWatcherChangeType.Delete);
                            Directory.Delete(shortChildrenDirectory.FullName);
                        });
                    }
                    catch (Exception exception)
                    {
                        throw new SfsDeleteException("Error deleting SFS directory " + shortChildrenDirectory, exception);
                    }
                    AfterFilesystemDelete(shortChildrenDirectory.FullName);
                }
            }
        }
コード例 #3
0
        public void Perform_PerformsAction()
        {
            bool run = false;

            ActionRetryer.Perform(() => { run = true; });

            run.Should().BeTrue();
        }
コード例 #4
0
        public virtual void Clear()
        {
            // since we're tearing everything down we dispose all existing trees, watchers, etc and start over
            foreach (var tree in Trees)
            {
                tree.Dispose();
            }
            Trees.Clear();

            ActionRetryer.Perform(ClearAllFiles);

            // bring the trees back up, which will reestablish watchers and such
            Trees.AddRange(InitializeTrees(_formatter, _useDataCache));
        }
コード例 #5
0
        public void Perform_RetrySucceeds()
        {
            bool first = false;
            bool run   = false;

            ActionRetryer.Perform(() =>
            {
                if (first)
                {
                    first = false;
                    throw new Exception("Derp.");
                }

                run = true;
            });

            run.Should().BeTrue();
        }