private static async Task <PromptResult> ReadAnswerFromStenoDeviceAsync(TermModel term) { string[] strokesAsSteno = term.Steno.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries); var strokes = new List <Stroke>(); var cancellationTokenSource = new CancellationTokenSource(); IDisposable strokesReceived = _stenoDevice.StrokeReceived.Subscribe( stroke => { strokes.Add(stroke); if (strokes.Count == strokesAsSteno.Length) { cancellationTokenSource.Cancel(); } }); _stenoDevice.StartReadingStrokes(); try { while (!cancellationTokenSource.IsCancellationRequested) { try { await Task.Delay(TimeSpan.FromSeconds(1), cancellationTokenSource.Token); } catch (TaskCanceledException) { } } } finally { strokesReceived.Dispose(); _stenoDevice.StopReadingStrokes(); } string steno = strokes.Count == 1 ? $"/{strokes[0].Steno}" : string.Join("/", strokes.Select(x => x.Steno)); Console.WriteLine(steno); return(PromptResult.Success(steno)); }
private static Task <PromptResult> ReadAnswerFromConsoleAsync(TermModel term) { string line = Console.ReadLine(); return(Task.FromResult(string.IsNullOrEmpty(line) ? PromptResult.Canceled() : PromptResult.Success(line))); }