示例#1
0
 public async Task<string> AskAsync(Question question)
 {
     var b = new WriteOnceBlock<string>(s => s);
     question.answerBlock = b;
     // TODO: handle if buffer refuses message? If task.Result is false
     var task = await buf.SendAsync(question);
     return await b.ReceiveAsync();
 }
示例#2
0
 public async Task<string> AskAsync(Question question) => await Task.Run(() =>
 {
     output.WriteLine(question.Preamble);
     var match = false;
     string response = null;
     while (!match)
     {
         output.WriteLine(question.Query);
         response = input.ReadLine()?.Trim();
         match = question.Answers.Any(a => a.EqualsOrdIgnoreCase(response));
         if (!match)
         {
             var answers = string.Join(", ", question.Answers);
             output.WriteLine($"\nAnswer must be one of these values: {answers}");
         }
     }
     return response;
 });
示例#3
0
 public Task<string> AskAsync(Question question)
 {
     return Task.FromResult(Answer);
 }
示例#4
0
 public Task<string> AskAsync(Question question)
 {
     return null;
 }