3using System.Text.Json.Serialization;
28 private static readonly JsonSerializerOptions SerializerOptions =
29 CreateSerializerOptions();
55 throw new NotSupportedException(
56 $
"Unsupported ULS solver configuration schema version " +
57 $
"'{SchemaVersion}'. Supported version: " +
58 $
"{CurrentSchemaVersion}.");
61 ArgumentException.ThrowIfNullOrWhiteSpace(
SolverId);
62 ArgumentNullException.ThrowIfNull(
Options);
67 Options.EnsureValidFor(descriptor);
85 return JsonSerializer.Serialize(
96 ArgumentException.ThrowIfNullOrWhiteSpace(path);
99 Path.GetFullPath(path);
102 Path.GetDirectoryName(fullPath);
104 if (!
string.IsNullOrWhiteSpace(directory))
106 Directory.CreateDirectory(directory);
111 ToJson() + Environment.NewLine,
113 encoderShouldEmitUTF8Identifier:
false));
124 ArgumentException.ThrowIfNullOrWhiteSpace(json);
130 ??
throw new JsonException(
131 "The JSON document did not contain a ULS solver configuration.");
133 configuration.Validate();
134 return configuration;
145 ArgumentException.ThrowIfNullOrWhiteSpace(path);
149 Path.GetFullPath(path),
153 private static JsonSerializerOptions CreateSerializerOptions()
156 new JsonSerializerOptions
158 PropertyNamingPolicy =
159 JsonNamingPolicy.CamelCase,
160 WriteIndented =
true,
161 DefaultIgnoreCondition =
162 JsonIgnoreCondition.WhenWritingNull,
163 UnmappedMemberHandling =
164 JsonUnmappedMemberHandling.Disallow,
165 PropertyNameCaseInsensitive =
false
168 options.Converters.Add(
169 new JsonStringEnumConverter(
170 JsonNamingPolicy.CamelCase,
171 allowIntegerValues:
false));
Canonical runtime inventory of every public IUlsSolver strategy.
static UlsSolverDescriptor Get(string id)
Gets one descriptor by stable identifier.
Versioned, serializable definition of one ULS strategy and its constructor-level options.
string SolverId
Gets or sets the stable solver identifier.
const int CurrentSchemaVersion
The first and current public JSON schema version.
IUlsSolver CreateSolver()
Creates a fresh solver from this validated configuration.
static UlsSolverConfiguration LoadJson(string path)
Loads and validates one UTF-8 JSON configuration file.
string ToJson()
Serializes this configuration to canonical, indented JSON.
void SaveJson(string path)
Writes this configuration as UTF-8 without a byte-order mark.
void Validate()
Validates the schema, stable solver ID and all strategy-specific options without constructing or solv...
UlsSolverCreationOptions Options
Gets or sets the constructor-level strategy options.
int SchemaVersion
Gets or sets the serialized schema version.
static UlsSolverConfiguration ParseJson(string json)
Parses and validates one JSON configuration.
Composes the existing strategy-specific constructor options used by UlsSolverFactory.
Creates public ULS strategies from stable catalog identifiers.
static IUlsSolver Create(string id)
Creates a new solver using its stable catalog identifier and default constructor policy.
Defines the common strategy contract implemented by every ULS solver.