Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement TableServiceClient #28

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 36 additions & 29 deletions CoreHelpers.WindowsAzure.Storage.Table/StorageContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,58 +5,65 @@
namespace CoreHelpers.WindowsAzure.Storage.Table
{
public partial class StorageContext : IStorageContext
{
private IStorageContextDelegate _delegate { get; set; }
private string _connectionString;
{
private IStorageContextDelegate _delegate { get; set; }
private TableServiceClient tableServiceClient { get; set; }

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);
}
public StorageContext(string storageAccountName, string storageAccountKey, string storageEndpointSuffix = null)
{
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)
{
{
// we reference the entity mapper
_entityMapperRegistry = new Dictionary<Type, StorageEntityMapper>(parentContext._entityMapperRegistry);

// we are using the delegate
this.SetDelegate(parentContext._delegate);
this.SetDelegate(parentContext._delegate);

// take the tablename prefix
_tableNamePrefix = parentContext._tableNamePrefix;
// take the tablename prefix
_tableNamePrefix = parentContext._tableNamePrefix;

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

public void Dispose()
{}
{ }

public void SetDelegate(IStorageContextDelegate delegateModel)
=> _delegate = delegateModel;
public void SetDelegate(IStorageContextDelegate delegateModel)
=> _delegate = delegateModel;

public IStorageContextDelegate GetDelegate()
=> _delegate;
public IStorageContextDelegate GetDelegate()
=> _delegate;

public IStorageContext CreateChildContext()
=> new StorageContext(this);

public IStorageContext CreateChildContext()
=> new StorageContext(this);

public TableClient GetTableClient<T>()
{
var tableName = GetTableName<T>();
return GetTableClient(tableName);
var tableName = GetTableName<T>();
return GetTableClient(tableName);
}

private TableClient GetTableClient(string tableName)
{
return new TableClient(_connectionString, tableName);
}
return tableServiceClient.GetTableClient(tableName);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ public async Task<List<string>> QueryTableList()
{
var tables = new List<string>();

var tsc = new TableServiceClient(_connectionString);
var tablePages = tsc.QueryAsync().AsPages();
var tablePages = tableServiceClient.QueryAsync().AsPages();

await foreach (var tablePage in tablePages)
tables.AddRange(tablePage.Values.Select(t => t.Name));
Expand Down
Loading