Example #1
0
 /// <summary> Cancel a running query synchronously (ie wait for it to cancel)
 /// This method is called when closing an executing query.
 /// </summary>
 public virtual void Cancel()
 {
     if (runState == RunStates.Running)
     {
         DoCancel();
         WaitForWorker();
         runState = RunStates.Idle;
     }
 }
Example #2
0
        protected virtual void InformCancelDone()
        {
            WaitForWorker();
            runState = RunStates.Idle;
            if (CancelDone != null)
            {
//            if (host != null)
                //                host.Invoke(CancelDone, new object[] {this, EventArgs.Empty});
                //            else
                CancelDone(this, EventArgs.Empty);
            }
        }
Example #3
0
 private void DoExecuteBatchesAsync()
 {
     execStartTime = DateTime.Now;
     SetupBatch();
     foreach (string query in queries)
     {
         IDataReader dr = null;
         try
         {
             selectCommand = GetDbCommand(query);
             selectCommand.CommandTimeout = queryOptions.ExecutionTimeout;
             dr = selectCommand.ExecuteReader();
             ReturnResults(dr);
             dr.Close();
         }
         catch (Exception ex)
         {
             ErrorEventArgs args = new ErrorEventArgs(ex.Message, ex);
             OnError(this, args);
             if ((ex as DbException) != null)
             {
                 if (connection.State == ConnectionState.Open)   // do not cancel if conneciton is still open
                 {
                     args.Cancel = false;
                 }
             }
             if (args.Cancel)
             {
                 break;
             }
         }
         finally
         {
             if (!(dr == null) && !dr.IsClosed)
             {
                 try { dr.Close(); }
                 catch (Exception) { }
             }
         }
     }
     ResetBatch();
     execDuration = DateTime.Now.Subtract(execStartTime);
     if (runState == RunStates.Cancelling)
     {
         return;
     }
     runState = RunStates.Idle;
     OnBatchDone(this, null);
 }
Example #4
0
 protected virtual void DoCancel()
 {
     if (runState == RunStates.Running)
     {
         runState = RunStates.Cancelling;
         // We have to cancel on a new thread - separate to the main worker thread (because the
         // worker thread will be busy) and separate to the main thread (as this is locked into the
         // main UI apartment, and its use could cause subsequent corruption to an ODBC connection).
         Thread cancelThread = new Thread(new ThreadStart(selectCommand.Cancel));
         cancelThread.Name = "DbClient Cancel Thread";
         cancelThread.Start();
         // wait for the command to finish: this won't take long (however the main worker thread that is
         // executing the actual command make take a while to register the cancel request & tidy up)
         cancelThread.Join();
     }
 }
Example #5
0
        public void Execute(string query)
        {
            // If 'GO' keyword is present, separate each subquery, so they can be run separately.
            // Use Regex class, as we need a case insensitive match.

            string          separator = queryOptions == null ? "GO" : queryOptions.BatchSeparator;
            Regex           r         = new Regex(string.Format(@"^\s*{0}\s*$", separator), RegexOptions.IgnoreCase | RegexOptions.Multiline);
            MatchCollection mc        = r.Matches(query);

            queries = new ArrayList();
            int pos = 0;

            foreach (Match m in mc)
            {
                string sub = query.Substring(pos, m.Index - pos).Trim();
                if (sub.Length > 0)
                {
                    queries.Add(sub);
                }
                pos = m.Index + m.Length + 1;
            }

            if (pos < query.Length)
            {
                string finalQuery = query.Substring(pos).Trim();
                if (finalQuery.Length > 0)
                {
                    queries.Add(finalQuery);
                }
            }

            runState = RunStates.Running;

            RunOnWorker(new MethodInvoker(DoExecuteBatchesAsync));
            return;
        }
Example #6
0
 public void ToolStarted(object sender)
 {
     this.RunState = RunStates.Running;
 }
Example #7
0
 public void ToolCompleted(object sender, Tool.Result e)
 {
     if (e.Error == null)
     {
         this.RunState = RunStates.Succeeded;
         if (this._autoCloseOnSuccess && string.IsNullOrEmpty(e.StdErr))
         {
             this.DialogResult = DialogResult.OK;
         }
     }
     else
     {
         this.AddLogLine("");
         this.AddLogLine(e.Error.Message, true, true);
         if (e.Cancelled)
         {
             this.RunState = RunStates.Cancelled;
         }
         else
         {
             this.RunState = RunStates.Failed;
         }
     }
 }