private ScriptExecutionResult DoBatchExecution(Batch batch)
        {
            Validate.IsNotNull(nameof(batch), batch);

            ScriptExecutionResult result = ScriptExecutionResult.Success;

            // TODO, fawinter: Do I need to keep this batch?
            if (batch.HasValidText)
            {
                try
                {
                    // Parsing mode we execute only once
                    if (conditions.IsParseOnly)
                    {
                        numBatchExecutionTimes = 1;
                    }

                    int timesLoop = numBatchExecutionTimes;
                    if (numBatchExecutionTimes > 1)
                    {
                        RaiseBatchMessage(String.Format(CultureInfo.CurrentCulture, SR.EE_ExecutionInfo_InitilizingLoop, numBatchExecutionTimes));
                    }

                    while (timesLoop > 0 && result != ScriptExecutionResult.Cancel && result != ScriptExecutionResult.Halted)
                    {
                        result = batch.Execute(connection, expectedShowPlan);

                        Debug.Assert(connection != null);
                        if (connection == null || connection.State != ConnectionState.Open)
                        {
                            result = ScriptExecutionResult.Halted;
                        }

                        if (result == ScriptExecutionResult.Failure)
                        {
                            if (errorAction == OnErrorAction.Ignore)
                            {
                                if (numBatchExecutionTimes > 1)
                                {
                                    RaiseBatchMessage(SR.EE_BatchExecutionError_Ignoring);
                                }
                            }
                            else
                            {
                                RaiseBatchMessage(SR.EE_BatchExecutionError_Halting);
                                result = ScriptExecutionResult.Halted;
                            }
                        }

                        timesLoop--;
                    }


                    if (result == ScriptExecutionResult.Cancel)
                    {
                        RaiseBatchMessage(String.Format(CultureInfo.CurrentCulture, SR.EE_ExecutionInfo_QueryCancelledbyUser));
                    }
                    else
                    {
                        if (numBatchExecutionTimes > 1)
                        {
                            RaiseBatchMessage(String.Format(CultureInfo.CurrentCulture, SR.EE_ExecutionInfo_FinalizingLoop, numBatchExecutionTimes));
                        }
                    }
                }
                catch (OutOfMemoryException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    // if anything goes wrong it will shutdown VS
                    Logger.Write(LogLevel.Error, "Exception Caught in ExecutionEngine.DoBatchExecution(Batch) :" + ex.ToString());
                    result = ScriptExecutionResult.Failure;
                }
            }
            else
            {
                // TODO, fawinter: Success will be returned on an Empty text batch
            }

            return(result);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Contructor method for the class
 /// </summary>
 public BatchParserExecutionStartEventArgs(TextSpan textSpan, Batch batch)
 {
     this.batch    = batch;
     this.textSpan = textSpan;
 }