Beispiel #1
0
            void BubbleUpClickEvent(object sender, EventArgs e)
            {
                TransferEntry entry = this as TransferEntry;

                //TransferListControl parent = entry.Item.Parent as TransferListControl;
                entry.Item.Selected = true;
            }
        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);
            }
        }
Beispiel #3
0
 private void CanceledItemFromList(TransferEntry entry)
 {
     entry.Remaining.Text = "";
     entry.Message.Text   = "Canceled";
     //entry.Item.BackColor = Color.SeaShell;
     entry.Item.SubItems[(int)ColumnIndex.Progress].Control = entry.Message;
     this.Invalidate();
 }
        protected override SingleObjectTransfer CreateTransfer(TransferEntry entry)
        {
            TransferLocation     sourceLocation = GetSourceTransferLocation(this.Source, entry);
            TransferLocation     destLocation   = GetDestinationTransferLocation(this.Destination, entry);
            SingleObjectTransfer transfer       = new SingleObjectTransfer(sourceLocation, destLocation, this.TransferMethod);

            transfer.Context = this.Context;
            return(transfer);
        }
Beispiel #5
0
        public void TransferStarted(object sender, TransferFileProgressArgs args)
        {
            string        key   = args.FilePath;
            TransferEntry entry = new TransferEntry(args);

            Debug.Assert(entry.Data.State == TransferState.STARTED);
            AddItemToList(entry);
            OnChangedTransferState(entry);
        }
Beispiel #6
0
        private void ListNewTransfers(CancellationToken cancellationToken)
        {
            // list new transfers
            if (this.enumerateContinuationToken != null)
            {
                this.SourceEnumerator.EnumerateContinuationToken = this.enumerateContinuationToken.ListContinuationToken;
            }

            ShouldTransferCallbackAsync shouldTransferCallback = this.DirectoryContext?.ShouldTransferCallbackAsync;

            try
            {
                var enumerator = this.SourceEnumerator.EnumerateLocation(cancellationToken).GetEnumerator();

                while (true)
                {
                    Utils.CheckCancellation(cancellationToken);

                    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);
                        }
                    }

                    this.shouldTransferQueue.EnqueueJob(async() =>
                    {
                        SingleObjectTransfer candidate = this.CreateTransfer(entry);

                        bool shouldTransfer = shouldTransferCallback == null || await shouldTransferCallback(candidate.Source.Instance, candidate.Destination.Instance);

                        return(new Tuple <SingleObjectTransfer, TransferEntry>(shouldTransfer ? candidate : null, entry));
                    });
                }
            }
            finally
            {
                this.shouldTransferQueue.CompleteAdding();
            }
        }
Beispiel #7
0
        internal SingleObjectTransfer CreateTransfer(TransferEntry entry)
        {
            TransferLocation sourceLocation = GetSourceTransferLocation(this.Source, entry);

            sourceLocation.IsInstanceInfoFetched = true;
            TransferLocation destLocation = GetDestinationTransferLocation(this.Destination, entry);
            var transferMethod            = IsDummyCopy(entry) ? TransferMethod.DummyCopy : this.TransferMethod;
            SingleObjectTransfer transfer = new SingleObjectTransfer(sourceLocation, destLocation, transferMethod);

            transfer.Context = this.Context;
            return(transfer);
        }
Beispiel #8
0
 private bool IsDummyCopy(TransferEntry entry)
 {
     if (this.Source.Type == TransferLocationType.AzureBlobDirectory &&
         this.Destination.Type == TransferLocationType.LocalDirectory)
     {
         if (IsDirectoryBlob((entry as AzureBlobEntry)?.Blob))
         {
             return(true);
         }
     }
     return(false);
 }
Beispiel #9
0
        public void TransferCompleted(object sender, TransferFileProgressArgs args)
        {
            string        key   = args.FilePath;
            TransferEntry entry = Transfers[key];

            if (entry == null)
            {
                return;
            }
            Debug.Assert(entry.Data.State == TransferState.COMPLETED);
            OnChangedTransferState(entry);
        }
Beispiel #10
0
        public void TransferCanceled(object sender, TransferFileProgressArgs args)
        {
            string        key   = args.FilePath;
            TransferEntry entry = Transfers[key];

            if (entry == null)
            {
                return;
            }
            Debug.Assert(entry.Data.State == TransferState.CANCELED);
            entry.Exception = args.Exception;
            OnChangedTransferState(entry);
        }
Beispiel #11
0
        public void TransferProgress(object sender, TransferFileProgressArgs args)
        {
            string        key   = args.FilePath;
            TransferEntry entry = Transfers[key];

            if (entry == null)
            {
                return;
            }
            Debug.Assert(entry.Data.State == TransferState.TRANSFERRING);
            //entry.Remaining.Text = FileSizeToString(entry.Data.TotalBytes - entry.Data.TransferredBytes);
            OnChangedTransferState(entry);
        }
Beispiel #12
0
        private void OnChangedTransferState(TransferEntry entry)
        {
            switch (entry.Data.State)
            {
            case TransferState.CANCELED:
                CanceledItemFromList(entry);
                break;

            case TransferState.FAILED:
                FailedItemFromList(entry);
                break;

            case TransferState.COMPLETED:
                RemoveItemFromList(entry);
                break;
            }
        }
Beispiel #13
0
        private void AddItemToList(TransferEntry entry)
        {
            // Add to our fast-lookup collection.
            Transfers.Add(entry);

            // Add to UI.
            GLItem item = this.Items.Add("");

            item.Tag = entry;
            item.SubItems[(int)ColumnIndex.Path].Control      = entry.Path;
            item.SubItems[(int)ColumnIndex.Remaining].Control = entry.Remaining;
            item.SubItems[(int)ColumnIndex.Progress].Control  = entry.Progress;
            entry.Item = item;

            // Invalidation is required in order to immediately display the control.
            this.Invalidate();
        }
Beispiel #14
0
        private void FailedItemFromList(TransferEntry entry)
        {
            entry.Remaining.Text = "";
            entry.Message.Text   = "Failed";
            entry.Item.BackColor = Color.SeaShell;
            entry.Item.SubItems[(int)ColumnIndex.Progress].Control = entry.Message;
            this.Invalidate();

            if (entry.Tooltip == null)
            {
                entry.Tooltip = new ToolTip();
                entry.Tooltip.AutoPopDelay = 5000;
                entry.Tooltip.InitialDelay = 100;
                entry.Tooltip.ReshowDelay  = 100;
                entry.Tooltip.ToolTipIcon  = ToolTipIcon.Error;
                entry.Tooltip.ToolTipTitle = "Transfer failed";
            }
            entry.Tooltip.SetToolTip(entry.Message, entry.Exception.Message);
        }
Beispiel #15
0
        private TransferLocation GetDestinationTransferLocation(TransferLocation dirLocation, TransferEntry entry)
        {
            string destRelativePath = this.nameResolver.ResolveName(entry);

            switch (dirLocation.Type)
            {
            case TransferLocationType.AzureBlobDirectory:
            {
                AzureBlobDirectoryLocation blobDirLocation = dirLocation as AzureBlobDirectoryLocation;
                BlobType destBlobType = this.BlobType;

                AzureBlobEntry sourceBlobEntry = entry as AzureBlobEntry;
                if (sourceBlobEntry != null)
                {
                    // if source is Azure blob storage, source and destination blob share the same blob type
                    destBlobType = sourceBlobEntry.Blob.BlobType;
                }

                CloudBlob blob = null;
                switch (destBlobType)
                {
                case Blob.BlobType.BlockBlob:
                case Blob.BlobType.Unspecified:
                    blob = blobDirLocation.BlobDirectory.GetBlockBlobReference(destRelativePath);
                    break;

                case Blob.BlobType.PageBlob:
                    blob = blobDirLocation.BlobDirectory.GetPageBlobReference(destRelativePath);
                    break;

                case Blob.BlobType.AppendBlob:
                    blob = blobDirLocation.BlobDirectory.GetAppendBlobReference(destRelativePath);
                    break;
                }

                AzureBlobLocation retLocation = new AzureBlobLocation(blob);
                retLocation.BlobRequestOptions = blobDirLocation.BlobRequestOptions;
                return(retLocation);
            }

            case TransferLocationType.AzureFileDirectory:
            {
                AzureFileDirectoryLocation fileDirLocation = dirLocation as AzureFileDirectoryLocation;
                CloudFile file = fileDirLocation.FileDirectory.GetFileReference(destRelativePath);
                CreateParentDirectoryIfNotExists(file);

                AzureFileLocation retLocation = new AzureFileLocation(file);
                retLocation.FileRequestOptions = fileDirLocation.FileRequestOptions;
                return(retLocation);
            }

            case TransferLocationType.LocalDirectory:
            {
                DirectoryLocation localDirLocation = dirLocation as DirectoryLocation;
                string            path             = Path.Combine(localDirLocation.DirectoryPath, destRelativePath);
                CreateParentDirectoryIfNotExists(path);

                return(new FileLocation(path));
            }

            default:
                throw new ArgumentException("TransferLocationType");
            }
        }
Beispiel #16
0
        private static TransferLocation GetSourceTransferLocation(TransferLocation dirLocation, TransferEntry entry)
        {
            switch (dirLocation.Type)
            {
            case TransferLocationType.AzureBlobDirectory:
                AzureBlobDirectoryLocation azureBlobDirLocation = dirLocation as AzureBlobDirectoryLocation;
                AzureBlobEntry             azureBlobEntry       = entry as AzureBlobEntry;

                AzureBlobLocation azureBlobLocation = new AzureBlobLocation(azureBlobEntry.Blob);
                azureBlobLocation.BlobRequestOptions = azureBlobDirLocation.BlobRequestOptions;

                return(azureBlobLocation);

            case TransferLocationType.AzureFileDirectory:
                AzureFileDirectoryLocation azureFileDirLocation = dirLocation as AzureFileDirectoryLocation;
                AzureFileEntry             azureFileEntry       = entry as AzureFileEntry;

                AzureFileLocation azureFileLocation = new AzureFileLocation(azureFileEntry.File);
                azureFileLocation.FileRequestOptions = azureFileDirLocation.FileRequestOptions;

                return(azureFileLocation);

            case TransferLocationType.LocalDirectory:
                FileEntry fileEntry = entry as FileEntry;

                return(new FileLocation(fileEntry.FullPath));

            default:
                throw new ArgumentException("TransferLocationType");
            }
        }
Beispiel #17
0
 public string ResolveName(TransferEntry sourceEntry)
 {
     return(sourceEntry.RelativePath.Replace('\\', '/'));
 }
Beispiel #18
0
 private void RemoveItemFromList(TransferEntry entry)
 {
     this.Items.Remove(entry.Item);
     this.Invalidate();
 }
Beispiel #19
0
        protected TransferLocation GetDestTransferLocationForEmptyDir(TransferLocation dirLocation, TransferEntry entry)
        {
            string destRelativePath = this.nameResolver.ResolveName(entry);

            AzureBlobEntry sourceBlobEntry = entry as AzureBlobEntry;

            switch (dirLocation.Type)
            {
            case TransferLocationType.AzureBlobDirectory:
            {
                return(null);
            }

            case TransferLocationType.AzureFileDirectory:
            {
                AzureFileDirectoryLocation fileDirLocation = dirLocation as AzureFileDirectoryLocation;
                CloudFileDirectory         destDirLocation = fileDirLocation.FileDirectory;

                if (!string.IsNullOrEmpty(destRelativePath))
                {
                    destDirLocation = destDirLocation.GetDirectoryReference(destRelativePath);
                }

                AzureFileDirectoryLocation retLocation = new AzureFileDirectoryLocation(destDirLocation);
                retLocation.FileRequestOptions = fileDirLocation.FileRequestOptions;
                return(retLocation);
            }

            case TransferLocationType.LocalDirectory:
            {
                return(null);
            }

            default:
                throw new ArgumentException("TransferLocationType");
            }
        }
 public string ResolveName(TransferEntry sourceEntry)
 {
     return(sourceEntry.RelativePath.TrimEnd(new char[] { ' ' }).Replace('\\', '/'));
 }
        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);
                    });
                }
            }
        }
        protected TransferLocation GetDestinationSubDirTransferLocation(TransferLocation dirLocation, TransferEntry entry)
        {
            string destRelativePath = this.NameResolver.ResolveName(entry);

            switch (dirLocation.Type)
            {
            case TransferLocationType.AzureBlobDirectory:
            {
                AzureBlobDirectoryLocation blobDirLocation = dirLocation as AzureBlobDirectoryLocation;
                BlobType destBlobType = this.BlobType;

                // TODO: should handle blob type here.
                AzureBlobDirectoryLocation retLocation = new AzureBlobDirectoryLocation(blobDirLocation.BlobDirectory.GetDirectoryReference(destRelativePath));
                retLocation.BlobRequestOptions = blobDirLocation.BlobRequestOptions;
                return(retLocation);
            }

            case TransferLocationType.AzureFileDirectory:
            {
                AzureFileDirectoryLocation fileDirLocation = dirLocation as AzureFileDirectoryLocation;
                CloudFileDirectory         azureDirectory  = fileDirLocation.FileDirectory.GetDirectoryReference(destRelativePath);

                AzureFileDirectoryLocation retLocation = new AzureFileDirectoryLocation(azureDirectory);
                retLocation.FileRequestOptions = fileDirLocation.FileRequestOptions;
                return(retLocation);
            }

            case TransferLocationType.LocalDirectory:
            {
                DirectoryLocation localDirLocation = dirLocation as DirectoryLocation;
                string            path             = LongPath.Combine(localDirLocation.DirectoryPath, destRelativePath);

                return(new DirectoryLocation(path));
            }

            default:
                throw new ArgumentException("TransferLocationType");
            }
        }
 public string ResolveName(TransferEntry sourceEntry)
 {
     return sourceEntry.RelativePath.TrimEnd(new char[] {' '}).Replace('\\', '/');
 }
Beispiel #24
0
 protected abstract SingleObjectTransfer CreateTransfer(TransferEntry entry);
 public string ResolveName(TransferEntry sourceEntry)
 {
     return sourceEntry.RelativePath.Replace('\\', '/');
 }
Beispiel #26
0
        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);
            }
        }
Beispiel #27
0
        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);
            }
        }