Beispiel #1
0
        public override void RunCommand(object sender, Core.Script.ScriptAction parentCommand)
        {
            Core.Automation.Commands.BeginContinousLoopCommand loopCommand = (Core.Automation.Commands.BeginContinousLoopCommand)parentCommand.ScriptCommand;

            var engine = (Core.Automation.Engine.AutomationEngineInstance)sender;


            engine.ReportProgress("Starting Continous Loop From Line " + loopCommand.LineNumber);

            while (true)
            {
                foreach (var cmd in parentCommand.AdditionalScriptCommands)
                {
                    if (engine.IsCancellationPending)
                    {
                        return;
                    }

                    engine.ExecuteCommand(cmd);

                    if (engine.CurrentLoopCancelled)
                    {
                        engine.ReportProgress("Exiting Loop From Line " + loopCommand.LineNumber);
                        engine.CurrentLoopCancelled = false;
                        return;
                    }
                }
            }
        }
Beispiel #2
0
        public override void RunCommand(object sender, Core.Script.ScriptAction parentCommand)
        {
            var engine     = (Core.Automation.Engine.AutomationEngineInstance)sender;
            var loopResult = DetermineStatementTruth(sender);

            engine.ReportProgress("Starting Loop");

            while (loopResult)
            {
                foreach (var cmd in parentCommand.AdditionalScriptCommands)
                {
                    if (engine.IsCancellationPending)
                    {
                        return;
                    }

                    engine.ExecuteCommand(cmd);

                    if (engine.CurrentLoopCancelled)
                    {
                        engine.ReportProgress("Exiting Loop");
                        engine.CurrentLoopCancelled = false;
                        return;
                    }

                    if (engine.CurrentLoopContinuing)
                    {
                        engine.ReportProgress("Continuing Next Loop");
                        engine.CurrentLoopContinuing = false;
                        break;
                    }
                }
                loopResult = DetermineStatementTruth(sender);
            }
        }
        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());
                }
            }
        }
Beispiel #4
0
        public override void RunCommand(object sender, Core.Script.ScriptAction parentCommand)
        {
            Core.Automation.Commands.BeginNumberOfTimesLoopCommand loopCommand = (Core.Automation.Commands.BeginNumberOfTimesLoopCommand)parentCommand.ScriptCommand;

            var engine = (Core.Automation.Engine.AutomationEngineInstance)sender;

            if (!engine.VariableList.Any(f => f.VariableName == "Loop.CurrentIndex"))
            {
                engine.VariableList.Add(new Script.ScriptVariable()
                {
                    VariableName = "Loop.CurrentIndex", VariableValue = "0"
                });
            }


            int loopTimes;

            Script.ScriptVariable complexVarible = null;

            var loopParameter = loopCommand.v_LoopParameter.ConvertToUserVariable(sender);

            loopTimes = int.Parse(loopParameter);

            for (int i = 0; i < loopTimes; i++)
            {
                if (complexVarible != null)
                {
                    complexVarible.CurrentPosition = i;
                }

                (i + 1).ToString().StoreInUserVariable(engine, "Loop.CurrentIndex");

                engine.ReportProgress("Starting Loop Number " + (i + 1) + "/" + loopTimes + " From Line " + loopCommand.LineNumber);

                foreach (var cmd in parentCommand.AdditionalScriptCommands)
                {
                    if (engine.IsCancellationPending)
                    {
                        return;
                    }

                    engine.ExecuteCommand(cmd);

                    if (engine.CurrentLoopCancelled)
                    {
                        engine.ReportProgress("Exiting Loop From Line " + loopCommand.LineNumber);
                        engine.CurrentLoopCancelled = false;
                        return;
                    }
                }

                engine.ReportProgress("Finished Loop From Line " + loopCommand.LineNumber);
            }
        }
        public override void RunCommand(object sender, Core.Script.ScriptAction parentCommand)
        {
            Core.Automation.Commands.BeginExcelDatasetLoopCommand loopCommand = (Core.Automation.Commands.BeginExcelDatasetLoopCommand)parentCommand.ScriptCommand;
            var engine = (Core.Automation.Engine.AutomationEngineInstance)sender;

            var dataSetVariable = engine.VariableList.Where(f => f.VariableName == v_DataSetName).FirstOrDefault();

            if (dataSetVariable == null)
            {
                throw new Exception("DataSet Name Not Found - " + v_DataSetName);
            }

            if (!engine.VariableList.Any(f => f.VariableName == "Loop.CurrentIndex"))
            {
                engine.VariableList.Add(new Script.ScriptVariable()
                {
                    VariableName = "Loop.CurrentIndex", VariableValue = "0"
                });
            }


            DataTable excelTable = (DataTable)dataSetVariable.VariableValue;


            var loopTimes = excelTable.Rows.Count;

            for (int i = 0; i < excelTable.Rows.Count; i++)
            {
                dataSetVariable.CurrentPosition = i;

                (i + 1).ToString().StoreInUserVariable(engine, "Loop.CurrentIndex");

                foreach (var cmd in parentCommand.AdditionalScriptCommands)
                {
                    //bgw.ReportProgress(0, new object[] { loopCommand.LineNumber, "Starting Loop Number " + (i + 1) + "/" + loopTimes + " From Line " + loopCommand.LineNumber });

                    if (engine.IsCancellationPending)
                    {
                        return;
                    }
                    engine.ExecuteCommand(cmd);
                    // bgw.ReportProgress(0, new object[] { loopCommand.LineNumber, "Finished Loop From Line " + loopCommand.LineNumber });
                }
            }
        }
        public override void RunCommand(object sender, Core.Script.ScriptAction parentCommand)
        {
            var engine = (Core.Automation.Engine.AutomationEngineInstance)sender;

            foreach (var item in v_scriptActions)
            {
                //exit if cancellation pending
                if (engine.IsCancellationPending)
                {
                    return;
                }

                //only run if not commented
                if (!item.IsCommented)
                {
                    item.RunCommand(sender);
                }
            }
        }
Beispiel #7
0
        public override void RunCommand(object sender, Core.Script.ScriptAction parentCommand)
        {
            var engine = (Core.Automation.Engine.AutomationEngineInstance)sender;

            var ifResult = DetermineStatementTruth(sender);

            int startIndex, endIndex, elseIndex;

            if (parentCommand.AdditionalScriptCommands.Any(item => item.ScriptCommand is Core.Automation.Commands.ElseCommand))
            {
                elseIndex = parentCommand.AdditionalScriptCommands.FindIndex(a => a.ScriptCommand is Core.Automation.Commands.ElseCommand);

                if (ifResult)
                {
                    startIndex = 0;
                    endIndex   = elseIndex;
                }
                else
                {
                    startIndex = elseIndex + 1;
                    endIndex   = parentCommand.AdditionalScriptCommands.Count;
                }
            }
            else if (ifResult)
            {
                startIndex = 0;
                endIndex   = parentCommand.AdditionalScriptCommands.Count;
            }
            else
            {
                return;
            }

            for (int i = startIndex; i < endIndex; i++)
            {
                if ((engine.IsCancellationPending) || (engine.CurrentLoopCancelled) || (engine.CurrentLoopContinuing))
                {
                    return;
                }

                engine.ExecuteCommand(parentCommand.AdditionalScriptCommands[i]);
            }
        }
Beispiel #8
0
 public virtual void RunCommand(object sender, Core.Script.ScriptAction command)
 {
     System.Threading.Thread.Sleep(DefaultPause);
 }
        public void ExecuteCommand(Core.Script.ScriptAction command)
        {
            //get command
            Core.Automation.Commands.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.Automation.Commands.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.Automation.Commands.BeginNumberOfTimesLoopCommand) || (parentCommand is Core.Automation.Commands.BeginContinousLoopCommand) || (parentCommand is Core.Automation.Commands.BeginListLoopCommand) || (parentCommand is Core.Automation.Commands.BeginIfCommand) || (parentCommand is Core.Automation.Commands.BeginMultiIfCommand) || (parentCommand is Core.Automation.Commands.BeginExcelDatasetLoopCommand) || (parentCommand is Commands.TryCommand) || (parentCommand is Core.Automation.Commands.BeginLoopCommand) || (parentCommand is Core.Automation.Commands.BeginMultiLoopCommand))
                {
                    //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.Automation.Commands.SequenceCommand)
                {
                    parentCommand.RunCommand(this, command);
                }
                else if (parentCommand is Core.Automation.Commands.StopTaskCommand)
                {
                    IsCancellationPending = true;
                    return;
                }
                else if (parentCommand is Core.Automation.Commands.ExitLoopCommand)
                {
                    CurrentLoopCancelled = true;
                }
                else if (parentCommand is Core.Automation.Commands.NextLoopCommand)
                {
                    CurrentLoopContinuing = true;
                }
                else if (parentCommand is Core.Automation.Commands.SetEngineDelayCommand)
                {
                    //get variable
                    var setEngineCommand = (Core.Automation.Commands.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 ex;
                    }
                }
                else
                {
                    throw ex;
                }
            }
        }
        public override void RunCommand(object sender, Core.Script.ScriptAction parentCommand)
        {
            Core.Automation.Commands.BeginListLoopCommand loopCommand = (Core.Automation.Commands.BeginListLoopCommand)parentCommand.ScriptCommand;
            var engine = (Core.Automation.Engine.AutomationEngineInstance)sender;

            int loopTimes;

            Script.ScriptVariable complexVariable = null;


            //get variable by regular name
            complexVariable = engine.VariableList.Where(x => x.VariableName == v_LoopParameter).FirstOrDefault();


            if (!engine.VariableList.Any(f => f.VariableName == "Loop.CurrentIndex"))
            {
                engine.VariableList.Add(new Script.ScriptVariable()
                {
                    VariableName = "Loop.CurrentIndex", VariableValue = "0"
                });
            }

            //user may potentially include brackets []
            if (complexVariable == null)
            {
                complexVariable = engine.VariableList.Where(x => x.VariableName.ApplyVariableFormatting() == v_LoopParameter).FirstOrDefault();
            }

            //if still null then throw exception
            if (complexVariable == null)
            {
                throw new Exception("Complex Variable '" + v_LoopParameter + "' or '" + v_LoopParameter.ApplyVariableFormatting() + "' not found. Ensure the variable exists before attempting to modify it.");
            }

            dynamic listToLoop;

            if (complexVariable.VariableValue is List <string> )
            {
                listToLoop = (List <string>)complexVariable.VariableValue;
            }
            else if (complexVariable.VariableValue is List <OpenQA.Selenium.IWebElement> )
            {
                listToLoop = (List <OpenQA.Selenium.IWebElement>)complexVariable.VariableValue;
            }
            else if (complexVariable.VariableValue is DataTable)
            {
                listToLoop = ((DataTable)complexVariable.VariableValue).Rows;
            }
            else if ((complexVariable.VariableValue.ToString().StartsWith("[")) && (complexVariable.VariableValue.ToString().EndsWith("]")) && (complexVariable.VariableValue.ToString().Contains(",")))
            {
                //automatically handle if user has given a json array
                Newtonsoft.Json.Linq.JArray jsonArray = Newtonsoft.Json.JsonConvert.DeserializeObject(complexVariable.VariableValue.ToString()) as Newtonsoft.Json.Linq.JArray;

                var itemList = new List <string>();
                foreach (var item in jsonArray)
                {
                    var value = (Newtonsoft.Json.Linq.JValue)item;
                    itemList.Add(value.ToString());
                }

                complexVariable.VariableValue = itemList;
                listToLoop = itemList;
            }
            else
            {
                throw new Exception("Complex Variable List Type<T> Not Supported");
            }


            loopTimes = listToLoop.Count;


            for (int i = 0; i < loopTimes; i++)
            {
                if (complexVariable != null)
                {
                    complexVariable.CurrentPosition = i;
                }



                engine.ReportProgress("Starting Loop Number " + (i + 1) + "/" + loopTimes + " From Line " + loopCommand.LineNumber);

                foreach (var cmd in parentCommand.AdditionalScriptCommands)
                {
                    if (engine.IsCancellationPending)
                    {
                        return;
                    }

                    (i + 1).ToString().StoreInUserVariable(engine, "Loop.CurrentIndex");

                    engine.ExecuteCommand(cmd);


                    if (engine.CurrentLoopCancelled)
                    {
                        engine.ReportProgress("Exiting Loop From Line " + loopCommand.LineNumber);
                        engine.CurrentLoopCancelled = false;
                        return;
                    }

                    if (engine.CurrentLoopContinuing)
                    {
                        engine.ReportProgress("Continuing Next Loop From Line " + loopCommand.LineNumber);
                        engine.CurrentLoopContinuing = false;
                        break;
                    }
                }

                engine.ReportProgress("Finished Loop From Line " + loopCommand.LineNumber);
            }
        }
Beispiel #11
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());
                }
            }
        }
        public override void RunCommand(object sender, Core.Script.ScriptAction parentCommand)
        {
            Core.Automation.Commands.BeginListLoopCommand loopCommand = (Core.Automation.Commands.BeginListLoopCommand)parentCommand.ScriptCommand;
            var engine = (Core.Automation.Engine.AutomationEngineInstance)sender;

            int loopTimes;

            Script.ScriptVariable complexVariable = null;


            //get variable by regular name
            complexVariable = engine.VariableList.Where(x => x.VariableName == v_LoopParameter).FirstOrDefault();


            if (!engine.VariableList.Any(f => f.VariableName == "Loop.CurrentIndex"))
            {
                engine.VariableList.Add(new Script.ScriptVariable()
                {
                    VariableName = "Loop.CurrentIndex", VariableValue = "0"
                });
            }

            //user may potentially include brackets []
            if (complexVariable == null)
            {
                complexVariable = engine.VariableList.Where(x => x.VariableName.ApplyVariableFormatting() == v_LoopParameter).FirstOrDefault();
            }

            //if still null then throw exception
            if (complexVariable == null)
            {
                throw new Exception("Complex Variable '" + v_LoopParameter + "' or '" + v_LoopParameter.ApplyVariableFormatting() + "' not found. Ensure the variable exists before attempting to modify it.");
            }

            dynamic listToLoop;

            if (complexVariable.VariableValue is List <string> )
            {
                listToLoop = (List <string>)complexVariable.VariableValue;
            }
            else if (complexVariable.VariableValue is List <OpenQA.Selenium.IWebElement> )
            {
                listToLoop = (List <OpenQA.Selenium.IWebElement>)complexVariable.VariableValue;
            }
            else
            {
                throw new Exception("Complex Variable List Type<T> Not Supported");
            }


            loopTimes = listToLoop.Count;


            for (int i = 0; i < loopTimes; i++)
            {
                if (complexVariable != null)
                {
                    complexVariable.CurrentPosition = i;
                }

                (i + 1).ToString().StoreInUserVariable(engine, "Loop.CurrentIndex");

                engine.ReportProgress("Starting Loop Number " + (i + 1) + "/" + loopTimes + " From Line " + loopCommand.LineNumber);

                foreach (var cmd in parentCommand.AdditionalScriptCommands)
                {
                    if (engine.IsCancellationPending)
                    {
                        return;
                    }


                    engine.ExecuteCommand(cmd);


                    if (engine.CurrentLoopCancelled)
                    {
                        return;
                    }
                }

                engine.ReportProgress("Finished Loop From Line " + loopCommand.LineNumber);
            }
        }
Beispiel #13
0
        public override void RunCommand(object sender, Core.Script.ScriptAction parentCommand)
        {
            var engine = (Core.Automation.Engine.AutomationEngineInstance)sender;



            bool ifResult = false;


            if (v_IfActionType == "Value")
            {
                string value1 = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                  where rw.Field <string>("Parameter Name") == "Value1"
                                  select rw.Field <string>("Parameter Value")).FirstOrDefault());
                string operand = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                   where rw.Field <string>("Parameter Name") == "Operand"
                                   select rw.Field <string>("Parameter Value")).FirstOrDefault());
                string value2 = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                  where rw.Field <string>("Parameter Name") == "Value2"
                                  select rw.Field <string>("Parameter Value")).FirstOrDefault());

                value1 = value1.ConvertToUserVariable(sender);
                value2 = value2.ConvertToUserVariable(sender);



                decimal cdecValue1, cdecValue2;

                switch (operand)
                {
                case "is equal to":
                    ifResult = (value1 == value2);
                    break;

                case "is not equal to":
                    ifResult = (value1 != value2);
                    break;

                case "is greater than":
                    cdecValue1 = Convert.ToDecimal(value1);
                    cdecValue2 = Convert.ToDecimal(value2);
                    ifResult   = (cdecValue1 > cdecValue2);
                    break;

                case "is greater than or equal to":
                    cdecValue1 = Convert.ToDecimal(value1);
                    cdecValue2 = Convert.ToDecimal(value2);
                    ifResult   = (cdecValue1 >= cdecValue2);
                    break;

                case "is less than":
                    cdecValue1 = Convert.ToDecimal(value1);
                    cdecValue2 = Convert.ToDecimal(value2);
                    ifResult   = (cdecValue1 < cdecValue2);
                    break;

                case "is less than or equal to":
                    cdecValue1 = Convert.ToDecimal(value1);
                    cdecValue2 = Convert.ToDecimal(value2);
                    ifResult   = (cdecValue1 <= cdecValue2);
                    break;
                }
            }
            else if (v_IfActionType == "Date Compare")
            {
                string value1 = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                  where rw.Field <string>("Parameter Name") == "Value1"
                                  select rw.Field <string>("Parameter Value")).FirstOrDefault());
                string operand = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                   where rw.Field <string>("Parameter Name") == "Operand"
                                   select rw.Field <string>("Parameter Value")).FirstOrDefault());
                string value2 = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                  where rw.Field <string>("Parameter Name") == "Value2"
                                  select rw.Field <string>("Parameter Value")).FirstOrDefault());

                value1 = value1.ConvertToUserVariable(sender);
                value2 = value2.ConvertToUserVariable(sender);



                DateTime dt1, dt2;
                dt1 = DateTime.Parse(value1);
                dt2 = DateTime.Parse(value2);
                switch (operand)
                {
                case "is equal to":
                    ifResult = (dt1 == dt2);
                    break;

                case "is not equal to":
                    ifResult = (dt1 != dt2);
                    break;

                case "is greater than":
                    ifResult = (dt1 > dt2);
                    break;

                case "is greater than or equal to":
                    ifResult = (dt1 >= dt2);
                    break;

                case "is less than":
                    ifResult = (dt1 < dt2);
                    break;

                case "is less than or equal to":
                    ifResult = (dt1 <= dt2);
                    break;
                }
            }
            else if (v_IfActionType == "Variable Compare")
            {
                string value1 = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                  where rw.Field <string>("Parameter Name") == "Value1"
                                  select rw.Field <string>("Parameter Value")).FirstOrDefault());
                string operand = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                   where rw.Field <string>("Parameter Name") == "Operand"
                                   select rw.Field <string>("Parameter Value")).FirstOrDefault());
                string value2 = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                  where rw.Field <string>("Parameter Name") == "Value2"
                                  select rw.Field <string>("Parameter Value")).FirstOrDefault());

                string caseSensitive = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                         where rw.Field <string>("Parameter Name") == "Case Sensitive"
                                         select rw.Field <string>("Parameter Value")).FirstOrDefault());

                value1 = value1.ConvertToUserVariable(sender);
                value2 = value2.ConvertToUserVariable(sender);

                if (caseSensitive == "No")
                {
                    value1 = value1.ToUpper();
                    value2 = value2.ToUpper();
                }



                switch (operand)
                {
                case "contains":
                    ifResult = (value1.Contains(value2));
                    break;

                case "does not contain":
                    ifResult = (!value1.Contains(value2));
                    break;

                case "is equal to":
                    ifResult = (value1 == value2);
                    break;

                case "is not equal to":
                    ifResult = (value1 != value2);
                    break;
                }
            }
            else if (v_IfActionType == "Variable Has Value")
            {
                string variableName = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                        where rw.Field <string>("Parameter Name") == "Variable Name"
                                        select rw.Field <string>("Parameter Value")).FirstOrDefault());

                var actualVariable = variableName.ConvertToUserVariable(sender).Trim();

                if (!string.IsNullOrEmpty(actualVariable))
                {
                    ifResult = true;
                }
                else
                {
                    ifResult = false;
                }
            }
            else if (v_IfActionType == "Variable Is Numeric")
            {
                string variableName = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                        where rw.Field <string>("Parameter Name") == "Variable Name"
                                        select rw.Field <string>("Parameter Value")).FirstOrDefault());

                var actualVariable = variableName.ConvertToUserVariable(sender).Trim();

                var numericTest = decimal.TryParse(actualVariable, out decimal parsedResult);

                if (numericTest)
                {
                    ifResult = true;
                }
                else
                {
                    ifResult = false;
                }
            }
            else if (v_IfActionType == "Error Occured")
            {
                //get line number
                string userLineNumber = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                          where rw.Field <string>("Parameter Name") == "Line Number"
                                          select rw.Field <string>("Parameter Value")).FirstOrDefault());

                //convert to variable
                string variableLineNumber = userLineNumber.ConvertToUserVariable(sender);

                //convert to int
                int lineNumber = int.Parse(variableLineNumber);

                //determine if error happened
                if (engine.ErrorsOccured.Where(f => f.LineNumber == lineNumber).Count() > 0)
                {
                    var error = engine.ErrorsOccured.Where(f => f.LineNumber == lineNumber).FirstOrDefault();
                    error.ErrorMessage.StoreInUserVariable(sender, "Error.Message");
                    error.LineNumber.ToString().StoreInUserVariable(sender, "Error.Line");
                    error.StackTrace.StoreInUserVariable(sender, "Error.StackTrace");

                    ifResult = true;
                }
                else
                {
                    ifResult = false;
                }
            }
            else if (v_IfActionType == "Error Did Not Occur")
            {
                //get line number
                string userLineNumber = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                          where rw.Field <string>("Parameter Name") == "Line Number"
                                          select rw.Field <string>("Parameter Value")).FirstOrDefault());

                //convert to variable
                string variableLineNumber = userLineNumber.ConvertToUserVariable(sender);

                //convert to int
                int lineNumber = int.Parse(variableLineNumber);

                //determine if error happened
                if (engine.ErrorsOccured.Where(f => f.LineNumber == lineNumber).Count() == 0)
                {
                    ifResult = true;
                }
                else
                {
                    var error = engine.ErrorsOccured.Where(f => f.LineNumber == lineNumber).FirstOrDefault();
                    error.ErrorMessage.StoreInUserVariable(sender, "Error.Message");
                    error.LineNumber.ToString().StoreInUserVariable(sender, "Error.Line");
                    error.StackTrace.StoreInUserVariable(sender, "Error.StackTrace");

                    ifResult = false;
                }
            }
            else if (v_IfActionType == "Window Name Exists")
            {
                //get user supplied name
                string windowName = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                      where rw.Field <string>("Parameter Name") == "Window Name"
                                      select rw.Field <string>("Parameter Value")).FirstOrDefault());
                //variable translation
                string variablizedWindowName = windowName.ConvertToUserVariable(sender);

                //search for window
                IntPtr windowPtr = User32Functions.FindWindow(variablizedWindowName);

                //conditional
                if (windowPtr != IntPtr.Zero)
                {
                    ifResult = true;
                }
            }
            else if (v_IfActionType == "Active Window Name Is")
            {
                string windowName = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                      where rw.Field <string>("Parameter Name") == "Window Name"
                                      select rw.Field <string>("Parameter Value")).FirstOrDefault());

                string variablizedWindowName = windowName.ConvertToUserVariable(sender);

                var currentWindowTitle = User32Functions.GetActiveWindowTitle();

                if (currentWindowTitle == variablizedWindowName)
                {
                    ifResult = true;
                }
            }
            else if (v_IfActionType == "File Exists")
            {
                string fileName = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                    where rw.Field <string>("Parameter Name") == "File Path"
                                    select rw.Field <string>("Parameter Value")).FirstOrDefault());

                string trueWhenFileExists = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                              where rw.Field <string>("Parameter Name") == "True When"
                                              select rw.Field <string>("Parameter Value")).FirstOrDefault());

                var userFileSelected = fileName.ConvertToUserVariable(sender);

                bool existCheck = false;
                if (trueWhenFileExists == "It Does Exist")
                {
                    existCheck = true;
                }


                if (System.IO.File.Exists(userFileSelected) == existCheck)
                {
                    ifResult = true;
                }
            }
            else if (v_IfActionType == "Folder Exists")
            {
                string folderName = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                      where rw.Field <string>("Parameter Name") == "Folder Path"
                                      select rw.Field <string>("Parameter Value")).FirstOrDefault());

                string trueWhenFileExists = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                              where rw.Field <string>("Parameter Name") == "True When"
                                              select rw.Field <string>("Parameter Value")).FirstOrDefault());

                var userFolderSelected = folderName.ConvertToUserVariable(sender);

                bool existCheck = false;
                if (trueWhenFileExists == "It Does Exist")
                {
                    existCheck = true;
                }


                if (System.IO.Directory.Exists(folderName) == existCheck)
                {
                    ifResult = true;
                }
            }
            else if (v_IfActionType == "Web Element Exists")
            {
                string parameterName = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                         where rw.Field <string>("Parameter Name") == "Element Search Parameter"
                                         select rw.Field <string>("Parameter Value")).FirstOrDefault());

                string searchMethod = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                        where rw.Field <string>("Parameter Name") == "Element Search Method"
                                        select rw.Field <string>("Parameter Value")).FirstOrDefault());

                SeleniumBrowserElementActionCommand_cn newElementActionCommand = new SeleniumBrowserElementActionCommand_cn();
                newElementActionCommand.v_SeleniumSearchType = searchMethod;
                bool elementExists = newElementActionCommand.ElementExists(sender, searchMethod, parameterName);
                ifResult = elementExists;
            }
            else if (v_IfActionType == "GUI Element Exists")
            {
                string windowName = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                      where rw.Field <string>("Parameter Name") == "Window Name"
                                      select rw.Field <string>("Parameter Value")).FirstOrDefault().ConvertToUserVariable(sender));

                string elementSearchParam = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                              where rw.Field <string>("Parameter Name") == "Element Search Parameter"
                                              select rw.Field <string>("Parameter Value")).FirstOrDefault().ConvertToUserVariable(sender));

                string elementSearchMethod = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                               where rw.Field <string>("Parameter Name") == "Element Search Method"
                                               select rw.Field <string>("Parameter Value")).FirstOrDefault().ConvertToUserVariable(sender));


                UIAutomationCommand_cn newUIACommand = new UIAutomationCommand_cn();
                newUIACommand.v_WindowName = windowName;
                newUIACommand.v_UIASearchParameters.Rows.Add(true, elementSearchMethod, elementSearchParam);
                var handle = newUIACommand.SearchForGUIElement(sender, windowName);

                if (handle is null)
                {
                    ifResult = false;
                }
                else
                {
                    ifResult = true;
                }
            }
            else
            {
                throw new Exception("If type not recognized!");
            }



            int startIndex, endIndex, elseIndex;

            if (parentCommand.AdditionalScriptCommands.Any(item => item.ScriptCommand is Core.Automation.Commands.ElseCommand))
            {
                elseIndex = parentCommand.AdditionalScriptCommands.FindIndex(a => a.ScriptCommand is Core.Automation.Commands.ElseCommand);

                if (ifResult)
                {
                    startIndex = 0;
                    endIndex   = elseIndex;
                }
                else
                {
                    startIndex = elseIndex + 1;
                    endIndex   = parentCommand.AdditionalScriptCommands.Count;
                }
            }
            else if (ifResult)
            {
                startIndex = 0;
                endIndex   = parentCommand.AdditionalScriptCommands.Count;
            }
            else
            {
                return;
            }

            for (int i = startIndex; i < endIndex; i++)
            {
                if ((engine.IsCancellationPending) || (engine.CurrentLoopCancelled))
                {
                    return;
                }

                engine.ExecuteCommand(parentCommand.AdditionalScriptCommands[i]);
            }
        }
Beispiel #14
0
        public override void RunCommand(object sender, Core.Script.ScriptAction parentCommand)
        {
            var engine = (Core.Automation.Engine.AutomationEngineInstance)sender;

            bool isTrueStatement = true;

            foreach (DataRow rw in v_IfConditionsTable.Rows)
            {
                var commandData = rw["CommandData"].ToString();
                var ifCommand   = Newtonsoft.Json.JsonConvert.DeserializeObject <Commands.BeginIfCommand>(commandData);

                var statementResult = ifCommand.DetermineStatementTruth(sender);

                if (!statementResult)
                {
                    isTrueStatement = false;
                    break;
                }
            }

            //report evaluation
            if (isTrueStatement)
            {
                engine.ReportProgress("If Conditions Evaluated True");
            }
            else
            {
                engine.ReportProgress("If Conditions Evaluated False");
            }

            int startIndex, endIndex, elseIndex;

            if (parentCommand.AdditionalScriptCommands.Any(item => item.ScriptCommand is Core.Automation.Commands.ElseCommand))
            {
                elseIndex = parentCommand.AdditionalScriptCommands.FindIndex(a => a.ScriptCommand is Core.Automation.Commands.ElseCommand);

                if (isTrueStatement)
                {
                    startIndex = 0;
                    endIndex   = elseIndex;
                }
                else
                {
                    startIndex = elseIndex + 1;
                    endIndex   = parentCommand.AdditionalScriptCommands.Count;
                }
            }
            else if (isTrueStatement)
            {
                startIndex = 0;
                endIndex   = parentCommand.AdditionalScriptCommands.Count;
            }
            else
            {
                return;
            }

            for (int i = startIndex; i < endIndex; i++)
            {
                if ((engine.IsCancellationPending) || (engine.CurrentLoopCancelled))
                {
                    return;
                }

                engine.ExecuteCommand(parentCommand.AdditionalScriptCommands[i]);
            }
        }