/// <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; }
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="SubDirectoryTransfer"/> class. /// </summary> /// <param name="info">Serialization information.</param> /// <param name="context">Streaming context.</param> protected SubDirectoryTransfer(SerializationInfo info, StreamingContext context) { this.relativePath = info.GetString(SubDirRelativePathName); if (!(context.Context is StreamJournal)) { this.enumerateContinuationToken = (SerializableListContinuationToken)info.GetValue(SubDirListContinuationTokenName, typeof(SerializableListContinuationToken)); } }
public SubDirectoryTransfer( HierarchyDirectoryTransfer baseDirectoryTransfer, string relativePath) { this.enumerateContinuationToken = new SerializableListContinuationToken(null); this.baseDirectoryTransfer = baseDirectoryTransfer; this.relativePath = relativePath; this.baseDirectoryTransfer.GetSubDirLocation(this.relativePath, out this.source, out this.dest); this.InitializeEnumerator(); }
/// <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; }
/// <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)); if (context.Context is StreamJournal) { this.subTransfers = new TransferCollection <SingleObjectTransfer>(); } else { this.subTransfers = (TransferCollection <SingleObjectTransfer>)info.GetValue(SubTransfersName, typeof(TransferCollection <SingleObjectTransfer>)); } 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) { other.progressUpdateLock?.EnterWriteLock(); this.ProgressTracker = other.ProgressTracker.Copy(); lock (other.lockEnumerateContinuationToken) { // copy enumerator this.enumerateContinuationToken = other.enumerateContinuationToken; // copy transfers this.subTransfers = other.subTransfers.Copy(); } this.subTransfers.OverallProgressTracker.Parent = this.ProgressTracker; other.progressUpdateLock?.ExitWriteLock(); }
internal void AddSubDir(string relativePath, Func <SerializableListContinuationToken> updateContinuationToken) { if (null != this.Journal) { SerializableListContinuationToken continuationToken = updateContinuationToken(); this.Journal.AddSubDirTransfer(relativePath); this.Journal.UpdateJournalItem(continuationToken); } else { lock (this.continuationTokenLock) { this.subDirectories.Enqueue(relativePath); updateContinuationToken(); } } newAddSubDirResetEventSlim.Set(); }
internal void AddSingleObjectTransfer( SingleObjectTransfer singleObjectTransfer, Func <SerializableListContinuationToken> updateContinuationToken) { SerializableListContinuationToken listContinuationToken = null; // Add to subtransfers in the TransferCollection for checkpoint (journal without stream) lock (this.continuationTokenLock) { this.subTransfers.AddTransfer(singleObjectTransfer); listContinuationToken = updateContinuationToken(); } if (null != this.Journal) { this.Journal.AddSubtransfer(singleObjectTransfer); this.Journal.UpdateJournalItem(listContinuationToken); } this.TransferFile(singleObjectTransfer, this.currentScheduler, this.currentCancellationToken); }
private IEnumerable <SingleObjectTransfer> AllTransfers(CancellationToken cancellationToken) { if (null == this.Journal) { // return all existing transfers in subTransfers foreach (var transfer in this.subTransfers.GetEnumerator()) { Utils.CheckCancellation(cancellationToken); transfer.Context = this.Context; this.UpdateTransfer(transfer); yield return(transfer as SingleObjectTransfer); } } else { foreach (var transfer in this.Journal.ListSubTransfers()) { Utils.CheckCancellation(cancellationToken); transfer.Context = this.Context; this.UpdateTransfer(transfer); this.subTransfers.AddTransfer(transfer, false); yield return(transfer); } } while (true) { Utils.CheckCancellation(cancellationToken); Tuple <SingleObjectTransfer, TransferEntry> pair; try { pair = this.shouldTransferQueue.DequeueResult(); } catch (InvalidOperationException) { // Task queue is empty and CompleteAdding. No more transfer to dequeue. break; } catch (AggregateException aggregateException) { // Unwrap the AggregateException. ExceptionDispatchInfo.Capture(aggregateException.Flatten().InnerExceptions[0]).Throw(); break; } SingleObjectTransfer transfer = pair.Item1; TransferEntry entry = pair.Item2; lock (this.lockEnumerateContinuationToken) { if (null != transfer) { this.subTransfers.AddTransfer(transfer); } this.enumerateContinuationToken = new SerializableListContinuationToken(entry.ContinuationToken); } if (null != transfer) { this.Journal?.AddSubtransfer(transfer); } this.Journal?.UpdateJournalItem(this); if (null == transfer) { continue; } try { this.CreateParentDirectory(transfer); } catch (Exception ex) { transfer.OnTransferFailed(ex); // Don't keep failed transfers in memory if they can be persisted to a journal. if (null != this.Journal) { this.subTransfers.RemoveTransfer(transfer); } continue; } #if DEBUG FaultInjectionPoint fip = new FaultInjectionPoint(FaultInjectionPoint.FIP_ThrowExceptionAfterEnumerated); string fiValue; string filePath = entry.RelativePath; CloudBlob sourceBlob = transfer.Source.Instance as CloudBlob; if (sourceBlob != null && sourceBlob.IsSnapshot) { filePath = Utils.AppendSnapShotTimeToFileName(filePath, sourceBlob.SnapshotTime); } if (fip.TryGetValue(out fiValue) && string.Equals(fiValue, filePath, StringComparison.OrdinalIgnoreCase)) { throw new TransferException(TransferErrorCode.Unknown, "test exception thrown because of ThrowExceptionAfterEnumerated is enabled", null); } #endif yield return(transfer); } }
public SubDirectoryTransfer(SubDirectoryTransfer other) { this.relativePath = other.relativePath; this.enumerateContinuationToken = other.enumerateContinuationToken; }
public async Task ExecuteAsync(CancellationToken cancellationToken) { await Task.Yield(); this.CreateDestinationDirectory(cancellationToken); var enumerator = this.transferEnumerator.EnumerateLocation(cancellationToken).GetEnumerator(); while (true) { if (!enumerator.MoveNext()) { 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); } } if (entry.IsDirectory) { this.baseDirectoryTransfer.AddSubDir(entry.RelativePath, () => { var currentContinuationToken = new SerializableListContinuationToken(entry.ContinuationToken); currentContinuationToken.Journal = this.enumerateContinuationToken.Journal; currentContinuationToken.StreamJournalOffset = this.enumerateContinuationToken.StreamJournalOffset; this.enumerateContinuationToken = currentContinuationToken; return(this.enumerateContinuationToken); }); } else { SingleObjectTransfer transferItem = this.baseDirectoryTransfer.CreateTransfer(entry); #if DEBUG Utils.HandleFaultInjection(entry.RelativePath, transferItem); #endif this.CreateDestinationParentDirectoryRecursively(transferItem); this.baseDirectoryTransfer.AddSingleObjectTransfer(transferItem, () => { var currentContinuationToken = new SerializableListContinuationToken(entry.ContinuationToken); currentContinuationToken.Journal = this.enumerateContinuationToken.Journal; currentContinuationToken.StreamJournalOffset = this.enumerateContinuationToken.StreamJournalOffset; this.enumerateContinuationToken = currentContinuationToken; return(this.enumerateContinuationToken); }); } } }
private IEnumerable <SingleObjectTransfer> AllTransfers(CancellationToken cancellationToken) { if (null == this.Journal) { // return all existing transfers in subTransfers foreach (var transfer in this.subTransfers.GetEnumerator()) { Utils.CheckCancellation(cancellationToken); transfer.Context = this.Context; this.UpdateTransfer(transfer); yield return(transfer as SingleObjectTransfer); } } else { foreach (var transfer in this.Journal.ListSubTransfers()) { Utils.CheckCancellation(cancellationToken); transfer.Context = this.Context; this.UpdateTransfer(transfer); this.subTransfers.AddTransfer(transfer, false); yield return(transfer); } } while (true) { Utils.CheckCancellation(cancellationToken); Tuple <SingleObjectTransfer, TransferEntry> pair; try { pair = this.shouldTransferQueue.DequeueResult(); } catch (InvalidOperationException) { // Task queue is empty and CompleteAdding. No more transfer to dequeue. break; } catch (AggregateException aggregateException) { // Unwrap the AggregateException. ExceptionDispatchInfo.Capture(aggregateException.Flatten().InnerExceptions[0]).Throw(); break; } SingleObjectTransfer transfer = pair.Item1; TransferEntry entry = pair.Item2; lock (this.lockEnumerateContinuationToken) { if (null != transfer) { this.subTransfers.AddTransfer(transfer); } this.enumerateContinuationToken = new SerializableListContinuationToken(entry.ContinuationToken); } if (null != transfer) { this.Journal?.AddSubtransfer(transfer); } this.Journal?.UpdateJournalItem(this); if (null == transfer) { continue; } try { this.CreateParentDirectory(transfer); } catch (Exception ex) { transfer.OnTransferFailed(ex); // Don't keep failed transfers in memory if they can be persisted to a journal. if (null != this.Journal) { this.subTransfers.RemoveTransfer(transfer); } continue; } #if DEBUG Utils.HandleFaultInjection(entry.RelativePath, transfer); #endif yield return(transfer); } }