|
| 1 | +namespace CSharpCodeSamples |
| 2 | +{ |
| 3 | + using System; |
| 4 | + using System.Collections.ObjectModel; |
| 5 | + using System.Threading; |
| 6 | + using System.Threading.Tasks; |
| 7 | + using net.openstack.Core; |
| 8 | + using net.openstack.Core.Collections; |
| 9 | + using net.openstack.Core.Domain; |
| 10 | + using net.openstack.Core.Domain.Queues; |
| 11 | + using net.openstack.Core.Providers; |
| 12 | + using net.openstack.Providers.Rackspace; |
| 13 | + |
| 14 | + public class QueueingServiceExamples |
| 15 | + { |
| 16 | + CloudIdentity identity = |
| 17 | + new CloudIdentity() |
| 18 | + { |
| 19 | + Username = "MyUser", |
| 20 | + APIKey = "API_KEY_HERE" |
| 21 | + }; |
| 22 | + // use the default region for the account |
| 23 | + string region = null; |
| 24 | + // create a new client ID for this instance |
| 25 | + Guid clientId = Guid.NewGuid(); |
| 26 | + // access Cloud Queues over the public Internet |
| 27 | + bool internalUrl = false; |
| 28 | + // use a default CloudIdentityProvider for authentication |
| 29 | + IIdentityProvider identityProvider = null; |
| 30 | + |
| 31 | + public async Task GetHomeAsyncAwait() |
| 32 | + { |
| 33 | + #region GetHomeAsync (await) |
| 34 | + IQueueingService queueingService = new CloudQueuesProvider(identity, region, clientId, internalUrl, identityProvider); |
| 35 | + HomeDocument createdQueue = await queueingService.GetHomeAsync(CancellationToken.None); |
| 36 | + #endregion |
| 37 | + } |
| 38 | + |
| 39 | + public void GetHome() |
| 40 | + { |
| 41 | + #region GetHomeAsync (TPL) |
| 42 | + IQueueingService queueingService = new CloudQueuesProvider(identity, region, clientId, internalUrl, identityProvider); |
| 43 | + Task<HomeDocument> task = queueingService.GetHomeAsync(CancellationToken.None); |
| 44 | + #endregion |
| 45 | + } |
| 46 | + |
| 47 | + public async Task GetNodeHealthAsyncAwait() |
| 48 | + { |
| 49 | + #region GetNodeHealthAsync (await) |
| 50 | + IQueueingService queueingService = new CloudQueuesProvider(identity, region, clientId, internalUrl, identityProvider); |
| 51 | + await queueingService.GetNodeHealthAsync(CancellationToken.None); |
| 52 | + #endregion |
| 53 | + } |
| 54 | + |
| 55 | + public void GetNodeHealth() |
| 56 | + { |
| 57 | + #region GetNodeHealthAsync (TPL) |
| 58 | + IQueueingService queueingService = new CloudQueuesProvider(identity, region, clientId, internalUrl, identityProvider); |
| 59 | + Task task = queueingService.GetNodeHealthAsync(CancellationToken.None); |
| 60 | + #endregion |
| 61 | + } |
| 62 | + |
| 63 | + public async Task CreateQueueAsyncAwait() |
| 64 | + { |
| 65 | + #region CreateQueueAsync (await) |
| 66 | + IQueueingService queueingService = new CloudQueuesProvider(identity, region, clientId, internalUrl, identityProvider); |
| 67 | + QueueName queueName = new QueueName("ExampleQueue"); |
| 68 | + bool createdQueue = await queueingService.CreateQueueAsync(queueName, CancellationToken.None); |
| 69 | + #endregion |
| 70 | + } |
| 71 | + |
| 72 | + public void CreateQueue() |
| 73 | + { |
| 74 | + #region CreateQueueAsync (TPL) |
| 75 | + IQueueingService queueingService = new CloudQueuesProvider(identity, region, clientId, internalUrl, identityProvider); |
| 76 | + QueueName queueName = new QueueName("ExampleQueue"); |
| 77 | + Task<bool> task = queueingService.CreateQueueAsync(queueName, CancellationToken.None); |
| 78 | + #endregion |
| 79 | + } |
| 80 | + |
| 81 | + public async Task DeleteQueueAsyncAwait() |
| 82 | + { |
| 83 | + #region DeleteQueueAsync (await) |
| 84 | + IQueueingService queueingService = new CloudQueuesProvider(identity, region, clientId, internalUrl, identityProvider); |
| 85 | + QueueName queueName = new QueueName("ExampleQueue"); |
| 86 | + await queueingService.DeleteQueueAsync(queueName, CancellationToken.None); |
| 87 | + #endregion |
| 88 | + } |
| 89 | + |
| 90 | + public void DeleteQueue() |
| 91 | + { |
| 92 | + #region DeleteQueueAsync (TPL) |
| 93 | + IQueueingService queueingService = new CloudQueuesProvider(identity, region, clientId, internalUrl, identityProvider); |
| 94 | + QueueName queueName = new QueueName("ExampleQueue"); |
| 95 | + Task task = queueingService.DeleteQueueAsync(queueName, CancellationToken.None); |
| 96 | + #endregion |
| 97 | + } |
| 98 | + |
| 99 | + public async Task ListQueuesAsyncAwait() |
| 100 | + { |
| 101 | + #region ListQueuesAsync (await) |
| 102 | + IQueueingService queueingService = new CloudQueuesProvider(identity, region, clientId, internalUrl, identityProvider); |
| 103 | + ReadOnlyCollectionPage<CloudQueue> queuesPage = await queueingService.ListQueuesAsync(null, null, true, CancellationToken.None); |
| 104 | + ReadOnlyCollection<CloudQueue> queues = await queuesPage.GetAllPagesAsync(CancellationToken.None, null); |
| 105 | + #endregion |
| 106 | + } |
| 107 | + |
| 108 | + public void ListQueues() |
| 109 | + { |
| 110 | + #region ListQueuesAsync (TPL) |
| 111 | + IQueueingService queueingService = new CloudQueuesProvider(identity, region, clientId, internalUrl, identityProvider); |
| 112 | + Task<ReadOnlyCollectionPage<CloudQueue>> queuesPageTask = queueingService.ListQueuesAsync(null, null, true, CancellationToken.None); |
| 113 | + Task<ReadOnlyCollection<CloudQueue>> queuesTask = |
| 114 | + queuesPageTask |
| 115 | + .ContinueWith(task => task.Result.GetAllPagesAsync(CancellationToken.None, null)) |
| 116 | + .Unwrap(); |
| 117 | + #endregion |
| 118 | + } |
| 119 | + |
| 120 | + public async Task QueueExistsAsyncAwait() |
| 121 | + { |
| 122 | + #region QueueExistsAsync (await) |
| 123 | + IQueueingService queueingService = new CloudQueuesProvider(identity, region, clientId, internalUrl, identityProvider); |
| 124 | + QueueName queueName = new QueueName("ExampleQueue"); |
| 125 | + bool exists = await queueingService.QueueExistsAsync(queueName, CancellationToken.None); |
| 126 | + #endregion |
| 127 | + } |
| 128 | + |
| 129 | + public void QueueExists() |
| 130 | + { |
| 131 | + #region QueueExistsAsync (TPL) |
| 132 | + IQueueingService queueingService = new CloudQueuesProvider(identity, region, clientId, internalUrl, identityProvider); |
| 133 | + QueueName queueName = new QueueName("ExampleQueue"); |
| 134 | + Task<bool> task = queueingService.QueueExistsAsync(queueName, CancellationToken.None); |
| 135 | + #endregion |
| 136 | + } |
| 137 | + } |
| 138 | +} |
0 commit comments