コード例 #1
0
ファイル: CoreUtils.cs プロジェクト: AlexaProjects/Alexa
        /// <summary>
        /// Runs the method that insert text
        /// </summary>
        /// <param name="alexaStep">the xml node that contains the step</param>
        private static void StepMouseMove(XmlNode alexaStep)
        {
            try
            {
                //Create a new StepTiming object, it will be used by OutputUtils to write
                //current step info to the output file
                OutputUtils.StepTiming stepTiming = new OutputUtils.StepTiming();

                //save start date
                stepTiming.startTime = DateTime.Now;

                //create a stopwatch to mesea the elapsed time of this step
                Stopwatch stopWatch = new Stopwatch();
                stopWatch.Start();

                int x = 0;
                int y = 0;
                int speed = 10;

                x = Int32.Parse( alexaStep.Attributes["x"].Value);
                y = Int32.Parse(alexaStep.Attributes["y"].Value);
                try
                {

                    speed = Int32.Parse(alexaStep.Attributes["speed"].Value);
                }
                catch { }
                _autoIt.MouseMove(x,y,speed);

                stopWatch.Stop();

                //save all info that will be used by OutputUtils to write current
                //step info to the output file
                stepTiming.stepNumber = _stepNumber;
                stepTiming.stepNode = alexaStep;
                stepTiming.endTime = DateTime.Now;
                stepTiming.stepDuration = stopWatch.ElapsedMilliseconds;

                //add above info to StepTimingsCollection
                OutputUtils.StepTimingsCollection.Add(stepTiming);
            }
            catch (Exception ex)
            {
                //write the error
                LogUtils.Write(ex);
                Program.Finish(true);
            }
        }
コード例 #2
0
ファイル: CoreUtils.cs プロジェクト: AlexaProjects/Alexa
        /// <summary>
        /// Runs the method that click the mouse
        /// </summary>
        /// <param name="alexaStep">the xml node that contains the step</param>
        private static void StepMouseClick(XmlNode alexaStep)
        {
            try
            {
                //Create a new StepTiming object, it will be used by OutputUtils to write
                //current step info to the output file
                OutputUtils.StepTiming stepTiming = new OutputUtils.StepTiming();

                //save start date
                stepTiming.startTime = DateTime.Now;

                //create a stopwatch to mesea the elapsed time of this step
                Stopwatch stopWatch = new Stopwatch();
                stopWatch.Start();

                bool doubleClick = false;
                bool rightClick = false;
                int delay = 80;

                try
                {
                    if (alexaStep.Attributes["double.click"].Value == "enable")
                    {
                        doubleClick = true;
                    }
                }
                catch { }

                try
                {
                    if (alexaStep.Attributes["right.click"].Value == "enable")
                    {
                        rightClick = true;
                    }
                }
                catch { }

                try
                {
                    delay = Int32.Parse(alexaStep.Attributes["double.click.delay"].Value);
                }
                catch { }

                if(rightClick == true)
                {
                    _autoIt.MouseClick("RIGHT");
                    Thread.Sleep(_afterClickDelay);
                }
                else if (doubleClick)
                {
                    _autoIt.MouseClick("LEFT");
                    Thread.Sleep(delay);
                    _autoIt.MouseClick("LEFT");
                    Thread.Sleep(_afterClickDelay);

                }
                else
                {
                    _autoIt.MouseClick("LEFT");
                    Thread.Sleep(_afterClickDelay);
                }

                stopWatch.Stop();

                //save all info that will be used by OutputUtils to write current
                //step info to the output file
                stepTiming.stepNumber = _stepNumber;
                stepTiming.stepNode = alexaStep;
                stepTiming.endTime = DateTime.Now;
                stepTiming.stepDuration = stopWatch.ElapsedMilliseconds;

                //add above info to StepTimingsCollection
                OutputUtils.StepTimingsCollection.Add(stepTiming);
            }
            catch (Exception ex)
            {
                //write the error
                LogUtils.Write(ex);
                Program.Finish(true);
            }
        }
コード例 #3
0
ファイル: CoreUtils.cs プロジェクト: AlexaProjects/Alexa
        /// <summary>
        /// Runs the method that executes a step and then calculate the execution time
        /// </summary>
        /// <param name="stepType">the type of the step</param>
        /// <param name="alexaStep">the xml node that contains the step</param>
        private static void ExecStepMethod(StepType stepType, XmlNode alexaStep)
        {
            long stepDuration = 0;
            int stepTimeout = 30000; //default timeout is 30 seconds

            //Init a Stopwatch to measure elapsed time of a method that executes a single step
            Stopwatch stepExecutionTime = new Stopwatch();

            //Create a new StepTiming object, it will be used by OutputUtils to write
            //current step info to the output file
            OutputUtils.StepTiming stepTiming = new OutputUtils.StepTiming();

            #region common private variables
            _mouseClick = true;
            _mouseMove = true;

            //store debug properties
            _debugFullPath = "";
            _debugPath = "";
            _debugImageName = "";
            _debugCoreFolder = "";

            //flag that indicates if the input box was found
            _found = false;

            //step configuration properties
            _stepName = "";
            _labelPosition = "";
            _label = "";
            _textToInsert = "";
            _boxBrightness = -999; //default value, if it doesn't change I don't change brightness and contrast
            _boxContrast = -999;
            _labelBrightness = -999;
            _labelContrast = -999;

            //offset coordinate, the origin point of these coordinats
            //are the top left point of the box that will be found
            _clickOffsetX = 0;
            _clickOffsetY = 0;

            //store the properties of the label related to the inputbox
            //that the user wants find
            _labelBoxHeight = 0;
            _labelBoxWidth = 0;

            //store the properties of the box that the user wants find
            _boxHeight = -1;
            _boxWidth = -1;
            _boxTollerance = 0;

            //label offset, the origin point of these coordinats
            //are the top left point of the box that will be found
            _labelBoxOffsetX = 0;
            _labelBoxOffsetY = 0;

            //cotains the element to select from a drop down list
            _selectItem = "";

            //they will contain the desktop area to crop
            //if user doesn't set these options then all desktop image will be analyzed
            _cropRectX = -1;
            _cropRectY = -1;
            _cropRectHeight = -1;
            _cropRectWidth = -1;

            //char bounding rect properties
            _charRectMinHeight = 6;
            _charRectMaxHeight = 50;
            _charRectMinWidth = 50;
            _charRectMaxWidth = 300;
            _charRectThickness = 2;
            _charRectExtendLeft = 2;
            _charRectColor[0] = 255;
            _charRectColor[1] = _charRectColor[2] = 0;

            //word text
            _textValue = "";

            _performanceEnable = false;

            //variables for scroll
            _scrollStep = 1;
            _enableScroll = false;
            _scrollDirection = "down";
            _scrollLastdelay = 2000;

            //variables for the color change
            //   Red           Blue          Green
            _oldColor[0] = _oldColor[1] = _oldColor[2] = -1;
            _newColor[0] = _newColor[1] = _newColor[2] = -1;

            #endregion

            #region get step node attributes
            //get the timeout attribute, it isn't mandatory.
            try { stepTimeout = Int32.Parse(alexaStep.SelectSingleNode("performance").Attributes["timeout.value"].Value.ToLower()); }
            catch { }

            try
            {
                //this is not a mandatory option
                if (alexaStep.Attributes["mouse.click"].Value == "off") _mouseClick = false;
            }
            catch { }

            try
            {
                //this is not a mandatory option
                if (alexaStep.Attributes["mouse.move"].Value == "off") _mouseMove = false;
            }
            catch { }

            try //get the step name attribute, it isn't mandatory.
            {
                _stepName = GetStepNameNumber(alexaStep);
            }
            catch { }

            try
            {
                //get the label position attribute, it isn't mandatory.
                _labelPosition = alexaStep.SelectSingleNode("label").Attributes["position"].Value;
            }
            catch { }

            try
            {
                //this is not a mandatory option
                _boxBrightness = Int32.Parse(alexaStep.Attributes["brightness"].Value);
            }
            catch { _boxBrightness = -999; }

            try
            {
                //this is not a mandatory option
                _boxContrast = Int32.Parse(alexaStep.Attributes["contrast"].Value);
            }
            catch { _boxContrast = -999; }

            try
            {
                //this is not a mandatory option
                _labelBrightness = Int32.Parse(alexaStep.SelectSingleNode("label").Attributes["brightness"].Value);
            }
            catch { _labelBrightness = -999; }

            try
            {
                //this is not a mandatory option
                _labelContrast = Int32.Parse(alexaStep.SelectSingleNode("label").Attributes["contrast"].Value);
            }
            catch { _labelContrast = -999; }

            try
            {
                //it isn't a mandatory option
                _labelBoxHeight = Int32.Parse(alexaStep.SelectSingleNode("label").Attributes["height"].Value);
            }
            catch { }

            try
            {
                //it isn't a mandatory option
                _labelBoxWidth = Int32.Parse(alexaStep.SelectSingleNode("label").Attributes["width"].Value);
            }
            catch { }

            try
            {
                //get the label of the input box
                _label = alexaStep.SelectSingleNode("label").InnerText;
            }
            catch{}

            try
            {

                //get the text to insert into the input box
                _textToInsert = alexaStep.SelectSingleNode("insert").InnerText;
            }
            catch{}

            try
            {
                //get the text to insert into the Drop Down List
                _selectItem = alexaStep.SelectSingleNode("select").InnerText;
            }
            catch { }

            try
            {
                //they are not mandatory options
                _cropRectX = Int32.Parse(alexaStep.Attributes["croprect.x"].Value);
                _cropRectY = Int32.Parse(alexaStep.Attributes["croprect.y"].Value);
                _cropRectHeight = Int32.Parse(alexaStep.Attributes["croprect.height"].Value);
                _cropRectWidth = Int32.Parse(alexaStep.Attributes["croprect.width"].Value);
            }
            catch
            {
                _cropRectX = _cropRectY = _cropRectHeight = _cropRectWidth = -1;
            }

            try
            {
                _boxHeight = Int32.Parse(alexaStep.Attributes["height"].Value);
            }
            catch { }

            try
            {
                _boxWidth = Int32.Parse(alexaStep.Attributes["width"].Value);
            }
            catch { }

            try
            {
                _boxTollerance = Int32.Parse(alexaStep.Attributes["tollerance"].Value);
            }
            catch { }

            try
            {
                _labelBoxOffsetX = Int32.Parse(alexaStep.SelectSingleNode("label").Attributes["offset.x"].Value);
            }
            catch { }

            try
            {
                _labelBoxOffsetY = Int32.Parse(alexaStep.SelectSingleNode("label").Attributes["offset.y"].Value);
            }
            catch { }

            try
            {
                //it is not a mandatory options
                _clickOffsetX = Int32.Parse(alexaStep.Attributes["click.add.x"].Value);
            }
            catch { }

            try
            {
                //it is not a mandatory options
                _clickOffsetY = Int32.Parse(alexaStep.Attributes["click.add.y"].Value);
            }
            catch { }

            try
            {
                //they are not a mandatory options
                _charRectThickness = Int32.Parse(alexaStep.Attributes["rectbound.thickness"].Value);
            }
            catch { }

            try
            {
                //they are not a mandatory options
                _charRectExtendLeft = Int32.Parse(alexaStep.Attributes["rectbound.extend.left"].Value);
            }
            catch { }

            try
            {
                //they are not a mandatory options
                _charRectMinHeight = Int32.Parse(alexaStep.Attributes["rectbound.min.height"].Value);
                _charRectMaxHeight = Int32.Parse(alexaStep.Attributes["rectbound.max.height"].Value) + (_charRectThickness * 2);
                _charRectMinWidth = Int32.Parse(alexaStep.Attributes["rectbound.min.width"].Value);
                _charRectMaxWidth = Int32.Parse(alexaStep.Attributes["rectbound.max.width"].Value) + (_charRectThickness * 2);
            }
            catch { }

            try
            {
                string rectColor = alexaStep.Attributes["rectbound.color"].Value.Replace(" ", "");
                rectColor = rectColor.Replace("(", "");
                rectColor = rectColor.Replace(")", "");

                string[] colorArr = rectColor.Split(',');

                _charRectColor[0] = Int32.Parse(colorArr[0]);
                _charRectColor[1] = Int32.Parse(colorArr[1]);
                _charRectColor[2] = Int32.Parse(colorArr[2]);
            }
            catch { }

            try
            {
                _textValue = alexaStep.SelectSingleNode("text").InnerText;
            }
            catch { }

            if (alexaStep.SelectSingleNode("performance") != null) _performanceEnable = true;

            try
            {
                //they are not mandatory options
                _cropInterruptRegionRectX = Int32.Parse(alexaStep.SelectSingleNode("interrupt").Attributes["region.x"].Value);
                _cropInterruptRegionRectY = Int32.Parse(alexaStep.SelectSingleNode("interrupt").Attributes["region.y"].Value);
                _cropInterruptRegionRectHeight = Int32.Parse(alexaStep.SelectSingleNode("interrupt").Attributes["region.height"].Value);
                _cropInterruptRegionRectWidth = Int32.Parse(alexaStep.SelectSingleNode("interrupt").Attributes["region.width"].Value);
                _updateInterruptBindPoint = true;
            }
            catch
            {
            }

            try
            {
                //it's are not a mandatory options. It turns off interrupt on region
                if (alexaStep.SelectSingleNode("interrupt").Attributes["enable"].Value == "yes" && _performanceEnable == true) _mustCheckInterruptRegion = true;
                else
                    _mustCheckInterruptRegion = false;
            }
            catch { _mustCheckInterruptRegion = false; }

            try
            {
                //this is not a mandatory option
                _interruptBrightness = Int32.Parse(alexaStep.SelectSingleNode("interrupt").Attributes["brightness"].Value);
            }
            catch { }

            try
            {
                //this is not a mandatory option
                _interruptContrast = Int32.Parse(alexaStep.SelectSingleNode("interrupt").Attributes["contrast"].Value);
            }
            catch { }

            try
            {
                //this is not a mandatory option
                if (alexaStep.Attributes["scroll.enable"].Value == "yes")
                    _enableScroll = true;
            }
            catch { }

            try
            {
                //this is not a mandatory option
                _scrollStep = Int32.Parse(alexaStep.Attributes["scroll.step"].Value);
            }
            catch { }

            try
            {
                //this is not a mandatory option
                _scrollDirection = alexaStep.Attributes["scroll.direction"].Value;
            }
            catch { }

            try
            {
                //this is not a mandatory option
                _scrollLastdelay = Int32.Parse(alexaStep.Attributes["scroll.lastdelay"].Value);
            }
            catch { }

            try
            {
                string replaceColor = alexaStep.Attributes["color.replace"].Value.Replace(" ","");
                string oldColorStr = replaceColor.Split(')')[0];
                oldColorStr = oldColorStr.Replace("((", "");
                string[] oldColorArr = oldColorStr.Split(',');

                _oldColor[0] = Int32.Parse(oldColorArr[0]);
                _oldColor[1] = Int32.Parse(oldColorArr[1]);
                _oldColor[2] = Int32.Parse(oldColorArr[2]);

                string newColorStr = oldColorStr = replaceColor.Split(')')[1];
                newColorStr = newColorStr.Replace(",(", "");
                string[] newColorArr = newColorStr.Split(',');

                _newColor[0] = Int32.Parse(newColorArr[0]);
                _newColor[1] = Int32.Parse(newColorArr[1]);
                _newColor[2] = Int32.Parse(newColorArr[2]);
            }
            catch { }

            try
            {
                //check if we have to binarize the image
                if (alexaStep.Attributes["binarize"].Value == "yes")
                    _binarizeImage = true;
                else
                    _binarizeImage = false;
            }
            catch { _binarizeImage = false; }

            try
            {
                //check if we have to binarize the label
                if (alexaStep.SelectSingleNode("label").Attributes["binarize"].Value == "yes")
                    _binarizeLabel = true;
                else
                    _binarizeLabel = false;
            }
            catch { _binarizeLabel = false; }

            #endregion

            #region handle configuration error
            //write the error
            if (_textToInsert == "" && stepType == StepType.InteractInputBox && _mouseClick == true && _mouseMove == true)
            {
                LogUtils.Write(new StackFrame(0, true), LogUtils.ErrorLevel.Error, "You have to add the node \"insert\" on a \"interact\" step with \"inputbox\" as bind value. The step is " + GetStepNameNumber(alexaStep));
                Program.Finish(true);
            }

            //write the error
            if (_label == "" && (stepType == StepType.InteractInputBox || stepType == StepType.InteractButton || stepType == StepType.InteractDropDownList || stepType == StepType.InteractIconList))
            {
                LogUtils.Write(new StackFrame(0, true), LogUtils.ErrorLevel.Error, "You have to add the node \"label\" on a \"interact\" step with \"inputbox\" (or \"dropdownlist\" or \"button\" or \"iconlist\") as bind value. The step is " + GetStepNameNumber(alexaStep));
                Program.Finish(true);
            }

            //write the error
            if (_selectItem == "" && stepType == StepType.InteractDropDownList)
            {
                LogUtils.Write(new StackFrame(0, true), LogUtils.ErrorLevel.Error, "You have to add the node \"select\" on a \"interact\" step with \"dropdownlist\" as bind value. The step is " + GetStepNameNumber(alexaStep));
                Program.Finish(true);
            }

            //write the error
            if ((_boxHeight == -1 || _boxWidth == -1) && (stepType == StepType.InteractGenericBox))
            {
                LogUtils.Write(new StackFrame(0, true), LogUtils.ErrorLevel.Error, "You have to add the attributes \"height\" and \"width\" on a \"interact\" step with \"genericbox\" as bind value. The step is " + GetStepNameNumber(alexaStep));
                Program.Finish(true);
            }

            //write the error
            if (_textValue == "" && stepType == StepType.InteractText)
            {
                LogUtils.Write(new StackFrame(0, true), LogUtils.ErrorLevel.Error, "You have to add the node \"text\" on a \"interact\" step with \"word\" as bind value. The step is " + GetStepNameNumber(alexaStep));
                Program.Finish(true);
            }
            #endregion

            if (_enableScroll)
            {
                _mouseClick = false;
                _mouseMove = false;
            }

            //reset stopwatch
            _stepTime.Reset();
            //start stopwatch
            _stepTime.Start();

            stepTiming.startTime = DateTime.Now;

            while (true) //waits until we will find the input box or a timeout will occur
            {
                //reset stopwatch
                stepExecutionTime.Reset();
                //start stopwatch
                stepExecutionTime.Start();

                //if debug is active
                if (_debugLogLevel && stepType != StepType.RunExe)
                {
                    //get the log folder path for this step
                    _debugPath = Path.Combine(_debugHomeFolder, DateTime.Now.ToString(_debugFolderDateFormat) + "_Step_" + RemoveIllegalChars(_stepName.Replace(" ", "_")));

                    _debugFullPath = _debugPath;

                    //get the full path (otherwise the method Image.Save does not work)
                    DirectoryInfo dir = new DirectoryInfo(_debugFullPath);
                    _debugFullPath = dir.FullName;

                    //if the directory doesn't exist then create it
                    if (!Directory.Exists(dir.FullName)) dir.Create();

                    //set the debug folder for the Alexa.Core
                    _debugCoreFolder = Path.Combine(_debugFullPath, DateTime.Now.ToString(_debugImageDateFormat) + "_");
                    _core.SetDebugFolder(_debugCoreFolder);
                }

                //check what method we have to execute and then execute it
                if (stepType == StepType.InteractInputBox && StepInteractInputBox() == true ||
                    stepType == StepType.InteractGenericBox && StepInteractGenericBox() == true ||
                    stepType == StepType.InteractIcon && StepInteractIcon(alexaStep) == true ||
                    stepType == StepType.RunExe && StepRunExe(alexaStep) == true ||
                    stepType == StepType.InteractButton && StepInteractButton() == true ||
                    stepType == StepType.InteractIconList && StepInteractIconListItem() == true ||
                    stepType == StepType.InteractText && StepInteractText() == true ||
                    stepType == StepType.InteractDropDownList && StepInteractDropDownList() == true ||
                    stepType == StepType.Wait && StepWait(alexaStep) == true)
                {

                    if (_enableScroll)
                    {
                        Thread.Sleep(_scrollLastdelay);
                        _mouseClick = true;
                        _mouseMove = true;
                        _found = false;
                        if (stepType == StepType.InteractInputBox) StepInteractInputBox();
                        if (stepType == StepType.InteractGenericBox) StepInteractGenericBox();
                        if (stepType == StepType.InteractIcon) StepInteractIcon(alexaStep);
                        if (stepType == StepType.InteractButton) StepInteractButton();
                        if (stepType == StepType.InteractIconList) StepInteractIconListItem();
                        if (stepType == StepType.InteractText) StepInteractText();
                        if (stepType == StepType.InteractDropDownList) StepInteractDropDownList();
                    }

                    //stop all stopwatch
                    stepExecutionTime.Stop();
                    _stepTime.Stop();

                    //Save the execution time!!!
                    //How do I make the measurement of the time may seems strange, but I have to measure only the time taken by the control to appear
                    //WITHOUT THE TIME THAT THE Alexa.Core TAKE TO ANALYZE THE IMAGES. So, this is the way that I could find to measure the time
                    //efficiently.
                    if (_performanceMouseKeyboardEnable)
                        stepDuration = _stepTime.ElapsedMilliseconds - stepExecutionTime.ElapsedMilliseconds + _otherDelayTime.ElapsedMilliseconds;
                    else
                        stepDuration = _stepTime.ElapsedMilliseconds - stepExecutionTime.ElapsedMilliseconds;

                    //save all info that will be used by OutputUtils to write current
                    //step info to the output file
                    stepTiming.stepNumber = _stepNumber;
                    stepTiming.stepNode = alexaStep;
                    stepTiming.endTime = DateTime.Now;
                    stepTiming.stepDuration = stepDuration;

                    //add above info to StepTimingsCollection
                    OutputUtils.StepTimingsCollection.Add(stepTiming);

                    //LogUtils.Write(new StackFrame(0, true), LogUtils.ErrorLevel.Debug, "step " + _stepName + " method duration is: " + stepExecutionTime.ElapsedMilliseconds + "ms");

                    break;
                }

                //move mouse wheel
                if (_enableScroll) _autoIt.MouseWheel(_scrollDirection,_scrollStep);

                //stop the timer and save the execution time of the method that has execute the step
                stepExecutionTime.Stop();

                //LogUtils.Write(new StackFrame(0, true), LogUtils.ErrorLevel.Debug, "step " + _stepName + " method duration is: " + stepExecutionTime.ElapsedMilliseconds + "ms");

                if (_performanceEnable)
                {
                    //if a timeout has occurred...
                    if (_stepTime.ElapsedMilliseconds >= stepTimeout)
                    {

                        //set to false in case of next run
                        _executableStarted = false;

                        // ...write the error message
                        LogUtils.Write(new StackFrame(0, true), LogUtils.ErrorLevel.Error, "a timeout has occurred with the step number " + _stepNumber);

                        //save all info that will be used by OutputUtils to write current
                        //step info to the output file
                        stepTiming.stepNumber = _stepNumber;
                        stepTiming.stepNode = alexaStep;
                        stepTiming.endTime = DateTime.Now;
                        stepTiming.stepDuration = _stepTime.ElapsedMilliseconds;

                        //add above info to StepTimingsCollection
                        OutputUtils.StepTimingsCollection.Add(stepTiming);

                        //save the screenshot of the error
                        SaveScreenshotAfterTimeOut(alexaStep);

                        //Analyze all windows to find the control
                        if (AnalyzeWindow(stepType, alexaStep) == true) return;

                        try //check if we have to Jump to another step or if we have to execute a specific function
                        {
                            //Get timout action
                            string timeOutAction = alexaStep.SelectSingleNode("performance").Attributes["timeout.action"].Value;

                            //if user has defined a "continue" action, then break current loop so
                            //we can execute another step
                            if (timeOutAction.ToLower() == "continue") break;

                            //if user has defined a "break" action, then call the "Finish" method with "true" argument
                            //in this way the program will write the output file and then exit
                            if (timeOutAction.ToLower() == "break") Program.Finish(false);

                            //if we are here then we have to execute a function or a jump
                            //so, first of all check if we have to execute a jump
                            timeOutAction = timeOutAction.Replace("Jump(", "");
                            timeOutAction = timeOutAction.Replace(")", "");

                            //check if we have to jump to another step by its name
                            if (timeOutAction.IndexOf("step.name") != -1)
                            {
                                timeOutAction = timeOutAction.Replace("step.name='", "");
                                JumpToStep.stepName = timeOutAction.Remove(timeOutAction.Length - 1);
                                break;
                            }
                            //check if we have to jump to another step by its number
                            else if (timeOutAction.IndexOf("step.number") != -1)
                            {
                                timeOutAction = timeOutAction.Replace("step.number=", "");
                                JumpToStep.stepNumber = Int32.Parse(timeOutAction);
                                break;
                            }

                            //if we are here then we have to execute a function instead of a jump
                            timeOutAction = alexaStep.SelectSingleNode("performance").Attributes["timeout.action"].Value;
                            timeOutAction = timeOutAction.Replace("Exec(", "");
                            timeOutAction = timeOutAction.Replace(")", "");

                            //eseguire la funzione e brekkare
                            if (timeOutAction.IndexOf("action.name") != -1)
                            {
                                timeOutAction = timeOutAction.Replace("action.name='", "");
                                break;
                            }

                        }
                        //if an exception has occurred then we don't have to jump to another step or execute a function
                        catch
                        {
                            JumpToStep.stepName = "";
                            JumpToStep.stepNumber = 0;
                            break;
                        }

                    }
                }
            }
        }
コード例 #4
0
ファイル: CoreUtils.cs プロジェクト: AlexaProjects/Alexa
        /// <summary>
        /// Runs the method that insert text
        /// </summary>
        /// <param name="alexaStep">the xml node that contains the step</param>
        private static void InsertText(XmlNode alexaStep)
        {
            try
            {
                //Create a new StepTiming object, it will be used by OutputUtils to write
                //current step info to the output file
                OutputUtils.StepTiming stepTiming = new OutputUtils.StepTiming();

                //save start date
                stepTiming.startTime = DateTime.Now;

                //create a stopwatch to mesea the elapsed time of this step
                Stopwatch stopWatch = new Stopwatch();
                stopWatch.Start();

                string key = alexaStep.SelectSingleNode("text").InnerText;
                _autoIt.Send(key);

                stopWatch.Stop();

                //save all info that will be used by OutputUtils to write current
                //step info to the output file
                stepTiming.stepNumber = _stepNumber;
                stepTiming.stepNode = alexaStep;
                stepTiming.endTime = DateTime.Now;
                stepTiming.stepDuration = stopWatch.ElapsedMilliseconds;

                //add above info to StepTimingsCollection
                OutputUtils.StepTimingsCollection.Add(stepTiming);
            }
            catch (Exception ex)
            {
                //write the error
                LogUtils.Write(ex);
                Program.Finish(true);
            }
        }
コード例 #5
0
ファイル: CoreUtils.cs プロジェクト: AlexaProjects/Alexa
        /// <summary>
        /// Runs the method that executes Delay
        /// </summary>
        /// <param name="alexaStep">the xml node that contains the step</param>
        private static void ExecDelay(XmlNode alexaStep)
        {
            try
            {
                //Create a new StepTiming object, it will be used by OutputUtils to write
                //current step info to the output file
                OutputUtils.StepTiming stepTiming = new OutputUtils.StepTiming();

                //save start date
                stepTiming.startTime = DateTime.Now;

                int delay = Int32.Parse(alexaStep.SelectSingleNode("value").InnerText);
                Thread.Sleep(delay);

                //save all info that will be used by OutputUtils to write current
                //step info to the output file
                stepTiming.stepNumber = _stepNumber;
                stepTiming.stepNode = alexaStep;
                stepTiming.endTime = DateTime.Now;
                stepTiming.stepDuration = delay;

                //add above info to StepTimingsCollection
                OutputUtils.StepTimingsCollection.Add(stepTiming);
            }
            catch (Exception ex)
            {
                //write the error
                LogUtils.Write(ex);
                Program.Finish(true);
            }
        }