// The notion of a Validator is a standard pattern across all the Prompts private static Task TimexValidator(ITurnContext context, TimexResult value) { var cadidates = value.Resolutions; var constraints = new[] { TimexCreator.ThisWeek(), /* Take any entries for this week, no entries from past please */ TimexCreator.NextWeek(), /* Take any entries for next week, no dates from the past please */ TimexCreator.Evening, /* Evenings only */ }; var resolutions = TimexRangeResolver.Evaluate(cadidates, constraints); if (resolutions.Count == 0) { value.Resolutions = new string[] { }; value.Status = Microsoft.Bot.Builder.Prompts.PromptStatus.OutOfRange; } else { value.Resolutions = new[] { resolutions.First().TimexValue }; value.Status = Microsoft.Bot.Builder.Prompts.PromptStatus.Recognized; } return(Task.CompletedTask); }
/// <summary> /// Compares a set of candidate date time strings against our validation constraints, and /// returns a value that matches; or null, if no candidates meet the constraints. /// </summary> /// <param name="candidates">The candidate strings.</param> /// <returns>A value that matches; or null, if no candidates meet the constraints.</returns> /// <remarks>Valid dates are evenings within the next 2 weeks.</remarks> private static DateTimeResult.DateTimeResolution ResolveDate(IEnumerable <string> candidates) { // Find any matches within dates from this week or next (not in the past), and evenings only. var constraints = new[] { TimexCreator.NextWeeksFromToday(2), TimexCreator.Evening }; List <TimexProperty> resolutions = null; try { resolutions = TimexRangeResolver.Evaluate(candidates, constraints); } catch { return(null); } if (resolutions.Count is 0) { return(null); } // Use the first recognized value for the reservation time. var timex = resolutions[0]; return(new DateTimeResult.DateTimeResolution { Start = timex.ToNaturalLanguage(DateTime.Now), End = timex.ToNaturalLanguage(DateTime.Now), Value = timex.ToNaturalLanguage(DateTime.Now), Timex = timex.TimexValue }); }
private List <TimexProperty> evaluateTimeX(string[] candidates) { var constraints = new[] { TimexCreator.ThisWeek(), /* Take any entries for this week, no entries from past please */ TimexCreator.NextWeek(), /* Take any entries for next week, no dates from the past please */ TimexCreator.Evening, /* Evenings only */ }; return(TimexRangeResolver.Evaluate(candidates, constraints)); }
public void DataTypes_Creator_nextWeek() { var start = TimexDateHelpers.DateOfNextDay(DayOfWeek.Monday, System.DateTime.Now); var t = TimexProperty.FromDate(start); t.Days = 7; var expected = t.TimexValue; Assert.AreEqual(expected, TimexCreator.NextWeek()); }
public void DataTypes_Creator_Today() { var d = System.DateTime.Now; var expected = TimexFormat.Format(new TimexProperty { Year = d.Year, Month = d.Month, DayOfMonth = d.Day }); Assert.AreEqual(expected, TimexCreator.Today()); }
public void DataTypes_Creator_WeekBackFromToday() { var d = System.DateTime.Now; d = d.AddDays(-7); var expected = TimexFormat.Format(new TimexProperty { Year = d.Year, Month = d.Month, DayOfMonth = d.Day, Days = 7 }); Assert.AreEqual(expected, TimexCreator.WeekBackFromToday()); }
public static void Examples() { // When you give the recognzier the text "Wednesday 4 o'clock" you get these distinct TIMEX values back. // But our bot logic knows that whatever the user says it should be evaluated against the constraints of // a week from today with respect to the date part and in the evening with respect to the time part. var resolutions = TimexRangeResolver.Evaluate( new[] { "XXXX-WXX-3T04", "XXXX-WXX-3T16" }, new[] { TimexCreator.WeekFromToday(), TimexCreator.Evening }); var today = DateTime.Now; foreach (var resolution in resolutions) { Console.WriteLine(resolution.ToNaturalLanguage(today)); } }
// The notion of a Validator is a standard pattern across all the Prompts private static Task TimexValidator(ITurnContext context, TimexResult value) { var cadidates = value.Resolutions; var constraints = new[] { TimexCreator.ThisWeek(), TimexCreator.NextWeek(), TimexCreator.Evening }; var resolutions = TimexRangeResolver.Evaluate(cadidates, constraints); if (resolutions.Count == 0) { value.Resolutions = new string[] {}; value.Status = PromptStatus.OutOfRange; } else { value.Resolutions = new[] { resolutions.First().TimexValue }; value.Status = PromptStatus.Recognized; } return(Task.CompletedTask); }
public void DataTypes_Creator_WeekFromToday_Relative() { Assert.AreEqual("(2017-10-05,2017-10-12,P7D)", TimexCreator.WeekFromToday(new System.DateTime(2017, 10, 5))); }
public void DataTypes_Creator_Yesterday_Relative() { Assert.AreEqual("2017-10-04", TimexCreator.Yesterday(new System.DateTime(2017, 10, 5))); }
public void DataTypes_Creator_Tomorrow_Relative() { Assert.AreEqual("2017-10-06", TimexCreator.Tomorrow(new System.DateTime(2017, 10, 5))); }
public void DataTypes_Creator_NextWeeksFromToday_Relative() { Assert.AreEqual("(2017-10-05,2017-10-19,P14D)", TimexCreator.NextWeeksFromToday(2, new System.DateTime(2017, 10, 5))); }
public void DataTypes_Creator_LastWeek_Relative() { Assert.AreEqual("(2017-09-25,2017-10-02,P7D)", TimexCreator.LastWeek(new System.DateTime(2017, 10, 5))); }
public void DataTypes_Creator_NextWeek_Relative() { Assert.AreEqual("(2017-10-09,2017-10-16,P7D)", TimexCreator.NextWeek(new System.DateTime(2017, 10, 5))); }