public static VhdFooter GetVhdFooter(this CloudPageBlob basePageBlob) { var vhdFileFactory = new VhdFileFactory(); using (var file = vhdFileFactory.Create(basePageBlob.OpenReadAsync().ConfigureAwait(false).GetAwaiter().GetResult())) { return(file.Footer); } }
public static VhdFooter GetVhdFooter(this CloudPageBlob basePageBlob) { var vhdFileFactory = new VhdFileFactory(); using (var file = vhdFileFactory.Create(basePageBlob.OpenRead())) { return(file.Footer); } }
private void CreateRemoteBlob() { var baseBlob = this.blobObjectFactory.Create(baseVhdBlobUri); if (!baseBlob.Exists()) { throw new InvalidOperationException(String.Format("Base image to patch doesn't exist in blob storage: {0}", baseVhdBlobUri.Uri)); } var blobVhdFooter = baseBlob.GetVhdFooter(); long blobSize; VhdFilePath localBaseVhdPath; IEnumerable <Guid> childrenVhdIds; using (var vhdFile = new VhdFileFactory().Create(localVhd.FullName)) { localBaseVhdPath = vhdFile.GetFilePathBy(blobVhdFooter.UniqueId); childrenVhdIds = vhdFile.GetChildrenIds(blobVhdFooter.UniqueId).ToArray(); blobSize = vhdFile.Footer.CurrentSize; } FileMetaData fileMetaData = GetFileMetaData(baseBlob, localBaseVhdPath); var md5Hash = baseBlob.GetBlobMd5Hash(); if (!md5Hash.SequenceEqual(fileMetaData.MD5Hash)) { var message = String.Format("Patching cannot proceed, MD5 hash of base image in blob storage ({0}) and base VHD file ({1}) does not match ", baseBlob.Uri, localBaseVhdPath); throw new InvalidOperationException(message); } Program.SyncOutput.MessageCreatingNewPageBlob(blobSize); CopyBaseImageToDestination(); using (var vds = new VirtualDiskStream(localVhd.FullName)) { var streamExtents = vds.Extents.ToArray(); var enumerable = streamExtents.Where(e => childrenVhdIds.Contains(e.Owner)).ToArray(); foreach (var streamExtent in enumerable) { var indexRange = streamExtent.Range; destinationBlob.ClearPagesAsync(indexRange.StartIndex, indexRange.Length) .ConfigureAwait(false).GetAwaiter().GetResult(); } } using (var bmds = new BlobMetaDataScope(destinationBlob)) { bmds.Current.RemoveBlobMd5Hash(); bmds.Current.SetUploadMetaData(OperationMetaData); bmds.Complete(); } }
private void CreateRemoteBlob() { var baseBlob = this.blobObjectFactory.Create(baseVhdBlobUri); if (!baseBlob.Exists()) { throw new InvalidOperationException(String.Format("Base image to patch doesn't exist in blob storage: {0}", baseVhdBlobUri.Uri)); } var blobVhdFooter = baseBlob.GetVhdFooter(); long blobSize; VhdFilePath localBaseVhdPath; IEnumerable<Guid> childrenVhdIds; using (var vhdFile = new VhdFileFactory().Create(localVhd.FullName)) { localBaseVhdPath = vhdFile.GetFilePathBy(blobVhdFooter.UniqueId); childrenVhdIds = vhdFile.GetChildrenIds(blobVhdFooter.UniqueId).ToArray(); blobSize = vhdFile.Footer.VirtualSize; } FileMetaData fileMetaData = GetFileMetaData(baseBlob, localBaseVhdPath); var md5Hash = baseBlob.GetBlobMd5Hash(); if (!md5Hash.SequenceEqual(fileMetaData.MD5Hash)) { var message = String.Format("Patching cannot proceed, MD5 hash of base image in blob storage ({0}) and base VHD file ({1}) does not match ", baseBlob.Uri, localBaseVhdPath); throw new InvalidOperationException(message); } Program.SyncOutput.MessageCreatingNewPageBlob(blobSize); CopyBaseImageToDestination(); using (var vds = new VirtualDiskStream(localVhd.FullName)) { var streamExtents = vds.Extents.ToArray(); var enumerable = streamExtents.Where(e => childrenVhdIds.Contains(e.Owner)).ToArray(); foreach (var streamExtent in enumerable) { var indexRange = streamExtent.Range; destinationBlob.ClearPages(indexRange.StartIndex, indexRange.Length); } } using (var bmds = new BlobMetaDataScope(destinationBlob)) { bmds.Current.RemoveBlobMd5Hash(); bmds.Current.SetUploadMetaData(OperationMetaData); bmds.Complete(); } }
public static IList<VhdValidationResult> Validate(VhdValidationType validation, string path) { var fileFactory = new VhdFileFactory(); VhdFile vhdFile = null; Exception exception = null; try { vhdFile = fileFactory.Create(path); } catch (VhdParsingException e) { exception = e; } return DoValidate(validation, vhdFile, exception); }
public static IList <VhdValidationResult> Validate(VhdValidationType validation, Stream vhdStream) { var fileFactory = new VhdFileFactory(); VhdFile vhdFile = null; Exception exception = null; try { vhdFile = fileFactory.Create(vhdStream); } catch (VhdParsingException e) { exception = e; } return(DoValidate(validation, vhdFile, exception)); }
private static IEnumerable <CompletionPort> ValidateAsync(AsyncMachine <IList <VhdValidationResult> > machine, VhdValidationType validation, Stream vhdStream) { var result = new List <VhdValidationResult>(); var fileFactory = new VhdFileFactory(); fileFactory.BeginCreate(vhdStream, machine.CompletionCallback, null); yield return(CompletionPort.SingleOperation); VhdFile vhdFile = null; Exception exception = null; try { vhdFile = fileFactory.EndCreate(machine.CompletionResult); } catch (VhdParsingException e) { exception = e; } machine.ParameterValue = DoValidate(validation, vhdFile, exception); }
private static IEnumerable<CompletionPort> ValidateAsync(AsyncMachine<IList<VhdValidationResult>> machine, VhdValidationType validation, Stream vhdStream) { var result = new List<VhdValidationResult>(); var fileFactory = new VhdFileFactory(); fileFactory.BeginCreate(vhdStream, machine.CompletionCallback, null); yield return CompletionPort.SingleOperation; VhdFile vhdFile = null; Exception exception = null; try { vhdFile = fileFactory.EndCreate(machine.CompletionResult); } catch (VhdParsingException e) { exception = e; } machine.ParameterValue = DoValidate(validation, vhdFile, exception); }