/// <summary> /// Does the resize operation, based on the parameters specified when method <see cref="ResizeVhdBlob(int, Uri, string, string)"/> was called. /// Please first call method <see cref="ResizeVhdBlob(int, Uri, string, string)"/> before calling this method. /// </summary> /// <returns><see cref="ResizeResult.Success"/> if the resize operation went fine.</returns> public ResizeResult DoResizeVhdBlob() { Console.WriteLine("[{0}] VHD file format fixed, current size {1} bytes.", DateTime.Now.ToShortTimeString(), footerInstance.CurrentSize); // Expand the blob Console.WriteLine("[{0}] Resizing containing blob...", DateTime.Now.ToShortTimeString()); blob.Resize((long)NewSize.Bytes + 512L); // Change footer size values Console.WriteLine("[{0}] Updating VHD file format footer...", DateTime.Now.ToShortTimeString()); footerInstance.CurrentSize = (long)NewSize.Bytes; footerInstance.OriginalSize = (long)NewSize.Bytes; footerInstance.Geometry = Geometry.FromCapacity((long)NewSize.Bytes); footerInstance.UpdateChecksum(); footer = new byte[512]; footerInstance.ToBytes(footer, 0); Console.WriteLine("[{0}] New VHD file size {1} bytes, checksum {2}.", DateTime.Now.ToShortTimeString(), footerInstance.CurrentSize, footerInstance.Checksum); // Write new footer Console.WriteLine("[{0}] Writing VHD file format footer...", DateTime.Now.ToShortTimeString()); using (var stream = new MemoryStream(footer)) { blob.WritePages(stream, (long)NewSize.Bytes); } // Write 0 values where the footer used to be if (IsExpand) { Console.WriteLine("[{0}] Overwriting the old VHD file footer with zeroes...", DateTime.Now.ToShortTimeString()); blob.ClearPages(originalLength - 512, 512); } // Done! Console.WriteLine("[{0}] Done!", DateTime.Now.ToShortTimeString()); return(ResizeResult.Success); }