public void OutputResults(IQueryRunner runner)
        {
            try
            {
                runner.OutputMessage("Query Started");
                var start = DateTime.Now;

                var dq = runner.QueryText;
                runner.ExecuteQueryAsync(dq).ContinueWith((antecendant) =>
                {
                    var end        = DateTime.Now;
                    var durationMs = (end - start).TotalMilliseconds;
                    var res        = antecendant.Result;

                    // TODO write results to Excel
                    runner.Host.OutputStaticResult(res, runner.SelectedWorksheet);
                    //runner.ResultsTable = res;

                    runner.OutputMessage(
                        string.Format("Query Completed ({0} row{1} returned)", res.Rows.Count,
                                      res.Rows.Count == 1 ? "" : "s"), durationMs);
                    runner.ActivateResults();
                    runner.QueryCompleted();
                }, TaskScheduler.FromCurrentSynchronizationContext());
            }
            catch (Exception ex)
            {
                runner.ActivateOutput();
                runner.OutputError(ex.Message);
            }
        }
        public Task OutputResultsAsync(IQueryRunner runner)
        {
            return(Task.Factory.StartNew(() =>
            {
                try
                {
                    runner.OutputMessage("Query Started");
                    var start = DateTime.Now;

                    var dq = runner.QueryText;
                    var res = runner.ExecuteQuery(dq);

                    var end = DateTime.Now;
                    var durationMs = (end - start).TotalMilliseconds;


                    // TODO write results to Excel
                    runner.Host.OutputStaticResult(res, runner.SelectedWorksheet);
                    //runner.ResultsTable = res;

                    runner.OutputMessage(
                        string.Format("Query Completed ({0} row{1} returned)", res.Rows.Count,
                                      res.Rows.Count == 1 ? "" : "s"), durationMs);
                    runner.ActivateResults();
                    runner.QueryCompleted();
                }
                catch (Exception ex)
                {
                    runner.ActivateOutput();
                    runner.OutputError(ex.Message);
                }
            }));
        }
        public void OutputResults(IQueryRunner runner)
        {
            try
            {
                runner.OutputMessage("Query Started");
                var start = DateTime.Now;

                var dq = runner.QueryText;
                runner.ExecuteQueryAsync(dq).ContinueWith((antecendant) =>
                    {
                        var end = DateTime.Now;
                        var durationMs = (end - start).TotalMilliseconds;
                        var res = antecendant.Result;

                        // TODO write results to Excel
                        runner.Host.OutputStaticResult(res, runner.SelectedWorksheet);
                        //runner.ResultsTable = res;

                        runner.OutputMessage(
                            string.Format("Query Completed ({0} row{1} returned)", res.Rows.Count,
                                          res.Rows.Count == 1 ? "" : "s"), durationMs);
                        runner.ActivateResults();
                        runner.QueryCompleted();
                    },TaskScheduler.FromCurrentSynchronizationContext());
            }
            catch (Exception ex)
            {
                runner.ActivateOutput();
                runner.OutputError(ex.Message);
            }
        }
Exemple #4
0
        // This is the core method that handles the output of the results
        public Task OutputResultsAsync(IQueryRunner runner)
        {
            // Read the AutoFormat option from the options singleton
            bool autoFormat = _options.ResultAutoFormat;

            return(Task.Run(() =>
            {
                long durationMs = 0;
                int queryCnt = 1;
                try
                {
                    runner.OutputMessage("Query Started");
                    var sw = Stopwatch.StartNew();

                    var dq = runner.QueryText;
                    //var res = runner.ExecuteDataTableQuery(dq);
                    using (var dataReader = runner.ExecuteDataReaderQuery(dq))
                    {
                        if (dataReader != null)
                        {
                            Log.Verbose("Start Processing Grid DataReader (Elapsed: {elapsed})", sw.ElapsedMilliseconds);
                            runner.ResultsDataSet = dataReader.ConvertToDataSet(autoFormat);
                            Log.Verbose("End Processing Grid DataReader (Elapsed: {elapsed})", sw.ElapsedMilliseconds);

                            sw.Stop();
                            durationMs = sw.ElapsedMilliseconds;
                            var rowCnt = runner.ResultsDataSet.Tables[0].Rows.Count;
                            foreach (DataTable tbl in runner.ResultsDataSet.Tables)
                            {
                                runner.OutputMessage(
                                    string.Format("Query {2} Completed ({0:N0} row{1} returned)", tbl.Rows.Count,
                                                  tbl.Rows.Count == 1 ? "" : "s", queryCnt));
                                queryCnt++;
                            }
                            runner.RowCount = rowCnt;
                            // activate the result only when Counters are not selected...
                            runner.ActivateResults();
                            runner.OutputMessage("Query Batch Completed", durationMs);
                        }
                        else
                        {
                            runner.OutputError("Query Batch Completed with errors", durationMs);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.Error("{class} {method} {message} {stacktrace}", "ResultsTargetGrid", "OutputQueryResultsAsync", ex.Message, ex.StackTrace);
                    runner.ActivateOutput();
                    runner.OutputError(ex.Message);
                    runner.OutputError("Query Batch Completed with erros", durationMs);
                }
                finally
                {
                    runner.QueryCompleted();
                }
            }));
        }
        // This is the core method that handles the output of the results
        public async Task OutputResultsAsync(IQueryRunner runner, IQueryTextProvider textProvider)
        {
            // Read the AutoFormat option from the options singleton
            bool autoFormat = _options.ResultAutoFormat;
            await Task.Run(() =>
            {
                long durationMs = 0;
                int queryCnt    = 1;
                try
                {
                    runner.OutputMessage("Query Started");
                    var sw = Stopwatch.StartNew();

                    var dq = textProvider.QueryText;
                    //var res = runner.ExecuteDataTableQuery(dq);
                    var isSessionsDmv = dq.Contains(Common.Constants.SessionsDmv, StringComparison.OrdinalIgnoreCase);


                    using (var dataReader = runner.ExecuteDataReaderQuery(dq))
                    {
                        if (dataReader != null)
                        {
                            Log.Verbose("Start Processing Grid DataReader (Elapsed: {elapsed})", sw.ElapsedMilliseconds);
                            runner.ResultsDataSet = dataReader.ConvertToDataSet(autoFormat, isSessionsDmv);
                            Log.Verbose("End Processing Grid DataReader (Elapsed: {elapsed})", sw.ElapsedMilliseconds);

                            sw.Stop();

                            // add extended properties to DataSet
                            runner.ResultsDataSet.ExtendedProperties.Add("QueryText", dq);
                            runner.ResultsDataSet.ExtendedProperties.Add("IsDiscoverSessions", isSessionsDmv);

                            durationMs = sw.ElapsedMilliseconds;
                            var rowCnt = runner.ResultsDataSet.Tables[0].Rows.Count;
                            foreach (DataTable tbl in runner.ResultsDataSet.Tables)
                            {
                                runner.OutputMessage(
                                    string.Format("Query {2} Completed ({0:N0} row{1} returned)", tbl.Rows.Count,
                                                  tbl.Rows.Count == 1 ? "" : "s", queryCnt));
                                queryCnt++;
                            }
                            runner.RowCount = rowCnt;
                            // activate the result only when Counters are not selected...
                            runner.ActivateResults();
                            runner.OutputMessage("Query Batch Completed", durationMs);
                        }
                        else
                        {
                            runner.OutputError("Query Batch Completed with errors listed above (you may need to scroll up)", durationMs);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.Error("{class} {method} {message} {stacktrace}", nameof(ResultsTargetGrid), nameof(OutputResultsAsync), ex.Message, ex.StackTrace);
                    runner.ActivateOutput();
                    runner.OutputError(ex.Message);
                    runner.OutputError("Query Batch Completed with errors listed above (you may need to scroll up)", durationMs);
                }
                finally
                {
                    runner.QueryCompleted();
                }
            });
        }
        public Task OutputResultsAsync(IQueryRunner runner)
        {
            return Task.Factory.StartNew(() =>
                {
                    try
                    {
                        runner.OutputMessage("Query Started");
                        var sw = Stopwatch.StartNew();

                        var dq = runner.QueryText;
                        var res = runner.ExecuteQuery(dq);
                        if (res != null)
                        {
                            sw.Stop();
                            var durationMs =sw.ElapsedMilliseconds;
                            runner.ResultsTable = res;
                            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;
                            // activate the result only when Counters are not selected...
                            runner.ActivateResults();
                            //runner.QueryCompleted();
                        }

                    }
                    catch (Exception ex)
                    {
                        runner.ActivateOutput();
                        runner.OutputError(ex.Message);
                    }
                });
        }
        public Task OutputResultsAsync(IQueryRunner runner)
        {
            return Task.Factory.StartNew(() =>
                {
                    try
                    {
                        runner.OutputMessage("Query Started");
                        var start = DateTime.Now;

                        var dq = runner.QueryText;
                        var res = runner.ExecuteQuery(dq);

                        var end = DateTime.Now;
                        var durationMs = (end - start).TotalMilliseconds;

                        // TODO write results to Excel
                        runner.Host.OutputStaticResult(res, runner.SelectedWorksheet);
                        //runner.ResultsTable = res;

                        runner.OutputMessage(
                            string.Format("Query Completed ({0} row{1} returned)", res.Rows.Count,
                                          res.Rows.Count == 1 ? "" : "s"), durationMs);
                        runner.ActivateResults();
                        runner.QueryCompleted();

                    }
                    catch (Exception ex)
                    {
                        runner.ActivateOutput();
                        runner.OutputError(ex.Message);
                    }
                });
        }