コード例 #1
0
ファイル: DefaultDialog.cs プロジェクト: mohamedsaif/Mobile3
        public async Task SearchService(IDialogContext context, IAwaitable <IMessageActivity> message, LuisResult result)
        {
            var messageToForward = await message;

            EntityRecommendation productSearch;

            if (result.TryFindEntity(ServiceEntities.Product, out productSearch))
            {
                var model = ProductModel.GetContextData(context);
                // Title case the search entity for consistency
                model.SearchTerm = new CultureInfo("en").TextInfo.ToTitleCase(productSearch.Entity.ToLower());

                // Are we searching for an API?
                string query = result.Query.ToLower();
                if (query.Contains("api"))
                {
                    var matchedAPI = await searchService.CheckAPIExists(model.SearchTerm);

                    if (!string.IsNullOrEmpty(matchedAPI))
                    {
                        model.API = model.SearchTerm = matchedAPI;
                    }
                }

                // Are we searching for a Category?
                else if (query.Contains("category"))
                {
                    var matchedCategory = await searchService.CheckCategoryExists(model.SearchTerm);

                    if (!string.IsNullOrEmpty(matchedCategory))
                    {
                        model.Category = model.SearchTerm = matchedCategory;
                    }
                }

                // Is this a general product search?
                ProductModel.SetContextData(context, model);
                await context.PostAsync($"Ok, let me look for information on '{model.SearchTerm}'.");

                await context.Forward(new ServiceSearchDialog(), AfterDialog, messageToForward, CancellationToken.None);
            }

            // If we cant identify a product entity, start an explore dialog
            else
            {
                await context.PostAsync("let's explore what you can do with the Cognitive Services.");

                await context.Forward(new ServiceExploreDialog(), AfterDialog, messageToForward, CancellationToken.None);
            }
        }