-
Notifications
You must be signed in to change notification settings - Fork 644
/
StorageHub.cs
53 lines (47 loc) · 1.82 KB
/
StorageHub.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Auth;
using Microsoft.WindowsAzure.Storage.Blob;
using NuGet.Services.Configuration;
namespace NuGet.Services.Storage
{
public class StorageHub
{
private static Dictionary<string, Func<StorageHub, StorageAccountHub>> _knownAccounts = new Dictionary<string, Func<StorageHub, StorageAccountHub>>(StringComparer.OrdinalIgnoreCase) {
{"primary", s => s.Primary},
{"backup", s => s.Backup},
{"legacy", s => s.Legacy}
};
public StorageAccountHub Primary { get; private set; }
public StorageAccountHub Backup { get; private set; }
public StorageAccountHub Legacy { get; private set; }
protected StorageHub() { }
public StorageHub(ConfigurationHub configuration)
: this(
primary: TryLoadAccount(configuration, KnownStorageAccount.Primary),
backup: TryLoadAccount(configuration, KnownStorageAccount.Backup),
legacy: TryLoadAccount(configuration, KnownStorageAccount.Legacy))
{
}
public StorageHub(StorageAccountHub primary, StorageAccountHub backup, StorageAccountHub legacy)
: this()
{
Primary = primary;
Backup = backup;
Legacy = legacy;
}
private static StorageAccountHub TryLoadAccount(ConfigurationHub configuration, KnownStorageAccount account)
{
var connectionString = configuration.Storage.GetAccount(account);
if (connectionString == null)
{
return null;
}
return new StorageAccountHub(connectionString);
}
}
}