Skip to content

Commit

Permalink
AdaptiveCards Sample cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
pcostantini committed May 31, 2017
1 parent f7e71e4 commit b5f18cc
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 55 deletions.
1 change: 0 additions & 1 deletion CSharp/cards-AdaptiveCards/AdaptiveCards.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@
<ItemGroup>
<Compile Include="App_Start\WebApiConfig.cs" />
<Compile Include="Controllers\MessagesController.cs" />
<Compile Include="Dialogs\FlightsDialog.cs" />
<Compile Include="Dialogs\HotelsDialog.cs" />
<Compile Include="Dialogs\RootDialog.cs" />
<Compile Include="Dialogs\SupportDialog.cs" />
Expand Down
15 changes: 0 additions & 15 deletions CSharp/cards-AdaptiveCards/Dialogs/FlightsDialog.cs

This file was deleted.

6 changes: 2 additions & 4 deletions CSharp/cards-AdaptiveCards/Dialogs/HotelsDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ public async Task StartAsync(IDialogContext context)
}
catch (FormCanceledException ex)
{
string reply = $"Oops! Something went wrong :( Technical Details: {ex.InnerException.Message}";
await context.PostAsync(reply);
await context.PostAsync($"Oops! Something went wrong :( Technical Details: {ex.InnerException.Message}");
}
}

Expand Down Expand Up @@ -66,8 +65,7 @@ private async Task SearchHotels(IDialogContext context, HotelsQuery searchQuery)
};

var reply = context.MakeMessage();
var attachments = reply.Attachments = new List<Attachment>();
attachments.Add(attachment);
reply.Attachments.Add(attachment);

await context.PostAsync(reply);
}
Expand Down
65 changes: 30 additions & 35 deletions CSharp/cards-AdaptiveCards/Dialogs/RootDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,43 +31,40 @@ public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitabl
{
// Got an Action Submit
dynamic value = message.Value;
if (value.Type == "HotelSearch")
switch(value.Type.ToString())
{
// Hotel Search
HotelsQuery query;
try
{
query = HotelsQuery.Parse(value);
List<ValidationResult> results = new List<ValidationResult>();
bool valid = Validator.TryValidateObject(query, new ValidationContext(query, null, null), results, true);
if (!valid)
case "HotelSearch":
HotelsQuery query;
try
{
// Some field in the Hotel Query are not valid
var errors = string.Join("\n", results.Select(o => " - " + o.ErrorMessage));
var reply = context.MakeMessage();
reply.Text = "Please complete all the search parameters:\n" + errors;
await context.PostAsync(reply);
query = HotelsQuery.Parse(value);
List<ValidationResult> results = new List<ValidationResult>();
bool valid = Validator.TryValidateObject(query, new ValidationContext(query, null, null), results, true);
if (!valid)
{
// Some field in the Hotel Query are not valid
var errors = string.Join("\n", results.Select(o => " - " + o.ErrorMessage));
await context.PostAsync("Please complete all the search parameters:\n" + errors);
return;
}
}
catch (InvalidCastException)
{
// Hotel Query could not be parsed
await context.PostAsync("Please complete all the search parameters");
return;
}
}
catch (InvalidCastException)
{
// Hotel Query could not be parsed
var reply = context.MakeMessage();
reply.Text = "Please complete all the search parameters";
await context.PostAsync(reply);

// Proceed with hotels search
await context.Forward(new HotelsDialog(), this.ResumeAfterOptionDialog, message, CancellationToken.None);

return;
}

// Proceed with hotels search
await context.Forward(new HotelsDialog(), this.ResumeAfterOptionDialog, message, CancellationToken.None);
}
else if (value.Type == "HotelSelection")
{
// Hotel Selected
await SendHotelSelectionAsync(context, (Hotel)JsonConvert.DeserializeObject<Hotel>(value.ToString()));
context.Wait(MessageReceivedAsync);
return;
case "HotelSelection":
await SendHotelSelectionAsync(context, (Hotel)JsonConvert.DeserializeObject<Hotel>(value.ToString()));
context.Wait(MessageReceivedAsync);

return;
}
}

Expand Down Expand Up @@ -167,8 +164,7 @@ private async Task ShowOptionsAsync(IDialogContext context)
};

var reply = context.MakeMessage();
var attachments = reply.Attachments = new List<Attachment>();
attachments.Add(attachment);
reply.Attachments.Add(attachment);

await context.PostAsync(reply, CancellationToken.None);

Expand Down Expand Up @@ -288,8 +284,7 @@ private static async Task SendHotelSelectionAsync(IDialogContext context, Hotel
};

var reply = context.MakeMessage();
var attachments = reply.Attachments = new List<Attachment>();
attachments.Add(attachment);
reply.Attachments.Add(attachment);

await context.PostAsync(reply, CancellationToken.None);
}
Expand Down

0 comments on commit b5f18cc

Please sign in to comment.