public Task OutputResultsAsync(IQueryRunner runner) { return(Task.Run(() => { try { runner.OutputMessage("Query Started"); var sw = Stopwatch.StartNew(); var dq = runner.QueryText; var res = runner.ExecuteDataTableQuery(dq); sw.Stop(); var durationMs = sw.ElapsedMilliseconds; // write results to Excel 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", OutputTargets.Static); runner.QueryCompleted(); }, TaskScheduler.Default); } catch (Exception ex) { runner.ActivateOutput(); runner.OutputError(ex.Message); } })); }
private void OutputResults(IQueryRunner runner) { try { runner.OutputMessage("Query Started"); var sw = Stopwatch.StartNew(); var dq = runner.QueryText; var res = runner.ExecuteDataTableQuery(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", OutputTargets.Timer); //runner.QueryCompleted(); runner.ActivateOutput(); } catch (Exception ex) { runner.ActivateOutput(); runner.OutputError(ex.Message); } finally { runner.QueryCompleted(); } }