-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathCdnConfigurationClientManager.cs
More file actions
72 lines (59 loc) · 2.1 KB
/
CdnConfigurationClientManager.cs
File metadata and controls
72 lines (59 loc) · 2.1 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
70
71
72
using Azure.Data.AppConfiguration;
using Microsoft.Extensions.Azure;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Microsoft.Extensions.Configuration.AzureAppConfiguration
{
internal class CdnConfigurationClientManager : IConfigurationClientManager
{
private readonly IList<ConfigurationClientWrapper> _clients;
public CdnConfigurationClientManager(
IAzureClientFactory<ConfigurationClient> clientFactory,
IEnumerable<Uri> endpoints)
{
if (clientFactory == null)
{
throw new ArgumentNullException(nameof(clientFactory));
}
_clients = endpoints
.Select(endpoint => new ConfigurationClientWrapper(endpoint, clientFactory.CreateClient(endpoint.AbsoluteUri)))
.ToList();
}
public IEnumerable<ConfigurationClient> GetClients()
{
return _clients.Select(c => c.Client);
}
public void RefreshClients()
{
return;
}
public bool UpdateSyncToken(Uri endpoint, string syncToken)
{
if (endpoint == null)
{
throw new ArgumentNullException(nameof(endpoint));
}
if (string.IsNullOrWhiteSpace(syncToken))
{
throw new ArgumentNullException(nameof(syncToken));
}
ConfigurationClientWrapper clientWrapper = _clients.SingleOrDefault(c => new EndpointComparer().Equals(c.Endpoint, endpoint));
if (clientWrapper != null)
{
clientWrapper.Client.UpdateSyncToken(syncToken);
return true;
}
return false;
}
public Uri GetEndpointForClient(ConfigurationClient client)
{
if (client == null)
{
throw new ArgumentNullException(nameof(client));
}
ConfigurationClientWrapper currentClient = _clients.FirstOrDefault(c => c.Client == client);
return currentClient?.Endpoint;
}
}
}