示例#1
0
        private ListViewItem CreateScriptCommandListViewItem(Core.AutomationCommands.ScriptCommand cmdDetails)
        {
            ListViewItem newCommand = new ListViewItem();

            newCommand.Text = cmdDetails.GetDisplayValue(); //+ "(" + cmdDetails.SelectedVariables() + ")";
            newCommand.SubItems.Add(cmdDetails.GetDisplayValue());
            newCommand.Tag       = cmdDetails;
            newCommand.ForeColor = cmdDetails.DisplayForeColor;

            newCommand.ImageIndex = uiImages.Images.IndexOfKey(cmdDetails.GetType().Name);
            return(newCommand);
        }
        public void ExecuteCommand(Core.Script.ScriptAction command)
        {
            //get command
            Core.AutomationCommands.ScriptCommand parentCommand = command.ScriptCommand;

            //update execution line numbers
            LineNumberChanged(parentCommand.LineNumber);

            //handle pause request
            if (parentCommand.PauseBeforeExeucution)
            {
                ReportProgress("Pausing Before Execution");
                IsScriptPaused = true;
            }

            //handle pause
            bool isFirstWait = true;

            while (IsScriptPaused)
            {
                //only show pause first loop
                if (isFirstWait)
                {
                    CurrentStatus = EngineStatus.Paused;
                    ReportProgress("Paused at Line " + parentCommand.LineNumber + " - " + parentCommand.GetDisplayValue());
                    ReportProgress("Paused on Line " + parentCommand.LineNumber + ": " + parentCommand.GetDisplayValue());
                    ReportProgress("[Please select 'Resume' when ready]");
                    isFirstWait = false;
                }

                //wait
                System.Threading.Thread.Sleep(2000);
            }

            CurrentStatus = EngineStatus.Running;

            //handle if cancellation was requested
            if (IsCancellationPending)
            {
                return;
            }


            //bypass comments
            if (parentCommand is Core.AutomationCommands.CommentCommand || parentCommand.IsCommented)
            {
                ReportProgress("Skipping Line " + parentCommand.LineNumber + ": " + parentCommand.GetDisplayValue().ConvertToUserVariable(this));
                return;
            }

            //report intended execution
            ReportProgress("Running Line " + parentCommand.LineNumber + ": " + parentCommand.GetDisplayValue());


            //handle any errors
            try
            {
                //determine type of command
                if ((parentCommand is Core.AutomationCommands.BeginNumberOfTimesLoopCommand) || (parentCommand is Core.AutomationCommands.BeginContinousLoopCommand) || (parentCommand is Core.AutomationCommands.BeginListLoopCommand) || (parentCommand is Core.AutomationCommands.BeginIfCommand) || parentCommand is Core.AutomationCommands.BeginExcelDatasetLoopCommand)
                {
                    //run the command and pass bgw/command as this command will recursively call this method for sub commands
                    parentCommand.RunCommand(this, command);
                }
                else if (parentCommand is Core.AutomationCommands.SequenceCommand)
                {
                    parentCommand.RunCommand(this, command);
                }
                else if (parentCommand is Core.AutomationCommands.StopTaskCommand)
                {
                    IsCancellationPending = true;
                    return;
                }
                else if (parentCommand is Core.AutomationCommands.ExitLoopCommand)
                {
                    CurrentLoopCancelled = true;
                }
                else if (parentCommand is Core.AutomationCommands.SetEngineDelayCommand)
                {
                    //get variable
                    var setEngineCommand = (Core.AutomationCommands.SetEngineDelayCommand)parentCommand;
                    var engineDelay      = setEngineCommand.v_EngineSpeed.ConvertToUserVariable(this);
                    var delay            = int.Parse(engineDelay);

                    //update delay setting
                    this.engineSettings.DelayBetweenCommands = delay;
                }
                else
                {
                    //sleep required time
                    System.Threading.Thread.Sleep(engineSettings.DelayBetweenCommands);

                    //run the command
                    parentCommand.RunCommand(this);
                }
            }
            catch (Exception ex)
            {
                ErrorsOccured.Add(new ScriptError()
                {
                    LineNumber = parentCommand.LineNumber, ErrorMessage = ex.Message, StackTrace = ex.ToString()
                });

                //error occuured so decide what user selected
                if (ErrorHandler != null)
                {
                    switch (ErrorHandler.v_ErrorHandlingAction)
                    {
                    case "Continue Processing":

                        ReportProgress("Error Occured at Line " + parentCommand.LineNumber + ":" + ex.ToString());
                        ReportProgress("Continuing Per Error Handling");

                        break;

                    default:

                        throw new Exception(ex.ToString());
                    }
                }
                else
                {
                    throw new Exception(ex.ToString());
                }
            }
        }
        public void ExecuteCommand(Core.Script.ScriptAction command, BackgroundWorker bgw)
        {
            //get command
            Core.AutomationCommands.ScriptCommand parentCommand = command.ScriptCommand;

            //handle pause
            while (isPaused)
            {
                System.Threading.Thread.Sleep(2000);
            }

            //bypass comments
            if (parentCommand is Core.AutomationCommands.CommentCommand || parentCommand.IsCommented)
            {
                bgwRunScript.ReportProgress(0, new object[] { parentCommand.LineNumber, "Skipping Line " + parentCommand.LineNumber + ": " + parentCommand.GetDisplayValue() });
                return;
            }

            //update listbox
            bgwRunScript.ReportProgress(0, new object[] { parentCommand.LineNumber, "Running Line " + parentCommand.LineNumber + ": " + parentCommand.GetDisplayValue() });

            //handle any errors
            try
            {
                //determine type of command
                if ((parentCommand is Core.AutomationCommands.BeginLoopCommand) || (parentCommand is Core.AutomationCommands.BeginIfCommand))
                {
                    //run the command and pass bgw/command as this command will recursively call this method for sub commands
                    parentCommand.RunCommand(this, command, bgw);
                }
                else
                {
                    //run the command
                    parentCommand.RunCommand(this);
                }
            }
            catch (Exception ex)
            {
                //error occuured so decide what user selected
                if (errorHandling != null)
                {
                    switch (errorHandling.v_ErrorHandlingAction)
                    {
                    case "Continue Processing":
                        bgwRunScript.ReportProgress(0, new object[] { parentCommand.LineNumber, "Error Occured at Line " + parentCommand.LineNumber + ":" + ex.ToString() });
                        bgwRunScript.ReportProgress(0, new object[] { parentCommand.LineNumber, "Continuing Per Error Handling" });
                        break;

                    default:
                        throw new Exception(ex.ToString());
                    }
                }
                else
                {
                    throw new Exception(ex.ToString());
                }
            }
        }
示例#4
0
        public void ExecuteCommand(Core.Script.ScriptAction command, BackgroundWorker bgw)
        {
            //get command
            Core.AutomationCommands.ScriptCommand parentCommand = command.ScriptCommand;

            //handle pause request
            if (parentCommand.PauseBeforeExeucution)
            {
                bgwRunScript.ReportProgress(0, new PauseRequest());
                isPaused = true;
            }

            //handle pause
            bool isFirstWait = true;

            while (isPaused)
            {
                //only show pause first loop
                if (isFirstWait)
                {
                    bgwRunScript.ReportProgress(0, new ProgressUpdate()
                    {
                        LineNumber = parentCommand.LineNumber, UpdateText = "Paused on Line " + parentCommand.LineNumber + ": " + parentCommand.GetDisplayValue()
                    });
                    bgwRunScript.ReportProgress(0, new ProgressUpdate()
                    {
                        LineNumber = parentCommand.LineNumber, UpdateText = "[Please select 'Resume' when ready]"
                    });
                    isFirstWait = false;
                }

                //wait
                System.Threading.Thread.Sleep(2000);
            }



            //bypass comments
            if (parentCommand is Core.AutomationCommands.CommentCommand || parentCommand.IsCommented)
            {
                // bgwRunScript.ReportProgress(0, new object[] { parentCommand.LineNumber, "Skipping Line " + parentCommand.LineNumber + ": " + parentCommand.GetDisplayValue() });
                bgwRunScript.ReportProgress(0, new ProgressUpdate()
                {
                    LineNumber = parentCommand.LineNumber, UpdateText = "Skipping Line " + parentCommand.LineNumber + ": " + parentCommand.GetDisplayValue()
                });
                return;
            }

            //update listbox
            //bgwRunScript.ReportProgress(0, new object[] { parentCommand.LineNumber, "Running Line " + parentCommand.LineNumber + ": " + parentCommand.GetDisplayValue() });
            bgwRunScript.ReportProgress(0, new ProgressUpdate()
            {
                LineNumber = parentCommand.LineNumber, UpdateText = "Running Line " + parentCommand.LineNumber + ": " + parentCommand.GetDisplayValue()
            });


            //handle any errors
            try
            {
                //determine type of command
                if ((parentCommand is Core.AutomationCommands.BeginLoopCommand) || (parentCommand is Core.AutomationCommands.BeginIfCommand))
                {
                    //run the command and pass bgw/command as this command will recursively call this method for sub commands
                    parentCommand.RunCommand(this, command, bgw);
                }
                else
                {
                    //run the command
                    parentCommand.RunCommand(this);
                }
            }
            catch (Exception ex)
            {
                //error occuured so decide what user selected
                if (errorHandling != null)
                {
                    switch (errorHandling.v_ErrorHandlingAction)
                    {
                    case "Continue Processing":
                        //bgwRunScript.ReportProgress(0, new object[] { parentCommand.LineNumber, "Error Occured at Line " + parentCommand.LineNumber + ":" + ex.ToString() });
                        //bgwRunScript.ReportProgress(0, new object[] { parentCommand.LineNumber, "Continuing Per Error Handling" });
                        bgwRunScript.ReportProgress(0, new ProgressUpdate()
                        {
                            LineNumber = parentCommand.LineNumber, UpdateText = "Error Occured at Line " + parentCommand.LineNumber + ":" + ex.ToString()
                        });
                        bgwRunScript.ReportProgress(0, new ProgressUpdate()
                        {
                            LineNumber = parentCommand.LineNumber, UpdateText = "Continuing Per Error Handling"
                        });

                        break;

                    default:
                        throw new Exception(ex.ToString());
                    }
                }
                else
                {
                    throw new Exception(ex.ToString());
                }
            }
        }