Exemplo n.º 1
0
        /// <summary>
        /// Binds/Unbinds the methods defined in IBatchEventHandlers with the batch events
        /// </summary>
        /// <param name="batch">Batch to be used in the event binding</param>
        /// <param name="handlers">object implementing the IBatcgEventHandlers interface</param>
        /// <param name="isHookup">Binds or Unbinds the evnts</param>
        private static void ConfigureBatchEventHandlers(Batch batch, IBatchEventsHandler handlers, bool isHookup)
        {
            Validate.IsNotNull(nameof(batch), batch);

            if (isHookup)
            {
                Validate.IsNotNull(nameof(handlers), handlers);

                batch.BatchError               += new EventHandler <BatchErrorEventArgs>(handlers.OnBatchError);
                batch.BatchMessage             += new EventHandler <BatchMessageEventArgs>(handlers.OnBatchMessage);
                batch.BatchResultSetProcessing += new EventHandler <BatchResultSetEventArgs>(handlers.OnBatchResultSetProcessing);
                batch.BatchResultSetFinished   += new EventHandler <EventArgs>(handlers.OnBatchResultSetFinished);
                batch.BatchCancelling          += new EventHandler <EventArgs>(handlers.OnBatchCancelling);
            }
            else
            {
                if (handlers != null)
                {
                    batch.BatchError               -= new EventHandler <BatchErrorEventArgs>(handlers.OnBatchError);
                    batch.BatchMessage             -= new EventHandler <BatchMessageEventArgs>(handlers.OnBatchMessage);
                    batch.BatchResultSetProcessing -= new EventHandler <BatchResultSetEventArgs>(handlers.OnBatchResultSetProcessing);
                    batch.BatchResultSetFinished   -= new EventHandler <EventArgs>(handlers.OnBatchResultSetFinished);
                    batch.BatchCancelling          -= new EventHandler <EventArgs>(handlers.OnBatchCancelling);
                }
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Constructor method for ScriptExecutionArgs
 /// </summary>
 public ScriptExecutionArgs(
     string script,
     IDbConnection connection,
     int timeOut,
     ExecutionEngineConditions conditions,
     IBatchEventsHandler batchEventHandlers)
     : this(script, connection, timeOut, conditions, batchEventHandlers, 0, null)
 {
     // nothing
 }
        /// <summary>
        /// Parses the script locally
        /// </summary>
        /// <param name="script">script to parse</param>
        /// <param name="batchEventsHandler">batch handler</param>
        /// <remarks>
        /// The batch parser functionality is used in this case
        /// </remarks>
        public void ParseScript(string script, IBatchEventsHandler batchEventsHandler)
        {
            Validate.IsNotNull(nameof(script), script);
            Validate.IsNotNull(nameof(batchEventsHandler), batchEventsHandler);


            this.script        = script;
            batchEventHandlers = batchEventsHandler;
            isLocalParse       = true;

            DoExecute(/* isBatchParser */ true);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Constructor method for ScriptExecutionArgs
 /// </summary>
 public ScriptExecutionArgs(
     string script,
     SqlConnection connection,
     int timeOut,
     ExecutionEngineConditions conditions,
     IBatchEventsHandler batchEventHandlers,
     int startingLine,
     IDictionary <string, string> variables)
     : this(script, (IDbConnection)connection, timeOut, conditions, batchEventHandlers, startingLine, variables)
 {
     // nothing
 }
Exemplo n.º 5
0
        /// <summary>
        /// Resets the script's related fields
        /// </summary>
        /// <remarks>
        /// Once the execution thread is nulled, all handles will be closed and GC will collect it
        /// </remarks>
        private void ResetScript()
        {
            lock (stateSyncLock)
            {
                executionState = ExecutionState.Initial;
            }

            ConfigurePrePostConditionBatches(preConditionBatches);
            ConfigurePrePostConditionBatches(postConditionBatches);

            currentBatchIndex  = -1;
            conditions         = null;
            batchEventHandlers = null;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Parses the script locally
        /// </summary>
        /// <param name="script">script to parse</param>
        /// <param name="batchEventsHandler">batch handler</param>
        /// <param name="conditions">execution engine conditions if specified</param>
        /// <remarks>
        /// The batch parser functionality is used in this case
        /// </remarks>
        public void ParseScript(string script, IBatchEventsHandler batchEventsHandler, ExecutionEngineConditions conditions = null)
        {
            Validate.IsNotNull(nameof(script), script);
            Validate.IsNotNull(nameof(batchEventsHandler), batchEventsHandler);

            if (conditions != null)
            {
                this.conditions = conditions;
            }
            this.script        = script;
            batchEventHandlers = batchEventsHandler;
            isLocalParse       = true;

            DoExecute(/* isBatchParser */ true);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Setups the script execution
        /// </summary>
        /// <param name="scriptExecutionArgs"></param>
        private void ExecuteInternal(ScriptExecutionArgs scriptExecutionArgs, bool isBatchParser)
        {
            Validate.IsNotNull(nameof(scriptExecutionArgs), scriptExecutionArgs);

            Validate.IsNotNullOrEmptyString(nameof(scriptExecutionArgs.Script), scriptExecutionArgs.Script);
            Validate.IsNotNull(nameof(scriptExecutionArgs.ReliableConnection), scriptExecutionArgs.ReliableConnection);
            Validate.IsNotNull(nameof(scriptExecutionArgs.Conditions), scriptExecutionArgs.Conditions);
            Validate.IsNotNull(nameof(scriptExecutionArgs.BatchEventHandlers), scriptExecutionArgs.BatchEventHandlers);

            Debug.Assert(scriptExecutionArgs.TimeOut >= 0);

            executionTimeout   = scriptExecutionArgs.TimeOut < 0 ? 0 : scriptExecutionArgs.TimeOut;
            connection         = scriptExecutionArgs.ReliableConnection;
            conditions         = new ExecutionEngineConditions(scriptExecutionArgs.Conditions);
            script             = scriptExecutionArgs.Script;
            isSqlCmdConnection = false;
            batchEventHandlers = scriptExecutionArgs.BatchEventHandlers;
            startingLine       = scriptExecutionArgs.StartingLine;
            internalVariables  = scriptExecutionArgs.Variables;

            DoExecute(isBatchParser);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Constructor method for ScriptExecutionArgs
        /// </summary>
        public ScriptExecutionArgs(
            string script,
            IDbConnection connection,
            int timeOut,
            ExecutionEngineConditions conditions,
            IBatchEventsHandler batchEventHandlers,
            int startingLine,
            IDictionary <string, string> variables)
        {
            Script                  = script;
            this.connection         = connection;
            TimeOut                 = timeOut;
            Conditions              = conditions;
            this.batchEventHandlers = batchEventHandlers;
            this.startingLine       = startingLine;

            if (variables != null)
            {
                foreach (var variable in variables)
                {
                    Variables[variable.Key] = variable.Value;
                }
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Execut the script
        /// </summary>
        /// <param name="exec">Execution Engine</param>
        /// <param name="connection">SQL connection</param>
        /// <param name="script">script text</param>
        /// <param name="conditions">Execution condition</param>
        /// <param name="batchHandler">Batch event handler</param>
        /// <param name="timeout">time out value</param>
        static void ExecuteScript(ExecutionEngine exec, SqlConnection connection, string script, ExecutionEngineConditions conditions, IBatchEventsHandler batchHandler, int timeout)
        {
            Validate.IsNotNull(nameof(exec), exec);
            Validate.IsNotNull(nameof(connection), connection);
            Validate.IsNotNullOrEmptyString(nameof(script), script);
            Validate.IsNotNull(nameof(conditions), conditions);

            Console.WriteLine("------------------------ Executing Script ----------------------");

            //exec.BeginScriptExecution(script, connection, timeout, conditions, batchConsumer);
            ScriptExecutionArgs args = new ScriptExecutionArgs(script, connection, timeout, conditions, batchHandler);

            //exec.ExecuteScript(args);

            _executionThread = new Thread(new ParameterizedThreadStart(exec.ExecuteScript));
            _executionThread.Start(args);
        }