private async Task <Engines.CollectionActionResult> RemoteExecuteAsync( IRemoteTargetActions handler, Uri sourceUrl, SelectionResult sourceSelectionResult, Uri targetUrl, DepthHeader depth, bool overwrite, CancellationToken cancellationToken) { Debug.Assert(sourceSelectionResult.Collection != null, "sourceSelectionResult.Collection != null"); var parentCollectionUrl = targetUrl.GetParent(); var engine = new RecursiveExecutionEngine <RemoteCollectionTarget, RemoteDocumentTarget, RemoteMissingTarget>( handler, overwrite, Logger); var targetName = targetUrl.GetName(); var parentName = parentCollectionUrl.GetName(); var parentCollection = new RemoteCollectionTarget(null, parentName, parentCollectionUrl, false, handler); var targetItem = await handler.GetAsync(parentCollection, targetName, cancellationToken); return(await ExecuteAsync( engine, sourceUrl, sourceSelectionResult, parentCollection, targetItem, depth, cancellationToken) ); }
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) ); }
/// <summary> /// Executes the COPY or MOVE recursively /// </summary> /// <typeparam name="TCollection">The collection type</typeparam> /// <typeparam name="TDocument">The document type</typeparam> /// <typeparam name="TMissing">The type for a missing entry</typeparam> /// <param name="engine">The engine to use to perform the operation</param> /// <param name="sourceUrl">The source URL</param> /// <param name="sourceSelectionResult">The source element</param> /// <param name="parentCollection">The parent collection of the source element</param> /// <param name="targetItem">The target of the operation</param> /// <param name="depth">The depth</param> /// <param name="cancellationToken">The cancellcation token</param> /// <returns>The result of the operation</returns> private async Task <Engines.CollectionActionResult> ExecuteAsync <TCollection, TDocument, TMissing>( RecursiveExecutionEngine <TCollection, TDocument, TMissing> engine, Uri sourceUrl, SelectionResult sourceSelectionResult, TCollection parentCollection, ITarget targetItem, DepthHeader depth, CancellationToken cancellationToken) where TCollection : class, ICollectionTarget <TCollection, TDocument, TMissing> where TDocument : class, IDocumentTarget <TCollection, TDocument, TMissing> where TMissing : class, IMissingTarget <TCollection, TDocument, TMissing> { Debug.Assert(sourceSelectionResult.Collection != null, "sourceSelectionResult.Collection != null"); if (Logger.IsEnabled(LogLevel.Trace)) { Logger.LogTrace($"Copy or move from {sourceUrl} to {targetItem.DestinationUrl}"); } if (sourceSelectionResult.ResultType == SelectionResultType.FoundDocument) { ActionResult docResult; if (targetItem is TCollection) { // Cannot overwrite collection with document docResult = new ActionResult(ActionStatus.OverwriteFailed, targetItem); } else if (targetItem is TMissing) { var target = (TMissing)targetItem; docResult = await engine.ExecuteAsync( sourceUrl, sourceSelectionResult.Document, target, cancellationToken); } else { var target = (TDocument)targetItem; docResult = await engine.ExecuteAsync( sourceUrl, sourceSelectionResult.Document, target, cancellationToken); } var engineResult = new Engines.CollectionActionResult(ActionStatus.Ignored, parentCollection) { DocumentActionResults = new[] { docResult }, }; return(engineResult); } Engines.CollectionActionResult collResult; if (targetItem is TDocument) { // Cannot overwrite document with collection collResult = new Engines.CollectionActionResult(ActionStatus.OverwriteFailed, targetItem); } else if (targetItem is TMissing) { var target = (TMissing)targetItem; collResult = await engine.ExecuteAsync( sourceUrl, sourceSelectionResult.Collection, depth, target, cancellationToken); } else { var target = (TCollection)targetItem; collResult = await engine.ExecuteAsync( sourceUrl, sourceSelectionResult.Collection, depth, target, cancellationToken); } return(collResult); }