Example #1
0
        public static void AddRecordedUi(RecordedUiTask uiTask)
        {
            if (uiTask.GetTask() != UiTaskName.Inspect)
            {
                MainWindow.s_listRecordedUi.Add(uiTask);
                s_mainWin.btnClear.IsEnabled            = s_listRecordedUi.Count > 0;
                s_mainWin.btnWinAppDriverCode.IsEnabled = s_listRecordedUi.Count > 0;
            }

            s_mainWin.Dispatcher.Invoke(new Action(() =>
            {
                if (uiTask.GetTask() != UiTaskName.Inspect)
                {
                    s_mainWin.comboBoxRecordedUi.ItemsSource   = null;
                    s_mainWin.comboBoxRecordedUi.ItemsSource   = MainWindow.s_listRecordedUi;
                    s_mainWin.comboBoxRecordedUi.SelectedIndex = MainWindow.s_listRecordedUi.Count - 1;
                }
                else
                {
                    UpdateLastUi(uiTask);
                }
            }), System.Windows.Threading.DispatcherPriority.ContextIdle);
        }
Example #2
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);
            }
        }