Опубликован: 30.05.2011 | Доступ: свободный | Студентов: 2460 / 270 | Оценка: 4.12 / 4.41 | Длительность: 12:00:00
Специальности: Программист, Архитектор программного обеспечения
Самостоятельная работа 5:
Работа с Windows Azure Table
Приложение Б. Класс Contact.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace WebRole1
{
class Contact : Microsoft.WindowsAzure.StorageClient.TableServiceEntity
{
public String FirstName { get; set; }
public String LastName { get; set; }
public String TelNumber { get; set; }
public String Email { get; set; }
}
}Приложение В. Класс ContactContext.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.StorageClient;
using System.Data.Services.Client;
namespace WebRole1
{
class ContactContext : TableServiceContext
{
public IQueryable<Contact> ContactData
{
get
{
return this.CreateQuery<Contact>("Contacts");
}
}
public ContactContext(Uri baseAddress, StorageCredentials credentials) : base(baseAddress.AbsoluteUri, credentials) { }
public void Add(Contact cnt)
{
this.AddObject("Contacts", cnt);
this.SaveChanges();
}
public void Delete(Contact cnt)
{
this.DeleteObject(cnt);
this.SaveChanges();
}
public void Update(Contact cnt)
{
this.UpdateObject(cnt);
this.SaveChanges();
}
}
}Приложение Г. Global.asax.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.StorageClient;
using System.Data.Services.Client;
using Microsoft.WindowsAzure.ServiceRuntime;
namespace WebRole1
{
public class Global : System.Web.HttpApplication
{
void Application_Start(object sender, EventArgs e)
{
CloudStorageAccount.SetConfigurationSettingPublisher(
(configName, configSettingPublisher) =>
{
var connectionString =
RoleEnvironment.GetConfigurationSettingValue(configName);
configSettingPublisher(connectionString);
}
);
var account = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");
CloudTableClient _tc = null;
_tc = account.CreateCloudTableClient();
_tc.CreateTableIfNotExist("Contacts");
}
void Application_End(object sender, EventArgs e)
{
}
void Application_Error(object sender, EventArgs e)
{
}
void Session_Start(object sender, EventArgs e)
{
}
void Session_End(object sender, EventArgs e)
{
}
}
}