private static string GetRecognitionKeyBasedOnRequestedValue(UserDateTimeValueOptions requestedValue) { var requestedValueKey = string.Empty; switch (requestedValue) { case UserDateTimeValueOptions.Date: requestedValueKey = "datetimeV2.date"; break; case UserDateTimeValueOptions.Time: requestedValueKey = "datetimeV2.time"; break; default: requestedValueKey = "datetimeV2.date"; break; } return(requestedValueKey); }
private static bool GetDateOrTimeFromUserInput(string userInput, UserDateTimeValueOptions requestedValue, out DateTime userRequestedDateOrTime) { userRequestedDateOrTime = default(DateTime); var managedToRecognize = false; string requestedValueKey = GetRecognitionKeyBasedOnRequestedValue(requestedValue); var culture = Culture.English; var dateTimeRecognitionResult = DateTimeRecognizer.RecognizeDateTime(userInput, culture); if (dateTimeRecognitionResult.Any(entity => entity.TypeName == requestedValueKey)) { var recognizedDateResolution = dateTimeRecognitionResult .First(entity => entity.TypeName == requestedValueKey) .Resolution["values"] as List <Dictionary <string, string> >; DateTime dateTimeDump = default(DateTime); if (recognizedDateResolution.Any(foundDate => DateTime.TryParse(foundDate["value"], out dateTimeDump))) { managedToRecognize = true; userRequestedDateOrTime = dateTimeDump; } } return(managedToRecognize); }