IField.cs
1 //
2 // Copyright (c) Microsoft. All rights reserved.
3 // Licensed under the MIT license.
4 //
5 // Microsoft Bot Framework: http://botframework.com
6 //
7 // Bot Builder SDK GitHub:
8 // https://github.com/Microsoft/BotBuilder
9 //
10 // Copyright (c) Microsoft Corporation
11 // All rights reserved.
12 //
13 // MIT License:
14 // Permission is hereby granted, free of charge, to any person obtaining
15 // a copy of this software and associated documentation files (the
16 // "Software"), to deal in the Software without restriction, including
17 // without limitation the rights to use, copy, modify, merge, publish,
18 // distribute, sublicense, and/or sell copies of the Software, and to
19 // permit persons to whom the Software is furnished to do so, subject to
20 // the following conditions:
21 //
22 // The above copyright notice and this permission notice shall be
23 // included in all copies or substantial portions of the Software.
24 //
25 // THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND,
26 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 //
33 
35 using System;
36 using System.Collections.Generic;
37 using System.Linq;
38 using System.Threading.Tasks;
39 
40 namespace Microsoft.Bot.Builder.FormFlow.Advanced
41 {
46  public interface IFieldState<T>
47  {
53  object GetValue(T state);
54 
60  void SetValue(T state, object value);
61 
72  bool IsUnknown(T state);
73 
83  void SetUnknown(T state);
84 
87  Type Type { get; }
88 
93  bool Optional { get; }
94 
99  bool IsNullable { get; }
100 
109  bool Limits(out double min, out double max);
110 
116  string Pattern { get; }
117 
123  IEnumerable<string> Dependencies { get; }
124  }
125 
129  public enum FieldRole
130  {
135  Value,
136 
143  Confirm
144  };
145 
157  public interface IFieldDescription
158  {
163  FieldRole Role { get; }
164 
172  DescribeAttribute FieldDescription { get; }
173 
178  IEnumerable<string> FieldTerms { get; }
179 
185  DescribeAttribute ValueDescription(object value);
186 
191  IEnumerable<DescribeAttribute> ValueDescriptions { get; }
192 
198  IEnumerable<string> Terms(object value);
199 
204  IEnumerable<object> Values { get; }
205 
211  bool AllowsMultiple { get; }
212 
217  bool AllowDefault { get; }
218 
223  bool AllowNumbers { get; }
224  }
225 
226  #region Documentation
227  #endregion
229  public interface IFieldResources
230  {
232  void SaveResources();
233 
235  void Localize();
236  }
237 
248  public enum StepDirection
249  {
253  Complete,
254 
258  Named,
259 
263  Next,
264 
268  Previous,
269 
273  Quit,
274 
278  Reset
279  };
280 
284  [Serializable]
285  public class NextStep
286  {
290  public NextStep()
291  {
292  Direction = StepDirection.Next;
293  }
294 
299  public NextStep(StepDirection direction)
300  {
301  Direction = direction;
302  }
303 
308  public NextStep(IEnumerable<string> names)
309  {
310  Direction = StepDirection.Named;
311  Names = names.ToArray();
312  }
313 
318 
322  public string[] Names;
323  }
324 
329  public interface IFieldPrompt<T>
330  where T : class
331  {
340  bool Active(T state);
341 
347  TemplateAttribute Template(TemplateUsage usage);
348 
349  #region Documentation
350  #endregion
354  IPrompt<T> Prompt { get; }
355 
368  Task<bool> DefineAsync(T state);
369 
380  Task<ValidateResult> ValidateAsync(T state, object value);
381 
389  IPrompt<T> Help { get; }
390 
397  NextStep Next(object value, T state);
398  }
399 
405  where T : class
406  {
415  string Name { get; }
416 
420  IForm<T> Form { get; set; }
421  }
422 
427  public interface IFields<T> : IEnumerable<IField<T>>
428  where T : class
429  {
435  IField<T> Field(string name);
436  }
437 }
Core namespace for FormFlow and associated infrastructure.
Definition: Attributes.cs:39
FieldRole
The role the field plays in a form.
Definition: IField.cs:129
Define a template for generating strings.
Definition: Attributes.cs:571
NextStep()
By default move on to the next active, uncompleted step.
Definition: IField.cs:290
The form is complete and IFormBuilder<T>.OnCompletion(OnCompletionAsyncDelegate<T>) should be called...
StepDirection
Direction for next step.
Definition: IField.cs:248
Move to a named step. If there is more than one name, the user will be asked to choose.
Describe the information displayed about a field and its values.
Definition: IField.cs:157
TemplateUsage
All of the built-in templates.
Definition: Attributes.cs:321
What to display when asked for help.
NextStep(IEnumerable< string > names)
Ask the user which of the fields to move to next.
Definition: IField.cs:308
Interface to track all of the fields in a form.
Definition: IField.cs:427
string[] Names
If this is a named step, one or more named steps to move to. If there are more than one...
Definition: IField.cs:322
Interface that defines basic access to a field.
Definition: IField.cs:46
Interface for all the information about a specific field.
Definition: IField.cs:404
StepDirection Direction
Direction for next step.
Definition: IField.cs:317
Interface for a prompt and its associated recognizer.
Definition: IPrompt.cs:56
Form definition interface.
Definition: IForm.cs:47
Field is used to get a value to set in the form state.
This provides control information about a field.
Definition: IField.cs:329
Quit the form and return failure to the parent dialog.
Base class with declarative implementation of IField.
Definition: Field.cs:67
Move to the next step that is IFieldPrompt<T>.Active(T) and uncompleted.
Interface for saving/localizing generated resources.
Definition: IField.cs:229
Field is used to confirm some settings during the dialog.
Root namespace for the Microsoft Bot Builder SDK.
NextStep(StepDirection direction)
Move as specified in direction.
Definition: IField.cs:299
Attribute to override the default description of a field, property or enum value. ...
Definition: Attributes.cs:62