示例#1
0
        protected override void OnProcessRecord()
        {
            BlobUri blobUri;

            if (!BlobUri.TryParseUri(Source, out blobUri))
            {
                throw new ArgumentOutOfRangeException("Source", Source.ToString());
            }

            var storageKey = this.StorageKey;

            if (this.StorageKey == null)
            {
                var storageService = this.StorageClient.StorageAccounts.Get(blobUri.StorageAccountName);
                if (storageService != null)
                {
                    var storageKeys = this.StorageClient.StorageAccounts.GetKeys(storageService.StorageAccount.Name);
                    storageKey = storageKeys.PrimaryKey;
                }
            }

            var downloaderParameters = new DownloaderParameters
            {
                BlobUri               = blobUri,
                LocalFilePath         = LocalFilePath.FullName,
                ConnectionLimit       = NumberOfThreads,
                StorageAccountKey     = storageKey,
                ValidateFreeDiskSpace = true,
                OverWrite             = OverWrite
            };

            var vhdDownloadContext = VhdDownloaderModel.Download(downloaderParameters, this);

            WriteObject(vhdDownloadContext);
        }
示例#2
0
        private VhdDownloadContext DownloadFromBlobUri(
            ComputeClientBaseCmdlet cmdlet,
            Uri sourceUri,
            FileInfo localFileInfo,
            string storagekey,
            string resourceGroupName,
            int numThreads,
            bool overwrite)
        {
            BlobUri blobUri;

            if (!BlobUri.TryParseUri(sourceUri, out blobUri))
            {
                throw new ArgumentOutOfRangeException("Source", sourceUri.ToString());
            }

            if (storagekey == null)
            {
                var storageClient = AzureSession.Instance.ClientFactory.CreateArmClient <StorageManagementClient>(
                    DefaultProfile.DefaultContext, AzureEnvironment.Endpoint.ResourceManager);


                var storageService = storageClient.StorageAccounts.GetProperties(resourceGroupName, blobUri.StorageAccountName);
                if (storageService != null)
                {
                    var storageKeys = storageClient.StorageAccounts.ListKeys(resourceGroupName, storageService.Name);
                    storagekey = storageKeys.GetKey1();
                }
            }

            var downloaderParameters = new DownloaderParameters
            {
                BlobUri               = blobUri,
                LocalFilePath         = localFileInfo.FullName,
                ConnectionLimit       = numThreads,
                StorageAccountKey     = storagekey,
                ValidateFreeDiskSpace = true,
                OverWrite             = overwrite
            };

            return(VhdDownloaderModel.Download(downloaderParameters, cmdlet));
        }