/// <summary> /// Initializes a new instance of the <see cref="Transfer"/> class. /// </summary> protected Transfer(Transfer other) { this.Source = other.Source; this.Destination = other.Destination; this.TransferMethod = other.TransferMethod; this.ContentType = other.ContentType; this.ProgressTracker = other.ProgressTracker.Copy(); }
private async Task DoTransfer(Transfer transfer, TransferScheduler scheduler, CancellationToken cancellationToken) { using (transfer) { bool hasError = false; Interlocked.Increment(ref this.outstandingTasks); try { await transfer.ExecuteAsync(scheduler, cancellationToken); } catch { // catch exception thrown from sub-transfer as it's already recorded hasError = true; } finally { if (!hasError) { this.subTransfers.RemoveTransfer(transfer); } if (Interlocked.Decrement(ref this.outstandingTasks) == 0) { // all transfers are done this.allTransfersCompleteSource.SetResult(null); } this.enumerationResetEvent.Set(); } } }
protected abstract void UpdateTransfer(Transfer transfer);
/// <summary> /// Adds a transfer to the transfer checkpoint. /// </summary> /// <param name="transfer">The transfer to be kept track of.</param> internal void AddTransfer(Transfer transfer) { this.transfers.TryAdd(new TransferKey(transfer.Source, transfer.Destination), transfer); }
/// <summary> /// Adds a transfer to the transfer checkpoint. /// </summary> /// <param name="transfer">The transfer to be kept track of.</param> internal void AddTransfer(Transfer transfer) { this.TransferCollection.AddTransfer(transfer); }
private static bool TryAddTransfer(Transfer transfer) { return allTransfers.TryAdd(new TransferKey(transfer.Source, transfer.Destination), transfer); }
private static void RemoveTransfer(Transfer transfer) { Transfer unused = null; allTransfers.TryRemove(new TransferKey(transfer.Source, transfer.Destination), out unused); }
/// <summary> /// Initializes a new instance of the <see cref="TransferJob"/> class. /// </summary> /// <param name="transfer">Transfer object.</param> public TransferJob(Transfer transfer) { this.Transfer = transfer; this.CheckPoint = new SingleObjectCheckpoint(); }
private static async Task DoTransfer(Transfer transfer, CancellationToken cancellationToken) { if (!TryAddTransfer(transfer)) { throw new TransferException(TransferErrorCode.TransferAlreadyExists, Resources.TransferAlreadyExists); } try { await transfer.ExecuteAsync(scheduler, cancellationToken); } finally { RemoveTransfer(transfer); } }
protected override void UpdateTransfer(Transfer transfer) { DirectoryTransfer.UpdateCredentials(this.Source, transfer.Source); DirectoryTransfer.UpdateCredentials(this.Destination, transfer.Destination); }
private static async Task DoTransfer(Transfer transfer, TransferContext transferContext, CancellationToken cancellationToken) { using (transfer) { if (!TryAddTransfer(transfer)) { throw new TransferException(TransferErrorCode.TransferAlreadyExists, Resources.TransferAlreadyExists); } if (transferContext != null) { if (transfer.Context == null) { // associate transfer with transfer context transfer.Context = transferContext; } } try { await transfer.ExecuteAsync(scheduler, cancellationToken); } finally { RemoveTransfer(transfer); } } }
/// <summary> /// Remove a transfer. /// </summary> /// <param name="transfer">Transfer to be removed</param> /// <returns>True if the transfer is removed successfully, false otherwise.</returns> public bool RemoveTransfer(Transfer transfer) { Transfer unused = null; if (this.transfers.TryRemove(new TransferKey(transfer.Source, transfer.Destination), out unused)) { transfer.ProgressTracker.Parent = null; return true; } return false; }
/// <summary> /// Adds a transfer. /// </summary> /// <param name="transfer">The transfer to be added.</param> public void AddTransfer(Transfer transfer) { transfer.ProgressTracker.Parent = this.OverallProgressTracker; this.overallProgressTracker.AddProgress(transfer.ProgressTracker); bool unused = this.transfers.TryAdd(new TransferKey(transfer.Source, transfer.Destination), transfer); Debug.Assert(unused, "Transfer with the same source and destination already exists"); }