예제 #1
0
        public override void Execute()
        {
            var cmdlet =
                (ShowUiaBannerCommand)Cmdlet;

            UiaHelper.ShowBanner(cmdlet.Message);
        }
예제 #2
0
        public override void Execute()
        {
//            var cmdlet =
//                (AddUiaBannerTextCommand)Cmdlet;

            UiaHelper.HideBanner();
        }
예제 #3
0
        private void StartRecordingMethod(TranscriptCmdletBase cmdlet)
        {
            // UiaHelper.ProcessingTranscript(cmdlet);
            Global.GTranscript = true;
            int counter = 0;

            cmdlet.OddRootElement =
                // 20131109
                //System.Windows.Automation.AutomationElement.RootElement;
                UiElement.RootElement;
            cmdlet.StartDate =
                DateTime.Now;
            do
            {
                //Application.DoEvents();
                // 20131107
                counter++;
                //
                bool res =
                    // 20131114
                    //UiaHelper.ProcessingTranscriptOnce(cmdlet, counter);
                    UiaHelper.ProcessingTranscriptOnce(cmdlet, counter, System.Windows.Forms.Cursor.Position);
                if (!res)
                {
                    break;
                }
            } while (Global.GTranscript);
        }
예제 #4
0
        /// <summary>
        /// Processes the pipeline.
        /// </summary>
        protected override void ProcessRecord()
        {
            // 20131109
            //System.Windows.Automation.AutomationElement result = null;

            /*
             * IUiElement result = null;
             */

            foreach (IUiElement result in InputObject.Select(handle => UiaHelper.GetAutomationElementFromHandle(
                                                                 // this,
                                                                 handle)))
            {
                if (result != null)
                {
                    // 20140312
                    // WriteVerbose(this, "got the control: " + result.Current.Name);
                }
                WriteObject(this, result);
            }

            /*
             * foreach (int handle in InputObject) {
             *  IUiElement result = UiaHelper.GetAutomationElementFromHandle(
             *      this,
             *      handle);
             *  if (result != null) {
             *      WriteVerbose(this, "got the control: " + result.Current.Name);
             *  }
             *  WriteObject(this, result);
             * }
             */
        }
예제 #5
0
        protected override void BeginProcessing()
        {
            object result = null;

            result = UiaHelper.GetCurrentPatternFromPoint();
            WriteObject(this, result);
        }
예제 #6
0
        internal static IUiElement ConvertToProxiedElement <T>(T element)
        {
            Type[] supportedAdditionalInterfaces =
                UiaHelper.GetSupportedInterfaces(element);

            UiElement proxiedElement = null;

            try {
                if (null != supportedAdditionalInterfaces && 0 < supportedAdditionalInterfaces.Length)
                {
                    proxiedElement =
                        (UiElement)_generator.CreateClassProxy(
                            typeof(UiElement),
                            supportedAdditionalInterfaces,
                            new MethodSelectorAspect(), new ErrorHandlingAspect());
                }
                else
                {
                    proxiedElement =
                        (UiElement)_generator.CreateClassProxy(
                            typeof(UiElement),
                            new MethodSelectorAspect(), new ErrorHandlingAspect());
                }
            }
            catch (Exception) {
                // Console.WriteLine(eConvertation.Message);
            }
            return(proxiedElement);
        }
예제 #7
0
        public override void Execute()
        {
            var cmdlet =
                (AddUiaBannerTextCommand)Cmdlet;

            UiaHelper.AppendBanner(cmdlet.Message);
        }
예제 #8
0
        /// <summary>
        /// 点击toolBar句柄下某个按钮--这个有可能点不中--需要优化
        /// </summary>
        /// <param name="toolBar"></param>
        /// <param name="name"></param>
        public static bool ClickBtnByName(IntPtr toolBar, string name)
        {
            if (toolBar == IntPtr.Zero)
            {
                return(false);
            }
            //AmLogger.Info("ClickBtnByName", $"toolBar:{toolBar},name:{name}");
            try
            {
                var winBarUia = UiaHelper.GetUIAutomation().ElementFromHandle(toolBar);
                var element   = winBarUia.FindFirst(UIAutomationClient.TreeScope.TreeScope_Children, UiaHelper.GetUIAutomation().
                                                    CreatePropertyCondition(UIA_PropertyIds.UIA_NamePropertyId, name));
                Console.WriteLine($"{element.CurrentNativeWindowHandle}");
                var pattern = (IUIAutomationInvokePattern)element?.GetCurrentPattern(UIA_PatternIds.UIA_InvokePatternId);
                //var pattern = (IUIAutomationLegacyIAccessiblePattern)element?.GetCurrentPattern(UIA_PatternIds.UIA_LegacyIAccessiblePatternId);

                pattern?.Invoke();
                //pattern?.DoDefaultAction();
                Console.WriteLine("success....");
                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine($"error {e.Message}");
                //AmLogger.Error("ClickBtnUiaByName", $"{name},message:{e.Message},stacktrace:{e.StackTrace}");
            }
            return(false);
        }
예제 #9
0
        public static void SetCombox()
        {
            try
            {
                var comBoxMation = UiaHelper.GetUIAutomation().ElementFromHandle((IntPtr)5571680);

                //WinApi.ClickLocation((IntPtr) 5571680, 50, 20);
                //Thread.Sleep(100);

                //var childs = comBoxMation.FindAll(UIAutomationClient.TreeScope.TreeScope_Descendants,
                //    UiaHelper.GetUIAutomation().CreateTrueCondition());
                //for (var i = 0; i < childs.Length; i++)
                //{
                //    Console.WriteLine(childs.GetElement(i).CurrentName);
                //}


                var selectItem = comBoxMation?.FindFirst(UIAutomationClient.TreeScope.TreeScope_Descendants,
                                                         UiaHelper.GetUIAutomation().CreatePropertyCondition(
                                                             UIA_PropertyIds.UIA_NamePropertyId, "9%"));

                var pattern = (IUIAutomationSelectionItemPattern)selectItem?.GetCurrentPattern(UIA_PatternIds.UIA_SelectionItemPatternId);
                if (pattern == null)
                {
                    return;
                }

                pattern.Select();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
예제 #10
0
        /// <summary>
        /// Processes the pipeline.
        /// </summary>
        protected override void ProcessRecord()
        {
            //if (this.InputObject == null ||
            // !(this.InputObject is AutomationElement)) {
            bool save = GetType().Name == "SaveUiaScreenshotCommand";

            /*
             * bool save = false;
             * if (this.GetType().Name == "SaveUiaScreenshotCommand") {
             *  save = true;
             * }
             */

            UiaHelper.GetScreenshotOfCmdletInput(
                this,
                Description,
                save,
                new ScreenshotRect {
                Left   = Left,
                Top    = Top,
                Height = Height,
                Width  = Width
            },
                Path + @"\" + Name,
                As);
        }
예제 #11
0
        internal static bool TestControlWithAllSearchCriteria(
            IEnumerable <Hashtable> hashtables,
            IUiElement element)
        {
            bool result = false;

            if (null == hashtables || 0 == hashtables.Count())
            {
                return(result);
            }

            foreach (Hashtable hashtable in hashtables)
            {
                result =
                    element.TestControlByPropertiesFromDictionary(
                        hashtable.ConvertHashtableToDictionary());

                if (result)
                {
                    if (Preferences.HighlightCheckedControl)
                    {
                        UiaHelper.HighlightCheckedControl(element);
                    }

                    return(result);
                }
            }

            return(result);
        }
예제 #12
0
        static void ClickRedChar()
        {
            var winBar  = WinApi.FindWindow(null, "开具增值税专用发票");
            var childs  = WinApi.EnumChildWindowsCallback(winBar);
            var toolBar = childs[childs.Count - 1].hWnd;

            HxShengQing.ClickBtnByName(toolBar, "红字");
            Thread.Sleep(1000);

            var winBarUia = UiaHelper.GetUIAutomation().ElementFromHandle(winBar);
            var dropDown  = winBarUia.FindFirst(UIAutomationClient.TreeScope.TreeScope_Children,
                                                UiaHelper.GetUIAutomation().CreatePropertyCondition(
                                                    UIA_PropertyIds.UIA_NamePropertyId, "DropDown"));

            Console.WriteLine(JsonConvert.SerializeObject(dropDown.CurrentBoundingRectangle));

            var dropChilds = dropDown.FindAll(UIAutomationClient.TreeScope.TreeScope_Children,
                                              UiaHelper.GetUIAutomation().CreateTrueCondition());

            Console.WriteLine(JsonConvert.SerializeObject(dropChilds.GetElement(2).CurrentBoundingRectangle));

            var pt = (IUIAutomationInvokePattern)dropChilds.GetElement(2).GetCurrentPattern(UIA_PatternIds.UIA_InvokePatternId);

            pt.Invoke();

            var toolChilds = AutomationElement.FromHandle(toolBar)
                             .FindAll(TreeScope.Descendants, Condition.TrueCondition);

            for (var i = 0; i < toolChilds.Count; i++)
            {
                Console.WriteLine(toolChilds[i].Current.Name);
            }
        }
예제 #13
0
 List <IUiElement> GetWindowCollectionViaWin32(
     WindowSearcherData data)
 {
     return(UiaHelper.EnumChildWindowsFromHandle(
                data.Name,
                data.AutomationId,
                data.Class,
                IntPtr.Zero));
 }
예제 #14
0
        protected override void BeginProcessing()
        {
            // 20131109
            //System.Windows.Automation.AutomationElement result = null;
            //result =
            //    UiaHelper.GetAutomationElementFromPoint();
            IUiElement result =
                UiaHelper.GetAutomationElementFromPoint();

            WriteObject(this, result);
        }
예제 #15
0
        /// <summary>
        /// 操作航信自定义报错弹框
        /// </summary>
        static void OperatorCustomer()
        {
            var custoBar    = WinApi.FindWindow(null, "CusMessageBox");
            var editControl =
                UiaHelper.GetUIAutomation().ElementFromHandle(custoBar).FindFirst(UIAutomationClient.TreeScope.TreeScope_Descendants,
                                                                                  UiaHelper.GetUIAutomation().CreatePropertyCondition(UIA_PropertyIds.UIA_AutomationIdPropertyId, "rtbDescript"));

            var pt = (IUIAutomationValuePattern)editControl.GetCurrentPattern(UIA_PatternIds.UIA_ValuePatternId);

            Console.WriteLine(pt.CurrentValue);
        }
예제 #16
0
        protected void WriteObjectMethod045OnSuccessScreenshot(PSCmdletBase cmdlet, object outputObject)
        {
            WriteVerbose(this, "WriteObjectMethod045OnSuccessScreenshot UIAutomation");

            if (Preferences.OnSuccessScreenShot)
            {
                UiaHelper.GetScreenshotOfAutomationElement(
                    (cmdlet as HasControlInputCmdletBase),
                    (outputObject as IUiElement),
                    CmdletName(cmdlet),
                    true,
                    new ScreenshotRect(),
                    string.Empty,
                    Preferences.OnSuccessScreenShotFormat);
            }
        }
예제 #17
0
        protected override void ProcessRecord()
        {
            if (!CheckAndPrepareInput(this))
            {
                return;
            }
//

//            //Handle variables
//            int hwnd = 0;
//            int treeItem = 0;
//            IntPtr hwndChild = IntPtr.Zero;
//            IntPtr treeChild = IntPtr.Zero;

//            hwnd = FindWindow(null, "Application"); //Handle for the application to be controlled
//            if (hwnd > 0)
//            {
            //Select TreeView Item
//                treeChild = FindWindowEx((IntPtr)hwnd, IntPtr.Zero, "AfxMDIFrame80", null);
//                treeChild = FindWindowEx((IntPtr)treeChild, IntPtr.Zero, "AfxMDIFrame80", null);
//                treeChild = FindWindowEx((IntPtr)treeChild, IntPtr.Zero, "SysTreeView32", null);
//                treeItem = SendMessage((int)treeChild, TVM_GETNEXTITEM, TVGN_ROOT, IntPtr.Zero);
//                treeItem = SendMessage((int)treeChild, TVM_GETNEXTITEM, TVGN_NEXT, (IntPtr)treeItem);
//                treeItem = SendMessage((int)treeChild, TVM_GETNEXTITEM, TVGN_CHILD, (IntPtr)treeItem);
//                SendMessage((int)treeChild, TV_SELECTITEM, TVGN_CARET, (IntPtr)treeItem);

            // ...Continue with my automation...
//            }

            // 20131109
            //foreach (AutomationElement inputObject in this.InputObject) {
            foreach (IUiElement inputObject in InputObject)
            {
                UiaHelper.GetSheridanTreeItemByName(
                    this,
                    // 20140312
                    // (IntPtr)inputObject.Current.NativeWindowHandle,
                    (IntPtr)inputObject.GetCurrent().NativeWindowHandle,
                    Name);
            }
        }
예제 #18
0
        protected override void WriteErrorMethod045OnErrorScreenshot(PSCmdletBase cmdlet)
        {
            WriteVerbose(this, "WriteErrorMethod045OnErrorScreenshot UIAutomation");

            if (!Preferences.OnErrorScreenShot)
            {
                return;
            }

            IUiElement elementToTakeScreenShot = null;

            try {
                if (null != CurrentData.CurrentWindow)
                {
                    cmdlet.WriteVerbose(cmdlet, "taking screenshot of the current window");
                    elementToTakeScreenShot = CurrentData.CurrentWindow;
                }
                else
                {
                    cmdlet.WriteVerbose(cmdlet, "taking screenshot of the desktop object");
                    elementToTakeScreenShot = UiElement.RootElement;
                }
            }
            catch {
                cmdlet.WriteVerbose(cmdlet, "taking screenshot of the desktop object (on fail)");
                elementToTakeScreenShot = UiElement.RootElement;
            }

            cmdlet.WriteVerbose(cmdlet, "taking screenshot");
            UiaHelper.GetScreenshotOfAutomationElement(
                cmdlet,
                elementToTakeScreenShot,
                CmdletName(cmdlet),
                true,
                new ScreenshotRect(),
                string.Empty,
                Preferences.OnErrorScreenShotFormat);

            cmdlet.WriteVerbose(cmdlet, "done");
        }
예제 #19
0
        // 20131105
        // refactoring

        /*
         * public GetUiaWindowFromHandleCommand()
         * {
         * }
         */
        #endregion Constructor

        /// <summary>
        /// Processes the pipeline.
        /// </summary>
        protected override void ProcessRecord()
        {
            // 20131109
            //System.Windows.Automation.AutomationElement result = null;
            // 20131113
            foreach (IUiElement result in InputObject.Select(handle => UiaHelper.GetAutomationElementFromHandle(
                                                                 // this,
                                                                 handle)))
            {
                if (result != null)
                {
                    WriteVerbose(this, "got the window");
                }
                CurrentData.CurrentWindow = result;
                WriteObject(this, result);
            }

            /*
             * foreach (int handle in this.InputObject) {
             *
             *  // 20131109
             *  //result =
             *  //    UiaHelper.GetAutomationElementFromHandle(
             *  //        this,
             *  //        handle);
             *  IUiElement result =
             *      UiaHelper.GetAutomationElementFromHandle(
             *          this,
             *          handle);
             *
             *  if (result != null) {
             *      this.WriteVerbose(this, "got the window");
             *  }
             *  UIAutomation.CurrentData.CurrentWindow = result;
             *  this.WriteObject(this, result);
             * }
             */
        }
예제 #20
0
        // 20131114
        //this.getElementFromPoint();
        // 20131210
        // this.getElementFromPoint(Cursor.Position);

        //                        // use Windows forms mouse code instead of WPF
        //                        System.Drawing.Point mouse = System.Windows.Forms.Cursor.Position;
//
        //                        // commented 20120618 to switch to UiaCOMWrapper
        //                        element =
        //                            System.Windows.Automation.AutomationElement.FromPoint(
        //                                new System.Windows.Point(mouse.X, mouse.Y));
        //                        //element =
        //                        //    //(UiaNET::System.Windows.Automation.AutomationElement)
        //                        //    UiaCOM3.UiaCOMHelper.GetAutomationElementFromPoint();

        // 20120618 UiaCOMWrapper
        // && (int)element.Current.ProcessId > 0)
        // if (element != null && ((element as AutomationElement) != null)) { // && (int)element.Current.ProcessId > 0)
        //if (element != null && ((element as UiaCOM::System.Windows.Automation.AutomationElement) != null)) { // && (int)element.Current.ProcessId > 0)
        // 20131210
        // this.createTranscriptingCmdlet();

        // as UiaNET::System.Windows.Automation.AutomationElement);
        //


        //                                this.richTextBox1.Text +=
        //                                    "failed to get element.Current.ProcessId\r\n";
        //                                    this.richTextBox1.Text +=
        //                                        "failed to get  element.Cached.ProcessId\r\n";

        // ||

        // there is usually nothing to report

        // writing to the property grid control

        // writing to the family tree and the code

        //try {
        //}
        //catch (Exception eCollectAncestry) {
        //    this.richTextBox1.Text = eCollectAncestry.Message;
        //}

        // the Hierarchy tree

        // the code generated

        //
        // 20131114
        //

        // 20131210
        // writingAvailablePatterns(element);

        // end of if (elementPID != tabooPID)
        // end of if (element != null && ((element as AutomationElement) != null))
        // +


        public void ProcessSpyingCycle() //TranscriptCmdletBase cmdlet, IUiElement element)
        {
            do
            {
                Application.DoEvents();

                try {
                    // use Windows forms mouse code instead of WPF
                    IUiElement element = ExSpyCode.GetElementFromPoint(Cursor.Position);

                    if (null != element)
                    {
                        TranscriptCmdletBase cmdlet = ExSpyCode.CreateTranscriptingCmdlet();
                        try {
                            bool res = UiaHelper.ProcessingElement(cmdlet, element);
                            if (!res)
                            {
                            }
                        } catch (Exception eProcessingElement) {
                            txtFullCode.Text = "eProcessingElement element method:\r\n" + eProcessingElement.Message;
                            element          = null;
                            System.Threading.Thread.Sleep(Preferences.TranscriptInterval);
                            continue;
                        }

                        int elementPID = 0;
                        try {
                            // 20140312
                            // elementPID = element.Current.ProcessId;
                            elementPID = element.GetCurrent().ProcessId;
                        } catch {
                            try {
                                // 20140312
                                // elementPID = element.Cached.ProcessId;
                                // elementPID = (element as ISupportsCached).Cached.ProcessId;
                                elementPID = element.GetCached().ProcessId;
                            } catch (Exception) {
                            }
                        }

                        // 20131227
                        // int elementPID = UiaHelper.GetElementProcessIdSafely(element);
                        if (elementPID != tabooPID)
                        {
                            if (cmdlet.LastRecordedItem.Count > 0)
                            {
                                try {
                                    richControlCode.Text = cmdlet.WritingRecord(cmdlet.LastRecordedItem, null, null, null);
                                    if (chkClipboard.Checked)
                                    {
                                        Clipboard.SetDataObject(richControlCode.Text);
                                    }
                                } catch (Exception eCollectingElements) {
                                    txtFullCode.Text = "Collecting:\r\n" + eCollectingElements.Message;
                                    Exception eCollectingElements2 = new Exception("Collecting (eCollectingElements):\r\n" + eCollectingElements.Message);
                                    throw (eCollectingElements2);
                                }
                                guiWritingAutomationElementToPropertyGridControl(element);
                                try {
                                    collectAncestry(ref ancestorsNodesList, ref ancestorsCodeList, element);
                                    guiFillHierarchyTree();
                                    guiWriteCodeGenerated();
                                } catch (Exception eInner) {
                                    txtFullCode.Text += "Inner cycle (eInner):\r\n" + eInner.Message;
                                }
                            }
                            richPatterns.Text = ExSpyCode.WritingAvailablePatterns(element);
                        }
                    }

                    System.Threading.Thread.Sleep(Preferences.TranscriptInterval);
                } catch (Exception eUnknown) {
                    txtFullCode.Text += "External cycle (eUnknown):\r\n" + eUnknown.Message;
                    System.Threading.Thread.Sleep(Preferences.TranscriptInterval);
                }
            } while (!stopNow);
        }
예제 #21
0
        protected void WriteObjectMethod020Highlight(PSCmdletBase cmdlet, object outputObject)
        {
            if (null == (outputObject as IUiElement))
            {
                return;
            }

            if (string.Empty != ((HasScriptBlockCmdletBase)cmdlet).Banner)
            {
                UiaHelper.ShowBanner(((HasScriptBlockCmdletBase)cmdlet).Banner);
            }

            if (!Preferences.Highlight && !((HasScriptBlockCmdletBase)cmdlet).Highlight)
            {
                return;
            }

            IUiElement element = null;

            if (cmdlet == null || cmdlet is WizardCmdletBase)
            {
                return;
            }
            try {
                element = outputObject as IUiElement;
                if (null != element &&
                    // 20140312
                    // (int)element.Current.ProcessId > 0) {
                    (int)element.GetCurrent().ProcessId > 0)
                {
                    WriteVerbose(this, "current cmdlet: " + GetType().Name);
                    WriteVerbose(this, "highlighting the following element:");
                    // 20140312
//                    WriteVerbose(this, "Name = " + element.Current.Name);
//                    WriteVerbose(this, "AutomationId = " + element.Current.AutomationId);
//                    WriteVerbose(this, "ControlType = " + element.Current.ControlType.ProgrammaticName);
//                    WriteVerbose(this, "X = " + element.Current.BoundingRectangle.X.ToString());
//                    WriteVerbose(this, "Y = " + element.Current.BoundingRectangle.Y.ToString());
//                    WriteVerbose(this, "Width = " + element.Current.BoundingRectangle.Width.ToString());
//                    WriteVerbose(this, "Height = " + element.Current.BoundingRectangle.Height.ToString());
                }
            } catch { //(Exception eee) {
                // nothing to do
                // just failed to highlight
            }
            // 20140113
            // if (element == null || !(element is IUiElement) || (int) element.Current.ProcessId <= 0) return;
            // 20140312
            // if (element == null || !(element is IUiElement) || null == element.Current || (int) element.Current.ProcessId <= 0) return;
            if (element == null || !(element is IUiElement) || null == element.GetCurrent() || (int)element.GetCurrent().ProcessId <= 0)
            {
                return;
            }

            WriteVerbose(this, "as it is an IUiElement, it should be highlighted");

            try {
                WriteVerbose(this, "run Highlighter");
                if (Preferences.ShowExecutionPlan)
                {
                    if (Preferences.ShowInfoToolTip)
                    {
                        // 20131204
                        // ExecutionPlan.Enqueue(element, HighlighterGeneration, "name: " + element.Current.Name);
                        // 20140312
                        // ExecutionPlan.Enqueue(element, "name: " + element.Current.Name);
                        ExecutionPlan.Enqueue(element, "name: " + element.GetCurrent().Name);
                    }
                    else
                    {
                        // 20131204
                        // ExecutionPlan.Enqueue(element, HighlighterGeneration, string.Empty);
                        ExecutionPlan.Enqueue(element, string.Empty);
                    }
                    //this.Enqueue(element);
                }
                else
                {
//                                if (Preferences.ShowInfoToolTip) {
                    UiaHelper.Highlight(element);
//                                } else {
//                                    UiaHelper.Highlight(element);
//                                }
                }
                WriteVerbose(this, "after running the Highlighter");
            } catch (Exception ee) {
                WriteVerbose(this, "unable to highlight: " + ee.Message);
                WriteVerbose(this, outputObject.ToString());
            }
            //}
        }
예제 #22
0
        static void SearchInputFail()
        {
            WinApi.GetWindowRect(new HandleRef(null, (IntPtr)1901104), out var rectbefore);
            WinApi.MoveWindow((IntPtr)1901104, 10, 10, 3000, 2000, true);
            WinApi.GetWindowRect(new HandleRef(null, (IntPtr)1901104), out var rectbeafter);



            //Thread.Sleep(60000);
            //var formBar = WinApi.FindWindow(null, "票易通发票助手");
            var winBar      = WinApi.FindWindow(null, "增值税发票税控开票软件(金税盘版) V2.2.34.190728");
            var child1s     = WinApi.EnumChildWindowsCallback(winBar);
            var HmSearchBar = child1s.Find(b => b.szWindowName == "选择发票号码查询" || b.szTextName == "选择发票号码查询").hWnd;
            var childs      = WinApi.FindChildInfo(HmSearchBar);
            var bar         = childs.Find(b => b.szWindowName == "报送状态" || b.szTextName == "报送状态").hWnd;

            //WinApi.ClickLocation(bar, 5, 15);
            WinApi.ClickLocation(bar, 5, 15);

            Thread.Sleep(1000);

            //198352,
            var editControl = UiaHelper.GetUIAutomation().ElementFromHandle(winBar).FindFirst(UIAutomationClient.TreeScope.TreeScope_Descendants,
                                                                                              UiaHelper.GetUIAutomation().CreatePropertyCondition(UIA_PropertyIds.UIA_AutomationIdPropertyId, "198352"));


            //var editControls = UiaHelper.GetUIAutomation().ElementFromHandle(winBar).FindAll(UIAutomationClient.TreeScope.TreeScope_Descendants,
            //    UiaHelper.GetUIAutomation().CreatePropertyCondition(
            //        UIA_PropertyIds.UIA_ControlTypePropertyId,UIA_ControlTypeIds.UIA_EditControlTypeId));

            //for (var i = 0; i < editControls.Length; i++)
            //{
            //    var element = editControls.GetElement(i);
            //    var pt = (IUIAutomationValuePattern)element.GetCurrentPattern(UIA_PatternIds.UIA_ValuePatternId);
            //    if (i == 0)
            //        pt.SetValue("chenchangchenchang");
            //    Console.WriteLine($"CurrentName:{element.CurrentName} ,currentValue:{pt.CurrentValue}");
            //}

            //var child = UiaHelper.GetUIAutomation().ElementFromHandle(winBar).FindAll(
            //    UIAutomationClient.TreeScope.TreeScope_Children,
            //    UiaHelper.GetUIAutomation().CreateTrueCondition());
            //for (var i = 0; i < child.Length; i++)
            //{
            //    Console.WriteLine(child.GetElement(i).CurrentName);
            //}


            //var elements = child.GetElement(1).FindAll(UIAutomationClient.TreeScope.TreeScope_Children,
            //    UiaHelper.GetUIAutomation().CreateTrueCondition());
            //for (var i = 0; i < elements.Length; i++)
            //{
            //    Console.WriteLine(elements.GetElement(i).CurrentName);
            //}

            //var elements = UiaHelper.GetUIAutomation().ElementFromHandle(bar).FindAll(
            //    UIAutomationClient.TreeScope.TreeScope_Descendants,
            //    UiaHelper.GetUIAutomation().CreateTrueCondition());
            //for (var i = 0; i < elements.Length; i++)
            //{
            //    var ele = elements.GetElement(i);
            //    Console.WriteLine(ele.CurrentName);
            //}


            //var element = UiaHelper.GetUIAutomation().ElementFromHandle(bar).FindFirst(
            //    UIAutomationClient.TreeScope.TreeScope_Children,
            //    UiaHelper.GetUIAutomation().CreateTrueCondition());
            //if (element != null)
            //{
            //    var pt = (IUIAutomationLegacyIAccessiblePattern) element.GetCurrentPattern(
            //        patternId: UIA_PatternIds.UIA_LegacyIAccessiblePatternId);
            //    pt.DoDefaultAction();
            //}
        }
예제 #23
0
 public static IUiElement PerformHighlight(this IUiElement element)
 {
     UiaHelper.Highlight(element);
     return(element);
 }
        /// <summary>
        /// Processes the pipeline.
        /// </summary>
        protected override void ProcessRecord()
        {
            if (!CheckAndPrepareInput(this))
            {
                return;
            }

            // 20120823
            // 20131109
            //foreach (AutomationElement inputObject in this.InputObject) {
            foreach (IUiElement inputObject in InputObject)
            {
                string strData = String.Empty;
                // 20131109
                //System.Windows.Automation.AutomationElement _control =
                IUiElement currentControl =
                    // 20120823
                    //this.InputObject;
                    inputObject;
                // 20131208
                // TablePattern tblPattern = null;
                ITablePattern tblPattern = null;

                try {
                    tblPattern =
                        // 20120823
                        //this.InputObject.GetCurrentPattern(classic.TablePattern.Pattern)
                        // 20131208
                        // inputObject.GetCurrentPattern(classic.TablePattern.Pattern)
                        // inputObject.GetCurrentPattern<ITablePattern, TablePattern>(classic.TablePattern.Pattern)
                        // as TablePattern;
                        inputObject.GetCurrentPattern <ITablePattern>(classic.TablePattern.Pattern);

                    bool res1 =
                        UiaHelper.GetHeaderItems(ref currentControl, out strData, Delimiter);

                    if (res1)
                    {
                        WriteObject(strData);
                    }
                    else
                    {
                        WriteVerbose(this, strData);
                    }

                    // temporary!!!
                    // Selection
                    // 20131109
                    //System.Windows.Automation.AutomationElement[] selectedItems = null;
                    IUiElement[] selectedItems = null;
                    if (SelectedOnly)
                    {
                        // if there's a selection, get items in the selection
                        try
                        {
                            // 20131208
                            // SelectionPattern selPattern = inputObject.GetCurrentPattern(
                            // SelectionPattern selPattern = inputObject.GetCurrentPattern<ISelectionPattern, SelectionPattern>(
                            // SelectionPattern.Pattern)
                            // as SelectionPattern;
                            // SelectionPattern selPattern = inputObject.GetCurrentPattern<ISelectionPattern>(classic.SelectionPattern.Pattern);
                            ISelectionPattern selPattern = inputObject.GetCurrentPattern <ISelectionPattern>(classic.SelectionPattern.Pattern);

                            /*
                             * System.Windows.Automation.SelectionPattern selPattern;
                             * selPattern =
                             *  // 20120823
                             *  //this.InputObject.GetCurrentPattern(
                             *  inputObject.GetCurrentPattern(
                             *      System.Windows.Automation.SelectionPattern.Pattern)
                             *      as System.Windows.Automation.SelectionPattern;
                             */
                            selectedItems =
                                // 20131109
                                //selPattern.Current.GetSelection();
                                // 20131119
                                //new UiEltCollection(selPattern.Current.GetSelection()).Cast<UiElement>().ToArray();
                                AutomationFactory.GetUiEltCollection(selPattern.Current.GetSelection()).Cast <UiElement>().ToArray();
                        }
                        catch (Exception eSelection) {
                            WriteDebug(this, eSelection.Message);
                            WriteVerbose(this, "there wasn't a selection");
                        }
                    }


                    // temporary!!!
                    // get rows
                    if (tblPattern != null && tblPattern.Current.RowCount <= 0)
                    {
                        continue;
                    }

                    /*
                     * if (tblPattern.Current.RowCount <= 0) continue;
                     */
                    // 20130318
                    //RunOnSuccessScriptBlocks(this);
                    RunOnSuccessScriptBlocks(this, null);

                    for (int rowsCounter = 0;
                         rowsCounter < tblPattern.Current.RowCount;
                         rowsCounter++)
                    {
                        if (SelectedOnly && selectedItems.Length > 0)
                        {
                        }
                        else
                        {
                            // without a selection
                            string outString =
                                // 20131208
                                // UiaHelper.GetOutputStringUsingTableGridPattern<TablePattern>(
                                UiaHelper.GetOutputStringUsingTableGridPattern <ITablePattern>(
                                    tblPattern,
                                    tblPattern.Current.ColumnCount,
                                    rowsCounter,
                                    Delimiter);
                            // getOutputString(ref tblPattern,
                            // rowsCounter);
                            // output a row
                            WriteObject(outString);
                        }
                    }
                    //}

                    /*
                     * if (tblPattern.Current.RowCount > 0) {
                     *  // 20130318
                     *  //RunOnSuccessScriptBlocks(this);
                     *  RunOnSuccessScriptBlocks(this, null);
                     *      for (int rowsCounter = 0;
                     *           rowsCounter<tblPattern.Current.RowCount;
                     *           rowsCounter++) {
                     *          if (this.SelectedOnly && selectedItems.Length > 0) {
                     *          } else {
                     *              // without a selection
                     *              string outString =
                     *                  UiaHelper.GetOutputStringUsingTableGridPattern<System.Windows.Automation.TablePattern>(
                     *                      tblPattern,
                     *                      tblPattern.Current.ColumnCount,
                     *                      rowsCounter,
                     *                      this.Delimiter);
                     * // getOutputString(ref tblPattern,
                     * // rowsCounter);
                     *              // output a row
                     *              this.WriteObject(outString);
                     *          }
                     *      }
                     *  //}
                     * }
                     */
                } catch {
                    if (tblPattern != null)
                    {
                        continue;
                    }
                    WriteVerbose(this, "couldn't get TablePattern");
                    WriteVerbose(this, "trying to enumerate columns and rows");


                    bool res2 =
                        UiaHelper.GetHeaders(ref currentControl, out strData, Delimiter);
                    if (res2)
                    {
                        WriteObject(strData);
                    }
                    else
                    {
                        WriteVerbose(this, strData);
                    }

                    List <string> rows =
                        // 20120823
                        //UiaHelper.GetOutputStringUsingItemsValuePattern(this.InputObject,
                        UiaHelper.GetOutputStringUsingItemsValuePattern(inputObject,
                                                                        Delimiter);
                    if (rows.Count <= 0)
                    {
                        continue;
                    }
                    // 20130318
                    //RunOnSuccessScriptBlocks(this);
                    RunOnSuccessScriptBlocks(this, null);
                    foreach (string row in rows)
                    {
                        WriteObject(row);
                    }

                    // 20131119
                    // disposal
                    rows = null;

                    /*
                     * if (rows.Count > 0) {
                     *  // 20130318
                     *  //RunOnSuccessScriptBlocks(this);
                     *  RunOnSuccessScriptBlocks(this, null);
                     *  foreach (string row in rows) {
                     *      this.WriteObject(row);
                     *  }
                     * }
                     */

                    // WriteObject(this, false);
                    // return;

                    /*
                     * if (tblPattern == null)
                     * {
                     *  this.WriteVerbose(this, "couldn't get TablePattern");
                     *  this.WriteVerbose(this, "trying to enumerate columns and rows");
                     *
                     *
                     *  bool res2 =
                     *      UiaHelper.GetHeaders(ref _control, out strData, this.Delimiter);
                     *  if (res2) {
                     *      this.WriteObject(strData);
                     *  } else {
                     *      this.WriteVerbose(this, strData);
                     *  }
                     *
                     *  System.Collections.Generic.List<string> rows =
                     *      // 20120823
                     *      //UiaHelper.GetOutputStringUsingItemsValuePattern(this.InputObject,
                     *      UiaHelper.GetOutputStringUsingItemsValuePattern(inputObject,
                     *                                                      this.Delimiter);
                     *  if (rows.Count > 0) {
                     *      // 20130318
                     *      //RunOnSuccessScriptBlocks(this);
                     *      RunOnSuccessScriptBlocks(this, null);
                     *      foreach (string row in rows) {
                     *          this.WriteObject(row);
                     *      }
                     *  }
                     *  // WriteObject(this, false);
                     *  // return;
                     * }
                     */
                }
            } // 20120823
        }
// string errorMessageInTheGatheringCycle = String.Empty;
// bool errorInTheGatheringCycle = false;
// string errorMessageInTheInnerCycle = String.Empty;
// bool errorInTheInnerCycle = false;

        protected override void BeginProcessing()
        {
            if (!NoUI)
            {
                Timeout = 604800000;
                // frmRecorder formRecorder =
                CurrentData.formRecorder =
                    new RecorderForm(this);
                // formRecorder.ShowDialog();
                CurrentData.formRecorder.Show();
                CurrentData.formRecorder.Hide();
                try {
                    Events.SubscribeEvent((object)CurrentData.formRecorder.btnStop,
                                          "BtnStopClick",
                                          "formRecorder",
                                          new PSObject(),
                                          ScriptBlock.Create(""),  // CurrentData.formRecorder.BtnStopClick,
                                          true,
                                          false);
                } catch { }
                CurrentData.formRecorder.ShowDialog();
                return;
            }
            else
            {
                UiaHelper.ProcessingTranscript(this);
            }
            #region old
// Global.GTranscript = true;
// int counter = 0;
//
// if (!this.NoUI) {
// this.Timeout = 604800000;
// }
//
//  // 20120206 System.Windows.Automation.AutomationElement rootElement =
//  // 20120206     System.Windows.Automation.AutomationElement.RootElement;
// rootElement =
// System.Windows.Automation.AutomationElement.RootElement;
//  // 20120206 System.DateTime startDate =
// startDate =
// System.DateTime.Now;
// do
// {
// RunOnSleepScriptBlocks(this);
// System.Threading.Thread.Sleep(Preferences.TranscriptInterval);
// while (Paused) {
// System.Threading.Thread.Sleep(Preferences.TranscriptInterval);
// }
// counter++;
//
// try {
//  // use Windows forms mouse code instead of WPF
// System.Drawing.Point mouse = System.Windows.Forms.Cursor.Position;
// System.Windows.Automation.AutomationElement element =
// System.Windows.Automation.AutomationElement.FromPoint(
// new System.Windows.Point(mouse.X, mouse.Y));
// if (element != null)
// {
// processingElement(element);
// }
// if (errorInTheGatheringCycle) {
// WriteDebug(this, "An error is in the control hierarchy gathering cycle");
// WriteDebug(this, errorMessageInTheGatheringCycle);
// errorInTheGatheringCycle = false;
// }
// } catch (Exception eUnknown) {
// WriteDebug(this, eUnknown.Message);
// }
// System.DateTime nowDate = System.DateTime.Now;
// if ((nowDate - startDate).TotalSeconds > this.Timeout/1000) break;
// } while (Global.GTranscript);
            #endregion old
        }
        /// <summary>
        /// Processes the pipeline.
        /// </summary>
        protected override void ProcessRecord()
        {
            object result = null; // ?

            if (!CheckAndPrepareInput(this))
            {
                return;
            }

            // 20131014
            //this.WriteVerbose(this, _control.Current);

            // 20131014
            //this.WriteVerbose(this,
            //             (_control.GetSupportedPatterns()).Length.ToString());

            // 20131109
            //foreach (System.Windows.Automation.AutomationElement element in this.InputObject) {
            // 20131113
            foreach (classic.AutomationPattern p in InputObject.SelectMany(element => element.GetSupportedPatterns()))
            {
                WriteVerbose(this, p.ProgrammaticName);
            }

            /*
             * foreach (IUiElement element in this.InputObject) {
             *  foreach (System.Windows.Automation.AutomationPattern p in element.GetSupportedPatterns())
             *  {
             *      this.WriteVerbose(this, p.ProgrammaticName);
             *  }
             * }
             */

            // 20131014
            //foreach (System.Windows.Automation.AutomationPattern p in _control.GetSupportedPatterns())

            /*
             * foreach (AutomationPattern p in this.InputObject.SelectMany(element => element.GetSupportedPatterns()))
             * {
             *  this.WriteVerbose(this, p.ProgrammaticName);
             * }
             */

            /*
             * foreach (System.Windows.Automation.AutomationElement element in this.InputObject) {
             *  foreach (System.Windows.Automation.AutomationPattern p in element.GetSupportedPatterns())
             *  {
             *      this.WriteVerbose(this, p.ProgrammaticName);
             *  }
             * }
             */

            classic.AutomationPattern pattern =
                UiaHelper.GetPatternByName(Name);
            // 20131209
            result =
                UiaHelper.GetCurrentPattern(ref _control,
                                            pattern);
            // result =
            //     _control.GetCurrentPattern(pattern);

            WriteVerbose(this, result);

            WriteObject(this, result);
        }
예제 #27
0
 protected override void BeginProcessing()
 {
     UiaHelper.HideHighlighters();
 }
예제 #28
0
        internal static classic.Condition GetControlTypeCondition(IEnumerable <string> controlTypeNames)
        {
            if (null == controlTypeNames)
            {
                return(classic.Condition.TrueCondition);
            }

            List <classic.PropertyCondition> controlTypeCollection =
                // 20140302
                // controlTypeNames.Select(controlTypeName => new PropertyCondition(AutomationElement.ControlTypeProperty, UiaHelper.GetControlTypeByTypeName(controlTypeName))).ToList();
                controlTypeNames.Select(controlTypeName => new classic.PropertyCondition(classic.AutomationElement.ControlTypeProperty, UiaHelper.GetControlTypeByTypeName(controlTypeName))).ToList <classic.PropertyCondition>();

            return(1 == controlTypeCollection.Count ? (classic.Condition)controlTypeCollection[0] : (classic.Condition)GetOrCondition(controlTypeCollection));
        }
        protected override void BeginProcessing()
        {
            try {
                //CurrentData.CacheRequest = new CacheRequest();

                if (CurrentData.CacheRequest != null)
                {
                    WriteError(
                        this,
                        "There is already active CacheRequest. Please close it first",
                        "cacheRequestIsOpen",
                        ErrorCategory.InvalidOperation,
                        true);
                }

                CurrentData.CacheRequest = new classic.CacheRequest {
                    AutomationElementMode = classic.AutomationElementMode.None
                };
                CurrentData.CacheRequest.TreeFilter = UiaHelper.GetTreeFilter(Filter);
                CurrentData.CacheRequest.TreeScope  = UiaHelper.GetTreeScope(Scope);

                if (null == Property || 0 == Property.Length)
                {
                    WriteVerbose(this, "no properties were provided");
                    CurrentData.CacheRequest.Add(classic.AutomationElement.NameProperty);
                    CurrentData.CacheRequest.Add(classic.AutomationElement.AutomationIdProperty);
                    CurrentData.CacheRequest.Add(classic.AutomationElement.ClassNameProperty);
                    CurrentData.CacheRequest.Add(classic.AutomationElement.ControlTypeProperty);
                    CurrentData.CacheRequest.Add(classic.AutomationElement.NativeWindowHandleProperty);
                    CurrentData.CacheRequest.Add(classic.AutomationElement.BoundingRectangleProperty);
                    CurrentData.CacheRequest.Add(classic.AutomationElement.ClickablePointProperty);
                    CurrentData.CacheRequest.Add(classic.AutomationElement.IsEnabledProperty);
                    CurrentData.CacheRequest.Add(classic.AutomationElement.IsOffscreenProperty);
                    CurrentData.CacheRequest.Add(classic.AutomationElement.ProcessIdProperty);
                    // 20140208
                    CurrentData.CacheRequest.Add(classic.ValuePattern.ValueProperty);
                    CurrentData.CacheRequest.Add(classic.ExpandCollapsePattern.ExpandCollapseStateProperty);
                    CurrentData.CacheRequest.Add(classic.SelectionItemPattern.IsSelectedProperty);
                    CurrentData.CacheRequest.Add(classic.SelectionItemPattern.SelectionContainerProperty);
                    CurrentData.CacheRequest.Add(classic.SelectionPattern.CanSelectMultipleProperty);
                    CurrentData.CacheRequest.Add(classic.SelectionPattern.IsSelectionRequiredProperty);
                    CurrentData.CacheRequest.Add(classic.SelectionPattern.SelectionProperty);
                }
                else
                {
                    WriteVerbose(this, "using properties that were provided");
                    foreach (string propertyName in Property)
                    {
                        switch (propertyName.ToUpper())
                        {
                        case "NAME":
                            CurrentData.CacheRequest.Add(classic.AutomationElement.NameProperty);
                            break;

                        case "AUTOMATIONID":
                            CurrentData.CacheRequest.Add(classic.AutomationElement.AutomationIdProperty);
                            break;

                        case "CLASSNAME":
                        case "CLASS":
                            CurrentData.CacheRequest.Add(classic.AutomationElement.ClassNameProperty);
                            break;

                        case "CONTROLTYPE":
                            CurrentData.CacheRequest.Add(classic.AutomationElement.ControlTypeProperty);
                            break;

                        case "NATIVEWINDOWHANDLE":
                            CurrentData.CacheRequest.Add(classic.AutomationElement.NativeWindowHandleProperty);
                            break;

                        case "BOUNDINGRECTANGLE":
//                            case "RECTANGLE":
//                            case "BOUNDING":
                            CurrentData.CacheRequest.Add(classic.AutomationElement.BoundingRectangleProperty);
                            break;

                        case "CLICKABLEPOINT":
//                            case "POINT":
//                            case "CLICKABLE":
                            CurrentData.CacheRequest.Add(classic.AutomationElement.ClickablePointProperty);
                            break;

                        case "ISENABLED":
                        case "ENABLED":
                            CurrentData.CacheRequest.Add(classic.AutomationElement.IsEnabledProperty);
                            break;

                        case "ISOFFSCREEN":
                        case "ISVISIBLE":
                        case "VISIBLE":
                            CurrentData.CacheRequest.Add(classic.AutomationElement.IsOffscreenProperty);
                            break;

                        // 20140208
                        case "PROCESSID":
                            CurrentData.CacheRequest.Add(classic.AutomationElement.ProcessIdProperty);
                            break;

                        case "VALUE":
                            CurrentData.CacheRequest.Add(classic.RangeValuePattern.ValueProperty);
                            CurrentData.CacheRequest.Add(classic.ValuePattern.ValueProperty);
                            break;
//                            default:
//                                CurrentData.CacheRequest.Add(AutomationElement.NameProperty);
//                                CurrentData.CacheRequest.Add(AutomationElement.AutomationIdProperty);
//                                CurrentData.CacheRequest.Add(AutomationElement.ClassNameProperty);
//                                CurrentData.CacheRequest.Add(AutomationElement.ControlTypeProperty);
//                                CurrentData.CacheRequest.Add(AutomationElement.NativeWindowHandleProperty);
//                                CurrentData.CacheRequest.Add(AutomationElement.BoundingRectangleProperty);
//                                CurrentData.CacheRequest.Add(AutomationElement.ClickablePointProperty);
//                                CurrentData.CacheRequest.Add(AutomationElement.IsEnabledProperty);
//                                CurrentData.CacheRequest.Add(AutomationElement.IsOffscreenProperty);
//                                break;
                        }
                    }
                }

                if (null == Pattern || 0 == Pattern.Length)
                {
                    WriteVerbose(this, "no patterns were provided");
                    CurrentData.CacheRequest.Add(classic.ExpandCollapsePattern.Pattern);
                    CurrentData.CacheRequest.Add(classic.InvokePattern.Pattern);
                    CurrentData.CacheRequest.Add(classic.ScrollItemPattern.Pattern);
                    CurrentData.CacheRequest.Add(classic.SelectionItemPattern.Pattern);
                    CurrentData.CacheRequest.Add(classic.SelectionPattern.Pattern);
                    CurrentData.CacheRequest.Add(classic.TextPattern.Pattern);
                    CurrentData.CacheRequest.Add(classic.TogglePattern.Pattern);
                    CurrentData.CacheRequest.Add(classic.ValuePattern.Pattern);
                }
                else
                {
                    WriteVerbose(this, "using patterns that were provided");
                    foreach (string patternName in Pattern)
                    {
                        switch (patternName.ToUpper())
                        {
                        case "DOCK":
                        case "DOCKPATTERN":
                            CurrentData.CacheRequest.Add(classic.DockPattern.Pattern);
                            break;

                        case "EXPAND":
                        case "COLLAPSE":
                        case "EXPANDPATTERN":
                        case "COLLAPSEPATTERN":
                        case "EXPANDCOLLAPSEPATTERN":
                            CurrentData.CacheRequest.Add(classic.ExpandCollapsePattern.Pattern);
                            break;

                        case "GRIDITEM":
                        case "GRIDITEMPATTERN":
                            CurrentData.CacheRequest.Add(classic.GridItemPattern.Pattern);
                            break;

                        case "GRID":
                        case "GRIDPATTERN":
                            CurrentData.CacheRequest.Add(classic.GridPattern.Pattern);
                            break;

                        case "INVOKE":
                        case "INVOKEPATTERN":
                            CurrentData.CacheRequest.Add(classic.InvokePattern.Pattern);
                            break;

                        case "MULTIPLEVIEW":
                        case "MULTIPLEVIEWPATTERN":
                            CurrentData.CacheRequest.Add(classic.MultipleViewPattern.Pattern);
                            break;

                        case "RANGEVALUE":
                        case "RANGEVALUEPATTERN":
                            CurrentData.CacheRequest.Add(classic.RangeValuePattern.Pattern);
                            break;

                        case "SCROLLITEM":
                        case "SCROLLITEMPATTERN":
                            CurrentData.CacheRequest.Add(classic.ScrollItemPattern.Pattern);
                            break;

                        case "SCROLL":
                        case "SCROLLPATTERN":
                            CurrentData.CacheRequest.Add(classic.ScrollPattern.Pattern);
                            break;

                        case "SELECTIONITEM":
                        case "SELECTIONITEMPATTERN":
                            CurrentData.CacheRequest.Add(classic.SelectionItemPattern.Pattern);
                            break;

                        case "SELECTION":
                        case "SELECTIONPATTERN":
                            CurrentData.CacheRequest.Add(classic.SelectionPattern.Pattern);
                            break;

                        case "TABLEITEM":
                        case "TABLEITEMPATTERN":
                            CurrentData.CacheRequest.Add(classic.TableItemPattern.Pattern);
                            break;

                        case "TABLE":
                        case "TABLEPATTERN":
                            CurrentData.CacheRequest.Add(classic.TablePattern.Pattern);
                            break;

                        case "TEXT":
                        case "TEXTPATTERN":
                            CurrentData.CacheRequest.Add(classic.TextPattern.Pattern);
                            break;

                        case "TOGGLE":
                        case "TOGGLEPATTERN":
                            CurrentData.CacheRequest.Add(classic.TogglePattern.Pattern);
                            break;

                        case "TRANSFORM":
                        case "TRANSFORMPATTERN":
                            CurrentData.CacheRequest.Add(classic.TransformPattern.Pattern);
                            break;

                        case "VALUE":
                        case "VALUEPATTERN":
                            CurrentData.CacheRequest.Add(classic.ValuePattern.Pattern);
                            break;

                        case "WINDOW":
                        case "WINDOWPATTERN":
                            CurrentData.CacheRequest.Add(classic.WindowPattern.Pattern);
                            break;
//                            default:
//                                CurrentData.CacheRequest.Add(classic.DockPattern.Pattern);
//                                CurrentData.CacheRequest.Add(classic.ExpandCollapsePattern.Pattern);
//                                CurrentData.CacheRequest.Add(classic.GridItemPattern.Pattern);
//                                CurrentData.CacheRequest.Add(classic.GridPattern.Pattern);
//                                CurrentData.CacheRequest.Add(classic.InvokePattern.Pattern);
//                                CurrentData.CacheRequest.Add(classic.MultipleViewPattern.Pattern);
//                                CurrentData.CacheRequest.Add(classic.RangeValuePattern.Pattern);
//                                CurrentData.CacheRequest.Add(classic.ScrollItemPattern.Pattern);
//                                CurrentData.CacheRequest.Add(classic.ScrollPattern.Pattern);
//                                CurrentData.CacheRequest.Add(classic.SelectionItemPattern.Pattern);
//                                CurrentData.CacheRequest.Add(classic.SelectionPattern.Pattern);
//                                CurrentData.CacheRequest.Add(classic.TableItemPattern.Pattern);
//                                CurrentData.CacheRequest.Add(classic.TablePattern.Pattern);
//                                CurrentData.CacheRequest.Add(classic.TextPattern.Pattern);
//                                CurrentData.CacheRequest.Add(classic.TogglePattern.Pattern);
//                                CurrentData.CacheRequest.Add(classic.TransformPattern.Pattern);
//                                CurrentData.CacheRequest.Add(classic.ValuePattern.Pattern);
//                                CurrentData.CacheRequest.Add(classic.WindowPattern.Pattern);
//                                break;
                        }
                    }
                }

                // 20140208
                // Preferences.FromCache = true;
                Preferences.CacheRequestCalled = true;
                // CurrentData.CacheRequest.Push();
                //WriteObject(this, returnObject);
            }
            catch (Exception eCacheRequest) {
                WriteError(
                    this,
                    "Unable to start cache request. " +
                    eCacheRequest.Message,
                    "CacheRequestFailedToPush",
                    ErrorCategory.InvalidOperation,
                    true);
            }
        }
예제 #30
0
        private static void Main(string[] args)
        {
            // Console.WriteLine(System.Windows.Automation.ControlType.Button.ToString());
            // Console.WriteLine(System.Windows.Automation.ControlType.Button.ProgrammaticName.ToString());
            // Console.WriteLine(System.Windows.Automation.ControlType.Button.GetType().Name);


// Dumping types for further investigation

//            Console.WriteLine("Dumping the types...");
//            dumpTypes(System.Environment.GetEnvironmentVariable("TEMP",
//                                                                EnvironmentVariableTarget.User) +
//                      @"\types.txt");
//            Console.WriteLine("...completed");
//                      return;

            System.Windows.Forms.Application.EnableVisualStyles();
            System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);

            // the second command-line argument FormDelay
            if (args.Length > 1 && args[1] != null && args[1] != string.Empty)
            {
                try {
                    if ((Convert.ToInt32(args[0]) != 0) &&
                        (Convert.ToInt32(args[1]) != 0))
                    {
                        int sleepTime =
                            Convert.ToInt32(args[1]);
                        System.Threading.Thread.Sleep(sleepTime);
                    }
                } catch {
                    // Console.WriteLine("Wrong arguments!Use numbers:");
                    // Console.WriteLine("TetUIAutomation Forms SleepBefore");
                    return; // 1;
                }
            }

// if (Delay > 0) {
// System.Threading.Thread.Sleep(Delay);
// }
            // the first command-line argument FormType
            if (args.Length > 0 && args[0] != null && args[0] != "")
            {
                Forms formCode;
                try {
                    formCode = (Forms)(Convert.ToInt32(args[0]));
                } catch {
                    // Console.WriteLine("Wrong arguments!Use numbers:");
                    // Console.WriteLine("TetUIAutomation Forms SleepBefore");
                    return; // 2;
                }

                // System.Windows.Forms.Application.Run(new MainForm());

                #region reserved code
//                System.Windows.Automation.ControlType ctrlType = null;
//
//                // the third command-line argument ControlType
//                if (args.Length > 2 && args[2] != null && args[2] != "") {
//                    // string _controlType = String.Empty;
//                    //_controlType = args[2].ToUpper();
//                    ctrlType =
//                        UiaHelper.GetControlTypeByTypeName(args[2]);
//                }
//
//                int controlDelay = 0;
//
//                // the fourth command-line argument ControlDelay
//                if (args.Length > 3 && args[3] != null && args[3] != string.Empty) {
//                    try {
//                        controlDelay = System.Convert.ToInt32(args[3]);
//                    } catch { }
//                }
//
//                string controlName = string.Empty;
//
//                // the fifth command-line argument ControlName
//                if (args.Length > 4 && args[4] != null && args[4] != string.Empty) {
//                    try {
//                        controlName = args[4];
//                    } catch { }
//                }
//
//                string controlAutomationId = string.Empty;
//
//                // the sixth command-line argument ControlAutomationId
//                if (args.Length > 5 && args[5] != null && args[5] != string.Empty) {
//                    try {
//                        controlAutomationId = args[5];
//                    } catch { }
//                }
//
//                switch (formCode)
//                {
//                    case Forms.WinFormsEmpty:
//                        System.Windows.Forms.Application.Run(
//                            new WinFormsEmpty(ctrlType, controlName, controlAutomationId, controlDelay));
//                        // WinFormsEmpty frmWFE = new WinFormsEmpty();
//                        // frmWFE.ShowDialog();
//                        break;
//                    case Forms.WinFormsEmptyX2:
//                        System.Windows.Forms.Application.Run(
//                            new WinFormsEmpty(ctrlType, controlName, controlAutomationId, controlDelay));
//                        System.Windows.Forms.Application.Run(
//                            new WinFormsEmpty(ctrlType, controlName, controlAutomationId, controlDelay));
//                        break;
//                    case Forms.WinFormsAnonymous:
//                        System.Windows.Forms.Application.Run(
//                            new WinFormsAnonymous(
//                                ctrlType, controlName, controlAutomationId, controlDelay));
//                        break;
//                    case Forms.WinFormsMinimized:
//                        System.Windows.Forms.Application.Run(
//                            new WinFormsMinimized(ctrlType, controlName, controlAutomationId, controlDelay));
//                        break;
//                    case Forms.WinFormsMaximized:
//                        System.Windows.Forms.Application.Run(
//                            new WinFormsMaximized(ctrlType, controlName, controlAutomationId, controlDelay));
//                        break;
//                    case Forms.WinFormsNoTaskBar:
//                        System.Windows.Forms.Application.Run(
//                            new WinFormsNoTaskBar(ctrlType, controlName, controlAutomationId, controlDelay));
//                        break;
//                    case Forms.WinFormsRich:
//                        System.Windows.Forms.Application.Run(
//                            new WinFormsRich(ctrlType, controlName, controlAutomationId, controlDelay));
//                        break;
//
//
//                    case Forms.WPFEmpty:
//                        WPFEmpty frmWPFE = new WPFEmpty();
//                        frmWPFE.ShowDialog();
//                        //Application.Run(new MainForm());
//                        break;
//                    case Forms.WPFEmptyX2:
//                        WPFEmpty frmWPFE1 = new WPFEmpty();
//                        frmWPFE1.ShowDialog();
//                        WPFEmpty frmWPFE2 = new WPFEmpty();
//                        frmWPFE2.ShowDialog();
//                        break;
//                    case Forms.WPFAnonymous:
//                        WPFAnonymous frmWPFA = new WPFAnonymous();
//                        frmWPFA.ShowDialog();
//                        break;
//                    case Forms.WPFMinimized:
//                        WPFMinimized frmWPFMi = new WPFMinimized();
//                        frmWPFMi.ShowDialog();
//                        break;
//                    case Forms.WPFMaximized:
//                        WPFMaximized frmWPFMa = new WPFMaximized();
//                        frmWPFMa.ShowDialog();
//                        break;
//                    case Forms.WPFCollapsed:
//                        WPFCollapsed frmWPFCo = new WPFCollapsed();
//                        frmWPFCo.ShowDialog();
//                        break;
//
//                }
//            }
                #endregion reserved code

                System.Windows.Automation.ControlType ctrlType = null;
                int             controlDelay        = 0;
                string          controlName         = string.Empty;
                string          controlAutomationId = string.Empty;
                ControlToForm[] controls            = null;

                if (args.Length > 2)
                {
                    //    ControlToForm controlToForm = new ControlToForm();
                    //    for (int i = 2; i < args.Length; i++) {
                    //        controlto
                    //    }

                    System.Collections.ArrayList arrList =
                        new System.Collections.ArrayList();

                    for (int i = 2; i < args.Length; i = i + 4)
                    {
                        ControlToForm controlToForm =
                            new ControlToForm();

                        //System.Windows.Automation.ControlType ctrlType = null;
                        ctrlType = null;

                        // the third command-line argument ControlType
                        if (args[i] != null && args[i] != "")
                        {
                            ctrlType =
                                UiaHelper.GetControlTypeByTypeName(args[i]);
                            controlToForm.ControlType = ctrlType;
                        }

                        //int controlDelay = 0;
                        controlDelay = 0;

                        // the fourth command-line argument ControlDelay
                        if (args[i + 1] != null && args[i + 1] != string.Empty)
                        {
                            try {
                                controlDelay = Convert.ToInt32(args[i + 1]);
                                controlToForm.ControlDelayEn = controlDelay;
                            } catch { }
                        }

                        //string controlName = string.Empty;
                        controlName = string.Empty;

                        // the fifth command-line argument ControlName
                        if (args[i + 2] != null && args[i + 2] != string.Empty)
                        {
                            try {
                                controlName = args[i + 2];
                                controlToForm.ControlName = controlName;
                            } catch { }
                        }

                        //string controlAutomationId = string.Empty;
                        controlAutomationId = string.Empty;

                        // the sixth command-line argument ControlAutomationId
                        if (args[i + 3] != null && args[i + 3] != string.Empty)
                        {
                            try {
                                controlAutomationId = args[i + 3];
                                controlToForm.ControlAutomationId = controlAutomationId;
                            } catch { }
                        }

                        arrList.Add(controlToForm);
                    } // for (int i = 2; i < args.Length; i = i + 4)

                    controls =
                        (ControlToForm[])arrList.ToArray(typeof(ControlToForm));
                }

                switch (formCode)
                {
                case Forms.WinFormsEmpty:
                    System.Windows.Forms.Application.Run(
                        new WinFormsEmpty(controls));
                    break;

                case Forms.WinFormsEmptyX2:
                    System.Windows.Forms.Application.Run(
                        new WinFormsEmpty(controls));
                    System.Windows.Forms.Application.Run(
                        new WinFormsEmpty(controls));
                    break;

                case Forms.WinFormsAnonymous:
                    System.Windows.Forms.Application.Run(
                        new WinFormsAnonymous(
                            ctrlType, controlName, controlAutomationId, controlDelay));
                    break;

                case Forms.WinFormsMinimized:
                    System.Windows.Forms.Application.Run(
                        new WinFormsMinimized(ctrlType, controlName, controlAutomationId, controlDelay));
                    break;

                case Forms.WinFormsMaximized:
                    System.Windows.Forms.Application.Run(
                        new WinFormsMaximized(ctrlType, controlName, controlAutomationId, controlDelay));
                    break;

                case Forms.WinFormsNoTaskBar:
                    System.Windows.Forms.Application.Run(
                        new WinFormsNoTaskBar(ctrlType, controlName, controlAutomationId, controlDelay));
                    break;

                case Forms.WinFormsTripled:
                    System.Windows.Forms.Application.Run(
                        new WinFormsTripled(controls));
                    break;

                case Forms.WinFormsThreeSet:
                    System.Windows.Forms.Application.Run(
                        new WinFormsOuter()); //(controls));
                    break;

                case Forms.WinFormsWithMenus:
                    System.Windows.Forms.Application.Run(
                        new WinFormsWithMenus());
                    break;

                case Forms.WinFormsRich:
                    System.Windows.Forms.Application.Run(
                        new WinFormsRich()); //ctrlType, controlName, controlAutomationId, controlDelay));
                    break;

                case Forms.WinFormsFull:
                    System.Windows.Forms.Application.Run(
                        new WinFormsFull()); //ctrlType, controlName, controlAutomationId, controlDelay));
                    break;

                case Forms.WinFormsWizard:
                    System.Windows.Forms.Application.Run(
                        new WinFormsWizard()); //ctrlType, controlName, controlAutomationId, controlDelay));
                    break;

                case Forms.WinFormsWithGrid:
                    System.Windows.Forms.Application.Run(
                        new WinFormsWithGrid());
                    break;

                case Forms.WinFormsWithLists:
                    System.Windows.Forms.Application.Run(
                        new WinFormsWithLists());
                    break;

                case Forms.WPFEmpty:
                    WPFEmpty frmWPFE = new WPFEmpty();
                    frmWPFE.ShowDialog();
                    //Application.Run(new MainForm());
                    break;

                case Forms.WPFEmptyX2:
                    WPFEmpty frmWPFE1 = new WPFEmpty();
                    frmWPFE1.ShowDialog();
                    WPFEmpty frmWPFE2 = new WPFEmpty();
                    frmWPFE2.ShowDialog();
                    break;

                case Forms.WPFAnonymous:
                    WPFAnonymous frmWPFA = new WPFAnonymous();
                    frmWPFA.ShowDialog();
                    break;

                case Forms.WPFMinimized:
                    WPFMinimized frmWPFMi = new WPFMinimized();
                    frmWPFMi.ShowDialog();
                    break;

                case Forms.WPFMaximized:
                    WPFMaximized frmWPFMa = new WPFMaximized();
                    frmWPFMa.ShowDialog();
                    break;

                case Forms.WPFCollapsed:
                    WPFCollapsed frmWPFCo = new WPFCollapsed();
                    frmWPFCo.ShowDialog();
                    break;

                case Forms.WPFFull:
                    WPFFull frmWPFFull = new WPFFull();
                    frmWPFFull.ShowDialog();
                    break;
//                case Forms.WPFWizard:
//                    WPFWizard frmWPFWizard = new WPFWizard();
//                    frmWPFWizard.ShowDialog();
//                    break;
                }

//            } // if (args.Length > 2)
//            else {
//                System.Windows.Forms.Application.Run(
//                    new WinFormsEmpty(ctrlType, 0));
//            }
            }


//            // the third command-line argument ControlType
//            if (args.Length > 2 && args[2] != null && args[2] != string.Empty)
//            {
//
//
//                FormControls controls;
//                try {
//                    controls = (FormControls)(System.Convert.ToInt32(args[2]));
//                } catch {
//                    // Console.WriteLine("Wrong arguments!Use numbers:");
//                    // Console.WriteLine("TetUIAutomation Forms SleepBefore");
//                    return; // 2;
//                }
//
//                System.Windows.Forms.Application.EnableVisualStyles();
//                System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);
//                // System.Windows.Forms.Application.Run(new MainForm());
//
//
//                System.Windows.Automation.ControlType ctrlType = null;
//                if (args.Length > 2 && args[2] != null && args[2] != "") {
//                    // string _controlType = String.Empty;
//                    //_controlType = args[2].ToUpper();
//                    ctrlType =
//                        UiaHelper.GetControlTypeByTypeName(args[2]);
//
//
//                try {
//                    if ((System.Convert.ToInt32(args[0]) != 0) &&
//                        (System.Convert.ToInt32(args[1]) != 0))
//                    {
//                        int sleepTime =
//                            System.Convert.ToInt32(args[1]);
//                        System.Threading.Thread.Sleep(sleepTime);
//                    }
//                } catch {
//                    // Console.WriteLine("Wrong arguments!Use numbers:");
//                    // Console.WriteLine("TetUIAutomation Forms SleepBefore");
//                    return; // 1;
//                }
//            }
        }