Esempio n. 1
0
        public async override Task RunCommand(object sender)
        {
            var engine = (IAutomationEngineInstance)sender;

            //user image to bitmap
            Bitmap capturedBmp = new Bitmap(CommonMethods.Base64ToImage(v_ImageCapture));

            capturedBmp.SetVariableValue(engine, v_OutputUserVariableName);
        }
Esempio n. 2
0
        public override void RunCommand(object sender)
        {
            var engine = (IAutomationEngineInstance)sender;

            //user image to bitmap
            Bitmap capturedBmp = new Bitmap(CommonMethods.Base64ToImage(v_ImageCapture));

            capturedBmp.StoreInUserVariable(engine, v_OutputUserVariableName, nameof(v_OutputUserVariableName), this);
        }
        private void frmNewCommand_Load(object sender, EventArgs e)
        {
            // Initialize CommandControls with Current Editor
            _commandControls = new CommandControls(this, TypeContext, AContainer, ProjectPath);
            _errorToolTip    = AddValidationErrorToolTip();

            //order list
            CommandList = CommandList.OrderBy(itm => itm.FullName).ToList();

            //set command list
            cboSelectedCommand.DataSource = CommandList;

            //Set DisplayMember to track DisplayValue from the class
            cboSelectedCommand.DisplayMember = "FullName";

            if ((CreationModeInstance == CreationMode.Add) && (DefaultStartupCommand != null) && (CommandList.Where(x => x.FullName == DefaultStartupCommand).Count() > 0))
            {
                cboSelectedCommand.SelectedIndex = cboSelectedCommand.FindStringExact(DefaultStartupCommand);
            }
            else if (CreationModeInstance == CreationMode.Edit)
            {
                // var requiredCommand = commandList.Where(x => x.FullName.Contains(defaultStartupCommand)).FirstOrDefault(); //&& x.CommandClass.Name == originalCommand.CommandName).FirstOrDefault();

                var requiredCommand = CommandList.Where(x => x.Command.ToString() == EditingCommand.ToString()).FirstOrDefault();

                if (requiredCommand == null)
                {
                    MessageBox.Show("Command was not found! " + DefaultStartupCommand);
                }
                else
                {
                    cboSelectedCommand.SelectedIndex = cboSelectedCommand.FindStringExact(requiredCommand.FullName);
                }
            }
            else
            {
                cboSelectedCommand.SelectedIndex = 0;
            }

            //force commit event to populate the flow layout
            cboSelectedCommand_SelectionChangeCommitted(null, null);

            //apply original variables if command is being updated
            if (OriginalCommand != null)
            {
                //update bindings
                foreach (Control c in flw_InputVariables.Controls)
                {
                    foreach (Binding b in c.DataBindings)
                    {
                        b.ReadValue();
                    }

                    //helper for box
                    if (c is UIPictureBox)
                    {
                        var typedControl = (UIPictureBox)c;

                        dynamic cmd;
                        if (SelectedCommand.CommandName == "SurfaceAutomationCommand")
                        {
                            cmd = (IImageCommands)SelectedCommand;

                            if (!string.IsNullOrEmpty(cmd.v_ImageCapture))
                            {
                                typedControl.Image = CommonMethods.Base64ToImage(cmd.v_ImageCapture);
                            }
                        }
                        else if (SelectedCommand.CommandName == "CaptureImageCommand")
                        {
                            cmd = (IImageCommands)SelectedCommand;

                            if (!string.IsNullOrEmpty(cmd.v_ImageCapture))
                            {
                                typedControl.Image = CommonMethods.Base64ToImage(cmd.v_ImageCapture);
                            }
                        }
                    }
                }
                //handle selection change events
            }

            //gracefully handle post initialization setups (drop downs, etc)
            AfterFormInitialization();
            ScriptContext.AddIntellisenseControls(Controls);
        }
        public override void RunCommand(object sender)
        {
            var  engine   = (IAutomationEngineInstance)sender;
            bool testMode = TestMode;
            //user image to bitmap
            Bitmap userImage = new Bitmap(CommonMethods.Base64ToImage(v_ImageCapture));
            double accuracy;

            try
            {
                accuracy = double.Parse(v_MatchAccuracy.ConvertUserVariableToString(engine));
                if (accuracy > 1 || accuracy < 0)
                {
                    throw new ArgumentOutOfRangeException("Accuracy value is out of range (0-1)");
                }
            }
            catch (Exception)
            {
                throw new InvalidDataException("Accuracy value is invalid");
            }

            dynamic element = null;

            if (v_ImageAction == "Wait For Image To Exist")
            {
                var timeoutText = (from rw in v_ImageActionParameterTable.AsEnumerable()
                                   where rw.Field <string>("Parameter Name") == "Timeout (Seconds)"
                                   select rw.Field <string>("Parameter Value")).FirstOrDefault();

                timeoutText = timeoutText.ConvertUserVariableToString(engine);
                int timeOut   = Convert.ToInt32(timeoutText);
                var timeToEnd = DateTime.Now.AddSeconds(timeOut);

                while (timeToEnd >= DateTime.Now)
                {
                    try
                    {
                        element = CommandsHelper.FindImageElement(userImage, accuracy);

                        if (element == null)
                        {
                            throw new Exception("Image Element Not Found");
                        }
                        else
                        {
                            break;
                        }
                    }
                    catch (Exception)
                    {
                        engine.ReportProgress("Element Not Yet Found... " + (timeToEnd - DateTime.Now).Seconds + "s remain");
                        Thread.Sleep(1000);
                    }
                }

                if (element == null)
                {
                    throw new Exception("Image Element Not Found");
                }

                return;
            }
            else
            {
                element = CommandsHelper.FindImageElement(userImage, accuracy);
            }

            try
            {
                string clickPosition;
                int    xAdjust;
                int    yAdjust;
                switch (v_ImageAction)
                {
                case "Click Image":
                    string clickType = (from rw in v_ImageActionParameterTable.AsEnumerable()
                                        where rw.Field <string>("Parameter Name") == "Click Type"
                                        select rw.Field <string>("Parameter Value")).FirstOrDefault();
                    clickPosition = (from rw in v_ImageActionParameterTable.AsEnumerable()
                                     where rw.Field <string>("Parameter Name") == "Click Position"
                                     select rw.Field <string>("Parameter Value")).FirstOrDefault();
                    xAdjust = Convert.ToInt32((from rw in v_ImageActionParameterTable.AsEnumerable()
                                               where rw.Field <string>("Parameter Name") == "X Adjustment"
                                               select rw.Field <string>("Parameter Value")).FirstOrDefault().ConvertUserVariableToString(engine));
                    yAdjust = Convert.ToInt32((from rw in v_ImageActionParameterTable.AsEnumerable()
                                               where rw.Field <string>("Parameter Name") == "Y Adjustment"
                                               select rw.Field <string>("Parameter Value")).FirstOrDefault().ConvertUserVariableToString(engine));

                    Point clickPositionPoint = GetClickPosition(clickPosition, element);

                    //move mouse to position
                    var mouseX = (clickPositionPoint.X + xAdjust).ToString();
                    var mouseY = (clickPositionPoint.Y + yAdjust).ToString();
                    User32Functions.SendMouseMove(mouseX, mouseY, clickType);
                    break;

                case "Set Text":
                    string textToSet = (from rw in v_ImageActionParameterTable.AsEnumerable()
                                        where rw.Field <string>("Parameter Name") == "Text To Set"
                                        select rw.Field <string>("Parameter Value")).FirstOrDefault().ConvertUserVariableToString(engine);
                    clickPosition = (from rw in v_ImageActionParameterTable.AsEnumerable()
                                     where rw.Field <string>("Parameter Name") == "Click Position"
                                     select rw.Field <string>("Parameter Value")).FirstOrDefault();
                    xAdjust = Convert.ToInt32((from rw in v_ImageActionParameterTable.AsEnumerable()
                                               where rw.Field <string>("Parameter Name") == "X Adjustment"
                                               select rw.Field <string>("Parameter Value")).FirstOrDefault().ConvertUserVariableToString(engine));
                    yAdjust = Convert.ToInt32((from rw in v_ImageActionParameterTable.AsEnumerable()
                                               where rw.Field <string>("Parameter Name") == "Y Adjustment"
                                               select rw.Field <string>("Parameter Value")).FirstOrDefault().ConvertUserVariableToString(engine));
                    string encryptedData = (from rw in v_ImageActionParameterTable.AsEnumerable()
                                            where rw.Field <string>("Parameter Name") == "Encrypted Text"
                                            select rw.Field <string>("Parameter Value")).FirstOrDefault();

                    if (encryptedData == "Encrypted")
                    {
                        textToSet = EncryptionServices.DecryptString(textToSet, "OPENBOTS");
                    }

                    Point setTextPositionPoint = GetClickPosition(clickPosition, element);

                    //move mouse to position and set text
                    var xPos = (setTextPositionPoint.X + xAdjust).ToString();
                    var yPos = (setTextPositionPoint.Y + yAdjust).ToString();
                    User32Functions.SendMouseMove(xPos, yPos, "Left Click");

                    var simulator = new InputSimulator();
                    simulator.Keyboard.TextEntry(textToSet);
                    Thread.Sleep(100);
                    break;

                case "Set Secure Text":
                    var secureString = (from rw in v_ImageActionParameterTable.AsEnumerable()
                                        where rw.Field <string>("Parameter Name") == "Secure String Variable"
                                        select rw.Field <string>("Parameter Value")).FirstOrDefault();
                    clickPosition = (from rw in v_ImageActionParameterTable.AsEnumerable()
                                     where rw.Field <string>("Parameter Name") == "Click Position"
                                     select rw.Field <string>("Parameter Value")).FirstOrDefault();
                    xAdjust = Convert.ToInt32((from rw in v_ImageActionParameterTable.AsEnumerable()
                                               where rw.Field <string>("Parameter Name") == "X Adjustment"
                                               select rw.Field <string>("Parameter Value")).FirstOrDefault().ConvertUserVariableToString(engine));
                    yAdjust = Convert.ToInt32((from rw in v_ImageActionParameterTable.AsEnumerable()
                                               where rw.Field <string>("Parameter Name") == "Y Adjustment"
                                               select rw.Field <string>("Parameter Value")).FirstOrDefault().ConvertUserVariableToString(engine));

                    var secureStrVariable = secureString.ConvertUserVariableToObject(engine, typeof(SecureString));

                    if (secureStrVariable is SecureString)
                    {
                        secureString = ((SecureString)secureStrVariable).ConvertSecureStringToString();
                    }
                    else
                    {
                        throw new ArgumentException("Provided Argument is not a 'Secure String'");
                    }

                    Point setSecureTextPositionPoint = GetClickPosition(clickPosition, element);

                    //move mouse to position and set text
                    var xPosition = (setSecureTextPositionPoint.X + xAdjust).ToString();
                    var yPosition = (setSecureTextPositionPoint.Y + yAdjust).ToString();
                    User32Functions.SendMouseMove(xPosition, yPosition, "Left Click");

                    var simulator2 = new InputSimulator();
                    simulator2.Keyboard.TextEntry(secureString);
                    Thread.Sleep(100);
                    break;

                case "Image Exists":
                    var outputVariable = (from rw in v_ImageActionParameterTable.AsEnumerable()
                                          where rw.Field <string>("Parameter Name") == "Output Bool Variable Name"
                                          select rw.Field <string>("Parameter Value")).FirstOrDefault();

                    if (element != null)
                    {
                        true.StoreInUserVariable(engine, outputVariable, typeof(bool));
                    }
                    else
                    {
                        false.StoreInUserVariable(engine, outputVariable, typeof(bool));
                    }
                    break;

                default:
                    break;
                }
                FormsHelper.ShowAllForms();
            }
            catch (Exception ex)
            {
                FormsHelper.ShowAllForms();
                if (element == null)
                {
                    throw new Exception("Specified image was not found in window!");
                }
                else
                {
                    throw ex;
                }
            }
        }
Esempio n. 5
0
        public async override Task RunCommand(object sender)
        {
            var    engine     = (IAutomationEngineInstance)sender;
            string windowName = (string)await v_WindowName.EvaluateCode(engine);

            int timeout = (int)await v_Timeout.EvaluateCode(engine);

            var timeToEnd = DateTime.Now.AddSeconds(timeout);

            bool testMode = TestMode;
            //user image to bitmap
            Bitmap userImage = new Bitmap(CommonMethods.Base64ToImage(v_ImageCapture));
            double accuracy;

            try
            {
                accuracy = Convert.ToDouble(await v_MatchAccuracy.EvaluateCode(engine));
                if (accuracy > 1 || accuracy < 0)
                {
                    throw new ArgumentOutOfRangeException("Accuracy value is out of range (0-1)");
                }
            }
            catch (Exception)
            {
                throw new InvalidDataException("Accuracy value is invalid");
            }

            //Activate window if specified
            if (windowName != "None")
            {
                while (timeToEnd >= DateTime.Now)
                {
                    try
                    {
                        if (engine.IsCancellationPending)
                        {
                            break;
                        }

                        User32Functions.ActivateWindow(windowName);

                        if (!User32Functions.GetActiveWindowTitle().Equals(windowName))
                        {
                            throw new Exception($"Window '{windowName}' Not Yet Found... ");
                        }

                        break;
                    }
                    catch (Exception)
                    {
                        engine.ReportProgress($"Window '{windowName}' Not Yet Found... {(timeToEnd - DateTime.Now).Minutes}m, {(timeToEnd - DateTime.Now).Seconds}s remain");
                        Thread.Sleep(500);
                    }
                }

                if (!User32Functions.GetActiveWindowTitle().Equals(windowName))
                {
                    throw new Exception($"Window '{windowName}' Not Found");
                }
                else
                {
                    Thread.Sleep(500);
                }
            }

            dynamic element = null;

            while (timeToEnd >= DateTime.Now)
            {
                try
                {
                    if (engine.IsCancellationPending)
                    {
                        break;
                    }

                    element = CommandsHelper.FindImageElement(userImage, accuracy, engine, timeToEnd);

                    if (element == null)
                    {
                        throw new Exception("Specified image was not found in window!");
                    }
                    else
                    {
                        break;
                    }
                }
                catch (Exception)
                {
                    engine.ReportProgress("Element Not Yet Found... " + (timeToEnd - DateTime.Now).Seconds + "s remain");
                    Thread.Sleep(1000);
                }
            }

            if (element == null)
            {
                FormsHelper.ShowAllForms(engine.EngineContext.IsDebugMode);
                throw new Exception("Specified image was not found in window!");
            }

            PerformImageElementAction(engine, element);
        }