├── .gitattributes
├── .gitignore
├── Documentation
└── Screenshots
│ ├── Scenario1.png
│ ├── Scenario2.png
│ └── Scenario3.png
├── DynamicFormFlowSample.sln
├── DynamicFormFlowSample
├── App_Start
│ └── WebApiConfig.cs
├── Controllers
│ └── MessagesController.cs
├── Data
│ └── SpaceshipData.cs
├── Dialogs
│ └── SpaceshipSelectionDialog.cs
├── DynamicFormFlowSample.csproj
├── Forms
│ └── SpaceshipSelectionForm.cs
├── Global.asax
├── Global.asax.cs
├── Models
│ └── Spaceship.cs
├── Properties
│ └── AssemblyInfo.cs
├── Web.Debug.config
├── Web.Release.config
├── Web.config
├── default.htm
└── packages.config
├── LICENSE
└── README.md
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | x64/
19 | x86/
20 | bld/
21 | [Bb]in/
22 | [Oo]bj/
23 | [Ll]og/
24 |
25 | # Visual Studio 2015 cache/options directory
26 | .vs/
27 | # Uncomment if you have tasks that create the project's static files in wwwroot
28 | #wwwroot/
29 |
30 | # MSTest test Results
31 | [Tt]est[Rr]esult*/
32 | [Bb]uild[Ll]og.*
33 |
34 | # NUNIT
35 | *.VisualState.xml
36 | TestResult.xml
37 |
38 | # Build Results of an ATL Project
39 | [Dd]ebugPS/
40 | [Rr]eleasePS/
41 | dlldata.c
42 |
43 | # DNX
44 | project.lock.json
45 | artifacts/
46 |
47 | *_i.c
48 | *_p.c
49 | *_i.h
50 | *.ilk
51 | *.meta
52 | *.obj
53 | *.pch
54 | *.pdb
55 | *.pgc
56 | *.pgd
57 | *.rsp
58 | *.sbr
59 | *.tlb
60 | *.tli
61 | *.tlh
62 | *.tmp
63 | *.tmp_proj
64 | *.log
65 | *.vspscc
66 | *.vssscc
67 | .builds
68 | *.pidb
69 | *.svclog
70 | *.scc
71 |
72 | # Chutzpah Test files
73 | _Chutzpah*
74 |
75 | # Visual C++ cache files
76 | ipch/
77 | *.aps
78 | *.ncb
79 | *.opendb
80 | *.opensdf
81 | *.sdf
82 | *.cachefile
83 | *.VC.db
84 | *.VC.VC.opendb
85 |
86 | # Visual Studio profiler
87 | *.psess
88 | *.vsp
89 | *.vspx
90 | *.sap
91 |
92 | # TFS 2012 Local Workspace
93 | $tf/
94 |
95 | # Guidance Automation Toolkit
96 | *.gpState
97 |
98 | # ReSharper is a .NET coding add-in
99 | _ReSharper*/
100 | *.[Rr]e[Ss]harper
101 | *.DotSettings.user
102 |
103 | # JustCode is a .NET coding add-in
104 | .JustCode
105 |
106 | # TeamCity is a build add-in
107 | _TeamCity*
108 |
109 | # DotCover is a Code Coverage Tool
110 | *.dotCover
111 |
112 | # NCrunch
113 | _NCrunch_*
114 | .*crunch*.local.xml
115 | nCrunchTemp_*
116 |
117 | # MightyMoose
118 | *.mm.*
119 | AutoTest.Net/
120 |
121 | # Web workbench (sass)
122 | .sass-cache/
123 |
124 | # Installshield output folder
125 | [Ee]xpress/
126 |
127 | # DocProject is a documentation generator add-in
128 | DocProject/buildhelp/
129 | DocProject/Help/*.HxT
130 | DocProject/Help/*.HxC
131 | DocProject/Help/*.hhc
132 | DocProject/Help/*.hhk
133 | DocProject/Help/*.hhp
134 | DocProject/Help/Html2
135 | DocProject/Help/html
136 |
137 | # Click-Once directory
138 | publish/
139 |
140 | # Publish Web Output
141 | *.[Pp]ublish.xml
142 | *.azurePubxml
143 | # TODO: Comment the next line if you want to checkin your web deploy settings
144 | # but database connection strings (with potential passwords) will be unencrypted
145 | *.pubxml
146 | *.publishproj
147 |
148 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
149 | # checkin your Azure Web App publish settings, but sensitive information contained
150 | # in these scripts will be unencrypted
151 | PublishScripts/
152 |
153 | # NuGet Packages
154 | *.nupkg
155 | # The packages folder can be ignored because of Package Restore
156 | **/packages/*
157 | # except build/, which is used as an MSBuild target.
158 | !**/packages/build/
159 | # Uncomment if necessary however generally it will be regenerated when needed
160 | #!**/packages/repositories.config
161 | # NuGet v3's project.json files produces more ignoreable files
162 | *.nuget.props
163 | *.nuget.targets
164 |
165 | # Microsoft Azure Build Output
166 | csx/
167 | *.build.csdef
168 |
169 | # Microsoft Azure Emulator
170 | ecf/
171 | rcf/
172 |
173 | # Windows Store app package directories and files
174 | AppPackages/
175 | BundleArtifacts/
176 | Package.StoreAssociation.xml
177 | _pkginfo.txt
178 |
179 | # Visual Studio cache files
180 | # files ending in .cache can be ignored
181 | *.[Cc]ache
182 | # but keep track of directories ending in .cache
183 | !*.[Cc]ache/
184 |
185 | # Others
186 | ClientBin/
187 | ~$*
188 | *~
189 | *.dbmdl
190 | *.dbproj.schemaview
191 | *.pfx
192 | *.publishsettings
193 | node_modules/
194 | orleans.codegen.cs
195 |
196 | # Since there are multiple workflows, uncomment next line to ignore bower_components
197 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
198 | #bower_components/
199 |
200 | # RIA/Silverlight projects
201 | Generated_Code/
202 |
203 | # Backup & report files from converting an old project file
204 | # to a newer Visual Studio version. Backup files are not needed,
205 | # because we have git ;-)
206 | _UpgradeReport_Files/
207 | Backup*/
208 | UpgradeLog*.XML
209 | UpgradeLog*.htm
210 |
211 | # SQL Server files
212 | *.mdf
213 | *.ldf
214 |
215 | # Business Intelligence projects
216 | *.rdl.data
217 | *.bim.layout
218 | *.bim_*.settings
219 |
220 | # Microsoft Fakes
221 | FakesAssemblies/
222 |
223 | # GhostDoc plugin setting file
224 | *.GhostDoc.xml
225 |
226 | # Node.js Tools for Visual Studio
227 | .ntvs_analysis.dat
228 |
229 | # Visual Studio 6 build log
230 | *.plg
231 |
232 | # Visual Studio 6 workspace options file
233 | *.opt
234 |
235 | # Visual Studio LightSwitch build output
236 | **/*.HTMLClient/GeneratedArtifacts
237 | **/*.DesktopClient/GeneratedArtifacts
238 | **/*.DesktopClient/ModelManifest.xml
239 | **/*.Server/GeneratedArtifacts
240 | **/*.Server/ModelManifest.xml
241 | _Pvt_Extensions
242 |
243 | # Paket dependency manager
244 | .paket/paket.exe
245 | paket-files/
246 |
247 | # FAKE - F# Make
248 | .fake/
249 |
250 | # JetBrains Rider
251 | .idea/
252 | *.sln.iml
253 |
254 | # Web config
255 | #*.config
256 |
--------------------------------------------------------------------------------
/Documentation/Screenshots/Scenario1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tompaana/dynamic-form-flow-sample/5eed449497fc0c14232635204090a7ab647476e4/Documentation/Screenshots/Scenario1.png
--------------------------------------------------------------------------------
/Documentation/Screenshots/Scenario2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tompaana/dynamic-form-flow-sample/5eed449497fc0c14232635204090a7ab647476e4/Documentation/Screenshots/Scenario2.png
--------------------------------------------------------------------------------
/Documentation/Screenshots/Scenario3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tompaana/dynamic-form-flow-sample/5eed449497fc0c14232635204090a7ab647476e4/Documentation/Screenshots/Scenario3.png
--------------------------------------------------------------------------------
/DynamicFormFlowSample.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.25420.1
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DynamicFormFlowSample", "DynamicFormFlowSample\DynamicFormFlowSample.csproj", "{A8BA1066-5695-4D71-ABB4-65E5A5E0C3D4}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Release|Any CPU = Release|Any CPU
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {A8BA1066-5695-4D71-ABB4-65E5A5E0C3D4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15 | {A8BA1066-5695-4D71-ABB4-65E5A5E0C3D4}.Debug|Any CPU.Build.0 = Debug|Any CPU
16 | {A8BA1066-5695-4D71-ABB4-65E5A5E0C3D4}.Release|Any CPU.ActiveCfg = Release|Any CPU
17 | {A8BA1066-5695-4D71-ABB4-65E5A5E0C3D4}.Release|Any CPU.Build.0 = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(SolutionProperties) = preSolution
20 | HideSolutionNode = FALSE
21 | EndGlobalSection
22 | EndGlobal
23 |
--------------------------------------------------------------------------------
/DynamicFormFlowSample/App_Start/WebApiConfig.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 | using Newtonsoft.Json.Serialization;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Web.Http;
7 |
8 | namespace DynamicFormFlowSample
9 | {
10 | public static class WebApiConfig
11 | {
12 | public static void Register(HttpConfiguration config)
13 | {
14 | // Json settings
15 | config.Formatters.JsonFormatter.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
16 | config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
17 | config.Formatters.JsonFormatter.SerializerSettings.Formatting = Formatting.Indented;
18 | JsonConvert.DefaultSettings = () => new JsonSerializerSettings()
19 | {
20 | ContractResolver = new CamelCasePropertyNamesContractResolver(),
21 | Formatting = Newtonsoft.Json.Formatting.Indented,
22 | NullValueHandling = NullValueHandling.Ignore,
23 | };
24 |
25 | // Web API configuration and services
26 |
27 | // Web API routes
28 | config.MapHttpAttributeRoutes();
29 |
30 | config.Routes.MapHttpRoute(
31 | name: "DefaultApi",
32 | routeTemplate: "api/{controller}/{id}",
33 | defaults: new { id = RouteParameter.Optional }
34 | );
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/DynamicFormFlowSample/Controllers/MessagesController.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Net;
3 | using System.Net.Http;
4 | using System.Threading.Tasks;
5 | using System.Web.Http;
6 | using Microsoft.Bot.Connector;
7 | using Microsoft.Bot.Builder.Dialogs;
8 | using DynamicFormFlowSample.Models;
9 | using DynamicFormFlowSample.Dialogs;
10 | using DynamicFormFlowSample.Forms;
11 |
12 | namespace DynamicFormFlowSample
13 | {
14 | [BotAuthentication]
15 | public class MessagesController : ApiController
16 | {
17 | internal static IDialog MakeRootDialog()
18 | {
19 | return Chain.From(() => new SpaceshipSelectionDialog(SpaceshipSelectionForm.BuildForm));
20 | }
21 |
22 | public async Task Post([FromBody]Activity activity)
23 | {
24 | if (activity.Type == ActivityTypes.Message)
25 | {
26 | try
27 | {
28 | await Conversation.SendAsync(activity, MakeRootDialog);
29 | }
30 | catch (Exception e)
31 | {
32 | System.Diagnostics.Debug.WriteLine(e.Message);
33 | }
34 | }
35 | else
36 | {
37 | HandleSystemMessage(activity);
38 | }
39 | var response = Request.CreateResponse(HttpStatusCode.OK);
40 | return response;
41 | }
42 |
43 | private Activity HandleSystemMessage(Activity message)
44 | {
45 | if (message.Type == ActivityTypes.DeleteUserData)
46 | {
47 | // Implement user deletion here
48 | // If we handle user deletion, return a real message
49 | }
50 | else if (message.Type == ActivityTypes.ConversationUpdate)
51 | {
52 | // Handle conversation state changes, like members being added and removed
53 | // Use Activity.MembersAdded and Activity.MembersRemoved and Activity.Action for info
54 | // Not available in all channels
55 | }
56 | else if (message.Type == ActivityTypes.ContactRelationUpdate)
57 | {
58 | // Handle add/remove from contact lists
59 | // Activity.From + Activity.Action represent what happened
60 | }
61 | else if (message.Type == ActivityTypes.Typing)
62 | {
63 | // Handle knowing tha the user is typing
64 | }
65 | else if (message.Type == ActivityTypes.Ping)
66 | {
67 | }
68 |
69 | return null;
70 | }
71 | }
72 | }
--------------------------------------------------------------------------------
/DynamicFormFlowSample/Data/SpaceshipData.cs:
--------------------------------------------------------------------------------
1 | using DynamicFormFlowSample.Models;
2 | using System.Collections.Generic;
3 |
4 | namespace DynamicFormFlowSample.Data
5 | {
6 | ///
7 | /// Represents the data in an imaginary database.
8 | ///
9 | /// Note that normally this data would be retrieved online, but for the sake of simplicity of
10 | /// this sample, the dummy data here is local.
11 | ///
12 | public class SpaceshipData
13 | {
14 | private static SpaceshipData _instance;
15 | public static SpaceshipData Instance
16 | {
17 | get
18 | {
19 | if (_instance == null)
20 | {
21 | _instance = new SpaceshipData();
22 | }
23 |
24 | return _instance;
25 | }
26 | }
27 |
28 | public IList Spaceships
29 | {
30 | get;
31 | private set;
32 | }
33 |
34 | ///
35 | /// NOTE: This data should be session and user specific!
36 | /// For the sake of simplicity this data is local here, but in real-life scenario this
37 | /// would cause issues: Multiple user accessing the data simultaneously will lead to
38 | /// unwanted results.
39 | ///
40 | public IList LastSearchResults
41 | {
42 | get;
43 | set;
44 | }
45 |
46 | private SpaceshipData()
47 | {
48 | Spaceships = new List();
49 | CreateDummyData();
50 | }
51 |
52 | ///
53 | /// Looks for (partially) matching spaceships from the data based on the given criteria.
54 | ///
55 | /// The filter for the search.
56 | /// A list of partial matches or an empty list if none found.
57 | public IList SearchForPartialMatches(Spaceship spaceshipFilter)
58 | {
59 | IList partialMatches = new List();
60 |
61 | if (spaceshipFilter != null)
62 | {
63 | foreach (Spaceship spaceship in Spaceships)
64 | {
65 | if (spaceship.IsPartialMatch(spaceshipFilter))
66 | {
67 | partialMatches.Add(spaceship);
68 | }
69 | }
70 | }
71 |
72 | return partialMatches;
73 | }
74 |
75 | private void CreateDummyData()
76 | {
77 | // Star Trek
78 | Spaceships.Add(new Spaceship()
79 | {
80 | Size = Spaceship.Sizes.Small,
81 | Engines = new List() { Spaceship.EngineTypes.Inpulse },
82 | Weapons = new List() { Spaceship.WeaponTypes.Phaser, Spaceship.WeaponTypes.PhotonTorpedos },
83 | Crew = Spaceship.CrewTypes.GoodGuys,
84 | Name = "Federation attack fighter",
85 | ImageUri = "https://upload.wikimedia.org/wikipedia/en/thumb/9/9f/Star_Trek_movie_logo_2009.jpg/310px-Star_Trek_movie_logo_2009.jpg"
86 | });
87 | Spaceships.Add(new Spaceship()
88 | {
89 | Size = Spaceship.Sizes.Small,
90 | Engines = new List() { Spaceship.EngineTypes.Inpulse, Spaceship.EngineTypes.Warp },
91 | Weapons = new List() { Spaceship.WeaponTypes.None },
92 | Crew = Spaceship.CrewTypes.GoodGuys,
93 | Name = "NX Alpha",
94 | ImageUri = "https://upload.wikimedia.org/wikipedia/en/thumb/9/9f/Star_Trek_movie_logo_2009.jpg/310px-Star_Trek_movie_logo_2009.jpg"
95 | });
96 | Spaceships.Add(new Spaceship()
97 | {
98 | Size = Spaceship.Sizes.Large,
99 | Engines = new List() { Spaceship.EngineTypes.Inpulse, Spaceship.EngineTypes.Warp },
100 | Weapons = new List() { Spaceship.WeaponTypes.Phaser, Spaceship.WeaponTypes.PhotonTorpedos },
101 | Crew = Spaceship.CrewTypes.GoodGuys,
102 | Name = "Enterprise (NX-01)",
103 | ImageUri = "https://upload.wikimedia.org/wikipedia/en/thumb/9/9f/Star_Trek_movie_logo_2009.jpg/310px-Star_Trek_movie_logo_2009.jpg"
104 | });
105 | Spaceships.Add(new Spaceship()
106 | {
107 | Size = Spaceship.Sizes.Large,
108 | Engines = new List() { Spaceship.EngineTypes.Inpulse, Spaceship.EngineTypes.Warp },
109 | Weapons = new List() { Spaceship.WeaponTypes.Phaser, Spaceship.WeaponTypes.PhotonTorpedos },
110 | Crew = Spaceship.CrewTypes.GoodGuys,
111 | Name = "USS Franklin (NX-326)",
112 | ImageUri = "https://upload.wikimedia.org/wikipedia/en/thumb/9/9f/Star_Trek_movie_logo_2009.jpg/310px-Star_Trek_movie_logo_2009.jpg"
113 | });
114 | Spaceships.Add(new Spaceship()
115 | {
116 | Size = Spaceship.Sizes.Large,
117 | Engines = new List() { Spaceship.EngineTypes.Inpulse, Spaceship.EngineTypes.Warp },
118 | Weapons = new List() { Spaceship.WeaponTypes.Disruptor, Spaceship.WeaponTypes.PhotonTorpedos },
119 | Crew = Spaceship.CrewTypes.BadGuys,
120 | Name = "IKS Toh'Kaht (Klingon attack cruiser)",
121 | ImageUri = "https://upload.wikimedia.org/wikipedia/en/thumb/9/9f/Star_Trek_movie_logo_2009.jpg/310px-Star_Trek_movie_logo_2009.jpg"
122 | });
123 | Spaceships.Add(new Spaceship()
124 | {
125 | Size = Spaceship.Sizes.Large,
126 | Engines = new List() { Spaceship.EngineTypes.Inpulse, Spaceship.EngineTypes.Warp },
127 | Weapons = new List() { Spaceship.WeaponTypes.Disruptor, Spaceship.WeaponTypes.PhotonTorpedos },
128 | Crew = Spaceship.CrewTypes.BadGuys,
129 | Name = "Scimitar (Reman warbird)",
130 | ImageUri = "https://upload.wikimedia.org/wikipedia/en/thumb/9/9f/Star_Trek_movie_logo_2009.jpg/310px-Star_Trek_movie_logo_2009.jpg"
131 | });
132 |
133 | // Star Wars
134 | Spaceships.Add(new Spaceship()
135 | {
136 | Size = Spaceship.Sizes.Small,
137 | Engines = new List() { Spaceship.EngineTypes.Sublight },
138 | Weapons = new List() { Spaceship.WeaponTypes.Laser, Spaceship.WeaponTypes.ProtonTorpedos },
139 | Crew = Spaceship.CrewTypes.GoodGuys,
140 | Name = "X-Wing",
141 | ImageUri = "https://upload.wikimedia.org/wikipedia/commons/thumb/6/6c/Star_Wars_Logo.svg/1280px-Star_Wars_Logo.svg.png"
142 | });
143 | Spaceships.Add(new Spaceship()
144 | {
145 | Size = Spaceship.Sizes.Mid,
146 | Engines = new List() { Spaceship.EngineTypes.Sublight, Spaceship.EngineTypes.Hyper },
147 | Weapons = new List() { Spaceship.WeaponTypes.Laser, Spaceship.WeaponTypes.Missiles },
148 | Crew = Spaceship.CrewTypes.GoodGuys,
149 | Name = "Millenium Falcon (YT-1300)",
150 | ImageUri = "https://upload.wikimedia.org/wikipedia/commons/thumb/6/6c/Star_Wars_Logo.svg/1280px-Star_Wars_Logo.svg.png"
151 | });
152 | Spaceships.Add(new Spaceship()
153 | {
154 | Size = Spaceship.Sizes.Large,
155 | Engines = new List() { Spaceship.EngineTypes.Sublight, Spaceship.EngineTypes.Hyper },
156 | Weapons = new List() { Spaceship.WeaponTypes.Laser, Spaceship.WeaponTypes.Ion },
157 | Crew = Spaceship.CrewTypes.GoodGuys,
158 | Name = "Home One (MC80)",
159 | ImageUri = "https://upload.wikimedia.org/wikipedia/commons/thumb/6/6c/Star_Wars_Logo.svg/1280px-Star_Wars_Logo.svg.png"
160 | });
161 | Spaceships.Add(new Spaceship()
162 | {
163 | Size = Spaceship.Sizes.Small,
164 | Engines = new List() { Spaceship.EngineTypes.Sublight },
165 | Weapons = new List() { Spaceship.WeaponTypes.Laser, Spaceship.WeaponTypes.ProtonTorpedos },
166 | Crew = Spaceship.CrewTypes.BadGuys,
167 | Name = "Tie Fighter",
168 | ImageUri = "https://upload.wikimedia.org/wikipedia/commons/thumb/6/6c/Star_Wars_Logo.svg/1280px-Star_Wars_Logo.svg.png"
169 | });
170 | Spaceships.Add(new Spaceship()
171 | {
172 | Size = Spaceship.Sizes.Small,
173 | Engines = new List() { Spaceship.EngineTypes.Sublight, Spaceship.EngineTypes.Hyper },
174 | Weapons = new List()
175 | {
176 | Spaceship.WeaponTypes.Laser,
177 | Spaceship.WeaponTypes.Ion,
178 | Spaceship.WeaponTypes.ProtonTorpedos,
179 | Spaceship.WeaponTypes.Missiles
180 | },
181 | Crew = Spaceship.CrewTypes.BadGuys,
182 | Name = "Slave I (Firespray-31-class)",
183 | ImageUri = "https://upload.wikimedia.org/wikipedia/commons/thumb/6/6c/Star_Wars_Logo.svg/1280px-Star_Wars_Logo.svg.png"
184 | });
185 | Spaceships.Add(new Spaceship()
186 | {
187 | Size = Spaceship.Sizes.Large,
188 | Engines = new List() { Spaceship.EngineTypes.Sublight, Spaceship.EngineTypes.Hyper },
189 | Weapons = new List()
190 | {
191 | Spaceship.WeaponTypes.Laser,
192 | Spaceship.WeaponTypes.Ion,
193 | Spaceship.WeaponTypes.Missiles
194 | },
195 | Crew = Spaceship.CrewTypes.BadGuys,
196 | Name = "Star Destroyer (Imperial-class)",
197 | ImageUri = "https://upload.wikimedia.org/wikipedia/commons/thumb/6/6c/Star_Wars_Logo.svg/1280px-Star_Wars_Logo.svg.png"
198 | });
199 |
200 | // Battlestar Galactica
201 | Spaceships.Add(new Spaceship()
202 | {
203 | Size = Spaceship.Sizes.Small,
204 | Engines = new List() { Spaceship.EngineTypes.TurboThrust },
205 | Weapons = new List() { Spaceship.WeaponTypes.KineticEnergy, Spaceship.WeaponTypes.Missiles },
206 | Crew = Spaceship.CrewTypes.GoodGuys,
207 | Name = "Viper Mk VII",
208 | ImageUri = "https://upload.wikimedia.org/wikipedia/en/4/40/Battlestar_Galactica_intro.jpg"
209 | });
210 | Spaceships.Add(new Spaceship()
211 | {
212 | Size = Spaceship.Sizes.Large,
213 | Engines = new List() { Spaceship.EngineTypes.Sublight, Spaceship.EngineTypes.FTL },
214 | Weapons = new List() { Spaceship.WeaponTypes.Batteries, Spaceship.WeaponTypes.Missiles },
215 | Crew = Spaceship.CrewTypes.GoodGuys,
216 | Name = "Battlestar Galactica",
217 | ImageUri = "https://upload.wikimedia.org/wikipedia/en/4/40/Battlestar_Galactica_intro.jpg"
218 | });
219 | Spaceships.Add(new Spaceship()
220 | {
221 | Size = Spaceship.Sizes.Small,
222 | Engines = new List() { Spaceship.EngineTypes.Sublight },
223 | Weapons = new List() { Spaceship.WeaponTypes.KineticEnergy, Spaceship.WeaponTypes.Missiles },
224 | Crew = Spaceship.CrewTypes.BadGuys,
225 | Name = "Cylon Raider",
226 | ImageUri = "https://upload.wikimedia.org/wikipedia/en/4/40/Battlestar_Galactica_intro.jpg"
227 | });
228 | Spaceships.Add(new Spaceship()
229 | {
230 | Size = Spaceship.Sizes.Large,
231 | Engines = new List() { Spaceship.EngineTypes.Sublight, Spaceship.EngineTypes.FTL },
232 | Weapons = new List() { Spaceship.WeaponTypes.Missiles },
233 | Crew = Spaceship.CrewTypes.BadGuys,
234 | Name = "Cylon Basestar",
235 | ImageUri = "https://upload.wikimedia.org/wikipedia/en/4/40/Battlestar_Galactica_intro.jpg"
236 | });
237 | }
238 | }
239 | }
--------------------------------------------------------------------------------
/DynamicFormFlowSample/Dialogs/SpaceshipSelectionDialog.cs:
--------------------------------------------------------------------------------
1 | using DynamicFormFlowSample.Models;
2 | using Microsoft.Bot.Builder.Dialogs;
3 | using System;
4 | using System.Threading.Tasks;
5 | using Microsoft.Bot.Builder.FormFlow;
6 | using DynamicFormFlowSample.Data;
7 | using System.Collections.Generic;
8 | using Microsoft.Bot.Connector;
9 | using System.Linq;
10 |
11 | namespace DynamicFormFlowSample.Dialogs
12 | {
13 | [Serializable]
14 | public class SpaceshipSelectionDialog : IDialog
15 | {
16 | private readonly BuildFormDelegate BuildSpaceshipSelectionForm;
17 | private IList _spaceshipMatches;
18 |
19 | internal SpaceshipSelectionDialog(BuildFormDelegate buildSpaceshipSelectionForm)
20 | {
21 | BuildSpaceshipSelectionForm = buildSpaceshipSelectionForm;
22 | }
23 |
24 | #pragma warning disable 1998
25 | public async Task StartAsync(IDialogContext context)
26 | {
27 | _spaceshipMatches = null;
28 | SpaceshipData.Instance.LastSearchResults = null;
29 |
30 | var spaceshipSelectionForm = new FormDialog(new Spaceship(), BuildSpaceshipSelectionForm, FormOptions.None);
31 | context.Call(spaceshipSelectionForm, OnSpaceshipSelectionFormCompleteAsync);
32 | }
33 | #pragma warning restore 1998
34 |
35 | ///
36 | /// Called once the form is complete. The result will have the properties selected by the user.
37 | ///
38 | ///
39 | ///
40 | ///
41 | private async Task OnSpaceshipSelectionFormCompleteAsync(IDialogContext context, IAwaitable result)
42 | {
43 | Spaceship spaceship = null;
44 |
45 | try
46 | {
47 | spaceship = await result;
48 | }
49 | catch (FormCanceledException e)
50 | {
51 | System.Diagnostics.Debug.WriteLine($"Form canceled: {e.Message}");
52 | }
53 |
54 | if (spaceship != null)
55 | {
56 | System.Diagnostics.Debug.WriteLine($"We've got the criteria for the ship:\n{spaceship.PropertiesAsFormattedString()}");
57 | SpaceshipData spaceshipData = SpaceshipData.Instance;
58 | _spaceshipMatches = spaceshipData.SearchForPartialMatches(spaceship);
59 |
60 | if (_spaceshipMatches.Count == 1)
61 | {
62 | // Single match for the given property -> Choise is made!
63 | IMessageActivity messageActivity = context.MakeMessage();
64 | ThumbnailCard thumbnailCard = CreateSpaceshipThumbnailCard(_spaceshipMatches[0]);
65 | messageActivity.Attachments = new List() { thumbnailCard.ToAttachment() };
66 | messageActivity.Text = $"You've chosen \"{_spaceshipMatches[0].Name}\", well done!";
67 | await context.PostAsync(messageActivity);
68 | context.Done(_spaceshipMatches[0]);
69 | }
70 | else if (_spaceshipMatches.Count > 1)
71 | {
72 | // More than one match -> Show the available options
73 | await ShowSelectSpaceshipPromptAsync(context);
74 | }
75 | else
76 | {
77 | // Nothing found matching the given criteria
78 | await context.PostAsync("No spaceships found with the given criteria");
79 | context.Fail(new ArgumentException("No spaceships found with the given criteria"));
80 | }
81 | }
82 | else
83 | {
84 | context.Fail(new NullReferenceException("No spaceship :("));
85 | }
86 | }
87 |
88 | ///
89 | /// Called when the user selects a spaceship from the shown options.
90 | ///
91 | ///
92 | ///
93 | ///
94 | private async Task OnSpaceshipSelectedAsync(IDialogContext context, IAwaitable
11 |
12 |
13 |
--------------------------------------------------------------------------------
/DynamicFormFlowSample/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2016 Tomi Paananen
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Dynamic FormFlow Sample #
2 |
3 | This sample demonstrates how to add dynamic features to FormFlow implementation
4 | of a bot built on Microsoft Bot Framework. The central points are explained in
5 | my blog post creatively named
6 | [How to Create Dynamic FormFlow](http://tomipaananen.azurewebsites.net/?p=1641).
7 |
8 | The approach implemented by this sample is especially useful for scenarios where
9 | the user is searching an item from an existing catalog. Instead of displaying
10 | all the options for narrowing down the desired item, we only display options
11 | available based on the data previously collected. In some cases we can skip part
12 | of the queries altogether as they have but only one option. See the three
13 | example flows below.
14 |
15 | **Few examples of the flow:**
16 |
17 | | Flow 1 | Flow 2 | Flow 3 |
18 | | ------ | ------ | ------ |
19 | |  |  |  |
20 |
21 |
22 | ## Important classes ##
23 |
24 | **[Spaceship](/DynamicFormFlowSample/Models/Spaceship.cs)** represents the item
25 | we are searching for and its properties. This is the class the FormFlow takes
26 | and starts filling values with.
27 |
28 | **[SpaceshipData](/DynamicFormFlowSample/Data/SpaceshipData.cs)** contains the
29 | catalog and some helper methods.
30 |
31 | **[SpaceshipSelectionForm](/DynamicFormFlowSample/Forms/SpaceshipSelectionForm.cs)**
32 | contains the FormFlow builder and the methods implementing the dynamics:
33 | checking if the fields (queries) are necessary, what options should be available
34 | and response validation.
35 |
36 | **[SpaceshipSelectionDialog](/DynamicFormFlowSample/Dialogs/SpaceshipSelectionDialog.cs)**
37 | is the root dialog of the bot and takes control of the flow once the FormFlow
38 | is finished. If more than one option remains, it will display a carousel of the
39 | spaceships left for the user to choose from.
40 |
41 |
42 | ## See also ##
43 |
44 | * [FormFlow documentation](https://docs.botframework.com/en-us/csharp/builder/sdkreference/forms.html)
45 | * [Pizza Bot Sample](https://github.com/Microsoft/BotBuilder/tree/master/CSharp/Samples/PizzaBot)
46 |
--------------------------------------------------------------------------------