private IEnumerable<Transfer> AllTransfers(CancellationToken cancellationToken) { // return all existing transfers in subTransfers foreach (var transfer in this.subTransfers.GetEnumerator()) { Utils.CheckCancellation(cancellationToken); transfer.Context = this.Context; transfer.ContentType = this.ContentType; this.UpdateTransfer(transfer); yield return transfer; } // list new transfers if (this.enumerateContinuationToken != null) { this.SourceEnumerator.EnumerateContinuationToken = this.enumerateContinuationToken.ListContinuationToken; } var enumerator = this.SourceEnumerator.EnumerateLocation(cancellationToken).GetEnumerator(); while (true) { Utils.CheckCancellation(cancellationToken); // lock enumerator if (!enumerator.MoveNext()) { yield break; } TransferEntry entry = enumerator.Current; ErrorEntry errorEntry = entry as ErrorEntry; if (errorEntry != null) { TransferException exception = errorEntry.Exception as TransferException; if (null != exception) { throw exception; } else { throw new TransferException( TransferErrorCode.FailToEnumerateDirectory, errorEntry.Exception.GetExceptionMessage(), errorEntry.Exception); } } Transfer transfer = this.CreateTransfer(entry); lock (this.lockEnumerateContinuationToken) { this.subTransfers.AddTransfer(transfer); this.enumerateContinuationToken = new SerializableListContinuationToken(entry.ContinuationToken); } yield return transfer; } }
/// <summary> /// Initializes a new instance of the <see cref="MultipleObjectsTransfer"/> class. /// </summary> /// <param name="info">Serialization information.</param> /// <param name="context">Streaming context.</param> protected MultipleObjectsTransfer(SerializationInfo info, StreamingContext context) : base(info, context) { this.enumerateContinuationToken = (SerializableListContinuationToken)info.GetValue(ListContinuationTokenName, typeof(SerializableListContinuationToken)); this.subTransfers = (TransferCollection)info.GetValue(SubTransfersName, typeof(TransferCollection)); this.subTransfers.OverallProgressTracker.Parent = this.ProgressTracker; }
/// <summary> /// Initializes a new instance of the <see cref="MultipleObjectsTransfer"/> class. /// </summary> /// <param name="other">Another <see cref="MultipleObjectsTransfer"/> object.</param> protected MultipleObjectsTransfer(MultipleObjectsTransfer other) : base(other) { lock (other.lockEnumerateContinuationToken) { // copy enumerator this.enumerateContinuationToken = other.enumerateContinuationToken; // copy transfers this.subTransfers = other.subTransfers.Copy(); } this.subTransfers.OverallProgressTracker.Parent = this.ProgressTracker; }