public override object Run()
        {
            if (base.Server.Repository == null)
            {
                base.Server.PostStatus(new QueryStatusEventArgs("Could not execute", "Error: no database specified"));
                return(null);
            }
            if (string.IsNullOrEmpty(base.query))
            {
                base.Server.PostStatus(new QueryStatusEventArgs("Could not execute", "Error: empty query"));
                return(null);
            }
            QueryStatusEventArgs args      = new QueryStatusEventArgs();
            Stopwatch            stopwatch = new Stopwatch();

            try
            {
                string customAssemblyPath = base.Server.Repository.CustomAssemblyPath;
                if (File.Exists(customAssemblyPath))
                {
                    Assembly.LoadFrom(customAssemblyPath);
                }
                stopwatch.Start();
                base.Server.Repository.DriverLoader.Driver.ExecuteESqlQuery(base.Server.Repository, base.query);
            }
            catch (ThreadAbortException)
            {
                stopwatch.Stop();
            }
            catch (Exception innerException)
            {
                stopwatch.Stop();
                if (innerException is TargetInvocationException)
                {
                    innerException = ((TargetInvocationException)innerException).InnerException;
                }
                args.ErrorMessage  = innerException.GetType().Name + ": " + innerException.Message;
                args.StatusMessage = "Error running query";
                PropertyInfo property = innerException.GetType().GetProperty("Line");
                PropertyInfo info2    = innerException.GetType().GetProperty("Column");
                if ((property != null) && (property.PropertyType == typeof(int)))
                {
                    args.ErrorLine = (int)property.GetValue(innerException, null);
                }
                if ((info2 != null) && (info2.PropertyType == typeof(int)))
                {
                    args.ErrorColumn = (int)info2.GetValue(innerException, null);
                }
                Console.WriteLine(innerException);
            }
            finally
            {
                stopwatch.Stop();
                args.ExecTime = stopwatch.Elapsed;
            }
            base.Server.PostStatus(args);
            return(null);
        }
 public override object Run()
 {
     if (base.Server.Repository == null)
     {
         base.Server.PostStatus(new QueryStatusEventArgs("Could not execute", "Error: no database specified"));
         return null;
     }
     if (string.IsNullOrEmpty(base.query))
     {
         base.Server.PostStatus(new QueryStatusEventArgs("Could not execute", "Error: empty query"));
         return null;
     }
     QueryStatusEventArgs args = new QueryStatusEventArgs();
     Stopwatch stopwatch = new Stopwatch();
     try
     {
         string customAssemblyPath = base.Server.Repository.CustomAssemblyPath;
         if (File.Exists(customAssemblyPath))
         {
             Assembly.LoadFrom(customAssemblyPath);
         }
         stopwatch.Start();
         base.Server.Repository.DriverLoader.Driver.ExecuteESqlQuery(base.Server.Repository, base.query);
     }
     catch (ThreadAbortException)
     {
         stopwatch.Stop();
     }
     catch (Exception innerException)
     {
         stopwatch.Stop();
         if (innerException is TargetInvocationException)
         {
             innerException = ((TargetInvocationException) innerException).InnerException;
         }
         args.ErrorMessage = innerException.GetType().Name + ": " + innerException.Message;
         args.StatusMessage = "Error running query";
         PropertyInfo property = innerException.GetType().GetProperty("Line");
         PropertyInfo info2 = innerException.GetType().GetProperty("Column");
         if ((property != null) && (property.PropertyType == typeof(int)))
         {
             args.ErrorLine = (int) property.GetValue(innerException, null);
         }
         if ((info2 != null) && (info2.PropertyType == typeof(int)))
         {
             args.ErrorColumn = (int) info2.GetValue(innerException, null);
         }
         Console.WriteLine(innerException);
     }
     finally
     {
         stopwatch.Stop();
         args.ExecTime = stopwatch.Elapsed;
     }
     base.Server.PostStatus(args);
     return null;
 }
Example #3
0
 internal void OnQueryStatusChanged(QueryStatusEventArgs args)
 {
     lock (this._locker)
     {
         if (this._cancelRequest)
         {
             return;
         }
         if (args.ExecutionComplete)
         {
             this._executionProgress = LINQPad.ExecutionModel.ExecutionProgress.Finished;
         }
     }
     this.OnQueryCompleted(args);
 }
Example #4
0
        protected virtual void OnQueryCompleted(QueryStatusEventArgs e)
        {
            lock (this._locker)
            {
                if (e.ExecutionComplete)
                {
                    this._executionProgress = LINQPad.ExecutionModel.ExecutionProgress.Finished;
                }
                else if (e.Async && (this._executionProgress < LINQPad.ExecutionModel.ExecutionProgress.Finished))
                {
                    this._executionProgress = LINQPad.ExecutionModel.ExecutionProgress.Async;
                }
            }
            EventHandler <QueryStatusEventArgs> queryCompleted = this.QueryCompleted;

            if (queryCompleted != null)
            {
                queryCompleted(this, e);
            }
            this.QueryCompiled = null;
        }
Example #5
0
 internal void OnQueryStatusChanged(QueryStatusEventArgs args)
 {
     lock (this._locker)
     {
         if (this._cancelRequest)
         {
             return;
         }
         if (args.ExecutionComplete)
         {
             this._executionProgress = LINQPad.ExecutionModel.ExecutionProgress.Finished;
         }
     }
     this.OnQueryCompleted(args);
 }
Example #6
0
 protected virtual void OnQueryCompleted(QueryStatusEventArgs e)
 {
     lock (this._locker)
     {
         if (e.ExecutionComplete)
         {
             this._executionProgress = LINQPad.ExecutionModel.ExecutionProgress.Finished;
         }
         else if (e.Async && (this._executionProgress < LINQPad.ExecutionModel.ExecutionProgress.Finished))
         {
             this._executionProgress = LINQPad.ExecutionModel.ExecutionProgress.Async;
         }
     }
     EventHandler<QueryStatusEventArgs> queryCompleted = this.QueryCompleted;
     if (queryCompleted != null)
     {
         queryCompleted(this, e);
     }
     this.QueryCompiled = null;
 }
Example #7
0
 private QueryStatusEventArgs GetStatusArgs(Exception ex, bool completion, bool dumpExceptions)
 {
     QueryStatusEventArgs exceptionArgs;
     if (ex != null)
     {
         ex = this.StripFrivolousWrappings(ex);
         exceptionArgs = this.GetExceptionArgs(ex);
         if (dumpExceptions)
         {
             try
             {
                 Console.WriteLine(ex);
             }
             catch
             {
             }
         }
     }
     else
     {
         exceptionArgs = new QueryStatusEventArgs();
         if (!(!completion || this._faulted))
         {
             exceptionArgs.StatusMessage = this._compilationHadWarnings ? "Query completed successfully with warnings" : "Query successful";
         }
     }
     exceptionArgs.ExecutionComplete = completion;
     if (this._queryStarted && completion)
     {
         exceptionArgs.ExecTime = this._executionStopwatch.Elapsed - this.ResultsWriter.FormattingTime;
         if (exceptionArgs.ExecTime < TimeSpan.Zero)
         {
             exceptionArgs.ExecTime = TimeSpan.Zero;
         }
     }
     if (IsWpfLoaded() && HasWpfMsgLoopRun())
     {
         exceptionArgs.AppDomainRecycleSuggested = true;
     }
     return exceptionArgs;
 }
Example #8
0
 private QueryStatusEventArgs GetExceptionArgs(Exception ex)
 {
     this._faulted = true;
     QueryStatusEventArgs completionArgs = new QueryStatusEventArgs();
     try
     {
         completionArgs.ErrorMessage = ex.GetType().Name + ": " + ex.Message;
         if (this._queryStarted)
         {
             completionArgs.StatusMessage = "Error running query";
             if (!(this.PopulateErrorSource(ex, completionArgs) || !(ex is AggregateException)))
             {
                 this.PopulateErrorSource(ex.InnerException, completionArgs);
             }
             return completionArgs;
         }
         completionArgs.StatusMessage = "Error starting query";
     }
     catch (Exception exception)
     {
         try
         {
             Log.Write(exception);
             completionArgs.StatusMessage = "Error running query";
         }
         catch
         {
         }
     }
     return completionArgs;
 }
Example #9
0
 private void RunQuery(QueryRunner runner)
 {
     Action<Task> continuationAction = null;
     Action a = null;
     object obj2;
     runner.Prepare();
     this.QueryCompletionCountdown = new Countdown();
     this.Disposables = new List<IDisposable>();
     this.LambdaFormatter = new XhtmlWriter(false, false);
     LINQPadDbController.SqlLog = new StringWriterEx(0xf4240);
     DataContextBase.SqlLog = LINQPadDbController.SqlLog;
     this.ResultsWriter = new XhtmlWriter(true, true);
     this._explorables = this.ResultsWriter.Explorables;
     Console.SetOut(this.ResultsWriter);
     Console.SetIn(new ConsoleTextReader(new Func<string>(this.ReadLine)));
     Debug.Listeners.Clear();
     Debug.Listeners.Add(new TextWriterTraceListener(this.ResultsWriter));
     XhtmlFormatter.ResetTableID();
     lock ((obj2 = this._statusLocker))
     {
         if (this._cancelRequest)
         {
             return;
         }
     }
     object obj3 = null;
     try
     {
         obj3 = runner.Run();
     }
     catch (Exception exception)
     {
         this.PostStatus(this.GetStatusArgs(exception, false, true));
     }
     if (obj3 is Task)
     {
         this.QueryCompletionCountdown.Increment();
         QueryStatusEventArgs args = new QueryStatusEventArgs("Query continuing asynchronously...") {
             ExecutionComplete = false,
             Async = true
         };
         this.PostStatus(args);
         if (continuationAction == null)
         {
             continuationAction = delegate (Task ant) {
                 try
                 {
                     Exception ex = this.GetTaskException(ant);
                     if (ex != null)
                     {
                         this._faulted = true;
                         this.PostStatus(this.GetStatusArgs(ex, true, true));
                     }
                 }
                 catch
                 {
                 }
                 this.QueryCompletionCountdown.Decrement();
             };
         }
         ((Task) obj3).ContinueWith(continuationAction);
     }
     if (this.QueryCompletionCountdown.Value <= 0)
     {
         this._executionStopwatch.Stop();
     }
     lock ((obj2 = this._statusLocker))
     {
         if (this._cancelRequest)
         {
             return;
         }
     }
     PluginForm pluginForm = null;
     pluginForm = this.PrepareMessageLoop();
     if (pluginForm != null)
     {
         this.QueryCompletionCountdown.Increment();
     }
     if (this.QueryCompletionCountdown.Value <= 0)
     {
         this.PostStatus(this.GetStatusArgs(null, true, true));
         this.PerformCompletionCleanup(false, false);
     }
     else
     {
         QueryStatusEventArgs args2 = new QueryStatusEventArgs("Query continuing asynchronously...") {
             ExecutionComplete = false,
             Async = true
         };
         this.PostStatus(args2);
         if (a == null)
         {
             a = delegate {
                 this.PostStatus(this.GetStatusArgs(null, true, true));
                 this.PerformCompletionCleanup(false, false);
             };
         }
         this.QueryCompletionCountdown.ContinueWith(a);
     }
     this.RunMessageLoop(pluginForm, true);
 }
Example #10
0
 public void ReportSpecialMessage(StackTrace trace, string status, string message, bool isWarning, bool isInfo)
 {
     QueryStatusEventArgs args = new QueryStatusEventArgs(status, message) {
         ExecutionComplete = false
     };
     StackFrame[] queryFrames = GetQueryFrames(trace);
     if (queryFrames.Length > 0)
     {
         StackFrame frame = queryFrames[0];
         args.ErrorLine = frame.GetFileLineNumber() - this._lineOffset;
         args.ErrorColumn = frame.GetFileColumnNumber();
         args.ErrorFileName = frame.GetFileName();
         args.IsInfo = isInfo;
         args.IsWarning = isWarning;
         if (args.ErrorLine == this._lastSpecialMessageLine)
         {
             return;
         }
         this._lastSpecialMessageLine = args.ErrorLine;
     }
     if (this._client != null)
     {
         this._client.OnQueryStatusChanged(args);
     }
 }
Example #11
0
 public void PostStatus(QueryStatusEventArgs args)
 {
     Client client;
     lock (this._statusLocker)
     {
         client = this._client;
         if ((this._cancelRequest || (client == null)) || (this._finished && string.IsNullOrEmpty(args.ErrorMessage)))
         {
             return;
         }
         if (args.ExecutionComplete)
         {
             this._executionStopwatch.Stop();
             this._finished = true;
             if (this._executionTrackSignal != null)
             {
                 try
                 {
                     this._executionTrackSignal.Set();
                 }
                 catch
                 {
                 }
             }
         }
     }
     client.OnQueryStatusChanged(args);
 }
Example #12
0
 private bool PopulateErrorSource(Exception ex, QueryStatusEventArgs completionArgs)
 {
     Func<StackFrame, int> selector = null;
     StackTrace trace = new StackTrace(ex, true);
     StackFrame[] queryFrames = GetQueryFrames(trace);
     if (queryFrames.Length > 0)
     {
         completionArgs.ErrorLine = queryFrames[0].GetFileLineNumber() - this._lineOffset;
         completionArgs.ErrorColumn = queryFrames[0].GetFileColumnNumber();
         completionArgs.ErrorFileName = queryFrames[0].GetFileName();
         if (queryFrames.Length > 1)
         {
             if (selector == null)
             {
                 selector = f => f.GetFileLineNumber() - this._lineOffset;
             }
             completionArgs.StackTraceLines = queryFrames.Skip<StackFrame>(1).Select<StackFrame, int>(selector).ToArray<int>();
             completionArgs.StackTraceColumns = (from f in queryFrames.Skip<StackFrame>(1) select f.GetFileColumnNumber()).ToArray<int>();
         }
         return true;
     }
     if (ex.StackTrace != null)
     {
         int num;
         Match match = Regex.Match(ex.StackTrace.Replace("\r\n", ""), @"Server stack trace:.*?at UserQuery\..+? in (.+?\.cs):line (\d+)");
         if ((match.Success && (match.Groups.Count == 3)) && int.TryParse(match.Groups[2].Value, out num))
         {
             completionArgs.ErrorLine = num - this._lineOffset;
             completionArgs.ErrorFileName = match.Groups[1].Value;
             return true;
         }
     }
     return false;
 }
 public override object Run()
 {
     if (base.Server.Repository == null)
     {
         base.Server.PostStatus(new QueryStatusEventArgs("Could not execute", "Error: no database specified"));
         return null;
     }
     QueryStatusEventArgs args = new QueryStatusEventArgs();
     int num = 0;
     Stopwatch stopwatch = new Stopwatch();
     try
     {
         IDbConnection proxy = Server.OpenCachedCx(base.Server.Repository);
         if (proxy is LINQPadDbConnection)
         {
             proxy = ((LINQPadDbConnection) proxy).Proxy;
         }
         MatchCollection matchs = Regex.Matches(base.query, @"^\s*go\s*$", RegexOptions.Multiline | RegexOptions.IgnoreCase);
         int num2 = 0;
         int startIndex = 0;
         int num4 = 0;
         while (num2 != matchs.Count)
         {
             string input = base.query.Substring(startIndex, matchs[num2].Index - startIndex) + "\r\n";
             startIndex = matchs[num2].Index + matchs[num2].Length;
         Label_00DB:
             if (input.Trim().Length > 0)
             {
                 DbProviderFactory providerFactory = base.Server.Repository.GetProviderFactory(proxy as DbConnection);
                 DbDataAdapter adapter = providerFactory.CreateDataAdapter();
                 DbCommand command = providerFactory.CreateCommand();
                 if (command is LINQPadDbCommand)
                 {
                     command = ((LINQPadDbCommand) command).Proxy;
                 }
                 if (proxy.GetType().Name.ToString().IndexOf("Oracle", StringComparison.OrdinalIgnoreCase) > -1)
                 {
                     command.CommandText = input.Replace("\r\n", "\n");
                 }
                 else
                 {
                     command.CommandText = input;
                 }
                 command.Connection = (DbConnection) proxy;
                 command.CommandTimeout = 0;
                 adapter.SelectCommand = command;
                 base.Server.RunningCmd = command;
                 DataSet ds = new DataSet();
                 LINQPadDbController.SqlLog.WriteLine(Regex.Replace(input, "(?<!\r)\n", "\r\n").Trim() + "\r\n\r\nGO\r\n");
                 stopwatch.Start();
                 SqlConnection connection2 = proxy as SqlConnection;
                 SortedDictionary<int, StringBuilder> messages = new SortedDictionary<int, StringBuilder>();
                 SqlInfoMessageEventHandler handler = delegate (object sender, SqlInfoMessageEventArgs e) {
                     int key = ds.Tables.Count;
                     if (key == 0)
                     {
                         this.Server.ResultsWriter.WriteLine(e.Message);
                     }
                     else if (messages.ContainsKey(key))
                     {
                         messages[key].Append("\r\n" + e.Message);
                     }
                     else
                     {
                         messages[key] = new StringBuilder(e.Message);
                     }
                 };
                 try
                 {
                     if (connection2 != null)
                     {
                         connection2.InfoMessage += handler;
                     }
                     adapter.Fill(ds);
                 }
                 finally
                 {
                     stopwatch.Stop();
                     base.Server.RunningCmd = null;
                     if (connection2 != null)
                     {
                         connection2.InfoMessage -= handler;
                     }
                 }
                 int num5 = 0;
                 foreach (DataTable table in ds.Tables)
                 {
                     if (base.Server.WriteResultsToGrids)
                     {
                         table.Explore<DataTable>("Grid " + ++num4);
                     }
                     else
                     {
                         base.Server.ResultsWriter.WriteLine(table);
                     }
                     if (messages.ContainsKey(++num5))
                     {
                         base.Server.ResultsWriter.WriteLine(messages[num5].ToString());
                     }
                 }
             }
             num = base.query.Substring(0, startIndex).Count<char>(c => c == '\n');
             if (num2++ < matchs.Count)
             {
                 continue;
             }
             goto Label_039B;
         Label_0372:
             input = base.query.Substring(startIndex);
             goto Label_00DB;
         }
         goto Label_0372;
     Label_039B:
         args.StatusMessage = "Query successful";
         base.Server.ResultsWriter.Flush();
         if (base.Server.Repository.DynamicSchema)
         {
             args.DataContextRefreshRequired = true;
         }
     }
     catch (SqlException exception)
     {
         args.ErrorMessage = string.Concat(new object[] { "Error ", exception.Number, ": ", exception.Message });
         args.StatusMessage = "Runtime error";
         args.ErrorLine = exception.LineNumber + num;
     }
     catch (Exception exception2)
     {
         args.ErrorMessage = exception2.Message;
         args.StatusMessage = "Runtime error";
     }
     args.ExecTime = stopwatch.Elapsed;
     base.Server.PostStatus(args);
     return null;
 }
Example #14
0
 private void OnQueryCompleted(QueryStatusEventArgs args)
 {
     if (this.QueryCompleted != null)
     {
         this.QueryCompleted(this, args);
     }
 }
Example #15
0
 private void _client_QueryCompleted(object sender, QueryStatusEventArgs e)
 {
     lock (this._executionLock)
     {
         if (sender != this._client)
         {
             return;
         }
         if (e.ExecutionComplete)
         {
             this._queryWatch.Stop();
         }
         this._queryStarting = false;
         if (e.AppDomainRecycleSuggested)
         {
             this.PolluteCachedDomain(false);
         }
     }
     this.OnQueryCompleted(e);
     if (e.DataContextRefreshRequired && this._querySnapshot.Repository.IsEquivalent(base.Repository))
     {
         DataContextManager.RefreshDataContextInfo(base.Repository, SchemaChangeTestMode.TestAndFailNegative);
     }
 }
Example #16
0
 private void _query_QueryCompleted(object sender, QueryStatusEventArgs e)
 {
     if (e.ExecutionComplete)
     {
         this._clockTimer.Stop();
     }
     this.BeginInvoke(() => this.QueryCompleted(e));
 }
Example #17
0
 private void QueryCompleted(QueryStatusEventArgs e)
 {
     Exception exception;
     if (e.ExecutionComplete)
     {
         this._gotQueryCompletionMessage = true;
         this._executionTrackingTimer.Stop();
         this.ClearExecutionTrackingIndicators();
         if (this._editor.get_Document().get_LineIndicators().get_Count() == 0)
         {
             this._editor.set_IndicatorMarginVisible(false);
         }
     }
     this._refreshTimer.Interval = 1;
     try
     {
         this.ShowResultsUponQueryStart();
         if (!string.IsNullOrEmpty(e.StatusMessage))
         {
             this.lblStatus.Text = e.StatusMessage;
         }
         if (!(string.IsNullOrEmpty(e.ErrorMessage) || this.panError.Visible))
         {
             if (!e.IsInfo)
             {
                 this.DisplayError(e.ErrorMessage);
             }
         }
         else if ((e.ExecutionComplete && (e.ExecTime.TotalMilliseconds > 0.0)) && this.lblElapsed.Visible)
         {
             TimeSpan execTime = e.ExecTime;
             string str = execTime.Minutes.ToString("D2") + ":" + execTime.Seconds.ToString("D2") + "." + execTime.Milliseconds.ToString("D3");
             if (execTime.Hours > 0)
             {
                 str = ((int) execTime.TotalHours) + ":" + str;
             }
             this.lblExecTime.Text = "(" + str + ")";
             this.lblExecTime.Visible = true;
         }
         if ((e.ErrorLine > 0) && !this._modifiedWhenRunning)
         {
             this.HighlightErrorOrWarning(e.ErrorLine - 1, e.ErrorColumn - 1, e.ErrorMessage, e.IsWarning || e.IsInfo, false, !e.IsInfo);
             if ((e.StackTraceLines != null) && (e.StackTraceColumns != null))
             {
                 for (int i = 0; i < e.StackTraceLines.Length; i++)
                 {
                     this.HighlightStackTraceError(e.StackTraceLines[i] - 1, e.StackTraceColumns[i] - 1);
                 }
             }
         }
     }
     catch (Exception exception1)
     {
         exception = exception1;
         Program.ProcessException(exception);
     }
     finally
     {
         try
         {
             if (e.ExecutionComplete)
             {
                 this.lblElapsed.Visible = false;
             }
             this.EnableControls();
             if (e.ExecutionComplete && ((GC.GetTotalMemory(false) - this._memoryAtStart) > 0x2faf080L))
             {
                 MainForm.Instance.TriggerGC(2);
             }
         }
         catch (Exception exception2)
         {
             exception = exception2;
             Program.ProcessException(exception);
         }
     }
 }
Example #18
0
        public override object Run()
        {
            if (base.Server.Repository == null)
            {
                base.Server.PostStatus(new QueryStatusEventArgs("Could not execute", "Error: no database specified"));
                return(null);
            }
            QueryStatusEventArgs args = new QueryStatusEventArgs();
            int       num             = 0;
            Stopwatch stopwatch       = new Stopwatch();

            try
            {
                IDbConnection proxy = Server.OpenCachedCx(base.Server.Repository);
                if (proxy is LINQPadDbConnection)
                {
                    proxy = ((LINQPadDbConnection)proxy).Proxy;
                }
                MatchCollection matchs     = Regex.Matches(base.query, @"^\s*go\s*$", RegexOptions.Multiline | RegexOptions.IgnoreCase);
                int             num2       = 0;
                int             startIndex = 0;
                int             num4       = 0;
                while (num2 != matchs.Count)
                {
                    string input = base.query.Substring(startIndex, matchs[num2].Index - startIndex) + "\r\n";
                    startIndex = matchs[num2].Index + matchs[num2].Length;
Label_00DB:
                    if (input.Trim().Length > 0)
                    {
                        DbProviderFactory providerFactory = base.Server.Repository.GetProviderFactory(proxy as DbConnection);
                        DbDataAdapter     adapter         = providerFactory.CreateDataAdapter();
                        DbCommand         command         = providerFactory.CreateCommand();
                        if (command is LINQPadDbCommand)
                        {
                            command = ((LINQPadDbCommand)command).Proxy;
                        }
                        if (proxy.GetType().Name.ToString().IndexOf("Oracle", StringComparison.OrdinalIgnoreCase) > -1)
                        {
                            command.CommandText = input.Replace("\r\n", "\n");
                        }
                        else
                        {
                            command.CommandText = input;
                        }
                        command.Connection     = (DbConnection)proxy;
                        command.CommandTimeout = 0;
                        adapter.SelectCommand  = command;
                        base.Server.RunningCmd = command;
                        DataSet ds = new DataSet();
                        LINQPadDbController.SqlLog.WriteLine(Regex.Replace(input, "(?<!\r)\n", "\r\n").Trim() + "\r\n\r\nGO\r\n");
                        stopwatch.Start();
                        SqlConnection connection2 = proxy as SqlConnection;
                        SortedDictionary <int, StringBuilder> messages = new SortedDictionary <int, StringBuilder>();
                        SqlInfoMessageEventHandler            handler  = delegate(object sender, SqlInfoMessageEventArgs e) {
                            int key = ds.Tables.Count;
                            if (key == 0)
                            {
                                this.Server.ResultsWriter.WriteLine(e.Message);
                            }
                            else if (messages.ContainsKey(key))
                            {
                                messages[key].Append("\r\n" + e.Message);
                            }
                            else
                            {
                                messages[key] = new StringBuilder(e.Message);
                            }
                        };
                        try
                        {
                            if (connection2 != null)
                            {
                                connection2.InfoMessage += handler;
                            }
                            adapter.Fill(ds);
                        }
                        finally
                        {
                            stopwatch.Stop();
                            base.Server.RunningCmd = null;
                            if (connection2 != null)
                            {
                                connection2.InfoMessage -= handler;
                            }
                        }
                        int num5 = 0;
                        foreach (DataTable table in ds.Tables)
                        {
                            if (base.Server.WriteResultsToGrids)
                            {
                                table.Explore <DataTable>("Grid " + ++num4);
                            }
                            else
                            {
                                base.Server.ResultsWriter.WriteLine(table);
                            }
                            if (messages.ContainsKey(++num5))
                            {
                                base.Server.ResultsWriter.WriteLine(messages[num5].ToString());
                            }
                        }
                    }
                    num = base.query.Substring(0, startIndex).Count <char>(c => c == '\n');
                    if (num2++ < matchs.Count)
                    {
                        continue;
                    }
                    goto Label_039B;
Label_0372:
                    input = base.query.Substring(startIndex);
                    goto Label_00DB;
                }
                goto Label_0372;
Label_039B:
                args.StatusMessage = "Query successful";
                base.Server.ResultsWriter.Flush();
                if (base.Server.Repository.DynamicSchema)
                {
                    args.DataContextRefreshRequired = true;
                }
            }
            catch (SqlException exception)
            {
                args.ErrorMessage  = string.Concat(new object[] { "Error ", exception.Number, ": ", exception.Message });
                args.StatusMessage = "Runtime error";
                args.ErrorLine     = exception.LineNumber + num;
            }
            catch (Exception exception2)
            {
                args.ErrorMessage  = exception2.Message;
                args.StatusMessage = "Runtime error";
            }
            args.ExecTime = stopwatch.Elapsed;
            base.Server.PostStatus(args);
            return(null);
        }