public async Task <string> SimpleSearch(SearchRequest req, CancellationToken token) { req.endDT = DateTime.UtcNow; req.startDT = DateTime.UtcNow.AddDays(-7); await searchProvider.AsyncSearch(req.searchType, req.Request, req.startDT, req.endDT, req.Limit, req.isChannel, req.isGroup, token, req.ChatIds); return(Newtonsoft.Json.JsonConvert.SerializeObject(searchProvider.searchResultReciever.ViewResults())); }
public async override Task Search(SearchRequest request, IServerStreamWriter <SearchResult> responseStream, ServerCallContext context) { SearchingTask = searchProvider.AsyncSearch(request.SearchType, request.Request, request.StartTime.ToDateTime(), request.EndTime.ToDateTime(), request.Limit == 0 ? 1500 : request.Limit, request.IsChannel, request.IsGroup, tokenSource.Token, request.Ids != null && request.Ids.Count > 0 ? request.Ids.ToArray() : null); bool lastExecutionEnable = true; while (!SearchingTask.IsCompleted || lastExecutionEnable) { while (searchProvider.searchResultReciever.TryDequeueResult(out SearchResult res)) { await responseStream.WriteAsync(res); } await Task.WhenAny(Task.Delay(30), SearchingTask); if (SearchingTask.IsCompleted && lastExecutionEnable) { lastExecutionEnable = false; } } }