/// <summary> /// Добавление запроса пользователя /// </summary> /// <param name="botUser"></param> /// <param name="type"></param> /// <param name="answer"></param> /// <param name="query"></param> /// <param name="TimeToStartAnswer"></param> /// <param name="buRequest"></param> public void AddBotQuery(BotUser botUser, FindedInformation answer, DateTime TimeToStartAnswer, BotUserRequest buRequest) { try { buRequest.BotUserID = botUser.BotUserID; buRequest.NowIs = (MallBotWhatIsHappeningNow)botUser.NowIs; if (answer != null && answer.Result != null) { buRequest.Answer = JsonConvert.SerializeObject(answer.Result); } var TimeToAnswer = DateTime.Now.Subtract(TimeToStartAnswer); buRequest.TimeToAnswer = TimeToAnswer.Days.ToString() + ":" + TimeToAnswer.Hours.ToString() + ":" + TimeToAnswer.Minutes.ToString() + ":" + TimeToAnswer.Seconds.ToString() + ":" + TimeToAnswer.Milliseconds.ToString(); buRequest.DateTime = DateTime.Now; buRequest.BotUserID = botUser.BotUserID; buRequest.CustomerCompositeID = botUser.CustomerCompositeID; buRequest.Name = botUser.Name; botUser.LastActivityDate = DateTime.Now; BotUserRequest.Add(buRequest); SaveChanges(); } catch (Exception exc) { Logging.Logger.Error(exc); } }
public AnswerWithPhotoHelper(SocialNetworkType _type, FindedInformation _answer, ApiRouter _sender, BotUser _botUser, BotTextHelper _texter, CachedDataModel _dataOfBot) { answer = _answer; sender = _sender; botUser = _botUser; texter = _texter; type = _type; dataOfBot = _dataOfBot; }
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); }
public DrawHelper(CachedDataModel _dataOfBot, FindedInformation _answer, string _title) { dataOfBot = _dataOfBot; answer = _answer; title = _title; }