public static VhdUploadContext Upload(UploadParameters uploadParameters) { Program.SyncOutput = new PSSyncOutputEvents(uploadParameters.Cmdlet); BlobCreatorBase blobCreator; if (uploadParameters.BaseImageUri != null) { blobCreator = new PatchingBlobCreator(uploadParameters.LocalFilePath, uploadParameters.DestinationUri, uploadParameters.BaseImageUri, uploadParameters.BlobObjectFactory, uploadParameters.OverWrite); } else { blobCreator = new BlobCreator(uploadParameters.LocalFilePath, uploadParameters.DestinationUri, uploadParameters.BlobObjectFactory, uploadParameters.OverWrite); } using (var uploadContext = blobCreator.Create()) { var synchronizer = new BlobSynchronizer(uploadContext, uploadParameters.NumberOfUploaderThreads); if (synchronizer.Synchronize()) { return(new VhdUploadContext { LocalFilePath = uploadParameters.LocalFilePath, DestinationUri = uploadParameters.DestinationUri.Uri }); } return(null); } }
public static VhdUploadContext Upload(UploadParameters uploadParameters) { Program.SyncOutput = new PSSyncOutputEvents(uploadParameters.Cmdlet); BlobCreatorBase blobCreator; if (uploadParameters.BaseImageUri != null) { blobCreator = new PatchingBlobCreator(uploadParameters.LocalFilePath, uploadParameters.DestinationUri, uploadParameters.BaseImageUri, uploadParameters.BlobObjectFactory, uploadParameters.OverWrite); } else { blobCreator = new BlobCreator(uploadParameters.LocalFilePath, uploadParameters.DestinationUri, uploadParameters.BlobObjectFactory, uploadParameters.OverWrite); } using (var uploadContext = blobCreator.Create()) { var synchronizer = new BlobSynchronizer(uploadContext, uploadParameters.NumberOfUploaderThreads); if (synchronizer.Synchronize()) { return new VhdUploadContext {LocalFilePath = uploadParameters.LocalFilePath, DestinationUri = uploadParameters.DestinationUri.Uri}; } return null; } }
public UploadParameters ValidateParameters() { BlobUri destinationUri; if (!BlobUri.TryParseUri(Destination, out destinationUri)) { throw new ArgumentOutOfRangeException("Destination", this.Destination.ToString()); } BlobUri baseImageUri = null; if (this.BaseImageUriToPatch != null) { if (!BlobUri.TryParseUri(BaseImageUriToPatch, out baseImageUri)) { throw new ArgumentOutOfRangeException("BaseImageUriToPatch", this.BaseImageUriToPatch.ToString()); } if (!String.IsNullOrEmpty(destinationUri.Uri.Query)) { var message = String.Format(Rsrc.AddAzureVhdCommandSASUriNotSupportedInPatchMode, destinationUri.Uri); throw new ArgumentOutOfRangeException("Destination", message); } } var storageCredentialsFactory = CreateStorageCredentialsFactory(); PathIntrinsics currentPath = SessionState.Path; var filePath = new FileInfo(currentPath.GetUnresolvedProviderPathFromPSPath(LocalFilePath.ToString())); using (var vds = new VirtualDiskStream(filePath.FullName)) { if (vds.DiskType == DiskType.Fixed) { long divisor = Convert.ToInt64(Math.Pow(2, 9)); long rem = 0; Math.DivRem(filePath.Length, divisor, out rem); if (rem != 0) { throw new ArgumentOutOfRangeException("LocalFilePath", "Given vhd file is a corrupted fixed vhd"); } } } var parameters = new UploadParameters( destinationUri, baseImageUri, filePath, OverWrite.IsPresent, (NumberOfUploaderThreads) ?? DefaultNumberOfUploaderThreads) { Cmdlet = this, BlobObjectFactory = new CloudPageBlobObjectFactory(storageCredentialsFactory, TimeSpan.FromMinutes(1)) }; return parameters; }
public UploadParameters ValidateParameters() { BlobUri destinationUri; if (!BlobUri.TryParseUri(Destination, out destinationUri)) { throw new ArgumentOutOfRangeException("Destination", this.Destination.ToString()); } BlobUri baseImageUri = null; if (this.BaseImageUriToPatch != null) { if (!BlobUri.TryParseUri(BaseImageUriToPatch, out baseImageUri)) { throw new ArgumentOutOfRangeException("BaseImageUriToPatch", this.BaseImageUriToPatch.ToString()); } if (!String.IsNullOrEmpty(destinationUri.Uri.Query)) { var message = String.Format(Rsrc.AddAzureVhdCommandSASUriNotSupportedInPatchMode, destinationUri.Uri); throw new ArgumentOutOfRangeException("Destination", message); } } var storageCredentialsFactory = CreateStorageCredentialsFactory(); PathIntrinsics currentPath = SessionState.Path; var filePath = new FileInfo(currentPath.GetUnresolvedProviderPathFromPSPath(LocalFilePath.ToString())); var parameters = new UploadParameters( destinationUri, baseImageUri, filePath, OverWrite.IsPresent, (NumberOfUploaderThreads) ?? DefaultNumberOfUploaderThreads) { Cmdlet = this, BlobObjectFactory = new CloudPageBlobObjectFactory(storageCredentialsFactory, TimeSpan.FromMinutes(1)) }; return parameters; }