More Related Content Similar to Windows Azure Drive Similar to Windows Azure Drive (20) More from Pavel Revenkov (12) Windows Azure Drive1. Windows Azure Drive
Pavlo Revenkov
EPAM Cloud Computing Competency Center
Email: pavlo_revenkov@epam.com
Skype: rp_risingstar
Habrahabr: habrahabr.ru/users/risingstar/
4. Windows Azure Drive
4
Subscription
Storage Account
(100 ТВ)
Storage Account
(100 ТВ)
Container
Block Blob (200 GB)
Container
Page Blob (1 ТВ)
Storage Account
(100 ТВ)
Storage Account
(100 ТВ)
…
Container
…
Azure Drive (1 ТВ)
…
5. Blob content upload
var storageAccount = CloudStorageAccount.Parse(
ConfigurationManager
.ConnectionStrings[ConnectionStringSetting]
.ConnectionString);
var blobClient = storageAccount.CreateCloudBlobClient();
var container = blobClient.GetContainerReference(containerName);
var pageBlob = container.GetPageBlobReference(blobName);
using (var fileStream = new FileStream(filePath, FileMode.Open)) {
pageBlob.Create(fileStream.Length);
var buffer = new byte[partSize];
while (offset < fileStream.Length) {
var bytesRead = fileStream.Read(buffer, 0, partSize);
pageBlob.WritePages(new MemoryStream(buffer, 0, bytesRead), offset);
offset += bytesRead;
}
}
5
6. 1. public static void UploadVHDFile(string filePath, string containerName, string blobName)
2. {
3.
const int partSize = 1024 * 1024;
4.
5.
var storageAccount = CloudStorageAccount.Parse(
6.
ConfigurationManager.ConnectionStrings[ConnectionStringSetting].ConnectionString);
7.
8.
var blobClient = storageAccount.CreateCloudBlobClient();
9.
var container = blobClient.GetContainerReference(containerName);
10.
container.CreateIfNotExist();
11.
12.
var pageBlob = container.GetPageBlobReference(blobName);
13.
pageBlob.DeleteIfExists();
14.
pageBlob.Properties.ContentType = "binary/octet-stream";
15.
16.
using (var fileStream = new FileStream(filePath, FileMode.Open))
17.
{
18.
int offset = 0;
19.
20.
pageBlob.Create(fileStream.Length);
21.
22.
var buffer = new byte[partSize];
23.
while (offset < fileStream.Length)
24.
{
25.
var bytesRead = fileStream.Read(buffer, 0, partSize);
26.
27.
pageBlob.WritePages(new MemoryStream(buffer, 0, bytesRead), offset);
28.
29.
offset += bytesRead;
30.
31.
Console.Write('.');
32.
}
33.
}
34. }
6
8. Workflow
var account = CloudStorageAccount.Parse(
ConfigurationManager.AppSettings["ConnectionString“]);
var drive = new CloudDrive(blobUri, account.Credentials.*);
try
{
drive.Mount(0, DriveMountOptions.None);
...
}
catch (CloudDriveException e)
{
drive = new CloudDrive(new Uri(drive.Snapshot().AbsoluteUri), ...);
drive.Mount(0, DriveMountOptions.None);
}
finally
{
drive.Unmount();
}
8
10. References
Differences Between the Storage Emulator and
Windows Azure Storage Services
http://msdn.microsoft.com/en-us/gg433135
Windows Azure Drive whitepaper
http://go.microsoft.com/?linkid=9710117
10