-
Notifications
You must be signed in to change notification settings - Fork 157
/
Copy pathQueue.xaml.cs
70 lines (54 loc) · 2.25 KB
/
Queue.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using System;
using System.Collections.Generic;
using Xamarin.Forms;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Auth;
using Microsoft.WindowsAzure.Storage.Queue;
using System.Diagnostics;
namespace Teal
{
// http://azure.microsoft.com/en-us/documentation/articles/storage-dotnet-how-to-use-queues/#insert-a-message-into-a-queue
public partial class Queue : ContentPage
{
public Queue ()
{
InitializeComponent ();
}
// TODO: this will need to be generated by you in the GenerateSharedAccessSignatures command line app
string sas = "?sv=2014-02-14&sig=VNQeIjwPr0XtYTf%2FBkIj1rZfJ4LPUXK8b%2FcwBmGJ0ic%3D&st=2015-05-06T00%3A38%3A04Z&se=2015-05-07T00%3A53%3A04Z&sp=raup";
StorageUri queueStorageUri = new StorageUri(new Uri("https://FROM_PORTAL.queue.core.windows.net/")); // from Azure portal
async void Queue_Clicked (object sender, EventArgs ea) {
CloudStorageAccount storageAccount = CreateStorageAccount ();
// Create the queue client
CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
// Retrieve a reference to a queue
CloudQueue queue = queueClient.GetQueueReference("xqueue");
CloudQueueMessage message = new CloudQueueMessage("Mobile Queue !" + DateTime.Now.Second);
await queue.AddMessageAsync(message);
Debug.WriteLine ("added to queue");
Debug.WriteLine ("count : " + queue.ApproximateMessageCount);
CloudQueueMessage retrievedMessage = await queue.GetMessageAsync();
Debug.WriteLine ("retrieved from queue " + retrievedMessage.AsString);
}
private CloudStorageAccount CreateStorageAccount()
{
CloudStorageAccount storageAccount;
try
{
var creds = new StorageCredentials (sas);
storageAccount = new CloudStorageAccount (creds, null, queueStorageUri, null, null);
}
catch (FormatException)
{
Debug.WriteLine("Invalid storage account information provided. Please confirm the AccountName and AccountKey are valid in the app.config file - then restart the sample.");
throw;
}
catch (ArgumentException)
{
Debug.WriteLine("Invalid storage account information provided. Please confirm the AccountName and AccountKey are valid in the app.config file - then restart the sample.");
throw;
}
return storageAccount;
}
}
}