-
Notifications
You must be signed in to change notification settings - Fork 0
/
AbstractNatsCommand.cs
37 lines (32 loc) · 1 KB
/
AbstractNatsCommand.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
using System.IO;
using Newtonsoft.Json;
using NLog;
namespace nats_tools
{
public abstract class AbstractNatsCommand<T> where T : AbstractNatsOptions
{
protected Logger Logger { get; }
protected T Options {get; private set;}
public abstract int Run();
protected AbstractNatsCommand(Logger logger)
{
Logger = logger;
}
internal void Init(T options)
{
Options = options;
Options.Start();
}
public static string JsonPrettify(string json)
{
using (var stringReader = new StringReader(json))
using (var stringWriter = new StringWriter())
{
var jsonReader = new JsonTextReader(stringReader);
var jsonWriter = new JsonTextWriter(stringWriter) { Formatting = Formatting.Indented };
jsonWriter.WriteToken(jsonReader);
return stringWriter.ToString();
}
}
}
}