当前位置: 首页>>代码示例>>C#>>正文


C# CloudStorageAccount.CreateCloudQueueClient方法代码示例

本文整理汇总了C#中CloudStorageAccount.CreateCloudQueueClient方法的典型用法代码示例。如果您正苦于以下问题:C# CloudStorageAccount.CreateCloudQueueClient方法的具体用法?C# CloudStorageAccount.CreateCloudQueueClient怎么用?C# CloudStorageAccount.CreateCloudQueueClient使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CloudStorageAccount的用法示例。


在下文中一共展示了CloudStorageAccount.CreateCloudQueueClient方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: QueueSASTestAsync

        public async Task QueueSASTestAsync()
        {
            CloudQueueClient client = GenerateCloudQueueClient();
            CloudQueue queue = client.GetQueueReference(GenerateNewQueueName());
            await queue.CreateAsync();
            string messageContent = Guid.NewGuid().ToString();
            CloudQueueMessage message = new CloudQueueMessage(messageContent);
            await queue.AddMessageAsync(message);

            // Prepare SAS authentication with full permissions
            string id = Guid.NewGuid().ToString();
            DateTime start = DateTime.UtcNow;
            DateTime expiry = start.AddMinutes(30);
            QueuePermissions permissions = new QueuePermissions();
            SharedAccessQueuePermissions queuePerm = SharedAccessQueuePermissions.Add | SharedAccessQueuePermissions.ProcessMessages | SharedAccessQueuePermissions.Read | SharedAccessQueuePermissions.Update;
            permissions.SharedAccessPolicies.Add(id, new SharedAccessQueuePolicy()
            {
                SharedAccessStartTime = start,
                SharedAccessExpiryTime = expiry,
                Permissions = queuePerm
            });

            await queue.SetPermissionsAsync(permissions);
            await Task.Delay(30 * 1000);

            string sasTokenFromId = queue.GetSharedAccessSignature(null, id);
            StorageCredentials sasCredsFromId = new StorageCredentials(sasTokenFromId);

            CloudStorageAccount sasAcc = new CloudStorageAccount(sasCredsFromId, null /* blobEndpoint */, new Uri(TestBase.TargetTenantConfig.QueueServiceEndpoint), null /* tableEndpoint */, null /* fileEndpoint */);
            CloudQueueClient sasClient = sasAcc.CreateCloudQueueClient();

            CloudQueue sasQueueFromSasUri = new CloudQueue(sasClient.Credentials.TransformUri(queue.Uri));
            CloudQueueMessage receivedMessage = await sasQueueFromSasUri.PeekMessageAsync();
            Assert.AreEqual(messageContent, receivedMessage.AsString);

            CloudQueue sasQueueFromSasUri1 = new CloudQueue(new Uri(queue.Uri.ToString() + sasTokenFromId));
            CloudQueueMessage receivedMessage1 = await sasQueueFromSasUri1.PeekMessageAsync();
            Assert.AreEqual(messageContent, receivedMessage1.AsString);

            CloudQueue sasQueueFromId = new CloudQueue(queue.Uri, sasCredsFromId);
            CloudQueueMessage receivedMessage2 = await sasQueueFromId.PeekMessageAsync();
            Assert.AreEqual(messageContent, receivedMessage2.AsString);

            string sasTokenFromPolicy = queue.GetSharedAccessSignature(permissions.SharedAccessPolicies[id], null);
            StorageCredentials sasCredsFromPolicy = new StorageCredentials(sasTokenFromPolicy);
            CloudQueue sasQueueFromPolicy = new CloudQueue(queue.Uri, sasCredsFromPolicy);
            CloudQueueMessage receivedMessage3 = await sasQueueFromPolicy.PeekMessageAsync();
            Assert.AreEqual(messageContent, receivedMessage3.AsString);
            await queue.DeleteAsync();
        }
开发者ID:benaadams,项目名称:azure-storage-net,代码行数:50,代码来源:CloudQueueTest.cs

示例2: CloudStorageAccountClientUriVerify

        public void CloudStorageAccountClientUriVerify()
        {
            StorageCredentials cred = new StorageCredentials(TestBase.TargetTenantConfig.AccountName, TestBase.TargetTenantConfig.AccountKey);
            CloudStorageAccount cloudStorageAccount = new CloudStorageAccount(cred, true);

            CloudBlobClient blobClient = cloudStorageAccount.CreateCloudBlobClient();
            CloudBlobContainer container = blobClient.GetContainerReference("container1");
            Assert.AreEqual(cloudStorageAccount.BlobEndpoint.ToString() + "container1", container.Uri.ToString());

            CloudQueueClient queueClient = cloudStorageAccount.CreateCloudQueueClient();
            CloudQueue queue = queueClient.GetQueueReference("queue1");
            Assert.AreEqual(cloudStorageAccount.QueueEndpoint.ToString() + "queue1", queue.Uri.ToString());

            CloudTableClient tableClient = cloudStorageAccount.CreateCloudTableClient();
            CloudTable table = tableClient.GetTableReference("table1");
            Assert.AreEqual(cloudStorageAccount.TableEndpoint.ToString() + "table1", table.Uri.ToString());
        }
开发者ID:jdkillian,项目名称:azure-sdk-for-net,代码行数:17,代码来源:CloudStorageAccountTests.cs

示例3: CloudStorageAccountWithStorageUri

        public void CloudStorageAccountWithStorageUri()
        {
            StorageUri blobEndpoint = new StorageUri(
                new Uri("http://" + AccountName + BlobService + EndpointSuffix),
                new Uri("http://" + AccountName + SecondarySuffix + BlobService + EndpointSuffix));

            StorageUri queueEndpoint = new StorageUri(
                new Uri("http://" + AccountName + QueueService + EndpointSuffix),
                new Uri("http://" + AccountName + SecondarySuffix + QueueService + EndpointSuffix));

            StorageUri tableEndpoint = new StorageUri(
                new Uri("http://" + AccountName + TableService + EndpointSuffix),
                new Uri("http://" + AccountName + SecondarySuffix + TableService + EndpointSuffix));

            StorageUri fileEndpoint = new StorageUri(
                new Uri("http://" + AccountName + FileService + EndpointSuffix),
                new Uri("http://" + AccountName + SecondarySuffix + FileService + EndpointSuffix));

#if WINDOWS_RT || ASPNET_K
            CloudStorageAccount account = CloudStorageAccount.Create(new StorageCredentials(), blobEndpoint, queueEndpoint, tableEndpoint, fileEndpoint);
#else
            CloudStorageAccount account = new CloudStorageAccount(new StorageCredentials(), blobEndpoint, queueEndpoint, tableEndpoint, fileEndpoint);
#endif
            Assert.IsTrue(blobEndpoint.Equals(account.BlobStorageUri));
            Assert.IsTrue(queueEndpoint.Equals(account.QueueStorageUri));
            Assert.IsTrue(tableEndpoint.Equals(account.TableStorageUri));
            Assert.IsTrue(fileEndpoint.Equals(account.FileStorageUri));

            account = new CloudStorageAccount(new StorageCredentials(AccountName, TestBase.StorageCredentials.ExportBase64EncodedKey()), false);
            Assert.IsTrue(blobEndpoint.Equals(account.BlobStorageUri));
            Assert.IsTrue(queueEndpoint.Equals(account.QueueStorageUri));
            Assert.IsTrue(tableEndpoint.Equals(account.TableStorageUri));
            Assert.IsTrue(fileEndpoint.Equals(account.FileStorageUri));

            account = CloudStorageAccount.Parse(string.Format("DefaultEndpointsProtocol=http;AccountName={0};AccountKey=", AccountName));
            Assert.IsTrue(blobEndpoint.Equals(account.BlobStorageUri));
            Assert.IsTrue(queueEndpoint.Equals(account.QueueStorageUri));
            Assert.IsTrue(tableEndpoint.Equals(account.TableStorageUri));
            Assert.IsTrue(fileEndpoint.Equals(account.FileStorageUri));

            Assert.IsTrue(blobEndpoint.Equals(account.CreateCloudBlobClient().StorageUri));
            Assert.IsTrue(queueEndpoint.Equals(account.CreateCloudQueueClient().StorageUri));
            Assert.IsTrue(tableEndpoint.Equals(account.CreateCloudTableClient().StorageUri));
            Assert.IsTrue(fileEndpoint.Equals(account.CreateCloudFileClient().StorageUri));

            Assert.IsTrue(blobEndpoint.PrimaryUri.Equals(account.BlobEndpoint));
            Assert.IsTrue(queueEndpoint.PrimaryUri.Equals(account.QueueEndpoint));
            Assert.IsTrue(tableEndpoint.PrimaryUri.Equals(account.TableEndpoint));
            Assert.IsTrue(fileEndpoint.PrimaryUri.Equals(account.FileEndpoint));
        }
开发者ID:DaC24,项目名称:azure-storage-net,代码行数:50,代码来源:StorageUriTests.cs

示例4: CloudStorageAccountClientMethods

        public void CloudStorageAccountClientMethods()
        {
            CloudStorageAccount account = new CloudStorageAccount(TestBase.StorageCredentials, false);
            CloudBlobClient blob = account.CreateCloudBlobClient();
            CloudQueueClient queue = account.CreateCloudQueueClient();
            CloudTableClient table = account.CreateCloudTableClient();

            // check endpoints
            Assert.AreEqual(account.BlobEndpoint, blob.BaseUri, "Blob endpoint doesn't match account");
            Assert.AreEqual(account.QueueEndpoint, queue.BaseUri, "Queue endpoint doesn't match account");
            Assert.AreEqual(account.TableEndpoint, table.BaseUri, "Table endpoint doesn't match account");

            // check storage uris
            Assert.AreEqual(account.BlobStorageUri, blob.StorageUri, "Blob endpoint doesn't match account");
            Assert.AreEqual(account.QueueStorageUri, queue.StorageUri, "Queue endpoint doesn't match account");
            Assert.AreEqual(account.TableStorageUri, table.StorageUri, "Table endpoint doesn't match account");

            // check creds
            Assert.AreEqual(account.Credentials, blob.Credentials, "Blob creds don't match account");
            Assert.AreEqual(account.Credentials, queue.Credentials, "Queue creds don't match account");
            Assert.AreEqual(account.Credentials, table.Credentials, "Table creds don't match account");
        }
开发者ID:BurtHarris,项目名称:azure-storage-net,代码行数:22,代码来源:CloudStorageAccountTests.cs

示例5: CloudQueueOldSASVersion

        public void CloudQueueOldSASVersion()
        {
            CloudQueueClient client = GenerateCloudQueueClient();
            CloudQueue queue = client.GetQueueReference(GenerateNewQueueName());

            try
            {
                queue.Create();
                string messageContent = Guid.NewGuid().ToString();
                CloudQueueMessage message = new CloudQueueMessage(messageContent);
                queue.AddMessage(message);

                // Prepare SAS authentication with full permissions
                string id = Guid.NewGuid().ToString();
                DateTime start = DateTime.UtcNow;
                DateTime expiry = start.AddMinutes(30);
                QueuePermissions permissions = new QueuePermissions();
                SharedAccessQueuePermissions queuePerm = SharedAccessQueuePermissions.Add | SharedAccessQueuePermissions.ProcessMessages | SharedAccessQueuePermissions.Read | SharedAccessQueuePermissions.Update;
                permissions.SharedAccessPolicies.Add(id, new SharedAccessQueuePolicy()
                {
                    SharedAccessStartTime = start,
                    SharedAccessExpiryTime = expiry,
                    Permissions = queuePerm
                });

                queue.SetPermissions(permissions);
                Thread.Sleep(30 * 1000);

                string sasTokenFromId = queue.GetSharedAccessSignature(null, id, Constants.VersionConstants.February2012);
                StorageCredentials sasCredsFromId = new StorageCredentials(sasTokenFromId);

                CloudStorageAccount sasAcc = new CloudStorageAccount(sasCredsFromId, new Uri(TestBase.TargetTenantConfig.BlobServiceEndpoint), new Uri(TestBase.TargetTenantConfig.QueueServiceEndpoint), new Uri(TestBase.TargetTenantConfig.TableServiceEndpoint));
                CloudQueueClient sasClient = sasAcc.CreateCloudQueueClient();

                CloudQueue sasQueueFromSasUri = new CloudQueue(sasClient.Credentials.TransformUri(queue.Uri));
                CloudQueueMessage receivedMessage = sasQueueFromSasUri.PeekMessage();
                Assert.AreEqual(messageContent, receivedMessage.AsString);

                CloudQueue sasQueueFromSasUri1 = new CloudQueue(new Uri(queue.Uri.ToString() + sasTokenFromId));
                CloudQueueMessage receivedMessage1 = sasQueueFromSasUri1.PeekMessage();
                Assert.AreEqual(messageContent, receivedMessage1.AsString);

                CloudQueue sasQueueFromId = new CloudQueue(queue.Uri, sasCredsFromId);
                CloudQueueMessage receivedMessage2 = sasQueueFromId.PeekMessage();
                Assert.AreEqual(messageContent, receivedMessage2.AsString);

                string sasTokenFromPolicy = queue.GetSharedAccessSignature(permissions.SharedAccessPolicies[id], null);
                StorageCredentials sasCredsFromPolicy = new StorageCredentials(sasTokenFromPolicy);
                CloudQueue sasQueueFromPolicy = new CloudQueue(queue.Uri, sasCredsFromPolicy);
                CloudQueueMessage receivedMessage3 = sasQueueFromPolicy.PeekMessage();
                Assert.AreEqual(messageContent, receivedMessage3.AsString);
            }
            finally
            {
                queue.DeleteIfExists();
            }
        }
开发者ID:jasonnewyork,项目名称:azure-storage-net,代码行数:57,代码来源:CloudQueueTest.cs


注:本文中的CloudStorageAccount.CreateCloudQueueClient方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。