示例#1
0
 public UiEltCollection(IUiEltCollection elements)
 {
     foreach (IUiElement element in elements.Cast <IUiElement>().Where(element => null != element))
     {
         _collectionHolder.Add(element);
     }
 }
示例#2
0
        internal bool IsStepActive(WizardStep step, IUiEltCollection elements)
        {
            bool result = false;

            if (null == step)
            {
                return(result);
            }
            if (null == step.SearchCriteria || 0 == step.SearchCriteria.Count())
            {
                return(result);
            }
            var searchCriteria = step.SearchCriteria.Where(hashtable => null != hashtable);

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

            if (searchCriteria.All(criterion =>
                                   elements.ToArray().Any(elt => ControlSearcher.TestControlWithAllSearchCriteria(new Hashtable[] { criterion }, elt))
                                   ))
            {
                result = true;
            }

            return(result);
        }
示例#3
0
	    public UiEltCollection(IUiEltCollection elements)
	    {
	        foreach (IUiElement element in elements.Cast<IUiElement>().Where(element => null != element))
	        {
	            _collectionHolder.Add(element);
	        }
	    }
示例#4
0
        internal static List <IUiElement> SearchByContainsTextViaUia(
            IUiElement inputObject,
            classic.Condition conditionsForTextSearch)
        {
            IUiEltCollection textSearchCollection = inputObject.FindAll(classic.TreeScope.Descendants, conditionsForTextSearch);

            return(textSearchCollection.Cast <IUiElement>().ToList());
        }
示例#5
0
        public static bool GetResult_IsStepActive(Hashtable[] searchCriteria, IUiEltCollection elements)
        {
            var step = new WizardStep("stepName", 1)
            {
                Description    = "description",
                SearchCriteria = searchCriteria
            };

            var wizard = new Wizard("wizardName");

            return(wizard.IsStepActive(step, elements));
        }
        // 20140215
        // public static IEnumerable GetElementsByWildcard(this IUiEltCollection collection, string name, string automationId, string className, string txtValue, bool caseSensitive = false)
        public static IEnumerable GetElementsByWildcard(this IUiEltCollection collection, string name, string automationId, string className, string txtValue, bool caseSensitive)
        {
            WildcardOptions options;

            if (caseSensitive)
            {
                options =
                    WildcardOptions.Compiled;
            }
            else
            {
                options =
                    WildcardOptions.IgnoreCase |
                    WildcardOptions.Compiled;
            }

            List <IUiElement> list = collection.Cast <IUiElement>().ToList();

            var wildcardName =
                new WildcardPattern((string.IsNullOrEmpty(name) ? "*" : name), options);
            var wildcardAutomationId =
                new WildcardPattern((string.IsNullOrEmpty(automationId) ? "*" : automationId), options);
            var wildcardClassName =
                new WildcardPattern((string.IsNullOrEmpty(className) ? "*" : className), options);
            var wildcardValue =
                new WildcardPattern((string.IsNullOrEmpty(txtValue) ? "*" : txtValue), options);

            var queryByBigFour = from collectionItem
                                 in list
                                 // 20140312
//                where wildcardName.IsMatch(collectionItem.Current.Name) &&
//                      wildcardAutomationId.IsMatch(collectionItem.Current.AutomationId) &&
//                      wildcardClassName.IsMatch(collectionItem.Current.ClassName) &&
                                 where wildcardName.IsMatch(collectionItem.GetCurrent().Name) &&
                                 wildcardAutomationId.IsMatch(collectionItem.GetCurrent().AutomationId) &&
                                 wildcardClassName.IsMatch(collectionItem.GetCurrent().ClassName) &&
                                 // 20131209
                                 // (collectionItem.GetSupportedPatterns().Contains(classic.ValuePattern.Pattern) ?
                                 (collectionItem.GetSupportedPatterns().AsQueryable <IBasePattern>().Any <IBasePattern>(p => p is IValuePattern) ?
                                 // 20131208
                                 // wildcardValue.IsMatch((collectionItem.GetCurrentPattern(classic.ValuePattern.Pattern) as IValuePattern).Current.Value) :
                                 // wildcardValue.IsMatch((collectionItem.GetCurrentPattern<IValuePattern, ValuePattern>(classic.ValuePattern.Pattern) as IValuePattern).Current.Value) :
                                  wildcardValue.IsMatch(collectionItem.GetCurrentPattern <IValuePattern>(classic.ValuePattern.Pattern).Current.Value) :
                                 // check whether the -Value parameter has or hasn't value
                                  ("*" == txtValue ? true : false))
                                 select collectionItem;

            // disposal
            list = null;

            return(queryByBigFour);
        }
示例#7
0
            public                    IUiElement[] GetSelection()
            {
                // 20140302
                // AutomationElement[] nativeElements = (AutomationElement[])this._selectionPattern.GetParentElement().GetPatternPropertyValue(SelectionPattern.SelectionProperty, this._useCache);
                var nativeElements = (classic.AutomationElement[])_selectionPattern.GetParentElement().GetPatternPropertyValue(classic.SelectionPattern.SelectionProperty, _useCache);
                IUiEltCollection tempCollection = AutomationFactory.GetUiEltCollection(nativeElements);

                if (null == tempCollection || 0 == tempCollection.Count)
                {
                    return(new UiElement[] {});
                }
                else
                {
                    return(tempCollection.Cast <IUiElement>().ToArray <IUiElement>());
                }
            }
示例#8
0
 internal static IUiEltCollection GetUiEltCollection()
 {
     try {
         var boolArgument = new ConstructorArgument("fake", true);
         // IUiEltCollection adapterCollection = Kernel.Get<IUiEltCollection>("Empty", boolArgument);
         IUiEltCollection adapterCollection = ChildKernel.Get <IUiEltCollection>("Empty", boolArgument);
         return(adapterCollection);
     }
     catch (Exception) {
         // TODO
         // write error to error object!!!
         // Console.WriteLine("Collection 04");
         // Console.WriteLine(eFailedToIssueCollection.Message);
         return(null);
     }
 }
示例#9
0
            public                             IUiElement[] GetColumnHeaderItems()
            {
                // return (AutomationElement[])this._el.GetPatternPropertyValue(TableItemPattern.ColumnHeaderItemsProperty, this._useCache);
                // 20140302
                // AutomationElement[] nativeElements = (AutomationElement[])this._tableItemPattern.GetParentElement().GetPatternPropertyValue(TableItemPattern.ColumnHeaderItemsProperty, this._useCache);
                var nativeElements = (classic.AutomationElement[])_tableItemPattern.GetParentElement().GetPatternPropertyValue(classic.TableItemPattern.ColumnHeaderItemsProperty, _useCache);
                IUiEltCollection tempCollection = AutomationFactory.GetUiEltCollection(nativeElements);

                if (null == tempCollection || 0 == tempCollection.Count)
                {
                    return(new UiElement[] {});
                }
                else
                {
                    return(tempCollection.Cast <IUiElement>().ToArray());
                }
            }
示例#10
0
 internal static IUiEltCollection GetUiEltCollection(IEnumerable elements)
 {
     if (null == elements)
     {
         return(null);
     }
     try {
         var manyElements = new ConstructorArgument("elements", elements);
         // IUiEltCollection adapterCollection = Kernel.Get<IUiEltCollection>("AnyCollection", manyElements);
         IUiEltCollection adapterCollection = ChildKernel.Get <IUiEltCollection>("AnyCollection", manyElements);
         return(adapterCollection);
     }
     catch (Exception) {
         // TODO
         // write error to error object!!!
         // Console.WriteLine("Collection 03");
         // Console.WriteLine(eFailedToIssueCollection.Message);
         return(null);
     }
 }
        internal List <IUiElement> GetAutomationElementsWithFindAll(
            IUiElement element,
            ControlSearcherData data,
            classic.Condition conditions,
            bool caseSensitiveParam,
            bool onlyOneResult,
            bool onlyTopLevel,
            bool viaWildcardOrRegex)
        {
            var resultCollection = new List <IUiElement>();

            try {
                IUiEltCollection results =
                    element.FindAll(
                        classic.TreeScope.Descendants,
                        conditions);

                resultCollection =
                    WindowSearcher.ReturnOnlyRightElements(
                        results,
                        data,
                        caseSensitiveParam,
                        viaWildcardOrRegex);

                if (null != results)
                {
                    // results.Dispose(); // taboo!
                    results = null;
                }
                // results = null;
            }
            catch { //(Exception eWildCardSearch) {
            }

            return(resultCollection);
        }
示例#12
0
        internal static List <IUiElement> SearchByExactConditionsViaUia(
            IUiElement inputObject,
            Hashtable[] searchCriteria,
            classic.Condition conditions)
        {
            if (conditions == null)
            {
                return(new List <IUiElement>());
            }

            if (inputObject == null || (int)inputObject.GetCurrent().ProcessId <= 0)
            {
                return(new List <IUiElement>());
            }

            IUiEltCollection tempCollection = inputObject.FindAll(classic.TreeScope.Descendants, conditions);

            if (null == searchCriteria || 0 == searchCriteria.Length)
            {
                return(tempCollection.ToArray().ToList <IUiElement>());
            }

            return(tempCollection.ToArray().Where(element => TestControlWithAllSearchCriteria(searchCriteria, element)).ToList <IUiElement>());
        }
示例#13
0
        public static IUiElement GetElement_ForFindAll(IEnumerable <IUiElement> elements, Condition conditions)
        {
            var elementBeforeProxy =
                GetAutomationElement(ControlType.Pane, string.Empty, string.Empty, string.Empty, new IBasePattern[] {}, false);

            var element =
                AutomationFactory.GetUiElement(
                    elementBeforeProxy as IUiElement);

            Condition[] condCollection = null;
            if (null != conditions as AndCondition)
            {
                condCollection = (conditions as AndCondition).GetConditions();
            }

            if (null != conditions as OrCondition)
            {
                condCollection = (conditions as OrCondition).GetConditions();
            }

            IUiEltCollection descendants =
                AutomationFactory.GetUiEltCollection();

            descendants.SourceCollection.AddRange(
                AutomationFactory.GetUiEltCollection(elements)
                .ToArray().Where(elt => "expected" == elt.GetTag()));

//            element.FindAll(TreeScope.Descendants, Arg.Is<PropertyCondition>(x => (x as PropertyCondition).Value == ControlType.Button)).Returns<IEnumerable<IUiElement>>(descendants.ToArray().Select(elt => elt.Current.ControlType == ControlType.Button));
//            element.FindAll(TreeScope.Descendants, Arg.Is<PropertyCondition>(x => (x as PropertyCondition).Value == ControlType.Calendar)).Returns<IEnumerable<IUiElement>>(descendants.ToArray().Select(elt => elt.Current.ControlType == ControlType.Calendar));
//            element.FindAll(TreeScope.Descendants, Arg.Is<PropertyCondition>(x => (x as PropertyCondition).Value == ControlType.CheckBox)).Returns<IEnumerable<IUiElement>>(descendants.ToArray().Select(elt => elt.Current.ControlType == ControlType.CheckBox));
//            element.FindAll(TreeScope.Descendants, Arg.Is<PropertyCondition>(x => (x as PropertyCondition).Value == ControlType.ComboBox)).Returns<IEnumerable<IUiElement>>(descendants.ToArray().Select(elt => elt.Current.ControlType == ControlType.ComboBox));
//            element.FindAll(TreeScope.Descendants, Arg.Is<PropertyCondition>(x => (x as PropertyCondition).Value == ControlType.Custom)).Returns<IEnumerable<IUiElement>>(descendants.ToArray().Select(elt => elt.Current.ControlType == ControlType.Custom));
//            element.FindAll(TreeScope.Descendants, Arg.Is<PropertyCondition>(x => (x as PropertyCondition).Value == ControlType.DataItem)).Returns<IEnumerable<IUiElement>>(descendants.ToArray().Select(elt => elt.Current.ControlType == ControlType.DataItem));
//            element.FindAll(TreeScope.Descendants, Arg.Is<PropertyCondition>(x => (x as PropertyCondition).Value == ControlType.Document)).Returns<IEnumerable<IUiElement>>(descendants.ToArray().Select(elt => elt.Current.ControlType == ControlType.Document));
//            element.FindAll(TreeScope.Descendants, Arg.Is<PropertyCondition>(x => (x as PropertyCondition).Value == ControlType.Image)).Returns<IEnumerable<IUiElement>>(descendants.ToArray().Select(elt => elt.Current.ControlType == ControlType.Image));
//            element.FindAll(TreeScope.Descendants, Arg.Is<PropertyCondition>(x => (x as PropertyCondition).Value == ControlType.TreeItem)).Returns<IEnumerable<IUiElement>>(descendants.ToArray().Select(elt => elt.Current.ControlType == ControlType.TreeItem));
//            element.FindAll(TreeScope.Descendants, Arg.Is<PropertyCondition>(x => (x as PropertyCondition).Value == ControlType.Window)).Returns<IEnumerable<IUiElement>>(descendants.ToArray().Select(elt => elt.Current.ControlType == ControlType.Window));
            element.FindAll(TreeScope.Descendants, Arg.Any <Condition>()).Returns(descendants);

            IUiEltCollection children =
                AutomationFactory.GetUiEltCollection();

            children.SourceCollection.AddRange(
                AutomationFactory.GetUiEltCollection(elements)
                .ToArray().Where(elt => "expected" == elt.GetTag()));

//            element.FindAll(
//                TreeScope.Children,
//                new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button)).Returns<IEnumerable>(children.ToArray().Select(elt => elt.Current.ControlType == ControlType.Button));
//            element.FindAll(
//                TreeScope.Children,
//                new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Document)).Returns<IEnumerable>(children.ToArray().Select(elt => elt.Current.ControlType == ControlType.Document));
//            element.FindAll(
//                TreeScope.Children,
//                new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Image)).Returns<IEnumerable>(children.ToArray().Select(elt => elt.Current.ControlType == ControlType.Image));
//            element.FindAll(TreeScope.Children, Arg.Is<PropertyCondition>(x => (x as PropertyCondition).Value == ControlType.Button)).Returns<IEnumerable<IUiElement>>(children.ToArray().Select(elt => elt.Current.ControlType == ControlType.Button));
//            element.FindAll(TreeScope.Children, Arg.Is<PropertyCondition>(x => (x as PropertyCondition).Value == ControlType.Calendar)).Returns<IEnumerable<IUiElement>>(children.ToArray().Select(elt => elt.Current.ControlType == ControlType.Calendar));
//            element.FindAll(TreeScope.Children, Arg.Is<PropertyCondition>(x => (x as PropertyCondition).Value == ControlType.CheckBox)).Returns<IEnumerable<IUiElement>>(children.ToArray().Select(elt => elt.Current.ControlType == ControlType.CheckBox));
//            element.FindAll(TreeScope.Children, Arg.Is<PropertyCondition>(x => (x as PropertyCondition).Value == ControlType.ComboBox)).Returns<IEnumerable<IUiElement>>(children.ToArray().Select(elt => elt.Current.ControlType == ControlType.ComboBox));
//            element.FindAll(TreeScope.Children, Arg.Is<PropertyCondition>(x => (x as PropertyCondition).Value == ControlType.Custom)).Returns<IEnumerable<IUiElement>>(children.ToArray().Select(elt => elt.Current.ControlType == ControlType.Custom));
//            element.FindAll(TreeScope.Children, Arg.Is<PropertyCondition>(x => (x as PropertyCondition).Value == ControlType.DataItem)).Returns<IEnumerable<IUiElement>>(children.ToArray().Select(elt => elt.Current.ControlType == ControlType.DataItem));
//            element.FindAll(TreeScope.Children, Arg.Is<PropertyCondition>(x => (x as PropertyCondition).Value == ControlType.Document)).Returns<IEnumerable<IUiElement>>(children.ToArray().Select(elt => elt.Current.ControlType == ControlType.Document));
//            element.FindAll(TreeScope.Children, Arg.Is<PropertyCondition>(x => (x as PropertyCondition).Value == ControlType.Image)).Returns<IEnumerable<IUiElement>>(children.ToArray().Select(elt => elt.Current.ControlType == ControlType.Image));
//            element.FindAll(TreeScope.Children, Arg.Is<PropertyCondition>(x => (x as PropertyCondition).Value == ControlType.TreeItem)).Returns<IEnumerable<IUiElement>>(children.ToArray().Select(elt => elt.Current.ControlType == ControlType.TreeItem));
//            element.FindAll(TreeScope.Children, Arg.Is<PropertyCondition>(x => (x as PropertyCondition).Value == ControlType.Window)).Returns<IEnumerable<IUiElement>>(children.ToArray().Select(elt => elt.Current.ControlType == ControlType.Window));
            element.FindAll(TreeScope.Children, Arg.Any <Condition>()).Returns(children);

            return(element);
        }
示例#14
0
 public static bool GetResult_IsStepActive(Hashtable[] searchCriteria, IUiEltCollection elements)
 {
     var step = new WizardStep("stepName", 1) {
         Description = "description",
         SearchCriteria = searchCriteria
     };
     
     var wizard = new Wizard("wizardName");
     
     return wizard.IsStepActive(step, elements);
 }
示例#15
0
 internal bool IsStepActive(WizardStep step, IUiEltCollection elements)
 {
     bool result = false;
     
     if (null == step) return result;
     if (null == step.SearchCriteria || 0 == step.SearchCriteria.Count()) return result;
     var searchCriteria = step.SearchCriteria.Where(hashtable => null != hashtable);
     if (null == searchCriteria || 0 == searchCriteria.Count()) return result;
     if (null == elements || 0 == elements.Count) return result;
     
     if (searchCriteria.All(criterion =>   
                            elements.ToArray().Any(elt => ControlSearcher.TestControlWithAllSearchCriteria(new Hashtable[] { criterion }, elt))
                           )) {
         result = true;
     }
     
     return result;
 }
示例#16
0
        List <IUiElement> GetWindowCollectionByName(
            IUiElement rootElement,
            WindowSearcherData data)
        {
            var windowCollectionByProperties =
                new List <IUiElement>();
            var resultCollection =
                new List <IUiElement>();

            if (null == data.Name)
            {
                // 20141001
                // data.Name = new string[]{ string.Empty };
                data.Name = new [] { string.Empty };
            }

            classic.OrCondition conditionsSet = null;
            if (data.Recurse)
            {
                conditionsSet =
                    new classic.OrCondition(
                        new classic.PropertyCondition(
                            classic.AutomationElement.ControlTypeProperty,
                            classic.ControlType.Window),
                        classic.Condition.FalseCondition);
            }
            else
            {
                conditionsSet =
                    new classic.OrCondition(
                        new classic.PropertyCondition(
                            classic.AutomationElement.ControlTypeProperty,
                            classic.ControlType.Window),
                        new classic.PropertyCondition(
                            classic.AutomationElement.ControlTypeProperty,
                            classic.ControlType.Pane),
                        new classic.PropertyCondition(
                            classic.AutomationElement.ControlTypeProperty,
                            classic.ControlType.Menu));
            }

            foreach (string windowTitle in data.Name)
            {
                IUiEltCollection windowCollection =
                    rootElement.FindAll(data.Recurse ? classic.TreeScope.Descendants : classic.TreeScope.Children, conditionsSet);

                var controlSearcherData =
                    new ControlSearcherData {
                    Name         = windowTitle,
                    AutomationId = data.AutomationId,
                    Class        = data.Class,
                    Value        = string.Empty,
                    // 20141001
                    // ControlType = (new string[]{ "Window", "Pane", "Menu" })
                    ControlType = (new [] { "Window", "Pane", "Menu" })
                };

                windowCollectionByProperties =
                    ReturnOnlyRightElements(
                        windowCollection,
                        controlSearcherData,
                        false,
                        true);

                try {
                    if (null != windowCollectionByProperties && 0 < windowCollectionByProperties.Count)
                    {
                        foreach (IUiElement aeWndByTitle in windowCollectionByProperties
                                 .Where(aeWndByTitle => aeWndByTitle != null && (int)aeWndByTitle.GetCurrent().ProcessId > 0))
                        {
                            resultCollection.Add(aeWndByTitle);
                        }

                        windowCollectionByProperties.Clear();
                    }
                    else
                    {
                        IUiElement tempElement = null;

                        // one more attempt using the FindWindow function
                        IntPtr wndHandle = NativeMethods.FindWindowByCaption(IntPtr.Zero, windowTitle);
                        // 20141001
                        // if (wndHandle != null && wndHandle != IntPtr.Zero) {
                        if (wndHandle != IntPtr.Zero)
                        {
                            tempElement =
                                UiElement.FromHandle(wndHandle);
                        }

                        if (null == tempElement || (int)tempElement.GetCurrent().ProcessId <= 0)
                        {
                            continue;
                        }

                        resultCollection.Add(tempElement);
                    }
                }
                catch {}

                // 20140122
                // AutomationFactory.DisposeChildKernel();

                // 20140131
//                if (null != windowCollectionByProperties && 0 < windowCollectionByProperties.Count) {
//                    foreach (IUiElement element in windowCollectionByProperties) {
//                        element.Dispose();
//                    }
//                }
//                if (null != windowCollection && 0 < windowCollection.Count) {
//                    foreach (IUiElement element in windowCollection) {
//                        element.Dispose();
//                    }
//                }
            }

            return(resultCollection);
        }
 public static IUiElement[] ToArray(this IUiEltCollection collection)
 {
     return(collection.SourceCollection.ToArray());
 }
示例#18
0
 // 20131204
 // ????????
 public void WriteObject(PSCmdletBase cmdlet, IUiEltCollection outputObjectCollection)
 {
     HighlighterGeneration++;
     base.WriteObject(cmdlet, outputObjectCollection);
 }
示例#19
0
        internal List <IUiElement> GetWindowCollectionByPid(
            IUiElement rootElement,
            WindowSearcherData data)
        {
            classic.AndCondition conditionsForRecurseSearch = null;

            var elementsByProcessId =
                new List <IUiElement>();

            // 20141001
            // if ((null != data.Name && 0 < data.Name.Count()) ||
            if ((null != data.Name && data.Name.Any()) ||
                !string.IsNullOrEmpty(data.AutomationId) ||
                !string.IsNullOrEmpty(data.Class))
            {
                data.Recurse = true;
            }

            var conditionWindowPaneMenu =
                new classic.OrCondition(
                    new classic.PropertyCondition(
                        classic.AutomationElement.ControlTypeProperty,
                        classic.ControlType.Window),
                    new classic.PropertyCondition(
                        classic.AutomationElement.ControlTypeProperty,
                        classic.ControlType.Pane),
                    new classic.PropertyCondition(
                        classic.AutomationElement.ControlTypeProperty,
                        classic.ControlType.Menu));

            foreach (int processId in data.ProcessIds)
            {
                conditionsForRecurseSearch =
                    new classic.AndCondition(
                        new classic.PropertyCondition(
                            classic.AutomationElement.ProcessIdProperty,
                            processId),
                        new classic.PropertyCondition(
                            classic.AutomationElement.ControlTypeProperty,
                            classic.ControlType.Window));

                var conditionsProcessId =
                    new classic.AndCondition(
                        new classic.PropertyCondition(
                            classic.AutomationElement.ProcessIdProperty,
                            processId),
                        conditionWindowPaneMenu);

                try {
                    if (data.Recurse)
                    {
                        if (data.First)
                        {
                            IUiElement rootWindowElement =
                                rootElement.FindFirst(
                                    classic.TreeScope.Children,
                                    conditionsProcessId);

                            if (null != rootWindowElement)
                            {
                                elementsByProcessId.Add(rootWindowElement);
                            }
                        }
                        else
                        {
                            IUiEltCollection rootCollection =
                                rootElement.FindAll(
                                    classic.TreeScope.Children,
                                    conditionsProcessId);

                            if (null != rootCollection && 0 < rootCollection.Count)
                            {
                                elementsByProcessId.AddRange(rootCollection.Cast <IUiElement>());
                            }
                        }
                    }
                    else
                    {
                        if (data.First)
                        {
                            IUiElement tempElement =
                                rootElement.FindFirst(
                                    classic.TreeScope.Children,
                                    conditionsProcessId);

                            if (null != tempElement)
                            {
                                elementsByProcessId.Add(tempElement);
                            }
                        }
                        else
                        {
                            IUiEltCollection tempCollection =
                                rootElement.FindAll(
                                    classic.TreeScope.Children,
                                    conditionsProcessId);

                            if (null != tempCollection && 0 < tempCollection.Count)
                            {
                                elementsByProcessId.AddRange(tempCollection.Cast <IUiElement>());
                            }
                        }
                    }
                } catch (Exception) {
                    // WriteVerbose(
                    //     this,
                    //     "exception: " +
                    //     eGetFirstChildOfRootByProcessId.Message);
                }
            }

            if (!data.Recurse ||
                // 20141001
                // ((null == data.Name || 0 == data.Name.Count()) && string.IsNullOrEmpty(data.AutomationId) &&
                ((null == data.Name || !data.Name.Any()) && string.IsNullOrEmpty(data.AutomationId) &&
                 string.IsNullOrEmpty(data.Class)))
            {
                return(elementsByProcessId);
            }

            var resultList =
                new List <IUiElement>();

            /*
             * List<IUiElement> resultList =
             *  new List<IUiElement>();
             */

            // 20141001
            // if (null != data.Name && 0 < data.Name.Count()) {
            if (null != data.Name && data.Name.Any())
            {
                foreach (string name in data.Name)
                {
                    var controlSearcherData =
                        new ControlSearcherData {
                        Name         = name,
                        AutomationId = data.AutomationId,
                        Class        = data.Class,
                        Value        = string.Empty,
                        ControlType  = new string[] { "Window" }
                    };

                    resultList.AddRange(
                        ReturnOnlyRightElements(
                            elementsByProcessId,
                            controlSearcherData,
                            false,
                            true));
                }
            }
            else
            {
                var controlSearcherData =
                    new ControlSearcherData {
                    Name         = string.Empty,
                    AutomationId = data.AutomationId,
                    Class        = data.Class,
                    Value        = string.Empty,
                    ControlType  = new string[] { "Window" }
                };

                resultList.AddRange(
                    ReturnOnlyRightElements(
                        elementsByProcessId,
                        controlSearcherData,
                        false,
                        true));
            }

            elementsByProcessId = resultList;

            // 20140121
            // never !
            //            if (null != resultList) {
            //                resultList.Clear();
            //                resultList = null;
            //            }

            return(elementsByProcessId);
        }
示例#20
0
        protected void ifUltraGridProcessing(
            ifUltraGridOperations operation)
        {
            // collection of the selected rows
            // 20131109
            //System.Collections.Generic.List<AutomationElement> selectedItems =
            //    new System.Collections.Generic.List<AutomationElement>();
            List <IUiElement> selectedItems =
                new List <IUiElement>();

            try {
                // 20131109
                //foreach (AutomationElement inputObject in this.InputObject) {
                foreach (IUiElement inputObject in InputObject)
                {
                    // 20131109
                    //AutomationElementCollection tableItems =
                    IUiEltCollection tableItems =
                        inputObject.FindAll(
                            classic.TreeScope.Children,
                            new classic.PropertyCondition(
                                classic.AutomationElement.ControlTypeProperty,
                                classic.ControlType.Custom));

//                foreach (AutomationElementCollection tableItems in ((IAutomationElementCollection)this.InputObject).Select(inputObject => inputObject.FindAll(
//                    classic.TreeScope.Children,
//                    new PropertyCondition(
//                        AutomationElement.ControlTypeProperty,
//                        ControlType.Custom))))
//                {
                    if (tableItems.Count > 0)
                    {
                        int  currentRowNumber = 0;
                        bool notTheLastChild  = true;
                        // 20131109
                        //foreach (AutomationElement child in tableItems) {
                        foreach (IUiElement child in tableItems)
                        {
                            currentRowNumber++;
                            if (currentRowNumber == tableItems.Count)
                            {
                                notTheLastChild = false;
                            }
                            // 20131109
                            //AutomationElementCollection row =
                            IUiEltCollection row =
                                child.FindAll(classic.TreeScope.Children,
                                              new classic.PropertyCondition(
                                                  classic.AutomationElement.ControlTypeProperty,
                                                  classic.ControlType.Custom));
                            bool alreadyFoundInTheRow = false;
                            int  counter = 0;
                            // 20131109
                            //foreach (AutomationElement grandchild in row) {
                            foreach (IUiElement grandchild in row)
                            {
                                string strValue = String.Empty;
                                // 20131208
                                // ValuePattern valPattern = null;
                                IValuePattern valPattern = null;
                                try {
                                    valPattern =
                                        // 20131208
                                        // grandchild.GetCurrentPattern(classic.ValuePattern.Pattern)
                                        // grandchild.GetCurrentPattern<IValuePattern, ValuePattern>(classic.ValuePattern.Pattern)
                                        //    as ValuePattern;
                                        grandchild.GetCurrentPattern <IValuePattern>(classic.ValuePattern.Pattern);
                                    WriteVerbose(this,
                                                 "getting the valuePattern of the control");
                                } catch {
                                    WriteVerbose(this,
                                                 "unable to get ValuePattern of " +
                                                 // 20140312
                                                 // grandchild.Current.Name);
                                                 grandchild.GetCurrent().Name);
                                }
                                // string strValue = String.Empty;
                                try {
                                    strValue =
                                        valPattern.Current.Value;
                                    WriteVerbose(this,
                                                 "valuePattern of " +
                                                 // 20140312
                                                 // grandchild.Current.Name +
                                                 grandchild.GetCurrent().Name +
                                                 " = " +
                                                 strValue);
                                } catch {
                                    WriteVerbose(this,
                                                 "unable to get ValuePattern.Current.Value of " +
                                                 // 20140312
                                                 // grandchild.Current.Name);
                                                 grandchild.GetCurrent().Name);
                                }



                                if (!alreadyFoundInTheRow && IsInTheList(strValue))
                                {
                                    alreadyFoundInTheRow = true;
                                    counter++;

                                    WriteVerbose(this,
                                                 "this control is of requested value: " +
                                                 strValue +
                                                 ", sending a Ctrl+Click to it");


                                    switch (operation)
                                    {
                                    case ifUltraGridOperations.SelectItems:
                                        // in case of this operation is a selection of items
                                        // clicks are needed
                                        // otherwise, just return the set of rows found
                                        if (ClickControl(this,
                                                         child,
                                                         new ClickSettings()
                                        {
                                            Ctrl = true,
                                            RelativeX = Preferences.ClickOnControlByCoordX,
                                            RelativeY = Preferences.ClickOnControlByCoordY
                                        }))
                                        {
                                            /*
                                             * false,
                                             * false,
                                             * false,
                                             * false,
                                             * true, // notTheFirstChild,
                                             * false, // notTheLastChild, // true,
                                             * false,
                                             * // 20131125
                                             * 0,
                                             * Preferences.ClickOnControlByCoordX,
                                             * Preferences.ClickOnControlByCoordY)) {
                                             */
                                            selectedItems.Add(child);
                                            WriteVerbose(this,
                                                         // 20140312
                                                         // "the " + child.Current.Name +
                                                         "the " + child.GetCurrent().Name +
                                                         " added to the output collection");
                                        }

                                        const uint pressed = 0x8000;
                                        // uint pressed = 0x8000;
                                        if ((NativeMethods.GetKeyState(NativeMethods.VK_LCONTROL) & pressed) > 0)
                                        {
                                            NativeMethods.keybd_event(NativeMethods.VK_LCONTROL, 0x45, NativeMethods.KEYEVENTF_EXTENDEDKEY | NativeMethods.KEYEVENTF_KEYUP, 0);

                                            /*
                                             * NativeMethods.keybd_event((byte)NativeMethods.VK_LCONTROL, 0x45, NativeMethods.KEYEVENTF_EXTENDEDKEY | NativeMethods.KEYEVENTF_KEYUP, 0);
                                             */
                                        }
                                        if ((NativeMethods.GetKeyState(NativeMethods.VK_RCONTROL) & pressed) > 0)
                                        {
                                            NativeMethods.keybd_event(NativeMethods.VK_RCONTROL, 0x45, NativeMethods.KEYEVENTF_EXTENDEDKEY | NativeMethods.KEYEVENTF_KEYUP, 0);

                                            /*
                                             * NativeMethods.keybd_event((byte)NativeMethods.VK_RCONTROL, 0x45, NativeMethods.KEYEVENTF_EXTENDEDKEY | NativeMethods.KEYEVENTF_KEYUP, 0);
                                             */
                                        }
                                        if ((NativeMethods.GetKeyState(NativeMethods.VK_CONTROL) & pressed) > 0)
                                        {
                                            NativeMethods.keybd_event(NativeMethods.VK_CONTROL, 0x45, NativeMethods.KEYEVENTF_EXTENDEDKEY | NativeMethods.KEYEVENTF_KEYUP, 0);

                                            /*
                                             * NativeMethods.keybd_event((byte)NativeMethods.VK_CONTROL, 0x45, NativeMethods.KEYEVENTF_EXTENDEDKEY | NativeMethods.KEYEVENTF_KEYUP, 0);
                                             */
                                        }
                                        break;

                                    case ifUltraGridOperations.GetItems:
                                        selectedItems.Add(child);
                                        WriteVerbose(this,
                                                     // 20140312
                                                     // "the " + child.Current.Name +
                                                     "the " + child.GetCurrent().Name +
                                                     " added to the output collection");
                                        break;

                                    case ifUltraGridOperations.GetSelection:
                                        if (GetColorProbe(this,
                                                          child))
                                        {
                                            selectedItems.Add(child);
                                            WriteVerbose(this,
                                                         // 20140312
                                                         // "the " + child.Current.Name +
                                                         "the " + child.GetCurrent().Name +
                                                         " added to the output collection");
                                        }
                                        break;
                                    }
                                    if (Count > 0 && counter == Count)
                                    {
                                        break;
                                    }
                                }
                                WriteVerbose(this, "working with " +
                                             // 20140312
                                             // grandchild.Current.Name + "\t" + strValue);
                                             grandchild.GetCurrent().Name + "\t" + strValue);
                            }
                        }

                        WriteObject(this, selectedItems);
                    }
                    else
                    {
                        WriteVerbose(this, "no elements of type ControlType.Custom were found under the input control");
                    }
                }

                /*
                 *  foreach (AutomationElement inputObject in this.InputObject) {
                 *
                 * AutomationElementCollection tableItems =
                 *  inputObject.FindAll(
                 *      classic.TreeScope.Children,
                 *               new PropertyCondition(
                 *                   AutomationElement.ControlTypeProperty,
                 *                   ControlType.Custom));
                 *
                 * if (tableItems.Count > 0) {
                 *  int currentRowNumber = 0;
                 *  bool notTheLastChild = true;
                 *  foreach (AutomationElement child in tableItems) {
                 *      currentRowNumber++;
                 *      if (currentRowNumber == tableItems.Count) notTheLastChild = false;
                 *          AutomationElementCollection row =
                 *              child.FindAll(TreeScope.Children,
                 *                            new PropertyCondition(
                 *                                AutomationElement.ControlTypeProperty,
                 *                                ControlType.Custom));
                 *          bool alreadyFoundInTheRow = false;
                 *          int counter = 0;
                 *          foreach (AutomationElement grandchild in row) {
                 *
                 *              string strValue = String.Empty;
                 *                      ValuePattern valPattern = null;
                 *                      try {
                 *                          valPattern =
                 *                              grandchild.GetCurrentPattern(classic.ValuePattern.Pattern)
                 *                              as ValuePattern;
                 *                          WriteVerbose(this,
                 *                                       "getting the valuePattern of the control");
                 *                      } catch {
                 *                          WriteVerbose(this,
                 *                                        "unable to get ValuePattern of " +
                 *                                        grandchild.Current.Name);
                 *                      }
                 *                      // string strValue = String.Empty;
                 *                      try {
                 *                          strValue =
                 *                              valPattern.Current.Value;
                 *                          WriteVerbose(this,
                 *                                       "valuePattern of " +
                 *                                       grandchild.Current.Name +
                 *                                       " = " +
                 *                                       strValue);
                 *
                 *                      } catch {
                 *                          WriteVerbose(this,
                 *                                        "unable to get ValuePattern.Current.Value of " +
                 *                                        grandchild.Current.Name);
                 *                      }
                 *
                 *
                 *
                 *                      if (!alreadyFoundInTheRow && IsInTheList(strValue)) {
                 *                          alreadyFoundInTheRow = true;
                 *                          counter++;
                 *
                 *                          WriteVerbose(this,
                 *                                       "this control is of requested value: " +
                 *                                       strValue +
                 *                                       ", sending a Ctrl+Click to it");
                 *
                 *
                 *                          switch (operation) {
                 *                              case ifUltraGridOperations.selectItems:
                 *                                  // in case of this operation is a selection of items
                 *                                  // clicks are needed
                 *                                  // otherwise, just return the set of rows found
                 *                                  if (ClickControl(this,
                 *                                                    child,
                 *                                                    false,
                 *                                                    false,
                 *                                                    false,
                 *                                                    false,
                 *                                                    true, // notTheFirstChild,
                 *                                                    false, // notTheLastChild, // true,
                 *                                                    false,
                 *                                                    Preferences.ClickOnControlByCoordX,
                 *                                                    Preferences.ClickOnControlByCoordY)) {
                 *                                      selectedItems.Add(child);
                 *                                      WriteVerbose(this,
                 *                                                   "the " + child.Current.Name +
                 *                                                   " added to the output collection");
                 *                                  }
                 *
                 *                                  uint pressed = 0x8000;
                 *                                  if ((NativeMethods.GetKeyState(NativeMethods.VK_LCONTROL) & pressed) > 0) {
                 *                                      NativeMethods.keybd_event((byte)NativeMethods.VK_LCONTROL, 0x45, NativeMethods.KEYEVENTF_EXTENDEDKEY | NativeMethods.KEYEVENTF_KEYUP, 0);
                 *                                  }
                 *                                  if ((NativeMethods.GetKeyState(NativeMethods.VK_RCONTROL) & pressed) > 0) {
                 *                                      NativeMethods.keybd_event((byte)NativeMethods.VK_RCONTROL, 0x45, NativeMethods.KEYEVENTF_EXTENDEDKEY | NativeMethods.KEYEVENTF_KEYUP, 0);
                 *                                  }
                 *                                  if ((NativeMethods.GetKeyState(NativeMethods.VK_CONTROL) & pressed) > 0) {
                 *                                      NativeMethods.keybd_event((byte)NativeMethods.VK_CONTROL, 0x45, NativeMethods.KEYEVENTF_EXTENDEDKEY | NativeMethods.KEYEVENTF_KEYUP, 0);
                 *                                  }
                 *                                  break;
                 *                              case ifUltraGridOperations.getItems:
                 *                                  selectedItems.Add(child);
                 *                                  WriteVerbose(this,
                 *                                               "the " + child.Current.Name +
                 *                                               " added to the output collection");
                 *                                  break;
                 *                              case ifUltraGridOperations.getSelection:
                 *                                  if (GetColorProbe(this,
                 *                                                    child)) {
                 *                                      selectedItems.Add(child);
                 *                                      WriteVerbose(this,
                 *                                                   "the " + child.Current.Name +
                 *                                                   " added to the output collection");
                 *                                  }
                 *                                  break;
                 *                          }
                 *                          if (this.Count > 0 && counter == this.Count) {
                 *                              break;
                 *                          }
                 *                      }
                 *              WriteVerbose(this, "working with " +
                 *                           grandchild.Current.Name + "\t" + strValue);
                 *          }
                 *
                 *  }
                 *
                 *  WriteObject(this, selectedItems);
                 * } else {
                 *  WriteVerbose(this, "no elements of type ControlType.Custom were found under the input control");
                 * }
                 *
                 * } // 20120824
                 */
            } catch (Exception ee) {
                ErrorRecord err =
                    new ErrorRecord(
                        ee,
                        "ExceptionInSectingItems",
                        ErrorCategory.InvalidOperation,
                        InputObject);
                err.ErrorDetails = new ErrorDetails("Exception were thrown during the cycle of selecting items.");
                WriteObject(this, false);

//                this.WriteError(
//                    this,
//                    "",
//                    "",


                // TODO
                // this.WriteError();
            }
            // return result;
        }
示例#21
0
 // 20131204
 // ????????
 public void WriteObject(PSCmdletBase cmdlet, IUiEltCollection outputObjectCollection)
 {
     HighlighterGeneration++;
     base.WriteObject(cmdlet, outputObjectCollection);
 }
        protected void GetAutomationElements(classic.TreeScope scope)
        {
            if (!CheckAndPrepareInput(this))
            {
                return;
            }

            foreach (IUiElement inputObject in InputObject)
            {
                var searchResults =
                    new List <IUiElement>();

                if (scope == classic.TreeScope.Children ||
                    scope == classic.TreeScope.Descendants)
                {
                    // WriteVerbose(this, "selected TreeScope." + scope.ToString());

                    var controlSearch =
                        AutomationFactory.GetSearcherImpl <ControlSearcher>() as ControlSearcher;

                    classic.Condition conditions =
                        ControlSearcher.GetWildcardSearchCondition(
                            controlSearch.ConvertCmdletToControlSearcherData(this));

                    IUiEltCollection temporaryResults = null;
                    if (conditions != null)
                    {
                        temporaryResults =
                            inputObject.FindAll(
                                scope,
                                conditions);

                        searchResults.AddRange(temporaryResults.Cast <IUiElement>());
                    }
                    else
                    {
                        // WriteVerbose(this, "no conditions. Performing search with TrueCondition");
                        temporaryResults =
                            inputObject.FindAll(
                                scope,
                                classic.Condition.TrueCondition);
                        if (temporaryResults.Count > 0)
                        {
//                            WriteVerbose(this,
//                                         "returned " +
//                                         temporaryResults.Count.ToString() +
//                                         " results");
                            searchResults.AddRange(temporaryResults.Cast <IUiElement>());
                        }
                    }
                    // WriteVerbose(this, "results found: " + searchResults.Count.ToString());
                    WriteObject(this, searchResults.ToArray());
                }

                if (null != searchResults)
                {
                    searchResults.Clear();
                    searchResults = null;
                }

                if (scope != classic.TreeScope.Parent && scope != classic.TreeScope.Ancestors)
                {
                    continue;
                }

                IUiElement[] outResult = inputObject.GetParentOrAncestor(scope);
                WriteObject(this, outResult);

                if (null != outResult)
                {
                    outResult = null;
                }
            }
        }