Exemplo n.º 1
0
        protected override async Task MessageReceived(IDialogContext context, IAwaitable <IMessageActivity> item)
        {
            var activity = await item;

            if (Regex.IsMatch(activity.Text, RecipeStartRegEx))
            {
                try
                {
                    int recipeId      = -1;
                    var recipeIdMatch = Regex.Match(activity.Text.Remove(0, RecipeStartRaw.Length), "\\d+");
                    if (!Int32.TryParse(recipeIdMatch.Value, out recipeId))
                    {
                        await context.PostAsync(Resources.Message_Error_RecipeNotFound);
                    }
                    context.UserData.SetValue(Userdata_RecipeId, recipeId);
                    context.UserData.RemoveValue(Userdata_StepId);

                    using (var client = new GatewayClient())
                    {
                        await client.StartCookingAsync(recipeId);
                    }

                    await context.PostAsync(Resources.Message_StartCooking_HereWeGo + Bot_NewLine + Resources.Message_StartCooking_Desc);

                    var text = await GetIngrediantListAsync(recipeId);

                    await context.PostAsync(text);

                    await this.HandleGetRecipeStep(context, StepDirection.ThisStep);
                }
                catch (Exception e)
                {
                    await context.PostAsync("Es ist ein Fehler aufgetreten. Bitte versuch es später nochmal");
                }
                context.Wait(this.MessageReceived);
            }
            else
            {
                await base.MessageReceived(context, item);
            }
        }