public string GetCSCode(string focusedElemName)
        {
            StringBuilder sb = new StringBuilder();

            //sb.AppendLine("// " + this.Description);

            //string consoleWriteLine = "Console.WriteLine(\"" + this.Description.Replace("\"", "\\\"") + "\");";
            //sb.AppendLine(consoleWriteLine);

            if (this.UiTaskName == EnumUiTaskName.LeftClick)
            {
                sb.Append(GenerateCSCode.LeftClick(this, VariableName));
            }
            else if (this.UiTaskName == EnumUiTaskName.RightClick)
            {
                sb.Append(GenerateCSCode.RightClick(this, VariableName));
            }
            else if (this.UiTaskName == EnumUiTaskName.LeftDblClick)
            {
                sb.Append(GenerateCSCode.DoubleClick(this, VariableName));
            }
            else if (this.UiTaskName == EnumUiTaskName.MouseWheel)
            {
                sb.Append(GenerateCSCode.Wheel(this, VariableName));
            }
            else if (this.UiTaskName == EnumUiTaskName.KeyboardInput)
            {
                sb.Append(GenerateCSCode.SendKeys(this, focusedElemName));
            }

            return(sb.ToString());
        }
Beispiel #2
0
        public string GetCSCode(int nOrder, int nOrderFocused)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("// " + GetDescription());

            string consoleWriteLine = "Console.WriteLine(\"" + GetDescription().Replace("\"", "\\\"") + "\");";

            sb.AppendLine(consoleWriteLine);

            if (!string.IsNullOrEmpty(GetRootSessionXPath()))
            {
                sb.AppendLine($"// xpath excluding session root: {GetXPathExcludingSessinoRoot()}");
            }

            if (GetTask() == UiTaskName.LeftClick)
            {
                sb.AppendLine(GenerateCSCode.LeftClick(this, nOrder));
            }
            else if (GetTask() == UiTaskName.RightClick)
            {
                sb.AppendLine(GenerateCSCode.RightClick(this, nOrder));
            }
            else if (GetTask() == UiTaskName.LeftDblClick)
            {
                sb.AppendLine(GenerateCSCode.DoubleClick(this, nOrder));
            }
            else if (GetTask() == UiTaskName.MouseWheel)
            {
                sb.AppendLine(GenerateCSCode.Wheel(this, nOrder));
            }
            else if (GetTask() == UiTaskName.Drag)
            {
                sb.AppendLine(GenerateCSCode.Drag(this, nOrder));
            }
            else if (GetTask() == UiTaskName.MouseHover)
            {
                sb.AppendLine(GenerateCSCode.MouseHover(this, nOrder));
            }
            else if (GetTask() == UiTaskName.KeyboardInput)
            {
                sb.AppendLine(GenerateCSCode.SendKeys(this, nOrder, nOrderFocused));
            }
            else
            {
                sb.AppendLine(GenerateCSCode.FindByXPath(this, nOrder));
            }

            return(sb.ToString());
        }
        public void AppendKeyboardInput(string textToAppend)
        {
            byte[] data1 = Convert.FromBase64String(this.Base64Text);
            byte[] data2 = Convert.FromBase64String(textToAppend);
            byte[] data  = new byte[data1.Length + data2.Length];
            data1.CopyTo(data, 0);
            data2.CopyTo(data, data1.Length);
            this.Base64Text = Convert.ToBase64String(data);

            var           keyboardTaskDescription = GenerateCSCode.GetDecodedKeyboardInput(this.Base64Text, this.CapsLock, this.NumLock, this.ScrollLock);
            StringBuilder sb = new StringBuilder();

            foreach (var strLine in keyboardTaskDescription)
            {
                sb.Append(strLine);
            }

            this._strDescription = $"{this.UiTaskName} VirtualKeys=\"{sb.ToString()}\" CapsLock={this.CapsLock} NumLock={this.NumLock} ScrollLock={this.ScrollLock}";
        }
Beispiel #4
0
        public static void AddKeyboardInputTask(ref string strBase64, bool bCapsLock, bool bNumLock, bool bScrollLock)
        {
            if (string.IsNullOrEmpty(strBase64))
            {
                AppInsights.LogException("AddKeyboardInputTask", "strBase64 is null");
                return;
            }

            var keyboardTaskDescription = GenerateCSCode.GetDecodedKeyboardInput(strBase64, bCapsLock, bNumLock, bScrollLock);

            StringBuilder sb = new StringBuilder();

            foreach (var strLine in keyboardTaskDescription)
            {
                sb.Append(GenerateXPath.XmlEncode(strLine));
            }

            RecordedUiTask lastRecordedUi = null;

            lock (RecordedUiTask.s_lockRecordedUi)
            {
                if (RecordedUiTask.s_listRecordedUi.Count > 0)
                {
                    lastRecordedUi = RecordedUiTask.s_listRecordedUi.Last();
                }
            }

            if (lastRecordedUi != null && lastRecordedUi.UiTaskName == EnumUiTaskName.KeyboardInput)
            {
                lastRecordedUi.AppendKeyboardInput(strBase64);
            }
            else
            {
                var keyboarTask = new RecordedUiTask(EnumUiTaskName.KeyboardInput, strBase64, bCapsLock, bScrollLock, bNumLock);
                MainWindow.AddRecordedUi(keyboarTask);
            }

            strBase64 = null;
        }
Beispiel #5
0
        public string GetDescription()
        {
            if (_strDescription == null)
            {
                XmlDocument xmlDocument = new XmlDocument();
                try
                {
                    xmlDocument.LoadXml(_strXmlNode);
                }
                catch (Exception ex)
                {
                    return(ex.ToString());
                }

                XmlNodeList uiTasks = xmlDocument.GetElementsByTagName("UiTask");
                if (uiTasks.Count == 1)
                {
                    string strTask = uiTasks[0].Attributes["task"].Value;

                    _uiTaskName = ConstVariables.FromStringTaskName(strTask);

                    if (_uiTaskName == UiTaskName.KeyboardInput)
                    {
                        _strBase64Text = uiTasks[0].Attributes["base64String"].Value;

                        var varCapLock = uiTasks[0].Attributes["CapsLock"].Value;
                        if (varCapLock != null)
                        {
                            _bCapsLock = Convert.ToBoolean(varCapLock);
                        }

                        var varNumLock = uiTasks[0].Attributes["NumLock"].Value;
                        if (varNumLock != null)
                        {
                            _bNumLock = Convert.ToBoolean(varNumLock);
                        }

                        var varScrollLock = uiTasks[0].Attributes["ScrollLock"].Value;
                        if (varScrollLock != null)
                        {
                            _bScrollLock = Convert.ToBoolean(varScrollLock);
                        }

                        var           keyboardTaskDescription = GenerateCSCode.GetDecodedKeyboardInput(_strBase64Text, _bCapsLock, _bNumLock, _bScrollLock);
                        StringBuilder sb = new StringBuilder();
                        foreach (var strLine in keyboardTaskDescription)
                        {
                            sb.Append(strLine);
                        }

                        _strDescription = $"{_uiTaskName} VirtualKeys=\"{sb.ToString()}\" CapsLock={_bCapsLock} NumLock={_bNumLock} ScrollLock={_bScrollLock}";
                    }
                    else
                    {
                        var vleft = uiTasks[0].Attributes["x"];
                        _strLeft = vleft != null ? vleft.Value : "";

                        var vtop = uiTasks[0].Attributes["y"];
                        _strTop = vtop != null ? vtop.Value : "";

                        string name = uiTasks[0].LastChild.Attributes[ConstVariables.Name].Value;
                        if (string.IsNullOrEmpty(name))
                        {
                            name = uiTasks[0].LastChild.Attributes[ConstVariables.AutomationId].Value;
                            if (string.IsNullOrEmpty(name))
                            {
                                name = uiTasks[0].Name;
                            }
                        }

                        if (_uiTaskName == UiTaskName.Drag || _uiTaskName == UiTaskName.MouseWheel)
                        {
                            _strDescription = $"{_uiTaskName} on \"{name}\" at ({_strLeft},{_strTop}) drag ({_nDeltaX},{_nDeltaY})";
                        }
                        else
                        {
                            _strDescription = $"{_uiTaskName} on \"{name}\" at ({_strLeft},{_strTop})";
                        }
                    }
                }
            }

            return(_strDescription);
        }
Beispiel #6
0
        public static IntPtr ProcessMessage(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            handled = false;
            string left, top;

            if (msg == (int)UiTaskName.Inspect)
            {
                var nodesRootToLeaf = GetRootToLeafNodes(strUiToRootXmlNodesInspect, out left, out top);
                if (nodesRootToLeaf != null)
                {
                    string strXmlNodes = CreateUiTaskXmlNodeString(nodesRootToLeaf, ((UiTaskName)msg).ToString(), left, top);
                    if (string.IsNullOrEmpty(strXmlNodes) == false)
                    {
                        MainWindow.AddRecordedUi(new RecordedUiTask(strXmlNodes, 0, (UiTaskName)msg));
                    }
                }
                return(IntPtr.Zero);
            }

            if (MainWindow.IsRecording() == false)
            {
                return(IntPtr.Zero);
            }

            lock (lockUiPath)
            {
                if (msg == (int)UiTaskName.KeyboardInput)
                {
                    var           keyboardTaskDescription = GenerateCSCode.GetDecodedKeyboardInput(strBase64KeyboardInput, bCapsLock, bNumLock, bScrollLock);
                    StringBuilder sb = new StringBuilder();
                    foreach (var strLine in keyboardTaskDescription)
                    {
                        sb.Append(GenerateXPath.XmlEncode(strLine));
                    }

                    var keyboarTask = new RecordedUiTask($"<UiTask task=\"{UiTaskName.KeyboardInput}\" VirtualKeys=\"{sb.ToString()}\" base64String=\"{strBase64KeyboardInput}\" CapsLock=\"{bCapsLock}\" NumLock=\"{bNumLock}\" ScrollLock=\"{bScrollLock}\"/>\n", (int)wParam, (UiTaskName)msg);
                    MainWindow.AddRecordedUi(keyboarTask);
                }
                else if ((int)UiTaskName.LeftClick <= msg && msg <= (int)UiTaskName.MouseHover)
                {
                    RecordedUiTask lastRecordedUi = null;
                    if (MainWindow.s_listRecordedUi.Count > 0)
                    {
                        lastRecordedUi = MainWindow.s_listRecordedUi.Last();
                    }

                    string        strXmlNodes     = null;
                    List <string> nodesRootToLeaf = GetRootToLeafNodes(strUiToRootXmlNodes, out left, out top);
                    if (nodesRootToLeaf != null && nodesRootToLeaf.Count > 1)
                    {
                        strXmlNodes = CreateUiTaskXmlNodeString(nodesRootToLeaf, ((UiTaskName)msg).ToString(), left, top);
                    }

                    bool bAddNewTask = true;

                    // Completing last UI
                    if (msg == (int)UiTaskName.LeftDblClick && lastRecordedUi != null)
                    {
                        lastRecordedUi.ChangeClickToDoubleClick();
                        bAddNewTask = false;
                    }
                    else if (msg == (int)UiTaskName.DragStop && lastRecordedUi != null)
                    {
                        int deltaX = wParam.ToInt32() - ConstVariables.DragDeltaOffset;
                        int deltaY = lParam.ToInt32() - ConstVariables.DragDeltaOffset;
                        lastRecordedUi.DragComplete(deltaX, deltaY);
                        bAddNewTask = false;
                    }
                    else if (msg == (int)UiTaskName.MouseWheel)
                    {
                        int delta = wParam.ToInt32() - ConstVariables.DragDeltaOffset;

                        if (strXmlNodes != null)
                        {
                            if (lastRecordedUi == null || lastRecordedUi.GetTask() != UiTaskName.MouseWheel)
                            {
                                lastRecordedUi = new RecordedUiTask(strXmlNodes, 0, (UiTaskName)msg);
                                MainWindow.AddRecordedUi(lastRecordedUi);
                            }
                        }

                        if (lastRecordedUi != null && lastRecordedUi.GetTask() == UiTaskName.MouseWheel)
                        {
                            lastRecordedUi.UpdateWheelData(delta);
                        }

                        bAddNewTask = false;
                    }

                    // Adding newly recorded UI
                    if (bAddNewTask)
                    {
                        MainWindow.AddRecordedUi(new RecordedUiTask(strXmlNodes, 0, (UiTaskName)msg));
                    }
                    else
                    {
                        MainWindow.UpdateLastUi(lastRecordedUi);
                    }
                }

                return(IntPtr.Zero);
            }
        }