Building Applications with Windows Azure Storage Brad Calder Director/Architect Microsoft Corporation
BlobContainerAccount cohowinery images PIC01.JPG PIC02.JPG videos VID1.AVI /
StorageCredentialsAccountAndKey credentials = new StorageCredentialsAccountAndKey(accountName, key); string baseUri = string.Format(" accountName); CloudBlobClient blobClient = new CloudBlobClient(baseUri, credentials); // Create Container CloudBlobContainer cloudContainer = blobClient.GetContainerReference(containerName); bool hasCreated = cloudContainer.CreateIfNotExist(); // Access Blob in the Container CloudBlob cloudBlob = cloudContainer.GetBlobReference(blobName); //BlobRequestOptions has retry policy, timeout etc. BlobRequestOptions options = new BlobRequestOptions(); //Upload the local file to Blob service cloudBlob.UploadFile(uploadFileName, options); //Download to local file name cloudBlob.DownloadToFile(downloadFileName, options);
Windows Azure Blob Service Application Lease Drive X:
Windows Azure Drive Demo
Windows Azure
CloudStorageAccount account = CloudStorageAccount.FromConfigurationSetting("CloudStorageAccount"); //Initialize the local cache for drives mounted by this role instance CloudDrive.InitializeCache(localCacheDir, cacheSizeInMB); //Create a cloud drive (PageBlob) CloudDrive drive = account.CreateCloudDrive(pageBlobUri); drive.Create(1000 /* sizeInMB */); //Mount the network attached drive on the local file system string pathOnLocalFS = drive.Mount(cacheSizeInMB, DriveMountOptions.None); //Use NTFS APIs to Read/Write files to drive … //Snapshot drive while mounted to create backups Uri snapshotUri = drive.Snapshot(); //Unmount the drive drive.Unmount();
EntityTableAccount cohowinery customers Name =… = … Name =… = … winephotos Photo ID =… Date =… Photo ID =… Date =…
PartitionKey (Category) RowKey (Title) TimestampReleaseDate Action Fast & Furious…2009 Action The Bourne Ultimatum…2007 … ……… Animation Open Season 2…2009 Animation The Ant Bully…2006 PartitionKey (Category) RowKey (Title) TimestampReleaseDate Comedy Office Space…1999 … ……… SciFi X-Men Origins: Wolverine …2009 … ……… War Defiance…2008 PartitionKey (Category) RowKey (Title) TimestampReleaseDate Action Fast & Furious…2009 Action The Bourne Ultimatum…2007 … ……… Animation Open Season 2…2009 Animation The Ant Bully…2006 Comedy Office Space…1999 … ……… SciFi X-Men Origins: Wolverine …2009 … ……… War Defiance…2008
[DataServiceKey("PartitionKey", "RowKey")] public class Movie { /// Movie Category is the partition key public string PartitionKey { get; set; } /// Movie Title is the row key public string RowKey { get; set; } public DateTime Timestamp { get; set; } public int ReleaseYear { get; set; } public double Rating { get; set; } public string Language { get; set; } public bool Favorite { get; set; } }
string baseUri = string.Format(" accountName); CloudTableClient tableClient = new CloudTableClient(baseUri, credentials); // Create Movie Table string tableName = “Movies“; tableClient.CreateTableIfNotExist(tableName); TableServiceContext context = tableClient.GetDataServiceContext(); // Add movie context.AddObject(tableName, new Movie("Action", “White Water Rapids Survival")); context.SaveChangesWithRetries(); // Query movie var q = (from movie in context.CreateQuery (tableName) where movie.PartitionKey == "Action" && movie.Rating > 4.0 select movie).AsTableServiceQuery (); foreach (Movie movieToUpdate in q) { movieToUpdate.Favorite = true; context.UpdateObject(movieToUpdate); } context.SaveChangesWithRetries( ); SaveChangesOptions.Batch
MessageQueueAccount order processing customer ID order ID cohowinery
Azure Queue Input Queue (Work Items)
Azure Queue Input Queue (Work Items)
string baseUri = string.Format(" accountName); CloudQueueClient queueClient = new CloudQueueClient(baseUri, credentials); //Create Queue CloudQueue queue = queueClient.GetQueueReference(queueName); queue.CreateIfNotExist(); //Add Message CloudQueueMessage message = new CloudQueueMessage(“some content"); queue.AddMessage(message); //Get Message message = queue.GetMessage(TimeSpan.FromMinutes(3) /*Invisibility timeout*/); // Process Message within the Invisibility Timeout //Delete Message queue.DeleteMessage(message);