public async Task OutputResultsAsync(IQueryRunner runner, IQueryTextProvider textProvider) { try { runner.OutputMessage("Query Started"); var sw = Stopwatch.StartNew(); var dq = textProvider.QueryText; var res = await runner.ExecuteDataTableQueryAsync(dq); sw.Stop(); var durationMs = sw.ElapsedMilliseconds; runner.OutputMessage(string.Format("Query Completed ({0:N0} row{1} returned)", res.Rows.Count, res.Rows.Count == 1 ? "" : "s"), durationMs); runner.RowCount = res.Rows.Count; runner.SetResultsMessage("Query timings sent to output tab", OutputTarget.Timer); //runner.QueryCompleted(); runner.ActivateOutput(); } catch (Exception ex) { Log.Error(ex, Common.Constants.LogMessageTemplate, nameof(ResultsTargetTimer), nameof(OutputResultsAsync), ex.Message); runner.ActivateOutput(); runner.OutputError(ex.Message); } finally { runner.QueryCompleted(); } }
public async Task OutputResultsAsync(IQueryRunner runner, IQueryTextProvider textProvider) { await Task.Run(async() => { try { runner.OutputMessage("Query Started"); var sw = Stopwatch.StartNew(); var dq = textProvider.QueryText; DataTable res = await runner.ExecuteDataTableQueryAsync(dq); if (res == null || res.Rows?.Count == 0) { Log.Warning("{class} {method} {message}", nameof(ResultsTargetExcelStatic), nameof(OutputResultsAsync), "Query Result DataTable has no rows"); runner.ActivateOutput(); runner.OutputWarning("Unable to send results to Excel as there are no rows in the result set"); return; } sw.Stop(); var durationMs = sw.ElapsedMilliseconds; // write results to Excel await runner.Host.Proxy.OutputStaticResultAsync(res, runner.SelectedWorksheet); //.ContinueWith((ascendant) => { runner.OutputMessage( string.Format("Query Completed ({0:N0} row{1} returned)", res.Rows.Count, res.Rows.Count == 1 ? "" : "s"), durationMs); runner.RowCount = res.Rows.Count; runner.ActivateOutput(); runner.SetResultsMessage("Static results sent to Excel", OutputTarget.Static); //},TaskScheduler.Default); } catch (Exception ex) { Log.Error(ex, "{class} {method} {message}", nameof(ResultsTargetExcelStatic), nameof(OutputResultsAsync), ex.Message); runner.ActivateOutput(); runner.OutputError(ex.Message); } finally { runner.QueryCompleted(); } }); }