Example #1
0
        private void PerformAntiIdle()
        {
            lastAntiIdleEvent = DateTime.Now;
            var mouseMove = new Core.AutomationCommands.SendMouseMoveCommand();

            mouseMove.v_XMousePosition = Cursor.Position.X + 1;
            mouseMove.v_YMousePosition = Cursor.Position.Y + 1;
            Notify("Anti-Idle Triggered");
        }
Example #2
0
        private void ShowMouseCaptureForm(object sender, EventArgs e)
        {
            sharpRPA.UI.Forms.Supplemental.frmShowCursorPosition frmShowCursorPos = new sharpRPA.UI.Forms.Supplemental.frmShowCursorPosition();

            //if user made a successful selection
            if (frmShowCursorPos.ShowDialog() == DialogResult.OK)
            {
                //Todo - ideally one function to add to textbox which adds to class

                //add selected variables to associated control text
                flw_InputVariables.Controls["v_XMousePosition"].Text = frmShowCursorPos.xPos.ToString();
                flw_InputVariables.Controls["v_YMousePosition"].Text = frmShowCursorPos.yPos.ToString();

                //find current command and add to underlying class
                Core.AutomationCommands.SendMouseMoveCommand cmd = (Core.AutomationCommands.SendMouseMoveCommand)selectedCommand;
                cmd.v_XMousePosition = frmShowCursorPos.xPos;
                cmd.v_YMousePosition = frmShowCursorPos.yPos;
            }
        }
Example #3
0
        //handles generation of controls for the main flowlayout and tracking/assignment of input elements

        /// <summary>
        /// Generate UI elements for data-collection based on the selected command
        /// </summary>
        private void GenerateUIInputElements(Core.AutomationCommands.ScriptCommand currentCommand)
        {
            //remove all existing controls
            while (flw_InputVariables.Controls.Count > 0)
            {
                flw_InputVariables.Controls.RemoveAt(0);
            }

            //find all input variables -- all input variables start with "v_" in the associated class
            var inputVariableFields = currentCommand.GetType().GetProperties().Where(f => f.Name.StartsWith("v_")).ToList();

            //set form height
            int formHeight = 0;

            //loop through available variables
            foreach (var inputField in inputVariableFields)
            {
                //create a label for each variable name
                Label inputLabel = new Label();
                inputLabel.AutoSize  = true;
                inputLabel.Font      = new Font("Segoe UI", 10, FontStyle.Bold);
                inputLabel.ForeColor = Color.SteelBlue;
                inputLabel.Name      = "lbl_" + inputField.Name;
                formHeight          += 50;
                //apply friendly translation
                var propertyAttributesAssigned = inputField.GetCustomAttributes(typeof(Core.AutomationCommands.Attributes.PropertyAttributes.PropertyDescription), true);

                if (propertyAttributesAssigned.Length > 0)
                {
                    var attribute = (Core.AutomationCommands.Attributes.PropertyAttributes.PropertyDescription)propertyAttributesAssigned[0];
                    inputLabel.Text = attribute.propertyDescription;
                }
                else
                {
                    inputLabel.Text = inputField.Name;
                }

                var inputControl = GenerateInputControl(inputField, currentCommand);

                formHeight += inputControl.Height;

                //add label and input control to flow layout
                flw_InputVariables.Controls.Add(inputLabel);

                //find if UI helpers are applied
                var propertyAllowsVars = inputField.GetCustomAttributes(typeof(Core.AutomationCommands.Attributes.PropertyAttributes.PropertyUIHelper), true);

                if (propertyAllowsVars.Length > 0)
                {
                    foreach (Core.AutomationCommands.Attributes.PropertyAttributes.PropertyUIHelper attrib in propertyAllowsVars)
                    {
                        sharpRPA.UI.CustomControls.CommandItemControl variableInsertion = new sharpRPA.UI.CustomControls.CommandItemControl();
                        variableInsertion.Padding   = new System.Windows.Forms.Padding(10, 0, 0, 0);
                        variableInsertion.ForeColor = Color.Black;
                        variableInsertion.Tag       = inputControl;

                        switch (attrib.additionalHelper)
                        {
                        case Core.AutomationCommands.Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper:
                            //show variable selector
                            variableInsertion.CommandImage   = UI.Images.GetUIImage("VariableCommand");
                            variableInsertion.CommandDisplay = "Insert Variable";
                            variableInsertion.Click         += ShowVariableSelector;
                            flw_InputVariables.Controls.Add(variableInsertion);
                            break;

                        case Core.AutomationCommands.Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowFileSelectionHelper:
                            //show file selector
                            variableInsertion.CommandImage   = UI.Images.GetUIImage("ClipboardGetTextCommand");
                            variableInsertion.CommandDisplay = "Select a File";
                            variableInsertion.ForeColor      = Color.Black;
                            variableInsertion.Tag            = inputControl;
                            variableInsertion.Click         += ShowFileSelector;
                            flw_InputVariables.Controls.Add(variableInsertion);
                            break;

                        default:
                            break;
                        }
                    }

                    //var attribute = (Core.AutomationCommands.Attributes.PropertyAttributes.PropertyUIHelper)propertyAllowsVars[0];
                    //if (attribute.propertyAllowsVariables)
                    //{
                    //    //show variable selector
                    //    sharpRPA.UI.CustomControls.CommandItemControl variableInsertion = new sharpRPA.UI.CustomControls.CommandItemControl();
                    //    variableInsertion.CommandImage = UI.Images.GetUIImage("VariableCommand");
                    //    variableInsertion.CommandDisplay = "Insert Variable";
                    //    variableInsertion.ForeColor = Color.Black;
                    //    variableInsertion.Tag = inputControl;
                    //    variableInsertion.Click += ShowVariableSelector;
                    //    flw_InputVariables.Controls.Add(variableInsertion);
                    //}
                }

                //these types get a helper button to launch another form
                if (inputField.Name == "v_WebSearchTable")
                {
                    Core.AutomationCommands.IEBrowserElementCommand webCommand = (Core.AutomationCommands.IEBrowserElementCommand)currentCommand;
                    sharpRPA.UI.CustomControls.CommandItemControl   newitm     = new sharpRPA.UI.CustomControls.CommandItemControl();

                    newitm.CommandImage   = UI.Images.GetUIImage(webCommand.CommandName);
                    newitm.CommandDisplay = "Click here to Capture Web Element";
                    newitm.ForeColor      = Color.Black;
                    newitm.Click         += ShowElementCaptureForm;
                    flw_InputVariables.Controls.Add(newitm);
                }
                else if (inputField.Name == "v_XMousePosition")
                {
                    Core.AutomationCommands.SendMouseMoveCommand  mouseCommand = (Core.AutomationCommands.SendMouseMoveCommand)currentCommand;
                    sharpRPA.UI.CustomControls.CommandItemControl newitm       = new sharpRPA.UI.CustomControls.CommandItemControl();
                    newitm.CommandImage   = UI.Images.GetUIImage(mouseCommand.CommandName);
                    newitm.CommandDisplay = "Click here to Capture Mouse Position";
                    newitm.ForeColor      = Color.Black;
                    newitm.Click         += ShowMouseCaptureForm;
                    flw_InputVariables.Controls.Add(newitm);
                }

                //add to flow layout
                flw_InputVariables.Controls.Add(inputControl);

                //handle edit mode to add combobox data
                if ((creationMode == CreationMode.Edit) && (currentCommand is Core.AutomationCommands.BeginIfCommand) && (inputControl is DataGridView))
                {
                    Core.AutomationCommands.BeginIfCommand ifCmd = (Core.AutomationCommands.BeginIfCommand)currentCommand;
                    if (ifCmd.v_IfActionType == "Value")
                    {
                        DataGridViewComboBoxCell comparisonComboBox = new DataGridViewComboBoxCell();
                        comparisonComboBox.Items.Add("is equal to");
                        comparisonComboBox.Items.Add("is greater than");
                        comparisonComboBox.Items.Add("is greater than or equal to");
                        comparisonComboBox.Items.Add("is less than");
                        comparisonComboBox.Items.Add("is less than or equal to");
                        comparisonComboBox.Items.Add("is not equal to");

                        //assign cell as a combobox
                        DataGridView inputCtrl = (DataGridView)inputControl;
                        inputCtrl.Rows[1].Cells[1] = comparisonComboBox;
                    }
                }
            }

            if ((currentCommand is Core.AutomationCommands.IEBrowserElementCommand) && (creationMode == CreationMode.Edit))
            {
                Core.AutomationCommands.IEBrowserElementCommand webCommand = (Core.AutomationCommands.IEBrowserElementCommand)currentCommand;

                if (webCommand.v_WebAction == "Invoke Click")
                {
                    DataGridView webActionParameterBox    = (DataGridView)flw_InputVariables.Controls["v_WebActionParameterTable"];
                    Label        additionalParameterLabel = (Label)flw_InputVariables.Controls["lbl_v_WebActionParameterTable"];
                    additionalParameterLabel.Visible = false;
                    webActionParameterBox.Visible    = false;
                }
            }

            //add additional offset
            this.Height = formHeight + 200;
        }
Example #4
0
            //build mouse command
            private static void BuildMouseCommand(IntPtr lParam, MouseMessages mouseMessage)
            {
                string mouseEventClickType = string.Empty;

                switch (mouseMessage)
                {
                case MouseMessages.WM_LBUTTONDOWN:
                    mouseEventClickType = "Left Down";
                    break;

                case MouseMessages.WM_LBUTTONUP:
                    mouseEventClickType = "Left Up";
                    break;

                case MouseMessages.WM_MOUSEMOVE:
                    mouseEventClickType = "None";



                    if (lastMouseMove.ElapsedMilliseconds >= msResolution)
                    {
                        lastMouseMove.Restart();
                    }
                    else
                    {
                        return;
                    }


                    break;

                case MouseMessages.WM_RBUTTONDOWN:
                    mouseEventClickType = "Right Down";
                    break;

                case MouseMessages.WM_RBUTTONUP:
                    mouseEventClickType = "Right Up";
                    break;

                default:
                    return;
                }

                ////return if non matching event
                //if (mouseEventClickType == string.Empty)
                //    return;



                //return if we do not want to capture mouse moves
                if ((!performMouseMoveCapture) && (mouseEventClickType == "None"))
                {
                    return;
                }

                //return if we do not want to capture mouse clicks
                if ((!performMouseClickCapture) && (mouseEventClickType != "None"))
                {
                    return;
                }

                //build a pause command to track pause since last command
                BuildPauseCommand();


                //define new mouse command
                MSLLHOOKSTRUCT hookStruct = (MSLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(MSLLHOOKSTRUCT));



                var mouseMove = new Core.AutomationCommands.SendMouseMoveCommand
                {
                    v_XMousePosition = hookStruct.pt.x,
                    v_YMousePosition = hookStruct.pt.y,
                    v_MouseClick     = mouseEventClickType
                };

                if (mouseEventClickType != "None")
                {
                    IntPtr winHandle = WindowFromPoint(hookStruct.pt);

                    int length     = GetWindowText(winHandle, _Buffer, _Buffer.Capacity);
                    var windowName = _Buffer.ToString();

                    mouseMove.v_Comment = "Clicked On Window: " + windowName;
                }

                generatedCommands.Add(mouseMove);
            }