Example #1
0
		internal ValuePattern (IValuePattern source, AutomationElement element, bool cached)
		{
			this.element = element;
			this.cached = cached;
			this.Source = source;
			currentInfo = new ValuePatternInformation (this, false);
			if (cached)
				cachedInfo = new ValuePatternInformation (this, true);
		}
Example #2
0
 internal ValuePattern(IValuePattern source, AutomationElement element, bool cached)
 {
     this.element = element;
     this.cached  = cached;
     this.Source  = source;
     currentInfo  = new ValuePatternInformation(this, false);
     if (cached)
     {
         cachedInfo = new ValuePatternInformation(this, true);
     }
 }
Example #3
0
        public static IFakeUiElement GetAutomationElementNotExpected(ElementData data)
        {
            IValuePattern valuePattern = null;

            if (!string.IsNullOrEmpty(data.Current_Value))
            {
                valuePattern = GetValuePattern(new PatternsData {
                    ValuePattern_Value = data.Current_Value
                });
            }
            return(GetAutomationElement(data, new IBasePattern[] { valuePattern }, false));
        }
Example #4
0
        public static IValuePattern GetValuePattern(PatternsData data)
        {
            IValuePattern valuePattern = Substitute.For <IValuePattern>();

            valuePattern.SetValue(Arg.Do <string>(arg => data.ValuePattern_Value = arg));
            IValuePatternInformation valuePatternInformation = Substitute.For <IValuePatternInformation>();

            valuePatternInformation.Value.Returns(data.ValuePattern_Value);
            valuePattern.Current.Returns(valuePatternInformation);
            // FakeSourcePattern sourcePattern = new FakeSourcePattern();
            var sourcePattern = new FakeSourcePattern();

            FakeSourcePattern.Pattern = ValuePattern.Pattern;
            valuePattern.SetSourcePattern(sourcePattern);
            return(valuePattern);
        }
Example #5
0
 public ValuePatternInformation(IValuePattern valuePattern, bool useCache)
 {
     _valuePattern = valuePattern;
     _useCache     = useCache;
 }
Example #6
0
 public SelectedTextRange(ITextPattern textPattern, IValuePattern valuePattern, ITextRange range) : base(textPattern, valuePattern, range)
 {
 }
 /// <summary>
 /// Retrieves such element's properties as AutomationId, Name, Class(Name) and Value
 /// </summary>
 /// <param name="cmdlet">cmdlet to report</param>
 /// <param name="element">The element properties taken from</param>
 /// <param name="propertyName">The name of property</param>
 /// <param name="pattern">an object of the ValuePattern type</param>
 /// <param name="hasName">an object has Name</param>
 /// <returns></returns>
 internal static string GetElementPropertyString(
     this IUiElement element,
     PSCmdletBase cmdlet,
     string propertyName,
     IValuePattern pattern,
     ref bool hasName)
 {
     string tempString = string.Empty;
     try {
         
         switch (propertyName) {
             case "Name":
                 if (!string.IsNullOrEmpty(element.GetCurrent().Name)) {
                     tempString = element.GetCurrent().Name;
                     hasName = true;
                 }
                 break;
             case "AutomationId":
                 if (!string.IsNullOrEmpty(element.GetCurrent().AutomationId)) {
                     tempString = element.GetCurrent().AutomationId;
                 }
                 break;
             case "Class":
                 if (!string.IsNullOrEmpty(element.GetCurrent().ClassName)) {
                     tempString = element.GetCurrent().ClassName;
                 }
                 break;
             case "Value":
                 try {
                     if (!string.IsNullOrEmpty(pattern.Current.Value)) {
                         tempString = pattern.Current.Value;
                         hasName = true;
                     }
                 }
                 catch {}
                 break;
             case "Win32":
                 if (0 < element.GetCurrent().NativeWindowHandle) {
                     tempString = ".";
                 }
                 break;
             default:
                 
                 break;
         }
     } catch {
         switch (propertyName) {
             case "Name":
                 if (!string.IsNullOrEmpty(element.GetCached().Name)) {
                     tempString = element.GetCached().Name;
                     hasName = true;
                 }
                 break;
             case "AutomationId":
                 if (!string.IsNullOrEmpty(element.GetCached().AutomationId)) {
                     tempString = element.GetCached().AutomationId;
                 }
                 break;
             case "Class":
                 if (!string.IsNullOrEmpty(element.GetCached().ClassName)) {
                     tempString = element.GetCached().ClassName;
                 }
                 break;
             case "Value":
                 try {
                     if (!string.IsNullOrEmpty(pattern.Cached.Value)) {
                         tempString = pattern.Cached.Value;
                         hasName = true;
                     }
                 }
                 catch {}
                 break;
             case "Win32":
                 if (0 < element.GetCached().NativeWindowHandle) {
                     tempString = ".";
                 }
                 break;
             default:
                 
                 break;
         }
     }
     if (string.IsNullOrEmpty(tempString)) {
         return string.Empty;
     } else {
         if ("Win32" == propertyName) {
             tempString =
                 " -" + propertyName;
         } else {
             tempString =
                 " -" + propertyName + " '" + tempString + "'";
         }
         return tempString;
     }
 }
        private void TestParametersAgainstCollection(
            ControlType controlType,
            string name,
            string automationId,
            string className,
            string txtValue,
            IEnumerable <IUiElement> collection,
            UsualWildcardRegex selector,
            int expectedNumberOfElements)
        {
            // Arrange
            ControlType[] controlTypes =
                new[] { controlType };

            GetControlCmdletBase cmdlet =
                FakeFactory.Get_GetControlCmdletBase(controlTypes, name, automationId, className, txtValue);

            var data =
                new ControlSearcherData {
                ControlType  = controlTypes.ConvertControlTypeToStringArray(),
                Name         = name,
                AutomationId = automationId,
                Class        = className,
                Value        = txtValue
            };

            Condition condition;
            bool      useWildcardOrRegex = true;

            switch (selector)
            {
            case UsualWildcardRegex.Wildcard:
                condition =
                    ControlSearcher.GetWildcardSearchCondition(
                        data);
                useWildcardOrRegex = true;
                break;

            case UsualWildcardRegex.Regex:
                condition =
                    ControlSearcher.GetWildcardSearchCondition(
                        data);
                useWildcardOrRegex = false;
                break;
            }

            // Act
            var resultList = RealCodeCaller.GetResultList_ReturnOnlyRightElements(collection.ToArray(), data, useWildcardOrRegex);

            // Assert
            MbUnit.Framework.Assert.Count(expectedNumberOfElements, resultList);
            Assert.Equal(expectedNumberOfElements, resultList.Count);
            string[] controlTypeNames;
            switch (selector)
            {
            case UsualWildcardRegex.Wildcard:
                const WildcardOptions options = WildcardOptions.IgnoreCase;
                // 20140312
//                    WildcardPattern namePattern = new WildcardPattern(name, options);
//                    WildcardPattern automationIdPattern = new WildcardPattern(automationId, options);
//                    WildcardPattern classNamePattern = new WildcardPattern(className, options);
//                    WildcardPattern txtValuePattern = new WildcardPattern(txtValue, options);
                var namePattern         = new WildcardPattern(name, options);
                var automationIdPattern = new WildcardPattern(automationId, options);
                var classNamePattern    = new WildcardPattern(className, options);
                var txtValuePattern     = new WildcardPattern(txtValue, options);

                // 20140312
//                    if (!string.IsNullOrEmpty(name)) {
//                        MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => namePattern.IsMatch(x.Current.Name));
//                        resultList.All(x => namePattern.IsMatch(x.Current.Name));
//                    }
//                    if (!string.IsNullOrEmpty(automationId)) {
//                        MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => automationIdPattern.IsMatch(x.Current.AutomationId));
//                        resultList.All(x => automationIdPattern.IsMatch(x.Current.AutomationId));
//                    }
//                    if (!string.IsNullOrEmpty(className)) {
//                        MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => classNamePattern.IsMatch(x.Current.ClassName));
//                        resultList.All(x => classNamePattern.IsMatch(x.Current.ClassName));
//                    }
//                    controlTypeNames =
//                        controlTypes.Select(ct => null != ct ? ct.ProgrammaticName.Substring(12) : string.Empty).ToArray();
//                    if (null != controlType) {
//                        MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => controlTypeNames.Contains(x.Current.ControlType.ProgrammaticName.Substring(12)));
//                        resultList.All(x => controlTypeNames.Contains(x.Current.ControlType.ProgrammaticName.Substring(12)));
//                    }
                if (!string.IsNullOrEmpty(name))
                {
                    MbUnit.Framework.Assert.ForAll(resultList.Cast <IUiElement>().ToList <IUiElement>(), x => namePattern.IsMatch(x.GetCurrent().Name));
                    resultList.All(x => namePattern.IsMatch(x.GetCurrent().Name));
                }
                if (!string.IsNullOrEmpty(automationId))
                {
                    MbUnit.Framework.Assert.ForAll(resultList.Cast <IUiElement>().ToList <IUiElement>(), x => automationIdPattern.IsMatch(x.GetCurrent().AutomationId));
                    resultList.All(x => automationIdPattern.IsMatch(x.GetCurrent().AutomationId));
                }
                if (!string.IsNullOrEmpty(className))
                {
                    MbUnit.Framework.Assert.ForAll(resultList.Cast <IUiElement>().ToList <IUiElement>(), x => classNamePattern.IsMatch(x.GetCurrent().ClassName));
                    resultList.All(x => classNamePattern.IsMatch(x.GetCurrent().ClassName));
                }
                controlTypeNames =
                    controlTypes.Select(ct => null != ct ? ct.ProgrammaticName.Substring(12) : string.Empty).ToArray();
                if (null != controlType)
                {
                    MbUnit.Framework.Assert.ForAll(resultList.Cast <IUiElement>().ToList <IUiElement>(), x => controlTypeNames.Contains(x.GetCurrent().ControlType.ProgrammaticName.Substring(12)));
                    resultList.All(x => controlTypeNames.Contains(x.GetCurrent().ControlType.ProgrammaticName.Substring(12)));
                }

                if (!string.IsNullOrEmpty(txtValue))
                {
                    MbUnit.Framework.Assert.ForAll(
                        resultList
                        .Cast <IUiElement>()
                        .ToList <IUiElement>(), x =>
                    {
                        IValuePattern valuePattern = x.GetCurrentPattern <IValuePattern>(ValuePattern.Pattern) as IValuePattern;
                        return(valuePattern != null && txtValuePattern.IsMatch(valuePattern.Current.Value));
                    });

                    resultList.All(
                        x => {
                        IValuePattern valuePattern = x.GetCurrentPattern <IValuePattern>(ValuePattern.Pattern) as IValuePattern;
                        return(valuePattern != null && txtValuePattern.IsMatch(valuePattern.Current.Value));
                    });
                }
                break;

            case UsualWildcardRegex.Regex:
                // 20140312
//                    if (!string.IsNullOrEmpty(name)) {
//                        MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => Regex.IsMatch(x.Current.Name, name));
//                        resultList.All(x => Regex.IsMatch(x.Current.Name, name));
//                    }
//                    if (!string.IsNullOrEmpty(automationId)) {
//                        MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => Regex.IsMatch(x.Current.AutomationId, automationId));
//                        resultList.All(x => Regex.IsMatch(x.Current.AutomationId, automationId));
//                    }
//                    if (!string.IsNullOrEmpty(className)) {
//                        MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => Regex.IsMatch(x.Current.ClassName, className));
//                        resultList.All(x => Regex.IsMatch(x.Current.ClassName, className));
//                    }
//                    controlTypeNames =
//                        controlTypes.Select(ct => null != ct ? ct.ProgrammaticName.Substring(12) : string.Empty).ToArray();
//                    if (null != controlType) {
//                        MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => controlTypeNames.Contains(x.Current.ControlType.ProgrammaticName.Substring(12)));
//                        resultList.All(x => controlTypeNames.Contains(x.Current.ControlType.ProgrammaticName.Substring(12)));
//                    }
                if (!string.IsNullOrEmpty(name))
                {
                    MbUnit.Framework.Assert.ForAll(resultList.Cast <IUiElement>().ToList <IUiElement>(), x => Regex.IsMatch(x.GetCurrent().Name, name));
                    resultList.All(x => Regex.IsMatch(x.GetCurrent().Name, name));
                }
                if (!string.IsNullOrEmpty(automationId))
                {
                    MbUnit.Framework.Assert.ForAll(resultList.Cast <IUiElement>().ToList <IUiElement>(), x => Regex.IsMatch(x.GetCurrent().AutomationId, automationId));
                    resultList.All(x => Regex.IsMatch(x.GetCurrent().AutomationId, automationId));
                }
                if (!string.IsNullOrEmpty(className))
                {
                    MbUnit.Framework.Assert.ForAll(resultList.Cast <IUiElement>().ToList <IUiElement>(), x => Regex.IsMatch(x.GetCurrent().ClassName, className));
                    resultList.All(x => Regex.IsMatch(x.GetCurrent().ClassName, className));
                }
                controlTypeNames =
                    controlTypes.Select(ct => null != ct ? ct.ProgrammaticName.Substring(12) : string.Empty).ToArray();
                if (null != controlType)
                {
                    MbUnit.Framework.Assert.ForAll(resultList.Cast <IUiElement>().ToList <IUiElement>(), x => controlTypeNames.Contains(x.GetCurrent().ControlType.ProgrammaticName.Substring(12)));
                    resultList.All(x => controlTypeNames.Contains(x.GetCurrent().ControlType.ProgrammaticName.Substring(12)));
                }

                if (!string.IsNullOrEmpty(txtValue))
                {
                    MbUnit.Framework.Assert.ForAll(
                        resultList
                        .Cast <IUiElement>()
                        .ToList <IUiElement>(), x =>
                    {
                        IValuePattern valuePattern = x.GetCurrentPattern <IValuePattern>(ValuePattern.Pattern) as IValuePattern;
                        return(valuePattern != null && Regex.IsMatch(valuePattern.Current.Value, txtValue));
                    });
                    Assert.True(
                        resultList.All(
                            x => {
                        IValuePattern valuePattern = x.GetCurrentPattern <IValuePattern>(ValuePattern.Pattern) as IValuePattern;
                        return(valuePattern != null && Regex.IsMatch(valuePattern.Current.Value, txtValue));
                    })
                        );
                }
                break;
            }
        }
Example #9
0
 public ValuePatternInformation(IValuePattern valuePattern, bool useCache)
 {
     _valuePattern = valuePattern;
     _useCache = useCache;
 }
        /// <summary>
        /// Retrieves such element's properties as AutomationId, Name, Class(Name) and Value
        /// </summary>
        /// <param name="cmdlet">cmdlet to report</param>
        /// <param name="element">The element properties taken from</param>
        /// <param name="propertyName">The name of property</param>
        /// <param name="pattern">an object of the ValuePattern type</param>
        /// <param name="hasName">an object has Name</param>
        /// <returns></returns>
        internal static string GetElementPropertyString(
            this IUiElement element,
            PSCmdletBase cmdlet,
            string propertyName,
            IValuePattern pattern,
            ref bool hasName)
        {
            string tempString = string.Empty;

            try {
                switch (propertyName)
                {
                case "Name":
                    if (!string.IsNullOrEmpty(element.GetCurrent().Name))
                    {
                        tempString = element.GetCurrent().Name;
                        hasName    = true;
                    }
                    break;

                case "AutomationId":
                    if (!string.IsNullOrEmpty(element.GetCurrent().AutomationId))
                    {
                        tempString = element.GetCurrent().AutomationId;
                    }
                    break;

                case "Class":
                    if (!string.IsNullOrEmpty(element.GetCurrent().ClassName))
                    {
                        tempString = element.GetCurrent().ClassName;
                    }
                    break;

                case "Value":
                    try {
                        if (!string.IsNullOrEmpty(pattern.Current.Value))
                        {
                            tempString = pattern.Current.Value;
                            hasName    = true;
                        }
                    }
                    catch {}
                    break;

                case "Win32":
                    if (0 < element.GetCurrent().NativeWindowHandle)
                    {
                        tempString = ".";
                    }
                    break;

                default:

                    break;
                }
            } catch {
                switch (propertyName)
                {
                case "Name":
                    if (!string.IsNullOrEmpty(element.GetCached().Name))
                    {
                        tempString = element.GetCached().Name;
                        hasName    = true;
                    }
                    break;

                case "AutomationId":
                    if (!string.IsNullOrEmpty(element.GetCached().AutomationId))
                    {
                        tempString = element.GetCached().AutomationId;
                    }
                    break;

                case "Class":
                    if (!string.IsNullOrEmpty(element.GetCached().ClassName))
                    {
                        tempString = element.GetCached().ClassName;
                    }
                    break;

                case "Value":
                    try {
                        if (!string.IsNullOrEmpty(pattern.Cached.Value))
                        {
                            tempString = pattern.Cached.Value;
                            hasName    = true;
                        }
                    }
                    catch {}
                    break;

                case "Win32":
                    if (0 < element.GetCached().NativeWindowHandle)
                    {
                        tempString = ".";
                    }
                    break;

                default:

                    break;
                }
            }
            if (string.IsNullOrEmpty(tempString))
            {
                return(string.Empty);
            }
            else
            {
                if ("Win32" == propertyName)
                {
                    tempString =
                        " -" + propertyName;
                }
                else
                {
                    tempString =
                        " -" + propertyName + " '" + tempString + "'";
                }
                return(tempString);
            }
        }
 public TextRange(ITextPattern textPattern, IValuePattern valuePattern, ITextRange range)
 {
     TextPattern  = textPattern;
     ValuePattern = valuePattern;
     Range        = range;
 }
Example #12
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;
        }
 public TextRange(ITextPattern textPattern, IValuePattern valuePattern, ITextRange range)
 {
     this.TextPattern  = textPattern;
     this.ValuePattern = valuePattern;
     this.Range        = range;
 }