Exemplo n.º 1
0
 public Downloader(BlobUri blobUri, string storageAccountKey, string locaFilePath)
 {
     this.parameters = new DownloaderParameters
     {
         BlobUri                  = blobUri,
         LocalFilePath            = locaFilePath,
         ConnectionLimit          = DefaultConnectionLimit,
         StorageAccountKey        = storageAccountKey,
         ValidateFreeDiskSpace    = false,
         ProgressDownloadStatus   = Program.SyncOutput.ProgressDownloadStatus,
         ProgressDownloadComplete = Program.SyncOutput.ProgressDownloadComplete
     };
 }
Exemplo n.º 2
0
 public Downloader(BlobUri blobUri, string storageAccountKey, string locaFilePath)
 {
     this.parameters = new DownloaderParameters
     {
         BlobUri = blobUri,
         LocalFilePath = locaFilePath,
         ConnectionLimit = DefaultConnectionLimit,
         StorageAccountKey = storageAccountKey,
         ValidateFreeDiskSpace = false,
         ProgressDownloadStatus = Program.SyncOutput.ProgressDownloadStatus,
         ProgressDownloadComplete = Program.SyncOutput.ProgressDownloadComplete
     };
 }
        public static VhdDownloadContext Download(DownloaderParameters downloadParameters, ServiceManagementBaseCmdlet cmdlet)
        {
            Program.SyncOutput = new PSSyncOutputEvents(cmdlet);

            downloadParameters.ProgressDownloadComplete = Program.SyncOutput.ProgressDownloadComplete;
            downloadParameters.ProgressDownloadStatus = Program.SyncOutput.ProgressDownloadStatus;

            var downloader = new Downloader(downloadParameters);
            downloader.Download();

            return new VhdDownloadContext
            {
                LocalFilePath =  new FileInfo(downloadParameters.LocalFilePath),
                Source = downloadParameters.BlobUri.Uri
            };
        }
Exemplo n.º 4
0
 public Downloader(DownloaderParameters parameters)
 {
     this.parameters = parameters;
 }
Exemplo n.º 5
0
 public Downloader(DownloaderParameters parameters)
 {
     this.parameters = parameters;
 }
        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.ClientFactory.CreateClient<StorageManagementClient>(
                        DefaultProfile.Context, AzureEnvironment.Endpoint.ResourceManager);


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

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

            return VhdDownloaderModel.Download(downloaderParameters, cmdlet);
        }
        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);
        }