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


C# CloudStorageAccount.CreateCloudTableClient方法代码示例

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


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

示例1: 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

示例2: TableSASConstructors

        public void TableSASConstructors()
        {
            CloudTableClient tableClient = GenerateCloudTableClient();
            CloudTable table = tableClient.GetTableReference("T" + Guid.NewGuid().ToString("N"));
            try
            {
                table.Create();

                TableServiceContext context = tableClient.GetTableServiceContext();
                context.AddObject(table.Name, new BaseEntity("PK", "RK"));
                context.SaveChangesWithRetries();

                // Prepare SAS authentication with full permissions
                string sasToken = table.GetSharedAccessSignature(
                    new SharedAccessTablePolicy
                    {
                        Permissions = SharedAccessTablePermissions.Add | SharedAccessTablePermissions.Delete | SharedAccessTablePermissions.Query,
                        SharedAccessExpiryTime = DateTimeOffset.Now.AddMinutes(30)
                    },
                    null /* accessPolicyIdentifier */,
                    null /* startPk */,
                    null /* startRk */,
                    null /* endPk */,
                    null /* endRk */);

                CloudStorageAccount sasAccount;
                StorageCredentials sasCreds;
                CloudTableClient sasClient;
                CloudTable sasTable;
                TableServiceContext sasContext;
                Uri baseUri = new Uri(TestBase.TargetTenantConfig.TableServiceEndpoint);
                int count;

                // SAS via connection string parse
                sasAccount = CloudStorageAccount.Parse(string.Format("TableEndpoint={0};SharedAccessSignature={1}", baseUri.AbsoluteUri, sasToken));
                sasClient = sasAccount.CreateCloudTableClient();
                sasTable = sasClient.GetTableReference(table.Name);
                sasContext = sasClient.GetTableServiceContext();
                count = sasContext.CreateQuery<BaseEntity>(sasTable.Name).AsTableServiceQuery(sasContext).Execute().Count();
                Assert.AreEqual(1, count);

                // SAS via account constructor
                sasCreds = new StorageCredentials(sasToken);
                sasAccount = new CloudStorageAccount(sasCreds, null, null, baseUri, null);
                sasClient = sasAccount.CreateCloudTableClient();
                sasTable = sasClient.GetTableReference(table.Name);
                sasContext = sasClient.GetTableServiceContext();
                count = sasContext.CreateQuery<BaseEntity>(sasTable.Name).AsTableServiceQuery(sasContext).Execute().Count();
                Assert.AreEqual(1, count);

                // SAS via client constructor URI + Creds
                sasCreds = new StorageCredentials(sasToken);
                sasClient = new CloudTableClient(baseUri, sasCreds);
                sasContext = sasClient.GetTableServiceContext();
                count = sasContext.CreateQuery<BaseEntity>(sasTable.Name).AsTableServiceQuery(sasContext).Execute().Count();
                Assert.AreEqual(1, count);

            }
            finally
            {
                table.DeleteIfExists();
            }
        }
开发者ID:vinaysh-msft,项目名称:azure-storage-net,代码行数:63,代码来源:TableSasUnitTests.cs

示例3: TableClient

        private CloudTableClient TableClient()
        {
            if (this._storageAccount == null)
            {
                this._storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting(this.Attributes[_azureStorageCnnAttributeName]));
                this._tableClient = _storageAccount.CreateCloudTableClient();
            }

            return this._tableClient;
        }
开发者ID:jordivila,项目名称:Net_MVC_NLayer_Generator,代码行数:10,代码来源:CustomTraceListenerAzureTableStorage.cs

示例4: TableSASConstructorsAsync

        public async Task TableSASConstructorsAsync()
        {
            CloudTableClient tableClient = GenerateCloudTableClient();
            CloudTable table = tableClient.GetTableReference("T" + Guid.NewGuid().ToString("N"));
            try
            {
                await table.CreateAsync();

                await table.ExecuteAsync(TableOperation.Insert(new BaseEntity("PK", "RK")));

                // Prepare SAS authentication with full permissions
                string sasToken = table.GetSharedAccessSignature(
                    new SharedAccessTablePolicy
                    {
                        Permissions = SharedAccessTablePermissions.Add | SharedAccessTablePermissions.Delete | SharedAccessTablePermissions.Query,
                        SharedAccessExpiryTime = DateTimeOffset.Now.AddMinutes(30)
                    },
                    null /* accessPolicyIdentifier */,
                    null /* startPk */,
                    null /* startRk */,
                    null /* endPk */,
                    null /* endRk */);

                CloudStorageAccount sasAccount;
                StorageCredentials sasCreds;
                CloudTableClient sasClient;
                CloudTable sasTable;
                Uri baseUri = new Uri(TestBase.TargetTenantConfig.TableServiceEndpoint);

                // SAS via connection string parse
                sasAccount = CloudStorageAccount.Parse(string.Format("TableEndpoint={0};SharedAccessSignature={1}", baseUri.AbsoluteUri, sasToken));
                sasClient = sasAccount.CreateCloudTableClient();
                sasTable = sasClient.GetTableReference(table.Name);

                Assert.AreEqual(1, (await sasTable.ExecuteQuerySegmentedAsync(new TableQuery<BaseEntity>(), null)).Results.Count());

                // SAS via account constructor
                sasCreds = new StorageCredentials(sasToken);
                sasAccount = new CloudStorageAccount(sasCreds, null, null, baseUri, null);
                sasClient = sasAccount.CreateCloudTableClient();
                sasTable = sasClient.GetTableReference(table.Name);
                Assert.AreEqual(1, (await sasTable.ExecuteQuerySegmentedAsync(new TableQuery<BaseEntity>(), null)).Results.Count());

                // SAS via client constructor URI + Creds
                sasCreds = new StorageCredentials(sasToken);
                sasClient = new CloudTableClient(baseUri, sasCreds);
                Assert.AreEqual(1, (await sasTable.ExecuteQuerySegmentedAsync(new TableQuery<BaseEntity>(), null)).Results.Count());

                // SAS via CloudTable constructor Uri + Client
                sasCreds = new StorageCredentials(sasToken);
                sasTable = new CloudTable(table.Uri, tableClient.Credentials);
                sasClient = sasTable.ServiceClient;
                Assert.AreEqual(1, (await sasTable.ExecuteQuerySegmentedAsync(new TableQuery<BaseEntity>(), null)).Results.Count());
            }
            finally
            {
                table.DeleteIfExistsAsync().AsTask().Wait();
            }
        }
开发者ID:benaadams,项目名称:azure-storage-net,代码行数:59,代码来源:TableSasUnitTests.cs

示例5: TableSasUriTestAsync

        public async Task TableSasUriTestAsync()
        {
            CloudTableClient tableClient = GenerateCloudTableClient();
            CloudTable table = tableClient.GetTableReference("T" + Guid.NewGuid().ToString("N"));

            try
            {
                await table.CreateAsync();

                BaseEntity entity = new BaseEntity("PK", "RK");
                BaseEntity entity1 = new BaseEntity("PK", "RK1");
                await table.ExecuteAsync(TableOperation.Insert(entity));
                await table.ExecuteAsync(TableOperation.Insert(entity1));

                SharedAccessTablePolicy policy = new SharedAccessTablePolicy()
                {
                    SharedAccessStartTime = DateTimeOffset.UtcNow.AddMinutes(-5),
                    SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddMinutes(30),
                    Permissions = SharedAccessTablePermissions.Delete,
                };

                string sasToken = table.GetSharedAccessSignature(policy, null, null, null, null, null);
                StorageCredentials creds = new StorageCredentials(sasToken);
                CloudStorageAccount sasAcc = new CloudStorageAccount(creds, null /* blobEndpoint */, null /* queueEndpoint */, new Uri(TestBase.TargetTenantConfig.TableServiceEndpoint), null /* fileEndpoint */);
                CloudTableClient client = sasAcc.CreateCloudTableClient();

                CloudTable sasTable = new CloudTable(client.Credentials.TransformUri(table.Uri));
                await sasTable.ExecuteAsync(TableOperation.Delete(entity));

                CloudTable sasTable2 = new CloudTable(new Uri(table.Uri.ToString() + sasToken));
                await sasTable2.ExecuteAsync(TableOperation.Delete(entity1));
            }
            finally
            {
                table.DeleteIfExistsAsync().AsTask().Wait();
            }
        }
开发者ID:benaadams,项目名称:azure-storage-net,代码行数:37,代码来源:TableSasUnitTests.cs

示例6: 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

示例7: 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


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