Example #1
0
        public async Task <FindedInformation> Main(object usefulData)
        {
            string query = "";

            if (botUser.InputDataType == InputDataType.Text)
            {
                query = usefulData.ToString();
                if (await AnaliseCommands(query) == 1)
                {
                    return(null);
                }
            }

            FindedInformation answer;
            var searcher = new Search.Mall.SearchHelper();
            List <FuzzySearchResult> res;
            object alreadyFinded;
            AnswerWithPhotoHelper answererWithPhoto;

            switch (botUser.NowIs)
            {
            case MallBotWhatIsHappeningNow.SettingCustomer:

                switch (botUser.InputDataType)
                {
                case InputDataType.GeoLocation:
                    res = searcher.SearchCustomerByGeocode((DbGeography)usefulData, dataGetter.GetStructuredCustomers(Convert.ToBoolean(botUser.IsTestMode)));
                    break;

                case InputDataType.Text:
                    alreadyFinded = cacher.Get($"SETCUSTOMER{botUser.BotUserID}");
                    if (alreadyFinded == null)
                    {
                        res = searcher.SearchCustomerByName(query, dataGetter.GetStructuredCustomers(Convert.ToBoolean(botUser.IsTestMode)));
                    }
                    else
                    {
                        res = searcher.SearchCustomerByName(query, dataGetter.GetStructuredCustomers(Convert.ToBoolean(botUser.IsTestMode)), (string)alreadyFinded);
                    }
                    break;

                default:
                    res = new List <FuzzySearchResult>();
                    break;
                }
                answer = new FindedInformation {
                    Result = new SearchResult(query, res)
                };
                await AnaliseSearchCustomerResult(res);

                break;

            case MallBotWhatIsHappeningNow.SearchingOrganization:
                cacher.Clear(botUser.BotUserID);
                var dataOfbot = dataGetter.GetDataForOneCustomer(currentCustomer.CustomerID, botUser.CustomerCompositeID);
                res    = searcher.SearchOrganization(query, dataOfbot.Organizations.OfType <IOrganization>(), dataOfbot.Categories.OfType <ICategory>(), dataOfbot.Synonyms.OfType <IOrganizationSynonym>());
                answer = new FindedInformation {
                    Result = new SearchResult(query, res), GroopedResult = BotMapHelper.GroupFuzzySearchResult(res, dataOfbot)
                };

                DrawHelper drawer;
                if (botUser.Locale == "ru_RU")
                {
                    drawer = new DrawHelper(dataOfbot, answer, $"Этаж %floornumber%   {currentCustomer.Name} {currentCustomer.LocaleCity[0]}");
                }
                else
                {
                    if (currentCustomer.LocaleCity.Length == 1)
                    {
                        drawer = new DrawHelper(dataOfbot, answer, $"Floor %floornumber%   {currentCustomer.Name} {currentCustomer.LocaleCity[0]}");
                    }
                    else
                    {
                        drawer = new DrawHelper(dataOfbot, answer, $"Floor %floornumber%   {currentCustomer.Name} {currentCustomer.LocaleCity[1]}");
                    }
                }
                answer = drawer.DrawFindedShops();

                answererWithPhoto = new AnswerWithPhotoHelper(type, answer, sender, botUser, texter, dataOfbot);
                await answererWithPhoto.AnalyseSearchOrganizationResult();

                break;

            case MallBotWhatIsHappeningNow.SearchingWay:
                if (cacher.Get($"FINDEDFIRSTORG{botUser.BotUserID}") == null || query == "нет" || query == "no" || query == "не хочу" || query == "неа" || query == "не надо" || query == "но")
                {
                    cacher.Clear(botUser.BotUserID);
                    botUser.NowIs = MallBotWhatIsHappeningNow.SearchingOrganization;
                    await sender.SendText(texter.GetMessage("%ready%", "%mall%", currentCustomer.Name, currentCustomer.LocaleCity) + "\\r\\n\\r\\n" + texter.GetMessage("%orgsrchstartback%"));

                    return(null);
                }

                dataOfbot     = dataGetter.GetDataForOneCustomer(currentCustomer.CustomerID, botUser.CustomerCompositeID);
                alreadyFinded = cacher.Get($"SEARCHWAY{botUser.BotUserID}");
                if (alreadyFinded == null)
                {
                    res = searcher.SearchOrganization(query, dataOfbot.Organizations.OfType <IOrganization>(), dataOfbot.Categories.OfType <ICategory>(), dataOfbot.Synonyms.OfType <IOrganizationSynonym>());
                }
                else
                {
                    res = searcher.SearchOrganization(query, dataOfbot.Organizations.OfType <IOrganization>().ToList(), dataOfbot.Categories.OfType <ICategory>().ToList(), dataOfbot.Synonyms.OfType <IOrganizationSynonym>().ToList(), (string)alreadyFinded);
                }

                answer = new FindedInformation {
                    Result = new SearchResult(query, res)
                };
                answererWithPhoto = new AnswerWithPhotoHelper(type, answer, sender, botUser, texter, dataOfbot);
                await answererWithPhoto.AnalyseSearchOrganizationForWayResult();

                break;

            case MallBotWhatIsHappeningNow.GettingAllOrganizations:
                alreadyFinded = cacher.Get($"VIEWALLORG{botUser.BotUserID}");
                dataOfbot     = dataGetter.GetDataForOneCustomer(currentCustomer.CustomerID, botUser.CustomerCompositeID);
                botUser.NowIs = MallBotWhatIsHappeningNow.SearchingOrganization;

                if (alreadyFinded != null && (query == "да" || query == "хочу" || query == "конечно" || query == "yes" || query == "of corse" || query == "ага"))
                {
                    answererWithPhoto = new AnswerWithPhotoHelper(type, (FindedInformation)alreadyFinded, sender, botUser, texter, dataOfbot);
                    await answererWithPhoto.AnalyseSearchOrganizationResult(true);

                    return((FindedInformation)alreadyFinded);
                }
                await sender.SendText(texter.GetMessage("%ready%", "%mall%", currentCustomer.Name, currentCustomer.LocaleCity) + "\\r\\n\\r\\n" + texter.GetMessage("%orgsrchstartback%"));

                if (alreadyFinded != null)
                {
                    answer = (FindedInformation)alreadyFinded;
                }
                else
                {
                    answer = null;
                }
                cacher.Remove($"VIEWALLORG{botUser.BotUserID}");
                break;

            default:
                answer = null;
                break;
            }
            return(answer);
        }