-
Notifications
You must be signed in to change notification settings - Fork 494
/
ConsistencyConfig.cs
56 lines (48 loc) · 2 KB
/
ConsistencyConfig.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
54
55
56
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// ------------------------------------------------------------
namespace Microsoft.Azure.Cosmos.Tracing.TraceData
{
using System;
using System.Collections.Generic;
using System.Globalization;
internal class ConsistencyConfig
{
public ConsistencyConfig(
ConsistencyLevel? consistencyLevel,
IReadOnlyList<string> preferredRegions,
string applicationRegion)
{
this.ConsistencyLevel = consistencyLevel;
this.PreferredRegions = preferredRegions;
this.ApplicationRegion = applicationRegion;
this.lazyString = new Lazy<string>(() => string.Format(CultureInfo.InvariantCulture,
"(consistency: {0}, prgns:[{1}], apprgn: {2})",
consistencyLevel?.ToString() ?? "NotSet",
ConsistencyConfig.PreferredRegionsInternal(preferredRegions),
applicationRegion));
this.lazyJsonString = new Lazy<string>(() => Newtonsoft.Json.JsonConvert.SerializeObject(this));
}
public ConsistencyLevel? ConsistencyLevel { get; }
public IReadOnlyList<string> PreferredRegions { get; }
public string ApplicationRegion { get; }
private readonly Lazy<string> lazyString;
private readonly Lazy<string> lazyJsonString;
public override string ToString()
{
return this.lazyString.Value;
}
public string ToJsonString()
{
return this.lazyJsonString.Value;
}
private static string PreferredRegionsInternal(IReadOnlyList<string> applicationPreferredRegions)
{
if (applicationPreferredRegions == null)
{
return string.Empty;
}
return string.Join(", ", applicationPreferredRegions);
}
}
}