-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathStorageContext.cs
More file actions
69 lines (54 loc) · 2.41 KB
/
StorageContext.cs
File metadata and controls
69 lines (54 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using System;
using System.Collections.Generic;
using Azure.Data.Tables;
namespace CoreHelpers.WindowsAzure.Storage.Table
{
public partial class StorageContext : IStorageContext
{
private IStorageContextDelegate _delegate { get; set; }
private TableServiceClient tableServiceClient { get; set; }
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)
{
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);
// take the tablename prefix
_tableNamePrefix = parentContext._tableNamePrefix;
// store the connection string
tableServiceClient = parentContext.tableServiceClient;
}
public void Dispose()
{ }
public void SetDelegate(IStorageContextDelegate delegateModel)
=> _delegate = delegateModel;
public IStorageContextDelegate GetDelegate()
=> _delegate;
public IStorageContext CreateChildContext()
=> new StorageContext(this);
public TableClient GetTableClient<T>()
{
var tableName = GetTableName<T>();
return GetTableClient(tableName);
}
private TableClient GetTableClient(string tableName)
{
return tableServiceClient.GetTableClient(tableName);
}
}
}