-
Notifications
You must be signed in to change notification settings - Fork 2k
/
AdoNetGrainStorageOptions.cs
73 lines (67 loc) · 2.93 KB
/
AdoNetGrainStorageOptions.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using Orleans.Persistence.AdoNet.Storage;
using Orleans.Runtime;
using Orleans.Storage;
namespace Orleans.Configuration
{
/// <summary>
/// Options for AdonetGrainStorage
/// </summary>
public class AdoNetGrainStorageOptions : IStorageProviderSerializerOptions
{
/// <summary>
/// Connection string for AdoNet storage.
/// </summary>
[Redact]
public string ConnectionString { get; set; }
/// <summary>
/// Stage of silo lifecycle where storage should be initialized. Storage must be initialized prior to use.
/// </summary>
public int InitStage { get; set; } = DEFAULT_INIT_STAGE;
/// <summary>
/// Default init stage in silo lifecycle.
/// </summary>
public const int DEFAULT_INIT_STAGE = ServiceLifecycleStage.ApplicationServices;
/// <summary>
/// The default ADO.NET invariant used for storage if none is given.
/// </summary>
public const string DEFAULT_ADONET_INVARIANT = AdoNetInvariants.InvariantNameSqlServer;
/// <summary>
/// The invariant name for storage.
/// </summary>
public string Invariant { get; set; } = DEFAULT_ADONET_INVARIANT;
/// <inheritdoc/>
public IGrainStorageSerializer GrainStorageSerializer { get; set; }
}
/// <summary>
/// ConfigurationValidator for AdoNetGrainStorageOptions
/// </summary>
public class AdoNetGrainStorageOptionsValidator : IConfigurationValidator
{
private readonly AdoNetGrainStorageOptions options;
private readonly string name;
/// <summary>
/// Constructor
/// </summary>
/// <param name="configurationOptions">The option to be validated.</param>
/// <param name="name">The name of the option to be validated.</param>
public AdoNetGrainStorageOptionsValidator(AdoNetGrainStorageOptions configurationOptions, string name)
{
if(configurationOptions == null)
throw new OrleansConfigurationException($"Invalid AdoNetGrainStorageOptions for AdoNetGrainStorage {name}. Options is required.");
this.options = configurationOptions;
this.name = name;
}
/// <inheritdoc cref="IConfigurationValidator"/>
public void ValidateConfiguration()
{
if (string.IsNullOrWhiteSpace(this.options.Invariant))
{
throw new OrleansConfigurationException($"Invalid {nameof(AdoNetGrainStorageOptions)} values for {nameof(AdoNetGrainStorage)} \"{name}\". {nameof(options.Invariant)} is required.");
}
if (string.IsNullOrWhiteSpace(this.options.ConnectionString))
{
throw new OrleansConfigurationException($"Invalid {nameof(AdoNetGrainStorageOptions)} values for {nameof(AdoNetGrainStorage)} \"{name}\". {nameof(options.ConnectionString)} is required.");
}
}
}
}