Exemplo n.º 1
0
        /// <summary>   Prompt for a long. </summary>
        /// <param name="context">  The context. </param>
        /// <param name="resume">   Resume handler. </param>
        /// <param name="prompt">   The prompt to show to the user. </param>
        /// <param name="retry">    What to show on retry. </param>
        /// <param name="attempts"> The number of times to retry. </param>
        public static void Number(IDialogContext context, ResumeAfter <long> resume, string prompt, string retry = null, int attempts = 3)
        {
            var child = new PromptInt64(prompt, retry, attempts);

            context.Call <long>(child, resume);
        }
        private void EnsureRequiredInformation(IDialogContext ctx)
        {
            if (RequiredInformation != null && RequiredInformation.Count > 0)
            {
                CurrentInfo = RequiredInformation.Dequeue();
                string prompt = null;
                Prompt <string, string> dialog     = null;
                PromptInt64             sizeDialog = null;
                switch (CurrentInfo)
                {
                case "startDate":
                    prompt = BotMessages.Hint_ProvideStartDate;

                    dialog = new TimeRelatedPromptDialog <DateTimeOffset>(new PromptOptions <string>(
                                                                              prompt: prompt,
                                                                              retry: BotMessages.Question_RepeatQuestion,
                                                                              tooManyAttempts: BotMessages.Question_TooManyAttempts,
                                                                              attempts: 3,
                                                                              speak: prompt
                                                                              ),
                                                                          (dt) => StartDate = new DateTimeOffset(dt.DateTime, Offset.Value));
                    break;

                case "startTime":
                    prompt = BotMessages.Hint_ProvideStartTime;
                    dialog = new TimeRelatedPromptDialog <DateTimeOffset>(new PromptOptions <string>(
                                                                              prompt: prompt,
                                                                              retry: BotMessages.Question_RepeatQuestion,
                                                                              tooManyAttempts: BotMessages.Question_TooManyAttempts,
                                                                              attempts: 3,
                                                                              speak: prompt
                                                                              ),
                                                                          (dt) => StartTime = new DateTimeOffset(dt.DateTime, Offset.Value));
                    break;

                case "startDateTime":
                    prompt = BotMessages.Hint_ProvideStartDateTime;
                    dialog = new TimeRelatedPromptDialog <DateTimeOffset>(new PromptOptions <string>(
                                                                              prompt: prompt,
                                                                              retry: BotMessages.Question_RepeatQuestion,
                                                                              tooManyAttempts: BotMessages.Question_TooManyAttempts,
                                                                              attempts: 3,
                                                                              speak: prompt,
                                                                              recognizer: new PromptRecognizer()
                                                                              ),
                                                                          (dt) => StartTime = new DateTimeOffset(dt.DateTime, Offset.Value));
                    break;

                case "size":
                    prompt     = BotMessages.Hint_ProvideSize;
                    sizeDialog = new PromptInt64(
                        prompt: BotMessages.Hint_ProvideSize,
                        retry: BotMessages.Question_RepeatQuestion,
                        attempts: 3,
                        speak: prompt);
                    break;

                case "duration":
                    prompt = BotMessages.Hint_ProvideDuration;
                    dialog = new TimeRelatedPromptDialog <TimeSpan>(new PromptOptions <string>(
                                                                        prompt: prompt,
                                                                        retry: BotMessages.Question_RepeatQuestion,
                                                                        tooManyAttempts: BotMessages.Question_TooManyAttempts,
                                                                        attempts: 3,
                                                                        speak: prompt
                                                                        ),
                                                                    (dt) => { Duration = dt; });
                    break;
                }

                if (dialog != null)
                {
                    ctx.Call <object>(dialog, ResumeAfterPromptResponsed);
                }
                else if (sizeDialog != null)
                {
                    ctx.Call <long>(sizeDialog, ResumeAfterSizeResponsed);
                }
            }
            else
            {
                //Merge startData & startTime
                if (StartDate.HasValue && StartTime.HasValue)
                {
                    StartTime = new DateTimeOffset(StartDate.Value.Year, StartDate.Value.Month, StartDate.Value.Day,
                                                   StartTime.Value.Hour, StartTime.Value.Minute, StartTime.Value.Second,
                                                   StartTime.Value.Offset);
                }

                ctx.Done <object>(this);
            }
        }