Пример #1
0
        public override async Task StartTestRecordingAsync()
        {
            await base.StartTestRecordingAsync();

            TableName     = GetRandomTableName();
            ServiceClient = InstrumentClient(
                new TableServiceClient(
                    UseCosmos ? TestEnvironment.CosmosConnectionString : TestEnvironment.StorageConnectionString,
                    InstrumentClientOptions(new TableClientOptions())));

            TableClient = ServiceClient.GetTableClient(TableName);
            if (_createTable)
            {
                await TableClient.CreateAsync();
            }
        }
        public async Task CreateDeleteEntitiesAsync()
        {
            string storageUri        = StorageUri;
            string accountName       = StorageAccountName;
            string storageAccountKey = PrimaryStorageAccountKey;
            string tableName         = "OfficeSupplies2p2";
            string partitionKey      = "somePartition";
            string rowKey            = "A1";
            string rowKeyStrong      = "B1";

            #region Snippet:TablesSample2CreateTableClientAsync
            // Construct a new <see cref="TableClient" /> using a <see cref="TableSharedKeyCredential" />.
            var client = new TableClient(
                tableName,
                new Uri(storageUri),
                new TableSharedKeyCredential(accountName, storageAccountKey));

            // Create the table in the service.
            await client.CreateAsync();

            #endregion

            #region Snippet:TablesSample2CreateEntityAsync
            // Make an entity by defining a <see cref="Dictionary"> that includes the partition and row key.
            var entity = new TableEntity(partitionKey, rowKey)
            {
                { "Product", "Markers" },
                { "Price", 5.00 },
            };

            // Insert the newly created entity.
            await client.CreateEntityAsync(entity);

            #endregion

            #region Snippet:TablesSample2CreateStronglyTypedEntityAsync
            // Make a strongly typed entity by defining a custom class that extends <see cref="TableEntity">.
            var strongEntity = new OfficeSupplyEntity
            {
                PartitionKey = partitionKey,
                RowKey       = rowKeyStrong,
                Product      = "Notebook",
                Price        = 3.00
            };

            // Insert the newly created entity.
            await client.CreateEntityAsync(strongEntity);

            #endregion

            #region Snippet:TablesSample2DeleteEntityAsync
            // Delete the entity given the partition and row key.
            await client.DeleteEntityAsync(partitionKey, rowKey);

            #endregion

            #region Snippet:TablesSample2DeleteTableWithTableClientAsync
            await client.DeleteAsync();

            #endregion
        }
        public async Task CreateDeleteEntitiesAsync()
        {
            string storageUri        = StorageUri;
            string accountName       = StorageAccountName;
            string storageAccountKey = PrimaryStorageAccountKey;
            string tableName         = "OfficeSupplies2p2";
            string partitionKey      = "Stationery";
            string rowKey            = "A1";
            string rowKeyStrong      = "B1";

            #region Snippet:TablesSample2CreateTableClientAsync
            // Construct a new <see cref="TableClient" /> using a <see cref="TableSharedKeyCredential" />.
            var client = new TableClient(
                new Uri(storageUri),
                tableName,
                new TableSharedKeyCredential(accountName, storageAccountKey));

            // Create the table in the service.
            await client.CreateAsync();

            #endregion

            #region Snippet:TablesSample2CreateEntityAsync
            // Make a dictionary entity by defining a <see cref="TableEntity">.
            var entity = new TableEntity(partitionKey, rowKey)
            {
                { "Product", "Marker Set" },
                { "Price", 5.00 },
                { "Quantity", 21 }
            };

            Console.WriteLine($"{entity.RowKey}: {entity["Product"]} costs ${entity.GetDouble("Price")}.");
            #endregion

            #region Snippet:TablesSample2AddEntityAsync
            // Insert the newly created entity.
            await client.AddEntityAsync(entity);

            #endregion

            #region Snippet:TablesSample2CreateStronglyTypedEntityAsync
            // Create an instance of the strongly-typed entity and set their properties.
            var strongEntity = new OfficeSupplyEntity
            {
                PartitionKey = partitionKey,
                RowKey       = rowKeyStrong,
                Product      = "Notebook",
                Price        = 3.00,
                Quantity     = 50
            };

            Console.WriteLine($"{entity.RowKey}: {strongEntity.Product} costs ${strongEntity.Price}.");
            #endregion

            // Add the newly created entity.
            await client.AddEntityAsync(strongEntity);

            #region Snippet:TablesSample2DeleteEntityAsync
            // Delete the entity given the partition and row key.
            await client.DeleteEntityAsync(partitionKey, rowKey);

            #endregion

            #region Snippet:TablesSample2DeleteTableWithTableClientAsync
            await client.DeleteAsync();

            #endregion
        }
Пример #4
0
        public static async Task Create(string account, string key, string tableName)
        {
            TableClient table = new TableClient(Client.GetConnectionString(account, key), tableName);

            await table.CreateAsync();
        }