public Task <IEnumerable <SearchHistoryListItem> > GetPagedItems(int head, int count) { var items = SearchHistoryDb.GetHistoryItems().Skip(head).Take(count) .Select(x => new SearchHistoryListItem(x, _SearchPageViewModel.OnSearchHistorySelected)) .ToArray(); return(Task.FromResult(items.AsEnumerable())); }
private static IAsyncOperation <IReadOnlyList <object> > loadSuggestion(AutoSuggestBox sender) { var input = sender.Text; var sep = GetSeparator(sender); var useHistory = GetUseHistory(sender); return(Task.Run <IReadOnlyList <object> >(() => { input = input?.Trim() ?? ""; using (var db = new SearchHistoryDb()) { var history = useHistory ? ((IEnumerable <SearchHistory>)db.SearchHistorySet .Where(sh => sh.Content.Contains(input)) .OrderByDescending(sh => sh.Time)) .Distinct() .Select(sh => sh.SetHighlight(input)) : Enumerable.Empty <SearchHistory>(); splitKeyword(sep, input, out var lastwordNs, out var lastword, out var previous); var dictionary = default(IEnumerable <ITagRecord>); if (!string.IsNullOrEmpty(lastword) && lastwordNs != Namespace.Unknown) { var suffix = sep.EndsWith(" ") ? sep : sep + " "; dictionary = TagRecordFactory.GetTranslatedRecords(lastword, lastwordNs) .Concat <ITagRecord>(TagRecordFactory.GetRecords(lastword, lastwordNs)) .Where(t => t != null) .OrderByDescending(t => t.Score) .Take(25) .Distinct(tagComparer) .Select(tag => tag.SetPrefix(previous).SetSuffix(suffix)); } else { dictionary = Enumerable.Empty <ITagRecord>(); } try { return ((IEnumerable <object>)dictionary).Concat(history).ToList(); } catch (InvalidOperationException) { //Collection changed return null; } } }).AsAsyncOperation()); }
public Task <int> ResetSource() { return(Task.FromResult(SearchHistoryDb.GetHistoryCount())); }