WindowsAzure.StorageClient API
2010-05-03 10:33
267 查看
Microsoft.WindowsAzure.StorageClient.dll 封装了对Blob,Table,Queue 的常见操作。这样不用直接用REST去coding了,方便不少。
![](http://images.cnblogs.com/cnblogs_com/ginohuo/WindowsLiveWriter/Microsoft.WindowsAzure.StorageClient_92ED/image_thumb.png)
![](http://images.cnblogs.com/cnblogs_com/ginohuo/WindowsLiveWriter/Microsoft.WindowsAzure.StorageClient_92ED/image_thumb.png)
class Program { const string config = @"BlobEndpoint=http://***.blob.core.windows.net/;QueueEndpoint=http://***..queue.core.windows.net/;TableEndpoint=http://***..table.core.windows.net/;AccountName=***.;AccountKey=***."; static void Main(string[] args) { QueueTest(); Console.ReadKey(); } private static void BlobTest() { CloudStorageAccount acct = CloudStorageAccount.Parse(config); CloudBlobClient blobclient = new CloudBlobClient(new Uri("http://***..blob.core.windows.net/") , acct.Credentials); var container = blobclient.GetContainerReference("testcontainer"); container.CreateIfNotExist(); var blob = container.GetBlobReference("TestFile"); blob.UploadText("Hello World!"); // Display var blobcontent = blob.DownloadText(); Console.WriteLine(blobcontent); var blobs = container.ListBlobs(); foreach (var item in blobs) { Console.WriteLine(item.Uri.ToString()); } // Delete var succeed = blob.DeleteIfExists(); Console.WriteLine(succeed.ToString()); Console.ReadKey(); } private static void TableTest() { CloudStorageAccount acct = CloudStorageAccount.Parse(config); CloudTableClient tableclient = new CloudTableClient(acct.TableEndpoint.ToString() , acct.Credentials); string tableName = "users"; tableclient.CreateTableIfNotExist(tableName); UserInfo user = new UserInfo { UserID = "10" }; TableServiceContext context = tableclient.GetDataServiceContext(); context.AddObject(tableName, user); context.SaveChanges(); //query var query = context.CreateQuery<UserInfo>(tableName); foreach (var item in query.ToList<UserInfo>()) { Console.WriteLine(item.RowKey + item.UserID + item.Timestamp.ToString()); } //var result = query.ToList<UserInfo>(); } private static void QueueTest() { CloudStorageAccount acct = CloudStorageAccount.Parse(config); CloudQueueClient client = new CloudQueueClient(acct.QueueEndpoint, acct.Credentials); CloudQueue cq = client.GetQueueReference("testq"); cq.CreateIfNotExist(); //Receive Thread td = new Thread(new ThreadStart(() => { Thread.Sleep(3000); CloudQueueMessage msg1 = cq.GetMessage(); while (msg1 != null) { Console.WriteLine(string.Format("{0} Receive:{1}", DateTime.Now, msg1.AsString)); cq.DeleteMessage(msg1); msg1 = cq.GetMessage(); Thread.Sleep(3000); } Console.WriteLine("Receive Completed."); })); td.Start(); //Send for (int i = 0; i < 10; i++) { CloudQueueMessage msg = new CloudQueueMessage(i.ToString()); cq.AddMessage(msg); Console.WriteLine(string.Format("{0} Clinent add:{1}", DateTime.Now, i)); Thread.Sleep(2000); } Console.WriteLine("Add Completed."); } } public class UserInfo : TableServiceEntity { public string UserID { get; set; } public UserInfo() { PartitionKey = "UserInfo"; RowKey = Guid.NewGuid().ToString(); } } }
相关文章推荐
- Windows Azure Storage Client Library 2.0 入门
- Overview of Retry Policies in the Windows Azure Storage Client Library
- Windows Azure Traffic Manager的新的管理API
- Windows Azure Storage Emulator 无法安装和无法启动问题
- 通过构建Storage Explorer 应用学习Windows Azure Storage APIs
- Windows Azure Storage (19) 再谈Azure Block Blob和Page Blob
- 宣布降低Windows Azure Storage的定价
- 使用Windows Azure Storage Analytics新特性
- 使用Windows Azure Storage Analytics新特性
- Windows Azure Storage (18) 使用HTML5 Portal的Azure CDN服务
- Windows Azure Table Storage 解决 Guid 查询问题
- Overview of Running a Windows Azure Application with Local Storage
- Windows Azure Storage 3.0.1.0与Azure Storage Emulator 2.2.0.0兼容问题
- Designing Data Storage Architecture-Windows Azure Storage Abstractions and their Scalability Targets
- Designing Data Storage Architecture - Introducing the Windows Azure Content Delivery Network
- PartitionKey 与 RowKey 含有 ‘%’ 字符会导致Windows Azure Tables API出错
- Windows Azure Marketplaces上的Bing Search API可用啦!
- Windows下使用Subversion Client API编程环境配置
- Azure Storage Client Library 重试策略建议
- LINK - Windows Azure Storage - 跨域访问策略 CROS