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,也没让公司今天白出工资给我... 因为没有涉及到公司机密什么的,所以就拿出来跟大家分享一下. 首先要说明的是,在会议 ...
随机推荐
- poj 2992
http://poj.org/problem?id=2992 大意:求(n,k)的因子个数 解题思路:(n,k) = n!/(k!(n-k)!) 任意一个数都可以用其质因子来表示 eg: 26 = ...
- springMVC框架下JQuery传递并解析Json数据
springMVC框架下JQuery传递并解析Json数据
- 16个值得个人站长做的广告联盟[转自cnzz]
建站也有好多年了,也建了几个站,有些微波收入, 反复测试了挺多广告联盟, 下面介绍一下: 1.googleadsense联盟: 推荐指数:☆☆☆☆☆ Google广告联盟是现在信誉最好的广告提供商之一 ...
- Android Intent 解析之二
服务端Intent运行过程: Sticky:这个类型的BroadCast表示某些Intent须要被保留,当新的应用起来后,须要关注这个消息,可是呢,又不须要启动这个应用来接收此消息,比方耳机插入等消息 ...
- 判断是否是树(Is It A Tree?)
Description A tree is a well-known data structure that is either empty (null, void, nothing) or is a ...
- c++,纯虚函数与抽象类
1.纯虚函数的定义: (1)虚函数被“初始化”为0的函数.声明纯虚函数的一般形式是virtual 函数类型 函数名(参数表列) =0;(2)纯虚函数没有函数体:(3)最后面的“=0”并不表示函数返回值 ...
- application(expand)--easyui
一,效果图. 二,源代码. <!DOCTYPE html><html><head> <meta charset="UTF-8"> & ...
- js模态窗口
最近在看js,正好公司用的框架中用到了模态窗口,以前没有接触过,现在把模态窗口的用法先记下来. 常用的浏览器chrome,Firefox,ie11,这三种分别支持document.open(),win ...
- 【集训笔记】动态规划【HDOJ1159【HDOJ1003
终于开始DP了] HDOJ_1159 Common Subsequence 题目链接 Sample Input abcfbc abfcab programming contest abcd mnp ...
- 平衡二叉树算法实现 c语言版 插入 删除
#include <stdio.h>#include <malloc.h>#include<stdlib.h> #define EQ(a,b) ((a)==(b)) ...