windows azure 实例
- public class Album : TableServiceEntity
- {
- }
- public class PhotoAlbumDataContext : TableServiceContext
- {
- public PhotoAlbumDataContext()
- : this(CloudStorageAccount.FromConfigurationSetting("DataConnectionString"))
- {
- }
- public PhotoAlbumDataContext(Microsoft.WindowsAzure.CloudStorageAccount account)
- : base(account.TableEndpoint.ToString(), account.Credentials)
- {
- if (!initialized)
- {
- lock (initializationLock)
- {
- if (!initialized)
- {
- this.CreateTables();
- initialized = true;
- }
- }
- }
- }
- //getlist
- var context = new PhotoAlbumDataContext();
- var list=context.Albums.AsTableServiceQuery().AsEnumerable()
- //add
- context.AddObject("Alblum_TableName", new Album());
- //context.SaveChanges();
- context.SaveChanges(SaveChangesOptions.ContinueOnError);
- //get delete
- var album = context.Albums
- .Where(a => a.AlbumId == albumName && a.PartitionKey == owner.ToLowerInvariant()).AsTableServiceQuery()
- .Single();
- context.DeleteObject(album);
- context.SaveChanges();
- //delete
- context.AttachTo("TableName", photoRow, "*");
- context.DeleteObject(photoRow);
- context.SaveChanges();
- //update
- var albumRow = new Album(album);
- // attach and update the photo row
- context.AttachTo("TableName", albumRow, "*");
- context.UpdateObject(albumRow);
- context.SaveChanges();
Table Service
- public class Subscriber : TableEntity
- {
- [Required]
- [Display(Name = "List Name")]
- public string ListName
- {
- get
- {
- return this.PartitionKey; //分区键
- }
- set
- {
- this.PartitionKey = value;
- }
- }
- [Required]
- [Display(Name = "Email Address")]
- public string EmailAddress
- {
- get
- {
- return this.RowKey;
- }
- set
- {
- this.RowKey = value;
- }
- }
- public string SubscriberGUID { get; set; }
- public bool? Verified { get; set; }
- }
- }
- var storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString);
- var tableClient = storageAccount.CreateCloudTableClient();
- var mailingListTable = tableClient.GetTableReference("mailinglist");
- mailingListTable.CreateIfNotExists();
- //获取Get
- var retrieveOperation = TableOperation.Retrieve<T>(_partitionKey, _rowKey);
- var retrievedResult = mailingListTable.Execute(retrieveOperation);
- return retrievedResult.Result as T;
- //GetList
- string filter = TableQuery.CombineFilters(
- TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, _partitionKey),
- TableOperators.And,
- TableQuery.GenerateFilterCondition("SubscriberGUID", QueryComparisons.Equal, subscriberGUID));
- var query = new TableQuery<Subscriber>().Where(filter);
- var subscribers = mailingListTable.ExecuteQuery(query).ToList();
- //添加 Add
- var insertOperation = TableOperation.Insert(newSubscriber);
- mailingListTable.Execute(insertOperation);
- //Update Or Insert
- var upsertOperation = TableOperation.InsertOrReplace(emailRowInTable);
- mailingListTable.Execute(upsertOperation);
- //Update
- replaceOperation = TableOperation.Replace(emailRowInTable);
- mailingListTable.Execute(replaceOperation);
- //Delete
- var deleteOperation = TableOperation.Delete(emailRowToDelete);
- mailingListTable.Execute(deleteOperation);
Sotrage.Tables
- var storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString);
- var queueClient = storageAccount.CreateCloudQueueClient();
- foreach(var q in queueClient.ListQueues()){//所有队列
- var msg = q.GetMessage();
- var id = msg.Id;
- var name=q.Name; //队列名字:azuremailsubscribequeue
- }
- subscribeQueue = queueClient.GetQueueReference("azuremailsubscribequeue");
- subscribeQueue.CreateIfNotExists();
- subscribeQueue.AddMessage(new CloudQueueMessage(newSubscriber.SubscriberGUID + "," + newSubscriber.ListName));
- msg = subscribeQueue.GetMessage();
- subscribeQueue.DeleteMessage(msg);
- public class WorkerRole : RoleEntryPoint
- {
- }
CloudQueue
- using System.Net;
- using System.Net.Mail;
- using Microsoft.WindowsAzure.Diagnostics;
- using Microsoft.WindowsAzure.ServiceRuntime;
- using Microsoft.WindowsAzure.Storage.Blob;
- using Microsoft.WindowsAzure.Storage.Queue;
- using Microsoft.WindowsAzure.Storage.Table;
- using SendGridMail;
- using SendGridMail.Transport;
- var storageAccount=CloudStorageAccount.FromConfigurationSetting("DataConnectionString");
- private static void SendSubscribeEmail(string subscriberGUID, Subscriber subscriber, MailingList mailingList)
- {
- var email = SendGrid.GenerateInstance();
- email.From = new MailAddress(mailingList.FromEmailAddress);
- email.AddTo(subscriber.EmailAddress);
- string subscribeURL = RoleEnvironment.GetConfigurationSettingValue("AzureMailServiceURL") +
- "/subscribe?id=" + subscriberGUID + "&listName=" + subscriber.ListName;
- email.Html = String.Format("<p>Click the link below to subscribe to {0}. " +
- "If you don't confirm your subscription, you won't be subscribed to the list.</p>" +
- "<a href=\"{1}\">Confirm Subscription</a>", mailingList.Description, subscribeURL);
- email.Text = String.Format("Copy and paste the following URL into your browser in order to subscribe to {0}. " +
- "If you don't confirm your subscription, you won't be subscribed to the list.\n" +
- "{1}", mailingList.Description, subscribeURL);
- email.Subject = "Subscribe to " + mailingList.Description;
- var credentials = new NetworkCredential(RoleEnvironment.GetConfigurationSettingValue("SendGridUserName"), RoleEnvironment.GetConfigurationSettingValue("SendGridPassword"));
- var transportREST = REST.GetInstance(credentials);
- transportREST.Deliver(email);
- }
- private string GetBlobText(string blogRef)
- {
- var blob = blobContainer.GetBlockBlobReference(blogRef);
- blob.FetchAttributes();
- var blobSize = blob.Properties.Length;
- using (var memoryStream = new MemoryStream((int)blobSize))
- {
- blob.DownloadToStream(memoryStream);
- return System.Text.Encoding.UTF8.GetString(memoryStream.ToArray());
- }
- }
- //upload image (stream)
- var blob = container.GetBlobReference(file);
- blob.Properties.ContentType = mimeType;
- blob.UploadFromStream(binary);
- //down image
- var client = this.storageAccount.CreateCloudBlobClient();
- var container = client.GetContainerReference(owner);
- using (var ms = new MemoryStream())
- {
- container.GetBlobReference(file).DownloadToStream(ms);
- var image = Image.FromStream(ms);
- }
- // save it off to blob storage
- using (var thumbStream = new MemoryStream())
- {
- thumb.Save(
- thumbStream,
- System.Drawing.Imaging.ImageFormat.Jpeg);
- thumbStream.Position = ; // reset;
- var thumbBlob = container.GetBlobReference(Path.Combine("thumb", file));
- thumbBlob.Properties.ContentType = "image/jpeg";
- thumbBlob.UploadFromStream(thumbStream);
- }
- //use image
- var blobUri = client.GetContainerReference(owner).GetBlobReference(file).Uri.ToString();
- var thumbUri = client.GetContainerReference(owner).GetBlobReference(Path.Combine("thumb", file)).Uri.ToString();
- //delete
- var blobGone = container.GetBlobReference(filename).DeleteIfExists();
- var thumbGone = container.GetBlobReference(thumbname).DeleteIfExists();
Storage.Blob
windows azure 实例的更多相关文章
- Windows Azure 名词定义(Glossary)
Glossary(名词) Definition(定义) Availability Set 可用性组 refers to two or more Virtual Machines deployed ac ...
- CSV 客座文章系列: Pruffi 通过 Windows Azure 挖掘社交媒体的强大招聘潜能
编辑人员注释:今天这篇文章由 Pruffi 创始人 Alena Vladimirskaya 和 Pruffi 的 CTO Alexander Ivanov 联合撰写,介绍了该公司如何使用 Window ...
- CSV 客座文章系列:KGroup 通过 Windows Azure 将 Qoob 内容管理发布到云中
编辑人员注释: 今天这篇文章由 KGroup 首席软件架构师兼研发部主管 Jody Donetti 与 KGroup 技术总监 Simone Procopio 共同撰写,介绍了 KGroup 如何使用 ...
- Windows Azure Virtual Machine (28) 使用Azure实例级别IP,Instance-Level Public IP Address (PIP)
<Windows Azure Platform 系列文章目录> 本文介绍的是国内由世纪互联运维的Azure China 熟悉Azure平台的读者都知道,我们在使用Azure Virtual ...
- Windows Azure虚拟机和云服务实例计费方式更新
在之前的Windows Azure计费账单中,A0,A1,A2,A3,A4系列的虚拟机(云服务实例)都是以A1为基准计费单位的,即: 虚拟机大小 计费单位(小时) A0 A1*0.25 A1 A1*1 ...
- 宣布在 Azure 镜像库中正式推出 Windows Server 2012 R2 并降低 Windows Azure 的实例定价
我们今天将宣布两条消息,为使用基础结构服务的客户提供更多选择和成本节约:在镜像库中推出 Windows Server 2012 R2 以及降低 Memory Intensive 计算实例定价. 虚拟机 ...
- 禁用 Windows Azure 网站中的 ARR 实例关联
编辑人员注释: 本博客文章由 Windows Azure 网站团队的项目经理 Erez Benari 撰写. 在 Windows Azure 网站中设置网站的多个实例是横向扩展网站的绝佳方式,Azur ...
- 简化 Web 应用程序与 Windows Azure Active Directory、ASP.NET 和 Visual Studio 的集成
大家好! 今天的博文深入讨论我们今天推出的开发人员工具和框架中的一些新功能.我们通过与 ASP.NET 和 Visual Studio 团队合作开发了一些重大的增强功能,让开发人员能够轻松使用 Win ...
- 今天Windows Azure Live to Code的分享
今天参加了微软广州的Live to Code,晚上回公司OT写了封报告E-mail,也没让公司今天白出工资给我... 因为没有涉及到公司机密什么的,所以就拿出来跟大家分享一下. 首先要说明的是,在会议 ...
随机推荐
- 2013 南京邀请赛 A play the dice 求概率
/** 大意:给定一个色子,有n个面,每一个面上有一个数字,在其中的m个面上有特殊的颜色,当掷出的色子出现这m个颜色之一时,可以再掷一次..求其最后的期望 思路:假设 期望为ans 4 ans = 1 ...
- Multiple markers at this line @Override的解决方法
Multiple markers at this line - implements java.awt.event.ActionListener.actionPerformed - The metho ...
- TPM 2.0 近况及模拟器开发
可信计算平台模块TPM 2.0的相关标准和技术准则由 TCG ( Trust Computing Group )于2011年前后提出,至今已经过了多次修改.该标准无疑将成为下一代可信计算平台模块的业界 ...
- Windows Azure 网站上的 WebSocket 简介
编辑人员注释:本文章由 Windows Azure 网站团队的首席项目经理 Stefan Schackow 撰写. Windows Azure 网站最近新增了对 WebSocket 协议的支持..NE ...
- c# datagridviewcomboboxcell值无效的解决办法
一直认为是数据库存储的数据和datagridviewcomboboxcell对不上导致,今天碰到两者对应上了,预览的时候还是提示错误, 查看了下网上其他大神的解决方法,是数据库字段类型有误,查看了下, ...
- 【Eclipse】离线插件安装
1.在eclipse里根目录里,dropins里建一个目录,名字叫sonar(这个名字随便),再在svn下面建一个目录eclipse.在根目录里建一个目录links目录,并建一个sonar.link文 ...
- Java Pattern Matcher 正则应用
转自:http://www.itzhai.com/java-notes-regex-matches-and-lookingat.html#read-more 1.基本语法 2.String内建的正则表 ...
- django cookie
设置:auth.login(request, user) response = HttpResponseRedirect(reverse("index" ...
- QT窗口置顶/真透明/背景模糊/非矩形/跳过任务栏分页器/无边框/无焦点点击/焦点穿透
qt 窗口置顶/真透明/背景模糊/非矩形/跳过任务栏分页器/无边框/无焦点点击/焦点穿透 窗口置顶qt 里是 setWindowFlags(Qt::WindowStaysOnTopHint)kde 里 ...
- BNU 26579 Andrew the Ant 【蚂蚁】
链接: http://www.bnuoj.com/bnuoj/problem_show.php?pid=26579 http://www.bnuoj.com/bnuoj/contest_show.ph ...