コード例 #1
0
        private IPrompt <T> NextClarifyPrompt(T state, FieldStepState stepState, IRecognize <T> recognizer, out Ambiguous clarify)
        {
            IPrompt <T> prompter = null;

            clarify = null;
            foreach (var clarification in stepState.Clarifications)
            {
                if (clarification.Values.Length > 1)
                {
                    clarify = clarification;
                    break;
                }
            }
            if (clarify != null)
            {
                var field = new Field <T>("__clarify__", FieldRole.Value);
                field.Form = _field.Form;
                var template     = _field.Template(TemplateUsage.Clarify);
                var helpTemplate = _field.Template(template.AllowNumbers ? TemplateUsage.EnumOneNumberHelp : TemplateUsage.EnumManyNumberHelp);
                field.SetPrompt(new PromptAttribute(template));
                field.ReplaceTemplate(_field.Template(TemplateUsage.Clarify));
                field.ReplaceTemplate(helpTemplate);
                foreach (var value in clarify.Values)
                {
                    field.AddDescription(value, recognizer.ValueDescription(value));
                    field.AddTerms(value, recognizer.ValidInputs(value).ToArray());
                }
                var choiceRecognizer = new RecognizeEnumeration <T>(field);
                prompter = new Prompter <T>(template, _field.Form, choiceRecognizer);
            }
            return(prompter);
        }
コード例 #2
0
ファイル: Field.cs プロジェクト: ObsidianAdvisoryLLP/Bot
        protected void DefineRecognizer()
        {
            if (_recognizer == null)
            {
                if (_type == null || _type.IsEnum)
                {
                    _recognizer = new RecognizeEnumeration <T>(this);
                }
                else if (_type == typeof(bool))
                {
                    _recognizer = new RecognizeBool <T>(this);
                }
                else if (_type == typeof(string))
                {
                    _recognizer = new RecognizeString <T>(this);
                }
                else if (_type.IsIntegral())
                {
                    _recognizer = new RecognizeNumber <T>(this);
                }
                else if (_type.IsDouble())
                {
                    _recognizer = new RecognizeDouble <T>(this);
                }
                else if (_type == typeof(DateTime))
                {
                    _recognizer = new RecognizeDateTime <T>(this);
                }
                else if (_type.IsAttachmentType() || _type.IsAttachmentCollection())
                {
                    _recognizer = new RecognizeAttachment <T>(this, _type.IsAttachmentCollection());
                }
                else if (_type.IsIEnumerable())
                {
                    var elt = _type.GetGenericElementType();
                    if (elt.IsEnum)
                    {
                        _recognizer = new RecognizeEnumeration <T>(this);
                    }
                }
                _buildPrompts = true;
            }

            if (_buildPrompts)
            {
                var template = Template(TemplateUsage.Help);
                _help = new Prompter <T>(template, _form, _recognizer);
                var prompt = _promptDefinition;
                _prompt       = new Prompter <T>(_promptDefinition, _form, _recognizer);
                _buildPrompts = false;
            }
        }
コード例 #3
0
 protected void DefineRecognizer()
 {
     if (_recognizer == null)
     {
         if (_type == null || _type.IsEnum)
         {
             _recognizer = new RecognizeEnumeration <T>(this);
         }
         else if (_type == typeof(bool))
         {
             _recognizer = new RecognizeBool <T>(this);
         }
         else if (_type == typeof(string))
         {
             _recognizer = new RecognizeString <T>(this);
         }
         else if (_type.IsIntegral())
         {
             _recognizer = new RecognizeNumber <T>(this, Thread.CurrentThread.CurrentUICulture);
         }
         else if (_type.IsDouble())
         {
             _recognizer = new RecognizeDouble <T>(this, Thread.CurrentThread.CurrentUICulture);
         }
         else if (_type == typeof(DateTime))
         {
             _recognizer = new RecognizeDateTime <T>(this, Thread.CurrentThread.CurrentUICulture);
         }
         else if (_type.IsIEnumerable())
         {
             var elt = _type.GetGenericElementType();
             if (elt.IsEnum)
             {
                 _recognizer = new RecognizeEnumeration <T>(this);
             }
         }
         var template = Template(TemplateUsage.Help);
         _help = new Prompter <T>(template, _form, _recognizer);
         var prompt = _promptDefinition;
         _prompt = new Prompter <T>(_promptDefinition, _form, _recognizer);
     }
 }
コード例 #4
0
        public NavigationStep(string name, IForm <T> form, T state, FormState formState)
        {
            _name   = name;
            _form   = form;
            _fields = form.Fields;
            var field    = _fields.Field(_name);
            var template = field.Template(TemplateUsage.Navigation);
            var recField = new Field <T>("__navigate__", FieldRole.Value)
                           .SetPrompt(new PromptAttribute(template));

            recField.Form = form;
            var fieldPrompt = field.Template(TemplateUsage.NavigationFormat);

            foreach (var value in formState.Next.Names)
            {
                var prompter = new Prompter <T>(fieldPrompt, form, _fields.Field(value as string).Prompt.Recognizer);
                recField
                .AddDescription(value, prompter.Prompt(state, value as string))
                .AddTerms(value, _fields.Field(value as string).FieldTerms.ToArray());
            }
            var recognizer = new RecognizeEnumeration <T>(recField);

            _prompt = new Prompter <T>(template, form, recognizer);
        }
コード例 #5
0
ファイル: Extensions.cs プロジェクト: wballard/BotBuilder
        internal static IRecognize <T> BuildCommandRecognizer <T>(this IForm <T> form) where T : class
        {
            var field = new Field <T>("__commands__", FieldRole.Value);

            field.Form = form;
            field.SetPrompt(new PromptAttribute(""));
            foreach (var entry in form.Configuration.Commands)
            {
                field.AddDescription(entry.Key, entry.Value.Description);
                field.AddTerms(entry.Key, entry.Value.Terms);
            }
            foreach (var nav in form.Fields)
            {
                var fterms = nav.FieldTerms;
                if (fterms != null)
                {
                    field.AddDescription(nav.Name, nav.FieldDescription);
                    field.AddTerms(nav.Name, fterms.ToArray());
                }
            }
            var commands = new RecognizeEnumeration <T>(field);

            return(commands);
        }