/// <summary> /// Initialises a new instance. /// </summary> /// <param name="configuration"></param> /// <param name="anonymiser"></param> /// <param name="stringScrambler"></param> /// <param name="writer"></param> public JsonProcessor(Configuration configuration, Anonymiser anonymiser, StringScrambler stringScrambler, TextWriter writer) { this._anonymiser = anonymiser ?? throw new ArgumentNullException(nameof(anonymiser)); this._configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); this._stringScrambler = stringScrambler ?? throw new ArgumentNullException(nameof(stringScrambler)); this._writer = writer; }
internal static async Task <int> Main(string[] args) { try { await Parser.Default.ParseArguments <Options>(args) .WithParsedAsync(async o => { var output = o.IsVerbose ? Console.Out : null; var config = await Configuration.Load(o.Configuration, output) .ConfigureAwait(false); using (var anonymiser = new Anonymiser(config.CryptoPAnKey)) using (var scrambler = new StringScrambler(config.StringCryptoKey)) { var processor = new JsonProcessor(config, anonymiser, scrambler, output); if (o.IsStandardInput) { string l; var sb = new StringBuilder(); while (((l = Console.ReadLine()) != null) && (l != string.Empty)) { sb.Append(l); } Console.WriteLine(processor.ProcessRecord(sb.ToString())); } else { await processor.ProcessAsync().ConfigureAwait(false); } } }); return(0); } catch (Exception ex) { #if DEBUG if (Debugger.IsAttached) { Debugger.Break(); } #endif // DEBUG Console.Error.WriteLine(ex.Message); return(-1); } }