Ejemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MissingTarget"/> class.
 /// </summary>
 /// <param name="destinationUrl">The destination URL for this entry</param>
 /// <param name="name">The name of the missing target</param>
 /// <param name="parent">The parent collection</param>
 /// <param name="targetActions">The target actions implementation to use</param>
 public MissingTarget(Uri destinationUrl, string name, CollectionTarget parent, ITargetActions <CollectionTarget, DocumentTarget, MissingTarget> targetActions)
 {
     _targetActions = targetActions;
     DestinationUrl = destinationUrl;
     Name           = name;
     Parent         = parent;
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FileSystemTarget"/> class.
 /// </summary>
 /// <param name="destinationUrl">The destination URL for this entry</param>
 /// <param name="collection">The underlying collection</param>
 /// <param name="targetActions">The target actions implementation to use</param>
 public FileSystemTarget([NotNull] Uri destinationUrl, [NotNull] ICollection collection, [NotNull] ITargetActions <CollectionTarget, DocumentTarget, MissingTarget> targetActions)
 {
     DestinationUrl = destinationUrl;
     Collection     = collection;
     Name           = collection.Name;
     Parent         = collection.Parent;
     _targetActions = targetActions;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FileSystemTarget"/> class.
 /// </summary>
 /// <param name="destinationUrl">The destination URL for this entry</param>
 /// <param name="document">The underlying document</param>
 /// <param name="targetActions">The target actions implementation to use</param>
 public FileSystemTarget([NotNull] Uri destinationUrl, [NotNull] IDocument document, [NotNull] ITargetActions <CollectionTarget, DocumentTarget, MissingTarget> targetActions)
 {
     DestinationUrl = destinationUrl;
     Document       = document;
     Name           = document.Name;
     Parent         = document.Parent;
     _targetActions = targetActions;
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DocumentTarget"/> class.
 /// </summary>
 /// <param name="parent">The parent collection</param>
 /// <param name="destinationUrl">The destination URL for this collection</param>
 /// <param name="document">The underlying document</param>
 /// <param name="targetActions">The target actions implementation to use</param>
 public DocumentTarget(
     [NotNull] CollectionTarget parent,
     [NotNull] Uri destinationUrl,
     [NotNull] IDocument document,
     [NotNull] ITargetActions <CollectionTarget, DocumentTarget, MissingTarget> targetActions)
     : base(targetActions, parent, destinationUrl, document)
 {
     Document = document;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="DocumentTarget"/> class.
 /// </summary>
 /// <param name="parent">The parent collection</param>
 /// <param name="destinationUrl">The destination URL for this collection</param>
 /// <param name="document">The underlying document</param>
 /// <param name="targetActions">The target actions implementation to use</param>
 public DocumentTarget(
     CollectionTarget parent,
     Uri destinationUrl,
     IDocument document,
     ITargetActions <CollectionTarget, DocumentTarget, MissingTarget> targetActions)
     : base(targetActions, parent, destinationUrl, document)
 {
     Document = document;
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CollectionTarget"/> class.
 /// </summary>
 /// <param name="destinationUrl">The destination URL for this collection</param>
 /// <param name="parent">The parent collection</param>
 /// <param name="collection">The underlying collection</param>
 /// <param name="created">Was this collection created by the <see cref="RecursiveExecutionEngine{TCollection,TDocument,TMissing}"/></param>
 /// <param name="targetActions">The target actions implementation to use</param>
 public CollectionTarget(
     Uri destinationUrl,
     CollectionTarget parent,
     ICollection collection,
     bool created,
     ITargetActions <CollectionTarget, DocumentTarget, MissingTarget> targetActions)
     : base(targetActions, parent, destinationUrl, collection)
 {
     Collection = collection;
     Created    = created;
 }
Ejemplo n.º 7
0
        private async Task <Engines.CollectionActionResult> LocalExecuteAsync(
            ITargetActions <CollectionTarget, DocumentTarget, MissingTarget> handler,
            Uri sourceUrl,
            SelectionResult sourceSelectionResult,
            FileSystemTarget targetInfo,
            DepthHeader depth,
            bool overwrite,
            CancellationToken cancellationToken)
        {
            Debug.Assert(sourceSelectionResult.Collection != null, "sourceSelectionResult.Collection != null");

            var engine = new RecursiveExecutionEngine <CollectionTarget, DocumentTarget, MissingTarget>(
                handler,
                overwrite,
                Logger);

            CollectionTarget parentCollection;
            ITarget          targetItem;

            if (targetInfo.Collection != null)
            {
                var collTarget = targetInfo.NewCollectionTarget();
                parentCollection = collTarget.Parent;
                targetItem       = collTarget;
            }
            else if (targetInfo.Document != null)
            {
                var docTarget = targetInfo.NewDocumentTarget();
                parentCollection = docTarget.Parent;
                targetItem       = docTarget;
            }
            else
            {
                var missingTarget = targetInfo.NewMissingTarget();
                parentCollection = missingTarget.Parent;
                targetItem       = missingTarget;
            }

            Debug.Assert(parentCollection != null, "Cannt copy or move the root collection.");
            if (parentCollection == null)
            {
                throw new InvalidOperationException("Cannt copy or move the root collection.");
            }

            return(await ExecuteAsync(
                       engine,
                       sourceUrl,
                       sourceSelectionResult,
                       parentCollection,
                       targetItem,
                       depth,
                       cancellationToken)
                   );
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CollectionTarget"/> class.
 /// </summary>
 /// <param name="destinationUrl">The destination URL for this collection</param>
 /// <param name="parent">The parent collection</param>
 /// <param name="collection">The underlying collection</param>
 /// <param name="created">Was this collection created by the <see cref="RecursiveExecutionEngine{TCollection,TDocument,TMissing}"/></param>
 /// <param name="targetActions">The target actions implementation to use</param>
 public CollectionTarget(
     [NotNull] Uri destinationUrl,
     [CanBeNull] CollectionTarget parent,
     [NotNull] ICollection collection,
     bool created,
     [NotNull] ITargetActions <CollectionTarget, DocumentTarget, MissingTarget> targetActions)
     : base(targetActions, parent, destinationUrl, collection)
 {
     Collection = collection;
     Created    = created;
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FileSystemTarget"/> class.
 /// </summary>
 /// <param name="destinationUrl">The destination URL for this entry</param>
 /// <param name="collection">The parent collection</param>
 /// <param name="name">The name of the missing target</param>
 /// <param name="targetActions">The target actions implementation to use</param>
 public FileSystemTarget(
     Uri destinationUrl,
     ICollection collection,
     string name,
     ITargetActions <CollectionTarget, DocumentTarget, MissingTarget> targetActions)
 {
     DestinationUrl = destinationUrl;
     Parent         = collection;
     Name           = name;
     _targetActions = targetActions;
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Creates a new instance of the <see cref="MissingTarget"/> class.
        /// </summary>
        /// <param name="destinationUrl">The destination URL for this entry</param>
        /// <param name="parent">The parent collection</param>
        /// <param name="name">The name of the missing target</param>
        /// <param name="targetActions">The target actions implementation to use</param>
        /// <returns>The newly created missing target object</returns>
        public static MissingTarget NewInstance(
            Uri destinationUrl,
            ICollection parent,
            string name,
            ITargetActions <CollectionTarget, DocumentTarget, MissingTarget> targetActions)
        {
            var collUrl    = destinationUrl.GetCollectionUri();
            var collTarget = new CollectionTarget(collUrl, null, parent, false, targetActions);
            var target     = new MissingTarget(destinationUrl, name, collTarget, targetActions);

            return(target);
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EntryTarget"/> class.
 /// </summary>
 /// <param name="targetActions">The target actions implementation to use</param>
 /// <param name="parent">The parent collection</param>
 /// <param name="destinationUrl">The destination URL for this entry</param>
 /// <param name="entry">The underlying entry</param>
 protected EntryTarget(
     ITargetActions <CollectionTarget, DocumentTarget, MissingTarget> targetActions,
     CollectionTarget parent,
     Uri destinationUrl,
     IEntry entry)
 {
     TargetActions  = targetActions;
     _entry         = entry;
     Name           = entry.Name;
     Parent         = parent;
     DestinationUrl = destinationUrl;
 }
Ejemplo n.º 12
0
        public static DocumentTarget NewInstance(
            [NotNull] Uri destinationUrl,
            [NotNull] IDocument document,
            [NotNull] ITargetActions <CollectionTarget, DocumentTarget, MissingTarget> targetActions)
        {
            var collUrl = destinationUrl.GetCollectionUri();

            Debug.Assert(document.Parent != null, "document.Parent != null");
            if (document.Parent == null)
            {
                throw new InvalidOperationException("A document must always have a parent collection.");
            }
            var collTarget = new CollectionTarget(collUrl, null, document.Parent, false, targetActions);
            var docTarget  = new DocumentTarget(collTarget, destinationUrl, document, targetActions);

            return(docTarget);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Creates a new instance of the <see cref="CollectionTarget"/> class.
        /// </summary>
        /// <param name="destinationUrl">The destination URL for this collection</param>
        /// <param name="collection">The underlying collection</param>
        /// <param name="targetActions">The target actions implementation to use</param>
        /// <returns>The created collection target object</returns>
        public static CollectionTarget NewInstance(
            Uri destinationUrl,
            ICollection collection,
            ITargetActions <CollectionTarget, DocumentTarget, MissingTarget> targetActions)
        {
            CollectionTarget parentTarget;

            if (collection.Parent != null)
            {
                var collUrl = destinationUrl.GetParent();
                parentTarget = new CollectionTarget(collUrl, null, collection.Parent, false, targetActions);
            }
            else
            {
                parentTarget = null;
            }

            var target = new CollectionTarget(destinationUrl, parentTarget, collection, false, targetActions);

            return(target);
        }
Ejemplo n.º 14
0
        public static FileSystemTarget FromSelectionResult(
            [NotNull] SelectionResult selectionResult,
            [NotNull] Uri destinationUri,
            [NotNull] ITargetActions <CollectionTarget, DocumentTarget, MissingTarget> targetActions)
        {
            if (selectionResult.IsMissing)
            {
                if (selectionResult.MissingNames.Count != 1)
                {
                    throw new InvalidOperationException();
                }
                return(new FileSystemTarget(destinationUri, selectionResult.Collection, selectionResult.MissingNames.Single(), targetActions));
            }

            if (selectionResult.ResultType == SelectionResultType.FoundCollection)
            {
                return(new FileSystemTarget(destinationUri, selectionResult.Collection, targetActions));
            }

            Debug.Assert(selectionResult.Document != null, "selectionResult.Document != null");
            return(new FileSystemTarget(destinationUri, selectionResult.Document, targetActions));
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="RecursiveExecutionEngine{TCollection,TDocument,TMissing}"/> class.
 /// </summary>
 /// <param name="handler">The handler that performs the operation on the targets</param>
 /// <param name="allowOverwrite">Is overwriting the destination allowed?</param>
 /// <param name="logger">The logger</param>
 public RecursiveExecutionEngine(ITargetActions <TCollection, TDocument, TMissing> handler, bool allowOverwrite, ILogger logger)
 {
     _handler        = handler;
     _allowOverwrite = allowOverwrite;
     _logger         = logger;
 }