static async Task <int> RunListenAndReturnExitCode(ListenOptions opts) { CancellationTokenSource tokenSource = new CancellationTokenSource(); var locoClient = new LocoClient(); locoClient.Log += (sender, args) => { Console.WriteLine(args.Log); }; await locoClient.ConnectAsync(tokenSource.Token); locoClient.ListenAsync(opts.RoadNumber, opts.Attribute, tokenSource.Token); // Wait until a key is pressed and then exit. await Task.Factory.StartNew(() => { Console.ReadKey(); tokenSource.Cancel(); }); await Task.Delay(100); return(0); }
static async Task <int> RunScanAndReturnExitCode(ScanOptions opts) { CancellationTokenSource tokenSource = new CancellationTokenSource(); var locoClient = new LocoClient(); locoClient.Log += (sender, args) => { Console.WriteLine(args.Log); }; await locoClient.ConnectAsync(tokenSource.Token); locoClient.ScanResultFound += (sender, args) => { Console.WriteLine($"Locomotive found: {args.RoadNumber}"); }; locoClient.ScanAsync(tokenSource.Token); // Wait until a key is pressed and then exit. await Task.Factory.StartNew(() => { Console.ReadKey(); tokenSource.Cancel(); }); await Task.Delay(100); return(0); }
static async Task <int> RunResetAndReturnExitCode(ResetOptions opts) { CancellationTokenSource tokenSource = new CancellationTokenSource(); var locoClient = new LocoClient(); locoClient.Log += (sender, args) => { Console.WriteLine(args.Log); }; await locoClient.ConnectAsync(tokenSource.Token); await locoClient.SendResetAsync(opts.RoadNumber, tokenSource.Token); return(0); }