/// <summary> /// Given the search request, build the response. /// </summary> /// <param name="search"></param> /// <returns></returns> private async Task <ISearchResponse> BuildResponse(SearchRequest search) { // we want the stopwatch to include the getting of the transaction as well. var stopwatch = new Stopwatch(); stopwatch.Start(); var log = new StringBuilder(); var token = CancellationToken.None; var transaction = await Persister.BeginRead(token).ConfigureAwait(false); log.AppendLine($" > Got transaction Time Elapsed: {stopwatch.Elapsed:g}"); try { // search the words. var words = await GetWords(search, token).ConfigureAwait(false); log.AppendLine($" > Got Words Time Elapsed: {stopwatch.Elapsed:g}"); // get the percent complete var status = await GetStatus(token).ConfigureAwait(false); log.AppendLine($" > Got Status Time Elapsed: {stopwatch.Elapsed:g}"); // we are done here. Persister.Commit(transaction); log.AppendLine($" > Committed Time Elapsed: {stopwatch.Elapsed:g}"); // log it. stopwatch.Stop(); log.Append($"Completed search for '{search.What}' found {words.Count} result(s) (Time Elapsed: {stopwatch.Elapsed:g})"); Logger.Information(log.ToString()); // we can now build the response model. return(new SearchResponse(words, stopwatch.ElapsedMilliseconds, status)); } catch (Exception e) { Persister.Rollback(transaction); Logger.Exception(e); } // return nothing return(new SearchResponse()); }