2017-05-18 31 views
0

我在Bot框架應用程序中有以下代碼。 您可以在下面的代碼中看到我已經評論了ValidateStartDate委託,其背後的原因是如果我將委託包含在formflow中,那麼委託執行代碼直接跳轉到「context.Call(Booking,BookingComplete)」的BookingComplete委託後,即談話結束。但理想情況下,它應該執行表單構建器的其餘字段。 注意,這裏起始日期是String類型的,和我手動驗證日期part.Also,代碼執行過程中沒有發生明顯的例外FormBuilder代碼執行突然跳轉到FormCompletion委託

public static IForm<ConferenceBooking> BuildForm() 
{ 
    return new FormBuilder<ConferenceBooking>().Message("Tell me meeting details!") 
    .Field(nameof(title)) 
    .Field(nameof(StartDate))//, validate: ValidateStartDate 
    .Field(nameof(EntryTime), validate:ValidateCallTime) 
    .Build(); 
} 

下面是委託一部分起始日期

private static Task<ValidateResult> ValidateStartDate(ConferenceBooking state, object response) 
{ 
var result = new ValidateResult(); 
DateTime startDt = Convert.ToDateTime(GetDate(Convert.ToString(response))); 
if (startDt == null || startDt == DateTime.MinValue) 
{ 
    result.IsValid = false; 
    result.Feedback = "I could not understand this format."; 
} 
else if (startDt.Date < DateTime.Now.Date) 
{ 
    result.IsValid = false; 
    result.Feedback = "Sorry, back dated bookings are not allowed"; 
} 
else 
{ 
    result.IsValid = true; 
    result.Value = startDt; 
} 
    return Task.FromResult(result); 
} 
+0

什麼是您的ValidateCallTime方法,也請發佈ConferenceBooking和GetDate的代碼。 –

回答

0

我也有之前注意到這種行爲,這總是由於例外。 FormBuilder似乎捕獲所有異常並退出catch塊中的表單。這就是爲什麼你沒有看到任何異常彈出。嘗試一步一步地執行代碼或從表單外部執行代碼。

+0

好的,謝謝.. –