/// <summary> /// Initializes a new instance of the <see cref="TransferJob"/> class. /// </summary> /// <param name="source">Source location.</param> /// <param name="dest">Destination location.</param> public TransferJob(TransferLocation source, TransferLocation dest) { this.Source = source; this.Destination = dest; this.CheckPoint = new SingleObjectCheckpoint(); }
/// <summary> /// Initializes a new instance of the <see cref="TransferJob"/> class. /// </summary> /// <param name="source">Source location.</param> /// <param name="dest">Destination location.</param> public TransferJob(TransferLocation source, TransferLocation dest) { this.Source = source; this.Destination = dest; this.CheckPoint = new SingleObjectCheckpoint(); }
/// <summary> /// Initializes a new instance of the <see cref="Transfer"/> class. /// </summary> /// <param name="source">Transfer source.</param> /// <param name="dest">Transfer destination.</param> /// <param name="transferMethod">Transfer method, see <see cref="TransferMethod"/> for detail available methods.</param> public Transfer(TransferLocation source, TransferLocation dest, TransferMethod transferMethod) { this.Source = source; this.Destination = dest; this.TransferMethod = transferMethod; this.ProgressTracker = new TransferProgressTracker(); }
/// <summary> /// Initializes a new instance of the <see cref="Transfer"/> class. /// </summary> /// <param name="source">Transfer source.</param> /// <param name="dest">Transfer destination.</param> /// <param name="transferMethod">Transfer method, see <see cref="TransferMethod"/> for detail available methods.</param> public Transfer(TransferLocation source, TransferLocation dest, TransferMethod transferMethod) { this.Source = source; this.Destination = dest; this.TransferMethod = transferMethod; this.ProgressTracker = new TransferProgressTracker(); }
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"); } }
/// <summary> /// Initializes a new instance of the <see cref="Transfer"/> class. /// </summary> /// <param name="source">Transfer source.</param> /// <param name="dest">Transfer destination.</param> /// <param name="transferMethod">Transfer method, see <see cref="TransferMethod"/> for detail available methods.</param> public Transfer(TransferLocation source, TransferLocation dest, TransferMethod transferMethod) { this.Source = source; this.Destination = dest; this.TransferMethod = transferMethod; this.ProgressTracker = new TransferProgressTracker(); this.OriginalFormatVersion = Constants.FormatVersion; }
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); }
// Summary: // Determines whether the specified transfer location is equal to the current transfer location. // // Parameters: // obj: // The transfer location to compare with the current transfer location. // // Returns: // true if the specified transfer location is equal to the current transfer location; otherwise, false. public override bool Equals(object obj) { TransferLocation location = obj as TransferLocation; if (location == null || this.Type != location.Type) { return(false); } return(this.ToString() == location.ToString()); }
protected override 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); }
private static void UpdateCredentials(TransferLocation dirLocation, TransferLocation subLocation) { if (dirLocation.Type == TransferLocationType.AzureBlobDirectory) { AzureBlobDirectoryLocation blobDirectoryLocation = dirLocation as AzureBlobDirectoryLocation; (subLocation as AzureBlobLocation).UpdateCredentials(blobDirectoryLocation.BlobDirectory.ServiceClient.Credentials); } else if (dirLocation.Type == TransferLocationType.AzureFileDirectory) { AzureFileDirectoryLocation fileDirectoryLocation = dirLocation as AzureFileDirectoryLocation; (subLocation as AzureFileLocation).UpdateCredentials(fileDirectoryLocation.FileDirectory.ServiceClient.Credentials); } }
private static INameResolver GetNameResolver(TransferLocation sourceLocation, TransferLocation destLocation) { Debug.Assert(sourceLocation != null, "sourceLocation"); Debug.Assert(destLocation != null, "destLocation"); switch (sourceLocation.Type) { case TransferLocationType.AzureBlobDirectory: if (destLocation.Type == TransferLocationType.AzureBlobDirectory) { return(new AzureBlobToAzureBlobNameResolver()); } else if (destLocation.Type == TransferLocationType.AzureFileDirectory) { return(new AzureBlobToAzureFileNameResolver(null)); } else if (destLocation.Type == TransferLocationType.LocalDirectory) { return(new AzureToFileNameResolver(null)); } break; case TransferLocationType.AzureFileDirectory: if (destLocation.Type == TransferLocationType.AzureBlobDirectory || destLocation.Type == TransferLocationType.AzureFileDirectory) { return(new AzureFileToAzureNameResolver()); } else if (destLocation.Type == TransferLocationType.LocalDirectory) { return(new AzureToFileNameResolver(null)); } break; case TransferLocationType.LocalDirectory: if (destLocation.Type == TransferLocationType.AzureBlobDirectory) { return(new FileToAzureBlobNameResolver()); } else if (destLocation.Type == TransferLocationType.AzureFileDirectory) { return(new FileToAzureFileNameResolver()); } break; default: throw new ArgumentException("Unsupported source location", "sourceLocation"); } throw new ArgumentException("Unsupported destination location", "destLocation"); }
/// <summary> /// Gets a transfer with the specified source location, destination location and transfer method. /// </summary> /// <param name="sourceLocation">Source location of the transfer.</param> /// <param name="destLocation">Destination location of the transfer.</param> /// <param name="transferMethod">Transfer method.</param> /// <returns>A transfer that matches the specified source location, destination location and transfer method; Or null if no matches.</returns> public Transfer GetTransfer(TransferLocation sourceLocation, TransferLocation destLocation, TransferMethod transferMethod) { Transfer transfer = null; if (this.transfers.TryGetValue(new TransferKey(sourceLocation, destLocation), out transfer)) { if (transfer.TransferMethod == transferMethod) { return(transfer); } } return(null); }
/// <summary> /// Creates the default request options for specific location. /// </summary> /// <param name="location">The location <see cref="TransferLocation"/> which needs get a default request options.</param> /// <returns>The default request options which implements <see cref="IRequestOptions"/> for specific location.</returns> internal static IRequestOptions CreateDefaultRequestOptions(TransferLocation location) { if (null == location) { throw new ArgumentNullException(nameof(location)); } IRequestOptions requestOptions; switch (location.Type) { case TransferLocationType.AzureBlob: requestOptions = ((AzureBlobLocation)location).Blob.Uri.Scheme == Uri.UriSchemeHttps ? DefaultHttpsBlobRequestOptions : DefaultBlobRequestOptions; break; case TransferLocationType.AzureBlobDirectory: requestOptions = ((AzureBlobDirectoryLocation)location).BlobDirectory.Uri.Scheme == Uri.UriSchemeHttps ? DefaultHttpsBlobRequestOptions : DefaultBlobRequestOptions; break; case TransferLocationType.AzureFile: requestOptions = ((AzureFileLocation)location).AzureFile.Uri.Scheme == Uri.UriSchemeHttps ? DefaultHttpsFileRequestOptions : DefaultFileRequestOptions; break; case TransferLocationType.AzureFileDirectory: requestOptions = ((AzureFileDirectoryLocation)location).FileDirectory.Uri.Scheme == Uri.UriSchemeHttps ? DefaultHttpsFileRequestOptions : DefaultFileRequestOptions; break; default: throw new ArgumentException( string.Format( CultureInfo.CurrentCulture, "{0} is invalid, cannot get IRequestOptions for location type {1}", nameof(location), location.Type)); } return(requestOptions); }
/// <summary> /// Initializes a new instance of the <see cref="SingleObjectTransfer"/> class. /// This constructor will check whether source and destination is valid for the operation: /// Uri is only valid for non-staging copy. /// cannot copy from local file/stream to local file/stream /// </summary> /// <param name="source">Transfer source.</param> /// <param name="dest">Transfer destination.</param> /// <param name="transferMethod">Transfer method, see <see cref="TransferMethod"/> for detail available methods.</param> public SingleObjectTransfer(TransferLocation source, TransferLocation dest, TransferMethod transferMethod) : base(source, dest, transferMethod) { if (null == source) { throw new ArgumentNullException("source"); } if (null == dest) { throw new ArgumentNullException("dest"); } if ((null != source.FilePath || null != source.Stream) && (null != dest.FilePath || null != dest.Stream)) { throw new InvalidOperationException(Resources.LocalToLocalTransferUnsupportedException); } if ((null != source.Blob) && (null != dest.Blob)) { if (source.Blob.BlobType != dest.Blob.BlobType) { throw new InvalidOperationException(Resources.SourceAndDestinationBlobTypeDifferent); } if (StorageExtensions.Equals(source.Blob, dest.Blob)) { throw new InvalidOperationException(Resources.SourceAndDestinationLocationCannotBeEqualException); } } if ((null != source.AzureFile) && (null != dest.AzureFile) && string.Equals(source.AzureFile.Uri.Host, dest.AzureFile.Uri.Host, StringComparison.OrdinalIgnoreCase) && string.Equals(source.AzureFile.Uri.AbsolutePath, dest.AzureFile.Uri.AbsolutePath, StringComparison.OrdinalIgnoreCase)) { throw new InvalidOperationException(Resources.SourceAndDestinationLocationCannotBeEqualException); } this.transferJob = new TransferJob(this.Source, this.Destination); this.transferJob.Transfer = this; }
/// <summary> /// Initializes a new instance of the <see cref="SingleObjectTransfer"/> class. /// This constructor will check whether source and destination is valid for the operation: /// Uri is only valid for non-staging copy. /// cannot copy from local file/stream to local file/stream /// </summary> /// <param name="source">Transfer source.</param> /// <param name="dest">Transfer destination.</param> /// <param name="transferMethod">Transfer method, see <see cref="TransferMethod"/> for detail available methods.</param> public SingleObjectTransfer(TransferLocation source, TransferLocation dest, TransferMethod transferMethod) : base(source, dest, transferMethod) { if (null == source) { throw new ArgumentNullException("source"); } if (null == dest) { throw new ArgumentNullException("dest"); } if ((null != source.FilePath || null != source.Stream) && (null != dest.FilePath || null != dest.Stream)) { throw new InvalidOperationException(Resources.LocalToLocalTransferUnsupportedException); } if ((null != source.Blob) && (null != dest.Blob)) { if (source.Blob.BlobType != dest.Blob.BlobType) { throw new InvalidOperationException(Resources.SourceAndDestinationBlobTypeDifferent); } if (StorageExtensions.Equals(source.Blob, dest.Blob)) { throw new InvalidOperationException(Resources.SourceAndDestinationLocationCannotBeEqualException); } } if ((null != source.AzureFile) && (null != dest.AzureFile) && string.Equals(source.AzureFile.Uri.Host, dest.AzureFile.Uri.Host, StringComparison.OrdinalIgnoreCase) && string.Equals(source.AzureFile.Uri.AbsolutePath, dest.AzureFile.Uri.AbsolutePath, StringComparison.OrdinalIgnoreCase)) { throw new InvalidOperationException(Resources.SourceAndDestinationLocationCannotBeEqualException); } this.transferJob = new TransferJob(this.Source, this.Destination); this.transferJob.Transfer = this; }
/// <summary> /// Initializes a new instance of the <see cref="SingleObjectTransfer"/> class. /// This constructor will check whether source and destination is valid for the operation: /// Uri is only valid for non-staging copy. /// cannot copy from local file/stream to local file/stream /// </summary> /// <param name="source">Transfer source.</param> /// <param name="dest">Transfer destination.</param> /// <param name="transferMethod">Transfer method, see <see cref="TransferMethod"/> for detail available methods.</param> public SingleObjectTransfer(TransferLocation source, TransferLocation dest, TransferMethod transferMethod) : base(source, dest, transferMethod) { Debug.Assert(source != null && dest != null); Debug.Assert( source.Type == TransferLocationType.FilePath || source.Type == TransferLocationType.Stream || source.Type == TransferLocationType.AzureBlob || source.Type == TransferLocationType.AzureFile || source.Type == TransferLocationType.SourceUri); Debug.Assert( dest.Type == TransferLocationType.FilePath || dest.Type == TransferLocationType.Stream || dest.Type == TransferLocationType.AzureBlob || dest.Type == TransferLocationType.AzureFile || dest.Type == TransferLocationType.SourceUri); Debug.Assert(!((source.Type == TransferLocationType.FilePath || source.Type == TransferLocationType.Stream) && (dest.Type == TransferLocationType.FilePath || dest.Type == TransferLocationType.Stream))); if (source.Type == TransferLocationType.AzureBlob && dest.Type == TransferLocationType.AzureBlob) { CloudBlob sourceBlob = (source as AzureBlobLocation).Blob; CloudBlob destBlob = (dest as AzureBlobLocation).Blob; if (sourceBlob.BlobType != destBlob.BlobType) { throw new InvalidOperationException(Resources.SourceAndDestinationBlobTypeDifferent); } if (StorageExtensions.Equals(sourceBlob, destBlob)) { throw new InvalidOperationException(Resources.SourceAndDestinationLocationCannotBeEqualException); } } if (source.Type == TransferLocationType.AzureFile && dest.Type == TransferLocationType.AzureFile) { CloudFile sourceFile = (source as AzureFileLocation).AzureFile; CloudFile destFile = (dest as AzureFileLocation).AzureFile; if (string.Equals(sourceFile.Uri.Host, destFile.Uri.Host, StringComparison.OrdinalIgnoreCase) && string.Equals(sourceFile.Uri.AbsolutePath, destFile.Uri.AbsolutePath, StringComparison.OrdinalIgnoreCase)) { throw new InvalidOperationException(Resources.SourceAndDestinationLocationCannotBeEqualException); } } this.transferJob = new TransferJob(this); }
/// <summary> /// Initializes a new instance of the <see cref="SingleObjectTransfer"/> class. /// This constructor will check whether source and destination is valid for the operation: /// Uri is only valid for non-staging copy. /// cannot copy from local file/stream to local file/stream /// </summary> /// <param name="source">Transfer source.</param> /// <param name="dest">Transfer destination.</param> /// <param name="transferMethod">Transfer method, see <see cref="TransferMethod"/> for detail available methods.</param> public SingleObjectTransfer(TransferLocation source, TransferLocation dest, TransferMethod transferMethod) : base(source, dest, transferMethod) { Debug.Assert(source != null && dest != null); Debug.Assert( source.Type == TransferLocationType.FilePath || source.Type == TransferLocationType.Stream || source.Type == TransferLocationType.AzureBlob || source.Type == TransferLocationType.AzureFile || source.Type == TransferLocationType.SourceUri); Debug.Assert( dest.Type == TransferLocationType.FilePath || dest.Type == TransferLocationType.Stream || dest.Type == TransferLocationType.AzureBlob || dest.Type == TransferLocationType.AzureFile || dest.Type == TransferLocationType.SourceUri); Debug.Assert(!((source.Type == TransferLocationType.FilePath || source.Type == TransferLocationType.Stream) && (dest.Type == TransferLocationType.FilePath || dest.Type == TransferLocationType.Stream))); if (source.Type == TransferLocationType.AzureBlob && dest.Type == TransferLocationType.AzureBlob) { CloudBlob sourceBlob = (source as AzureBlobLocation).Blob; CloudBlob destBlob = (dest as AzureBlobLocation).Blob; if (sourceBlob.BlobType != destBlob.BlobType) { throw new InvalidOperationException(Resources.SourceAndDestinationBlobTypeDifferent); } if (StorageExtensions.Equals(sourceBlob, destBlob)) { throw new InvalidOperationException(Resources.SourceAndDestinationLocationCannotBeEqualException); } } if (source.Type == TransferLocationType.AzureFile && dest.Type == TransferLocationType.AzureFile) { CloudFile sourceFile = (source as AzureFileLocation).AzureFile; CloudFile destFile = (dest as AzureFileLocation).AzureFile; if (string.Equals(sourceFile.Uri.Host, destFile.Uri.Host, StringComparison.OrdinalIgnoreCase) && string.Equals(sourceFile.Uri.AbsolutePath, destFile.Uri.AbsolutePath, StringComparison.OrdinalIgnoreCase)) { throw new InvalidOperationException(Resources.SourceAndDestinationLocationCannotBeEqualException); } } this.transferJob = new TransferJob(this); }
// Summary: // Determines whether the specified transfer location is equal to the current transfer location. // // Parameters: // obj: // The transfer location to compare with the current transfer location. // // Returns: // true if the specified transfer location is equal to the current transfer location; otherwise, false. public override bool Equals(object obj) { TransferLocation location = obj as TransferLocation; if (location == null || this.TransferLocationType != location.TransferLocationType) { return(false); } switch (this.TransferLocationType) { case TransferLocationType.AzureBlob: case TransferLocationType.AzureFile: case TransferLocationType.FilePath: case TransferLocationType.SourceUri: return(this.ToString() == location.ToString()); case TransferLocationType.Stream: default: return(false); } }
/// <summary> /// Initializes a new instance of the <see cref="DirectoryTransfer"/> class. /// </summary> /// <param name="source">Transfer source.</param> /// <param name="dest">Transfer destination.</param> /// <param name="transferMethod">Transfer method, see <see cref="TransferMethod"/> for detail available methods.</param> public DirectoryTransfer(TransferLocation source, TransferLocation dest, TransferMethod transferMethod) : base(source, dest, transferMethod) { this.Initialize(); }
private static DirectoryTransfer GetOrCreateDirectoryTransfer(TransferLocation sourceLocation, TransferLocation destLocation, TransferMethod transferMethod, TransferContext transferContext) { DirectoryTransfer directoryTransfer = null; Transfer transfer = GetTransfer(sourceLocation, destLocation, transferMethod, transferContext); if (transfer == null) { directoryTransfer = new DirectoryTransfer(sourceLocation, destLocation, transferMethod); if (transferContext != null) { transferContext.Checkpoint.AddTransfer(directoryTransfer); } } else { directoryTransfer = transfer as DirectoryTransfer; Debug.Assert(directoryTransfer != null, "directoryTransfer"); } directoryTransfer.MaxTransferConcurrency = configurations.ParallelOperations * Constants.ListSegmentLengthMultiplier; return directoryTransfer; }
/// <summary> /// Copy content, properties and metadata of an Azure file to another. /// </summary> /// <param name="sourceFile">The <see cref="CloudFile"/> that is the source Azure file.</param> /// <param name="destFile">The <see cref="CloudFile"/> that is the destination Azure file.</param> /// <param name="isServiceCopy">A flag indicating whether the copy is service-side asynchronous copy or not. /// If this flag is set to true, service-side asychronous copy will be used; if this flag is set to false, /// file is downloaded from source first, then uploaded to destination.</param> /// <param name="options">A <see cref="CopyOptions"/> object that specifies additional options for the operation.</param> /// <param name="context">A <see cref="TransferContext"/> object that represents the context for the current operation.</param> /// <param name="cancellationToken">A <see cref="CancellationToken"/> object to observe while waiting for a task to complete.</param> /// <returns>A <see cref="Task"/> object that represents the asynchronous operation.</returns> public static Task CopyAsync(CloudFile sourceFile, CloudFile destFile, bool isServiceCopy, CopyOptions options, TransferContext context, CancellationToken cancellationToken) { TransferLocation sourceLocation = new TransferLocation(sourceFile); TransferLocation destLocation = new TransferLocation(destFile); return CopyInternalAsync(sourceLocation, destLocation, isServiceCopy, options, context, cancellationToken); }
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"); } }
private static void UpdateTransferLocation(TransferLocation targetLocation, TransferLocation location) { // update storage credentials if (targetLocation.Type == TransferLocationType.AzureBlob) { AzureBlobLocation blobLocation = location as AzureBlobLocation; (targetLocation as AzureBlobLocation).UpdateCredentials(blobLocation.Blob.ServiceClient.Credentials); } else if (targetLocation.Type == TransferLocationType.AzureFile) { AzureFileLocation fileLocation = location as AzureFileLocation; (targetLocation as AzureFileLocation).UpdateCredentials(fileLocation.AzureFile.ServiceClient.Credentials); } else if (targetLocation.Type == TransferLocationType.AzureBlobDirectory) { AzureBlobDirectoryLocation blobDirectoryLocation = location as AzureBlobDirectoryLocation; (targetLocation as AzureBlobDirectoryLocation).UpdateCredentials(blobDirectoryLocation.BlobDirectory.ServiceClient.Credentials); } else if (targetLocation.Type == TransferLocationType.AzureFileDirectory) { AzureFileDirectoryLocation fileDirectoryLocation = location as AzureFileDirectoryLocation; (targetLocation as AzureFileDirectoryLocation).UpdateCredentials(fileDirectoryLocation.FileDirectory.ServiceClient.Credentials); } }
/// <summary> /// Initializes a new instance of the <see cref="MultipleObjectsTransfer"/> class. /// </summary> /// <param name="source">Transfer source.</param> /// <param name="dest">Transfer destination.</param> /// <param name="transferMethod">Transfer method, see <see cref="TransferMethod"/> for detail available methods.</param> public MultipleObjectsTransfer(TransferLocation source, TransferLocation dest, TransferMethod transferMethod) : base(source, dest, transferMethod) { this.subTransfers = new TransferCollection(); this.subTransfers.OverallProgressTracker.Parent = this.ProgressTracker; }
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"); } }
/// <summary> /// Download an Azure blob from Azure Blob Storage. /// </summary> /// <param name="sourceBlob">The <see cref="CloudBlob"/> that is the source Azure blob.</param> /// <param name="destPath">Path to the destination file.</param> /// <param name="options">A <see cref="DownloadOptions"/> object that specifies additional options for the operation.</param> /// <param name="context">A <see cref="TransferContext"/> object that represents the context for the current operation.</param> /// <param name="cancellationToken">A <see cref="CancellationToken"/> object to observe while waiting for a task to complete.</param> /// <returns>A <see cref="Task"/> object that represents the asynchronous operation.</returns> public static Task DownloadAsync(CloudBlob sourceBlob, string destPath, DownloadOptions options, TransferContext context, CancellationToken cancellationToken) { TransferLocation sourceLocation = new TransferLocation(sourceBlob); TransferLocation destLocation = new TransferLocation(destPath); if (options != null) { BlobRequestOptions requestOptions = Transfer_RequestOptions.DefaultBlobRequestOptions; requestOptions.DisableContentMD5Validation = options.DisableContentMD5Validation; sourceLocation.RequestOptions = requestOptions; } return DownloadInternalAsync(sourceLocation, destLocation, options, context, cancellationToken); }
private static void UpdateTransferLocation(TransferLocation targetLocation, TransferLocation location) { // update storage credentials if (targetLocation.TransferLocationType == TransferLocationType.AzureBlob) { targetLocation.UpdateCredentials(location.Blob.ServiceClient.Credentials); } else if (targetLocation.TransferLocationType == TransferLocationType.AzureFile) { targetLocation.UpdateCredentials(location.AzureFile.ServiceClient.Credentials); } }
private static Task CopyInternalAsync(TransferLocation sourceLocation, TransferLocation destLocation, bool isServiceCopy, CopyOptions options, TransferContext context, CancellationToken cancellationToken) { if (options != null) { sourceLocation.AccessCondition = options.SourceAccessCondition; destLocation.AccessCondition = options.DestinationAccessCondition; } Transfer transfer = CreateSingleObjectTransfer(sourceLocation, destLocation, isServiceCopy ? TransferMethod.AsyncCopy : TransferMethod.SyncCopy, context); return DoTransfer(transfer, cancellationToken); }
/// <summary> /// Initializes a new instance of the <see cref="DirectoryTransfer"/> class. /// </summary> /// <param name="source">Transfer source.</param> /// <param name="dest">Transfer destination.</param> /// <param name="transferMethod">Transfer method, see <see cref="TransferMethod"/> for detail available methods.</param> public DirectoryTransfer(TransferLocation source, TransferLocation dest, TransferMethod transferMethod) : base(source, dest, transferMethod) { this.Initialize(); }
private static Task DownloadInternalAsync(TransferLocation sourceLocation, TransferLocation destLocation, DownloadOptions options, TransferContext context, CancellationToken cancellationToken) { if (options != null) { sourceLocation.AccessCondition = options.SourceAccessCondition; } Transfer transfer = CreateSingleObjectTransfer(sourceLocation, destLocation, TransferMethod.SyncCopy, context); return DoTransfer(transfer, cancellationToken); }
private static Task UploadInternalAsync(TransferLocation sourceLocation, TransferLocation destLocation, UploadOptions options, TransferContext context, CancellationToken cancellationToken) { if (options != null) { destLocation.AccessCondition = options.DestinationAccessCondition; } Transfer transfer = CreateSingleObjectTransfer(sourceLocation, destLocation, TransferMethod.SyncCopy, context); if (options != null) { transfer.ContentType = options.ContentType; } return DoTransfer(transfer, cancellationToken); }
/// <summary> /// Copy file from an specified URI to an Azure file. /// </summary> /// <param name="sourceUri">The <see cref="System.Uri"/> of the source file.</param> /// <param name="destFile">The <see cref="CloudFile"/> that is the destination Azure file.</param> /// <param name="isServiceCopy">A flag indicating whether the copy is service-side asynchronous copy or not. /// If this flag is set to true, service-side asychronous copy will be used; if this flag is set to false, /// file is downloaded from source first, then uploaded to destination.</param> /// <param name="options">A <see cref="CopyOptions"/> object that specifies additional options for the operation.</param> /// <param name="context">A <see cref="TransferContext"/> object that represents the context for the current operation.</param> /// <param name="cancellationToken">A <see cref="CancellationToken"/> object to observe while waiting for a task to complete.</param> /// <returns>A <see cref="Task"/> object that represents the asynchronous operation.</returns> /// <remarks>Copying from an URI to Azure file synchronously is not supported yet.</remarks> public static Task CopyAsync(Uri sourceUri, CloudFile destFile, bool isServiceCopy, CopyOptions options, TransferContext context, CancellationToken cancellationToken) { if (!isServiceCopy) { throw new NotSupportedException(Resources.SyncCopyFromUriToAzureFileNotSupportedException); } TransferLocation sourceLocation = new TransferLocation(sourceUri); TransferLocation destLocation = new TransferLocation(destFile); return CopyInternalAsync(sourceLocation, destLocation, isServiceCopy, options, context, cancellationToken); }
private static INameResolver GetNameResolver(TransferLocation sourceLocation, TransferLocation destLocation) { Debug.Assert(sourceLocation != null, "sourceLocation"); Debug.Assert(destLocation != null, "destLocation"); switch(sourceLocation.Type) { case TransferLocationType.AzureBlobDirectory: if (destLocation.Type == TransferLocationType.AzureBlobDirectory) { return new AzureBlobToAzureBlobNameResolver(); } else if(destLocation.Type == TransferLocationType.AzureFileDirectory) { return new AzureBlobToAzureFileNameResolver(null); } else if(destLocation.Type == TransferLocationType.LocalDirectory) { return new AzureToFileNameResolver(null); } break; case TransferLocationType.AzureFileDirectory: if (destLocation.Type == TransferLocationType.AzureBlobDirectory || destLocation.Type == TransferLocationType.AzureFileDirectory) { return new AzureFileToAzureNameResolver(); } else if(destLocation.Type == TransferLocationType.LocalDirectory) { return new AzureToFileNameResolver(null); } break; case TransferLocationType.LocalDirectory: if (destLocation.Type == TransferLocationType.AzureBlobDirectory || destLocation.Type == TransferLocationType.AzureFileDirectory) { return new FileToAzureNameResolver(); } break; default: throw new ArgumentException("Unsupported source location", "sourceLocation"); } throw new ArgumentException("Unsupported destination location", "destLocation"); }
/// <summary> /// Upload a file to Azure Blob Storage. /// </summary> /// <param name="sourcePath">Path to the source file.</param> /// <param name="destBlob">The <see cref="CloudBlob"/> that is the destination Azure blob.</param> /// <param name="options">An <see cref="UploadOptions"/> object that specifies additional options for the operation.</param> /// <param name="context">A <see cref="TransferContext"/> object that represents the context for the current operation.</param> /// <returns>A <see cref="Task"/> object that represents the asynchronous operation.</returns> /// <param name="cancellationToken">A <see cref="CancellationToken"/> object to observe while waiting for a task to complete.</param> public static Task UploadAsync(string sourcePath, CloudBlob destBlob, UploadOptions options, TransferContext context, CancellationToken cancellationToken) { TransferLocation sourceLocation = new TransferLocation(sourcePath); TransferLocation destLocation = new TransferLocation(destBlob); return UploadInternalAsync(sourceLocation, destLocation, options, context, cancellationToken); }
private static void UpdateCredentials(TransferLocation dirLocation, TransferLocation subLocation) { if (dirLocation.Type == TransferLocationType.AzureBlobDirectory) { AzureBlobDirectoryLocation blobDirectoryLocation = dirLocation as AzureBlobDirectoryLocation; (subLocation as AzureBlobLocation).UpdateCredentials(blobDirectoryLocation.BlobDirectory.ServiceClient.Credentials); } else if (dirLocation.Type == TransferLocationType.AzureFileDirectory) { AzureFileDirectoryLocation fileDirectoryLocation = dirLocation as AzureFileDirectoryLocation; (subLocation as AzureFileLocation).UpdateCredentials(fileDirectoryLocation.FileDirectory.ServiceClient.Credentials); } }
/// <summary> /// Gets a transfer with the specified source location, destination location and transfer method. /// </summary> /// <param name="sourceLocation">Source location of the transfer.</param> /// <param name="destLocation">Destination location of the transfer.</param> /// <param name="transferMethod">Transfer method.</param> /// <returns>A transfer that matches the specified source location, destination location and transfer method; Or null if no matches.</returns> internal Transfer GetTransfer(TransferLocation sourceLocation, TransferLocation destLocation, TransferMethod transferMethod) { Transfer transfer = null; if (this.transfers.TryGetValue(new TransferKey(sourceLocation, destLocation), out transfer)) { if (transfer.TransferMethod == transferMethod) { return transfer; } } return null; }
private void SetRequestOptions(TransferLocation location, FileRequestOptions cmdletOptions) { FileRequestOptions requestOptions = location.RequestOptions as FileRequestOptions; if (null == requestOptions) { requestOptions = new FileRequestOptions(); } if (cmdletOptions.MaximumExecutionTime != null) { requestOptions.MaximumExecutionTime = cmdletOptions.MaximumExecutionTime; } if (cmdletOptions.ServerTimeout != null) { requestOptions.ServerTimeout = cmdletOptions.ServerTimeout; } requestOptions.DisableContentMD5Validation = true; location.RequestOptions = requestOptions; }
public SerializableTransferLocation(TransferLocation location) { this.Location = location; }
/// <summary> /// Initializes a new instance of the <see cref="DirectoryTransfer"/> class. /// </summary> /// <param name="source">Transfer source.</param> /// <param name="dest">Transfer destination.</param> /// <param name="transferMethod">Transfer method, see <see cref="TransferMethod"/> for detail available methods.</param> public DirectoryTransfer(TransferLocation source, TransferLocation dest, TransferMethod transferMethod) : base(source, dest, transferMethod) { }
private static SingleObjectTransfer GetOrCreateSingleObjectTransfer(TransferLocation sourceLocation, TransferLocation destLocation, TransferMethod transferMethod, TransferContext transferContext) { SingleObjectTransfer singleObjectTransfer = null; Transfer transfer = GetTransfer(sourceLocation, destLocation, transferMethod, transferContext); if (transfer == null) { singleObjectTransfer = new SingleObjectTransfer(sourceLocation, destLocation, transferMethod); if (transferContext != null) { transferContext.Checkpoint.AddTransfer(singleObjectTransfer); } } else { singleObjectTransfer = transfer as SingleObjectTransfer; Debug.Assert(singleObjectTransfer != null, "singleObjectTransfer"); } return singleObjectTransfer; }
/// <summary> /// Upload a file to Azure File Storage. /// </summary> /// <param name="sourceStream">A <see cref="System.IO.Stream"/> object providing the file content.</param> /// <param name="destFile">The <see cref="CloudFile"/> that is the destination Azure file.</param> /// <param name="options">An <see cref="UploadOptions"/> object that specifies additional options for the operation.</param> /// <param name="context">A <see cref="TransferContext"/> object that represents the context for the current operation.</param> /// <param name="cancellationToken">A <see cref="CancellationToken"/> object to observe while waiting for a task to complete.</param> /// <returns>A <see cref="Task"/> object that represents the asynchronous operation.</returns> public static Task UploadAsync(Stream sourceStream, CloudFile destFile, UploadOptions options, TransferContext context, CancellationToken cancellationToken) { TransferLocation sourceLocation = new TransferLocation(sourceStream); TransferLocation destLocation = new TransferLocation(destFile); return UploadInternalAsync(sourceLocation, destLocation, options, context, cancellationToken); }
public SerializableTransferLocation(TransferLocation location) { this.Location = location; }
/// <summary> /// Gets a transfer with the specified source location, destination location and transfer method. /// </summary> /// <param name="sourceLocation">Source location of the transfer.</param> /// <param name="destLocation">Destination location of the transfer.</param> /// <param name="transferMethod">Transfer method.</param> /// <returns>A transfer that matches the specified source location, destination location and transfer method; Or null if no matches.</returns> internal Transfer GetTransfer(TransferLocation sourceLocation, TransferLocation destLocation, TransferMethod transferMethod) { return(this.TransferCollection.GetTransfer(sourceLocation, destLocation, transferMethod)); }
/// <summary> /// Gets a transfer with the specified source location, destination location and transfer method. /// </summary> /// <param name="sourceLocation">Source location of the transfer.</param> /// <param name="destLocation">Destination location of the transfer.</param> /// <param name="transferMethod">Transfer method.</param> /// <returns>A transfer that matches the specified source location, destination location and transfer method; Or null if no matches.</returns> internal Transfer GetTransfer(TransferLocation sourceLocation, TransferLocation destLocation, TransferMethod transferMethod) { return this.TransferCollection.GetTransfer(sourceLocation, destLocation, transferMethod); }
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"); } }
/// <summary> /// Download an Azure file from Azure File Storage. /// </summary> /// <param name="sourceFile">The <see cref="CloudFile"/> that is the source Azure file.</param> /// <param name="destStream">A <see cref="System.IO.Stream"/> object representing the destination stream.</param> /// <param name="options">A <see cref="DownloadOptions"/> object that specifies additional options for the operation.</param> /// <param name="context">A <see cref="TransferContext"/> object that represents the context for the current operation.</param> /// <param name="cancellationToken">A <see cref="CancellationToken"/> object to observe while waiting for a task to complete.</param> /// <returns>A <see cref="Task"/> object that represents the asynchronous operation.</returns> public static Task DownloadAsync(CloudFile sourceFile, Stream destStream, DownloadOptions options, TransferContext context, CancellationToken cancellationToken) { TransferLocation sourceLocation = new TransferLocation(sourceFile); TransferLocation destLocation = new TransferLocation(destStream); if (options != null) { FileRequestOptions requestOptions = Transfer_RequestOptions.DefaultFileRequestOptions; requestOptions.DisableContentMD5Validation = options.DisableContentMD5Validation; sourceLocation.RequestOptions = requestOptions; } return DownloadInternalAsync(sourceLocation, destLocation, options, context, cancellationToken); }
private static Transfer CreateSingleObjectTransfer(TransferLocation sourceLocation, TransferLocation destLocation, TransferMethod transferMethod, TransferContext transferContext) { Transfer transfer = GetTransfer(sourceLocation, destLocation, transferMethod, transferContext); if (transfer == null) { transfer = new SingleObjectTransfer(sourceLocation, destLocation, transferMethod); if (transferContext != null) { transferContext.Checkpoint.AddTransfer(transfer); } } if (transferContext != null) { transfer.ProgressTracker.Parent = transferContext.OverallProgressTracker; transfer.Context = transferContext; } return transfer; }
protected void SetRequestOptions(TransferLocation location, BlobRequestOptions cmdletOptions) { BlobRequestOptions requestOptions = location.RequestOptions as BlobRequestOptions; if (null == requestOptions) { requestOptions = new BlobRequestOptions(); } if (cmdletOptions.MaximumExecutionTime != null) { requestOptions.MaximumExecutionTime = cmdletOptions.MaximumExecutionTime; } if (cmdletOptions.ServerTimeout != null) { requestOptions.ServerTimeout = cmdletOptions.ServerTimeout; } location.RequestOptions = requestOptions; }
/// <summary> /// Initializes a new instance of the <see cref="MultipleObjectsTransfer"/> class. /// </summary> /// <param name="source">Transfer source.</param> /// <param name="dest">Transfer destination.</param> /// <param name="transferMethod">Transfer method, see <see cref="TransferMethod"/> for detail available methods.</param> public MultipleObjectsTransfer(TransferLocation source, TransferLocation dest, TransferMethod transferMethod) : base(source, dest, transferMethod) { this.subTransfers = new TransferCollection <SingleObjectTransfer>(); this.subTransfers.OverallProgressTracker.Parent = this.ProgressTracker; }
private static Transfer GetTransfer(TransferLocation sourceLocation, TransferLocation destLocation, TransferMethod transferMethod, TransferContext transferContext) { Transfer transfer = null; if (transferContext != null) { transfer = transferContext.Checkpoint.GetTransfer(sourceLocation, destLocation, transferMethod); if (transfer != null) { // update transfer location information UpdateTransferLocation(transfer.Source, sourceLocation); UpdateTransferLocation(transfer.Destination, destLocation); } } return transfer; }