protected static TransferLocation GetSourceDirectoryTransferLocation(TransferLocation dirLocation, string relativePath)
        {
            if (dirLocation.Type == TransferLocationType.AzureFileDirectory)
            {
                AzureFileDirectoryLocation azureFileDirLocation = dirLocation as AzureFileDirectoryLocation;
                var destDirectory = azureFileDirLocation.FileDirectory.GetDirectoryReference(relativePath);

                AzureFileDirectoryLocation azureFileLocation = new AzureFileDirectoryLocation(destDirectory);
                azureFileLocation.FileRequestOptions = azureFileDirLocation.FileRequestOptions;

                return(azureFileLocation);
            }
            else if (dirLocation.Type == TransferLocationType.LocalDirectory)
            {
                DirectoryLocation localDirLocation = dirLocation as DirectoryLocation;
                var destDirectory = Path.Combine(localDirLocation.DirectoryPath, relativePath);

                DirectoryLocation localSubDirLocation = new DirectoryLocation(destDirectory);

                return(localSubDirLocation);
            }
            else
            {
                // For now, HierarchyDirectoryTransfer should only be used when source is Azure File Directory.
                throw new ArgumentException("TransferLocationType");
            }
        }
        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");
            }
        }
Пример #3
0
        protected TransferLocation GetDestinationTransferLocation(TransferLocation dirLocation, TransferEntry entry)
        {
            string destRelativePath = this.nameResolver.ResolveName(entry);

            AzureBlobEntry sourceBlobEntry = entry as AzureBlobEntry;

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

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

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

                return(new FileLocation(path, destRelativePath));
            }

            default:
                throw new ArgumentException("TransferLocationType");
            }
        }