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(Resources.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)
            {
                Cmdlet = this,
                BlobObjectFactory = new CloudPageBlobObjectFactory(storageCredentialsFactory, TimeSpan.FromMinutes(1))
            };

            return parameters;
        }