public override void Run()
{
var storageAccount = CloudStorageAccount.Parse
(RoleEnvironment.GetConfigurationSettingValue("StorageConnectionString"));
// Get table and queue objects for working with tables and queues.
while (!IsStopped)
{
try
{
// Receive the message
BrokeredMessage receivedMessage = null;
receivedMessage = Client.Receive();
if (receivedMessage != null)
{
// Process the message
Trace.WriteLine("Processing", receivedMessage.SequenceNumber.ToString());
NewCustomerCommand command = receivedMessage.GetBody<NewCustomerCommand>();
// Create the table client.
CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
// Create the CloudTable object that represents the "Customer" table.
CloudTable table = tableClient.GetTableReference("Customer");
// Create a new customer entity.
Customer customer=new Customer{
Id=Guid.NewGuid().ToString(),
PartitionKey = command.LastName,
RowKey = command.FirstName,
FirstName=command.FirstName,
LastName=command.LastName,
Address=command.Address,
Email=command.Email,
Phone=command.Phone
};
// Create the TableOperation that inserts the customer entity.
TableOperation insertOperation = TableOperation.Insert(customer);
// Execute the insert operation.
table.Execute(insertOperation);
receivedMessage.Complete();
}
}
catch (MessagingException e)
{
if (!e.IsTransient)
{
Trace.WriteLine(e.Message);
throw;
}
Thread.Sleep(10000);
}
catch (OperationCanceledException e)
{
if (!IsStopped)
{
Trace.WriteLine(e.Message);
throw;
}
}
}
}