public void GetData(string searchString, Dictionary <string, string> parameters, int offset, int count, Action <BackendResult <VKList <SearchHint>, ResultCode> > callback) { if (offset == 0 && string.IsNullOrWhiteSpace(searchString) && SearchHintsSearchDataProvider._preloadedSearchHintsLoaded) { Action <BackendResult <VKList <SearchHint>, ResultCode> > action = callback; int num = 0; VKList <SearchHint> resultData = new VKList <SearchHint>(); resultData.items = SearchHintsSearchDataProvider._preloadedSearchHints; int count1 = SearchHintsSearchDataProvider._preloadedSearchHints.Count; resultData.count = count1; BackendResult <VKList <SearchHint>, ResultCode> backendResult = new BackendResult <VKList <SearchHint>, ResultCode>((ResultCode)num, resultData); action(backendResult); } else { string query = searchString; SearchService.Instance.GetSearchHints(searchString, (Action <BackendResult <List <SearchHint>, ResultCode> >)(result => { if (result.ResultCode == ResultCode.Succeeded) { if (string.IsNullOrEmpty(query)) { if (!SearchHintsSearchDataProvider._preloadedSearchHintsLoaded) { SearchHintsSearchDataProvider._preloadedSearchHints = new List <SearchHint>((IEnumerable <SearchHint>)result.ResultData); SearchHintsSearchDataProvider._preloadedSearchHintsHeaders = new List <SearchHintHeader>((IEnumerable <SearchHintHeader>)Enumerable.Select <SearchHint, SearchHintHeader>(result.ResultData, (Func <SearchHint, SearchHintHeader>)(searchHint => new SearchHintHeader(searchHint)))); SearchHintsSearchDataProvider._preloadedSearchHintsLoaded = true; } } else { string internalLink = SearchHintsSearchDataProvider.TryGetInternalLink(query); if (!string.IsNullOrEmpty(internalLink)) { result.ResultData.Add(new SearchHint() { type = "internal_link", global = 1, description = internalLink }); } result.ResultData.Add(new SearchHint() { type = "extended_search", global = 1 }); } callback(new BackendResult <VKList <SearchHint>, ResultCode>(result.ResultCode, new VKList <SearchHint>() { count = result.ResultData.Count, items = result.ResultData })); } else { callback(new BackendResult <VKList <SearchHint>, ResultCode>(result.ResultCode, null)); } })); } }
private static string TryGetInternalLink(string query) { query = query.ToLowerInvariant(); bool isVKMe; string shortVkUrl = SearchHintsSearchDataProvider.GetShortVKUrl(query, out isVKMe); if (shortVkUrl != null) { query = shortVkUrl.Substring(shortVkUrl.LastIndexOf("/", (StringComparison)2) + 1); } if (!Regex.IsMatch(query, "(?![0-9_]+)^[a-zA-Z0-9_]*$")) { return(""); } if (!string.IsNullOrEmpty(query)) { query = (!isVKMe ? "vk.com/" : "vk.me/") + query; } return(query); }