Esempio n. 1
0
        public IForm <CogBankBotForm> BuildForm()
        {
            ActiveDelegate <CogBankBotForm> shouldShowContest =
                cogBankBotForm => DateTime.Now.DayOfWeek == DayOfWeek.Friday;

            var prompt = new PromptAttribute
            {
                Patterns =
                    new[]
                {
                    "Hi, May I ask a few questions?",
                    "How are you today? Can I ask a few questions?",
                    "Thanks for visiting - would you answer a few questions?"
                }
            };

            return(new FormBuilder <CogBankBotForm>()
                   .Confirm(prompt)
                   .Confirm(
                       "You can type \"help\" at any time for more info. Would you like to proceed?")
                   .Confirm(
                       "Would you like to enter a contest?",
                       shouldShowContest)
                   .OnCompletion(DoSearch)
                   .Build());
        }
Esempio n. 2
0
        public static IForm <BugReport> BuildForm()
        {
            return(new FormBuilder <BugReport>()
                   .Message("Welcome to Bug Report bot!")
                   .Field(new FieldReflector <BugReport>(nameof(Product))
                          .SetType(null)
                          .SetDefine((state, field) =>
            {
                foreach (var prod in GetProducts())
                {
                    field
                    .AddDescription(prod, prod)
                    .AddTerms(prod, prod);
                }

                return Task.FromResult(true);
            }))
                   .Field(nameof(Version),
                          validate: async(state, response) =>
            {
                var result = new ValidateResult {
                    IsValid = true, Value = response
                };

                foreach (var segment in (response as string ?? "").Split('.'))
                {
                    int digit;
                    if (!int.TryParse(segment, out digit))
                    {
                        result.Feedback =
                            "Version number must be numeric segments, optionally separated by dots. e.g. 7.2, 10, or 3.56";
                        result.IsValid = false;

                        if (++versionAttempts > 2)
                        {
                            throw new TooManyAttemptsException("Too many attempts at the version number.");
                        }

                        break;
                    }
                }

                return await Task.FromResult(result);
            })
                   .Field(nameof(Platform))
                   .AddRemainingFields()
                   .Confirm(async(bugReport) =>
            {
                var response = new PromptAttribute(
                    $"You entered {bugReport.Product}, {bugReport.Version}, {string.Join(", ", bugReport.Platform)}" +
                    $"{bugReport.ProblemDescription}, {bugReport.Priority}. Is this Correct?");
                return await Task.FromResult(response);
            })
                   .OnCompletion(async(context, bugReport) =>
            {
                await context.PostAsync("Thanks for the report!");
            })
                   .Build());
        }
Esempio n. 3
0
 public MessageStep(PromptAttribute prompt, ActiveDelegate <T> condition, IEnumerable <string> dependencies, IForm <T> form)
 {
     _name             = "message" + form.Steps.Count.ToString();
     _form             = form;
     _promptDefinition = prompt;
     _condition        = (condition == null ? (state) => true : condition);
     _dependencies     = dependencies ?? form.Dependencies(form.Steps.Count);
 }
Esempio n. 4
0
        private static PromptAttribute GenerateAvLoc()
        {
            GetMeetingRooms();

            var meetingR = string.Join(", ", meetingRooms.Select(x => x.Name));
            var ret      = new PromptAttribute("Elérhető tárgyalók: " + meetingR);

            return(ret);
        }
Esempio n. 5
0
        /// <summary>
        /// Construct a confirmation.
        /// </summary>
        /// <param name="prompt">Confirmation prompt expressed using \ref patterns.</param>
        /// <param name="condition">Delegate for whether confirmation applies.</param>
        /// <param name="dependencies">Fields that must have values before confirmation can run.</param>
        public Confirmation(PromptAttribute prompt, ConditionalDelegate <T> condition, IEnumerable <string> dependencies)
            : base(Guid.NewGuid().ToString(), FieldRole.Confirm)
        {
            SetPrompt(prompt);
            _condition    = condition;
            _dependencies = dependencies.ToArray();
            var noStep = (dependencies.Count() > 0 ? new NextStep(dependencies) : new NextStep());

            _next = (value, state) => value ? new NextStep() : noStep;
        }
Esempio n. 6
0
        /// <summary>
        /// Construct a confirmation.
        /// </summary>
        /// <param name="prompt">Confirmation prompt expressed using \ref patterns.</param>
        /// <param name="condition">Delegate for whether confirmation applies.</param>
        /// <param name="dependencies">Fields that must have values before confirmation can run.</param>
        /// <param name="form">Form that contains confirmation.</param>
        public Confirmation(PromptAttribute prompt, ActiveDelegate <T> condition, IEnumerable <string> dependencies, IForm <T> form)
            : base("confirmation" + form.Steps.Count, FieldRole.Confirm)
        {
            SetPrompt(prompt);
            SetType(typeof(bool));
            SetDependencies(dependencies.ToArray());
            SetActive(condition);
            var noStep = (dependencies.Any() ? new NextStep(dependencies) : new NextStep());

            _next = (value, state) => value ? new NextStep() : noStep;
        }
 protected void DefinePrompt()
 {
     if (_promptDefinition == null)
     {
         TemplateUsage usage = TemplateUsage.None;
         if (_type == null || _type.IsEnum)
         {
             usage = _allowsMultiple ? TemplateUsage.EnumSelectMany : TemplateUsage.EnumSelectOne;
         }
         else if (_type == typeof(string))
         {
             usage = TemplateUsage.String;
         }
         else if (_type.IsIntegral())
         {
             usage = TemplateUsage.Integer;
         }
         else if (_type == typeof(bool))
         {
             usage = TemplateUsage.Bool;
         }
         else if (_type.IsDouble())
         {
             usage = TemplateUsage.Double;
         }
         else if (_type == typeof(DateTime))
         {
             usage = TemplateUsage.DateTime;
         }
         else if (_type.IsAttachmentType())
         {
             usage = TemplateUsage.AttachmentField;
         }
         else if (_type.IsAttachmentCollection())
         {
             usage = TemplateUsage.AttachmentCollection;
         }
         else
         {
             throw new ArgumentException($"{_name} is not a type FormFlow understands.");
         }
         if (usage != TemplateUsage.None)
         {
             _promptDefinition = new PromptAttribute(Template(usage));
         }
         _promptSet = false;
     }
     _promptDefinition.ApplyDefaults(_form.Configuration.DefaultPrompt);
 }
        public override IFormBuilder <JObject> Field(string name, PromptAttribute prompt, ActiveDelegate <JObject> active = null, ValidateAsyncDelegate <JObject> validate = null)
        {
            var field = new FieldJson(this, name);

            field.SetPrompt(prompt);
            if (active != null)
            {
                field.SetActive(active);
            }
            if (validate != null)
            {
                field.SetValidate(validate);
            }
            return(Field(field));
        }
        public IForm <WineForm> BuildForm()
        {
            ActiveDelegate <WineForm> shouldShowContest =
                wineForm => DateTime.Now.DayOfWeek == DayOfWeek.Friday;

            var prompt = new PromptAttribute
            {
                Patterns =
                    new[]
                {
                    "Hi, May I ask a few questions?",
                    "How are you today? Can I ask a few questions?",
                    "Thanks for visiting - would you answer a few questions?"
                }
            };

            int numberOfBackOrderDays = 15;

            MessageDelegate <WineForm> generateMessage =
                async wineForm =>
                await Task.FromResult(
                    new PromptAttribute(
                        $"Delivery back order is {numberOfBackOrderDays} days. Are you sure?"));

            return(new FormBuilder <WineForm>()
                   .Confirm(prompt)
                   .Confirm(
                       "You can type \"help\" at any time for more info. Would you like to proceed?")
                   .Confirm(
                       "Would you like to enter a contest for free bottle of Wine?",
                       shouldShowContest)
                   .Confirm(
                       $"Low rated wines are limited in stock - are you sure?",
                       wineForm => wineForm.Rating == RatingType.Low,
                       new[] { nameof(Rating) })
                   .Confirm(
                       generateMessage,
                       wineForm => wineForm.InStock == StockingType.OutOfStock)
                   .OnCompletion(DoSearch)
                   .Build());
        }
Esempio n. 10
0
        public IForm <WineForm> BuildForm()
        {
            ActiveDelegate <WineForm> shouldShowSpecial =
                wineForm => DateTime.Now.DayOfWeek == DayOfWeek.Friday;

            var prompt = new PromptAttribute
            {
                Patterns =
                    new[]
                {
                    "Hi, I have a few questions to ask.",
                    "How are you today? I just have a few questions.",
                    "Thanks for visiting - please answer a few questions."
                }
            };

            int numberOfBackOrderDays = 15;

            MessageDelegate <WineForm> generateMessage =
                async wineForm =>
                await Task.FromResult(
                    new PromptAttribute(
                        $"Note: Delivery back order is {numberOfBackOrderDays} days."));

            return(new FormBuilder <WineForm>()
                   .Message(prompt)
                   .Message(
                       "You can type \"help\" at any time for more info.")
                   .Message(
                       "It's your lucky day - 10% discounts on Friday!",
                       shouldShowSpecial)
                   .Message(
                       $"Today you get an additional %5 off.",
                       wineForm => wineForm.Rating == RatingType.Low,
                       new[] { nameof(Rating) })
                   .Message(
                       generateMessage,
                       wineForm => wineForm.InStock == StockingType.OutOfStock)
                   .OnCompletion(DoSearch)
                   .Build());
        }
Esempio n. 11
0
        public static IForm <SubscriptionFormState> BuildSubscriptionForm()
        {
            var prompt = new PromptAttribute()
            {
                ChoiceStyle = ChoiceStyleOptions.PerLine
            };

            return(CreateCustomForm <SubscriptionFormState>()
                   .Field(new FieldReflector <SubscriptionFormState>(nameof(SubscriptionFormState.SubscriptionId))
                          .SetType(null)
                          .SetActive(x => x.AvailableSubscriptions.Any())
                          .SetPrompt(PerLinePromptAttribute("Please select the subscription you want to work with: {||}"))
                          .SetDefine((state, field) =>
            {
                foreach (var sub in state.AvailableSubscriptions)
                {
                    field.AddDescription(sub.SubscriptionId, sub.DisplayName)
                    .AddTerms(sub.SubscriptionId, sub.DisplayName);
                }

                return Task.FromResult(true);
            }))
                   .Build());
        }
Esempio n. 12
0
 /// <summary>   Sets the field prompt. </summary>
 /// <param name="prompt">   The prompt. </param>
 /// <returns>   A <see cref="Field{T}"/>. </returns>
 public Field <T> SetPrompt(PromptAttribute prompt)
 {
     _promptDefinition = prompt;
     _promptSet        = true;
     return(this);
 }
Esempio n. 13
0
 public MessageStep(PromptAttribute prompt, ConditionalDelegate <T> condition, IForm <T> form)
 {
     _name      = "message" + form.Steps.Count.ToString();
     _prompt    = new Prompter <T>(prompt, form, null);
     _condition = (condition == null ? (state) => true : condition);
 }
Esempio n. 14
0
 /// <summary>   Sets the field prompt. </summary>
 /// <param name="prompt">   The prompt. </param>
 /// <returns>   A Field&lt;T&gt; </returns>
 public Field <T> SetPrompt(PromptAttribute prompt)
 {
     UpdateAnnotations();
     _promptDefinition = prompt;
     return(this);
 }
Esempio n. 15
0
        private static PromptCommand GetPromptInformation(Prompt prompt, Type classType, MethodInfo methodInfo, PromptAttribute attribute)
        {
            var command = new PromptCommand
            {
                HelpText    = attribute.Help,
                CommandText = attribute.Command,
                MethodInfo  = methodInfo,
                ClassType   = classType,
                // If there are Any Parameters then set the Starts with flag -- TODO Should be able to remove this
                StartWith = methodInfo.GetParameters().Length > 0,
                Hide      = attribute.Hide
            };

            // Check if the class of this Method has PromptClass Attribute and add that information to the command
            if (classType.GetCustomAttributes(typeof(PromptClassAttribute), true).FirstOrDefault() is
                PromptClassAttribute promptClassAttribute)
            {
                command.KeepClassInstance = promptClassAttribute.Keep;
                command.Folder            = promptClassAttribute.Folder;
            }

            return(command);
        }