Change line endings to crlf in a few cs files
This commit is contained in:
1 parent
cfc60766d8
commit
d2e9fe8237
2 files changed
+116
-116
No files matched your search
@@ -1,67 +1,67 @@
|
||||
namespace Bts.PubSubServer;
|
||||
|
||||
using Bts.PubSub;
|
||||
|
||||
using CommandLine;
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
public class PubSubServerConfig {
|
||||
/// <summary>
|
||||
/// The config server url for sparkd
|
||||
/// </summary>
|
||||
[JsonPropertyName("sparkd")]
|
||||
[Option("sparkd", HelpText = "The sparkd config server")]
|
||||
public string? Sparkd { get; set; }
|
||||
|
||||
[JsonPropertyName("simple_echo_server")]
|
||||
[Option("simple-echo-server", HelpText = "Run a simple echo server (won't connect to sparkd)")]
|
||||
public bool? SimpleEchoServer { get; set; }
|
||||
|
||||
[JsonPropertyName("pubsub")]
|
||||
public PubSubConfig? PubSub { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
[Option(
|
||||
"config",
|
||||
MetaValue = "PATH",
|
||||
HelpText = "Path to json file representing these options (PubSubServerConfig)")]
|
||||
public string? ConfigFile { get; set; }
|
||||
|
||||
public static PubSubServerConfig Default() =>
|
||||
new() {
|
||||
Sparkd = "http://localhost:8000/config",
|
||||
SimpleEchoServer = false,
|
||||
PubSub = PubSubConfig.Default(),
|
||||
ConfigFile = null,
|
||||
};
|
||||
|
||||
public void MergeWith(PubSubServerConfig other) {
|
||||
Sparkd ??= other.Sparkd;
|
||||
SimpleEchoServer ??= other.SimpleEchoServer;
|
||||
PubSub ??= other.PubSub;
|
||||
ConfigFile ??= other.ConfigFile;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Merges options with those defined in `ConfigFile` (does not overwrite
|
||||
/// non-null existing values).
|
||||
/// </summary>
|
||||
/// <exception cref="InvalidOperationException">
|
||||
/// JsonSerializer.Deserialize returns null
|
||||
/// </exception>
|
||||
public void MergeWithConfigFile() {
|
||||
if (ConfigFile is null) {
|
||||
return;
|
||||
}
|
||||
var cfgString = File.ReadAllText(ConfigFile);
|
||||
var parsedCfg = JsonSerializer.Deserialize<PubSubServerConfig>(cfgString) ??
|
||||
throw new InvalidOperationException($"Failed to parse json from {ConfigFile}");
|
||||
MergeWith(parsedCfg);
|
||||
ConfigFile = null;
|
||||
}
|
||||
}
|
||||
|
||||
namespace Bts.PubSubServer;
|
||||
|
||||
using Bts.PubSub;
|
||||
|
||||
using CommandLine;
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
public class PubSubServerConfig {
|
||||
/// <summary>
|
||||
/// The config server url for sparkd
|
||||
/// </summary>
|
||||
[JsonPropertyName("sparkd")]
|
||||
[Option("sparkd", HelpText = "The sparkd config server")]
|
||||
public string? Sparkd { get; set; }
|
||||
|
||||
[JsonPropertyName("simple_echo_server")]
|
||||
[Option("simple-echo-server", HelpText = "Run a simple echo server (won't connect to sparkd)")]
|
||||
public bool? SimpleEchoServer { get; set; }
|
||||
|
||||
[JsonPropertyName("pubsub")]
|
||||
public PubSubConfig? PubSub { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
[Option(
|
||||
"config",
|
||||
MetaValue = "PATH",
|
||||
HelpText = "Path to json file representing these options (PubSubServerConfig)")]
|
||||
public string? ConfigFile { get; set; }
|
||||
|
||||
public static PubSubServerConfig Default() =>
|
||||
new() {
|
||||
Sparkd = "http://localhost:8000/config",
|
||||
SimpleEchoServer = false,
|
||||
PubSub = PubSubConfig.Default(),
|
||||
ConfigFile = null,
|
||||
};
|
||||
|
||||
public void MergeWith(PubSubServerConfig other) {
|
||||
Sparkd ??= other.Sparkd;
|
||||
SimpleEchoServer ??= other.SimpleEchoServer;
|
||||
PubSub ??= other.PubSub;
|
||||
ConfigFile ??= other.ConfigFile;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Merges options with those defined in `ConfigFile` (does not overwrite
|
||||
/// non-null existing values).
|
||||
/// </summary>
|
||||
/// <exception cref="InvalidOperationException">
|
||||
/// JsonSerializer.Deserialize returns null
|
||||
/// </exception>
|
||||
public void MergeWithConfigFile() {
|
||||
if (ConfigFile is null) {
|
||||
return;
|
||||
}
|
||||
var cfgString = File.ReadAllText(ConfigFile);
|
||||
var parsedCfg = JsonSerializer.Deserialize<PubSubServerConfig>(cfgString) ??
|
||||
throw new InvalidOperationException($"Failed to parse json from {ConfigFile}");
|
||||
MergeWith(parsedCfg);
|
||||
ConfigFile = null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user