Skip to content

Commit

Permalink
Implement TableServiceClient
Browse files Browse the repository at this point in the history
  • Loading branch information
petero-dk committed Aug 19, 2024
1 parent 7466947 commit f75d805
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions CoreHelpers.WindowsAzure.Storage.Table/StorageContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,25 @@ namespace CoreHelpers.WindowsAzure.Storage.Table
public partial class StorageContext : IStorageContext
{
private IStorageContextDelegate _delegate { get; set; }
private string _connectionString;
private TableServiceClient tableServiceClient { get; set; }

public StorageContext(string storageAccountName, string storageAccountKey, string storageEndpointSuffix = null)
public StorageContext(string storageAccountName, string storageAccountKey, string storageEndpointSuffix = null)
{
_connectionString = String.Format("DefaultEndpointsProtocol={0};AccountName={1};AccountKey={2}", "https", storageAccountName, storageAccountKey);
if (!String.IsNullOrEmpty(storageEndpointSuffix))
_connectionString = String.Format("DefaultEndpointsProtocol={0};AccountName={1};AccountKey={2};EndpointSuffix={3}", "https", storageAccountName, storageAccountKey, storageEndpointSuffix);
if (!String.IsNullOrEmpty(storageEndpointSuffix))
tableServiceClient = new TableServiceClient(string.Format("DefaultEndpointsProtocol={0};AccountName={1};AccountKey={2};EndpointSuffix={3}", "https", storageAccountName, storageAccountKey, storageEndpointSuffix));
else
tableServiceClient = new TableServiceClient(string.Format("DefaultEndpointsProtocol={0};AccountName={1};AccountKey={2}", "https", storageAccountName, storageAccountKey));

}

public StorageContext(string connectionString)
{
_connectionString = connectionString;
tableServiceClient = new TableServiceClient(connectionString);
}

public StorageContext(TableServiceClient tableServiceClient)
{
this.tableServiceClient = tableServiceClient;
}

public StorageContext(StorageContext parentContext)
Expand All @@ -32,8 +39,8 @@ public StorageContext(StorageContext parentContext)
// take the tablename prefix
_tableNamePrefix = parentContext._tableNamePrefix;

// store the connection string
_connectionString = parentContext._connectionString;
// store the connection string
tableServiceClient = parentContext.tableServiceClient;
}

public void Dispose()
Expand All @@ -56,7 +63,7 @@ public TableClient GetTableClient<T>()

private TableClient GetTableClient(string tableName)
{
return new TableClient(_connectionString, tableName);
return tableServiceClient.GetTableClient(tableName);
}
}
}

0 comments on commit f75d805

Please sign in to comment.