Ejemplo n.º 1
0
        private async Task <CloudTable> CreateOrGetBlobTable(
            StorageTableOptions options,
            StorageAccountOptions storageOptions,
            CancellationToken cancellationToken = default)
        {
            var sw = ValueStopwatch.StartNew();

            var storageAccount = CreateStorageAccountFromConnectionString(storageOptions.ConnectionString);

            if (storageAccount == null)
            {
                throw new NullReferenceException($"{nameof(storageAccount)} wasn't created please make sure Connection String is provided.");
            }

            var tableClient = storageAccount.CreateCloudTableClient(new TableClientConfiguration());

            var table = tableClient.GetTableReference(options.TableName);

            if (await table.CreateIfNotExistsAsync(cancellationToken))
            {
                _logger.LogInformation("[Azure Table] No Azure Table [{tableName}] found - so one was auto created.", options.TableName);
            }
            else
            {
                _logger.LogInformation("[Azure Table] Using existing Azure Table:[{tableName}].", options.TableName);
            }

            _logger.LogInformation("[Azure Table][{methodName}] Elapsed: {seconds}sec", nameof(CreateOrGetBlobTable), sw.GetElapsedTime().TotalSeconds);

            return(table);
        }
        private async Task <CloudTable> CreateOrGetBlobTable(
            StorageTableOptions options,
            StorageAccountOptions storageOptions,
            CancellationToken cancellationToken = default)
        {
            var storageAccount = CreateStorageAccountFromConnectionString(storageOptions.ConnectionString);

            var tableClient = storageAccount.CreateCloudTableClient(new TableClientConfiguration());

            var table = tableClient.GetTableReference(options.TableName);

            if (await table.CreateIfNotExistsAsync(cancellationToken))
            {
                _logger?.LogInformation("Created Table named: {0}", options.TableName);
            }
            else
            {
                _logger?.LogInformation("Table {0} already exists", options.TableName);
            }

            return(table);
        }
Ejemplo n.º 3
0
        private static void Configure(this StorageTableOptions tableOptions, IConfiguration configuration)
        {
            var section = configuration.GetSection("Azure:StorageTable");

            section.Bind(tableOptions);
        }