Exemplo n.º 1
0
        public static DesktopData[] AddProperties(string[] attributes, bool isPassword, bool isVisible, AutomationElement element)
        {
            List <DesktopData> result = new List <DesktopData>();

            FrameworkAutomationElementBase.IProperties        propertyValues = element.Properties;
            FrameworkAutomationElementBase.IFrameworkPatterns patternValues  = element.Patterns;

            for (int i = 0; i < attributes.Length; i++)
            {
                AddProperty(attributes[i], isPassword, isVisible, element, propertyValues, patternValues, ref result);
            }

            return(result.ToArray());
        }
Exemplo n.º 2
0
        public static void AddProperty(string propertyName, bool isPassword, bool isVisible, AutomationElement element, FrameworkAutomationElementBase.IProperties propertyValues, FrameworkAutomationElementBase.IFrameworkPatterns patternValues, ref List <DesktopData> properties)
        {
            switch (propertyName)
            {
            case BoundingX:
            case BoundingY:
            case BoundingWidth:
            case BoundingHeight:
            case BoundingRectangle:
                Rectangle rect = element.BoundingRectangle;
                if (BoundingRectangle.Equals(propertyName))
                {
                    StringBuilder sb = new StringBuilder().Append(rect.X).Append(",").Append(rect.Y).Append(",").Append(rect.Width).Append(",").Append(rect.Height);
                    properties.Add(new DesktopData(BoundingRectangle, sb.ToString()));
                }
                else if (BoundingX.Equals(propertyName))
                {
                    properties.Add(new DesktopData(BoundingX, rect.X));
                }
                else if (BoundingY.Equals(propertyName))
                {
                    properties.Add(new DesktopData(BoundingY, rect.Y));
                }
                else if (BoundingWidth.Equals(propertyName))
                {
                    properties.Add(new DesktopData(BoundingWidth, rect.Width));
                }
                else if (BoundingHeight.Equals(propertyName))
                {
                    properties.Add(new DesktopData(BoundingHeight, rect.Height));
                }
                break;

            case Name:
                string value = "";
                if (propertyValues.Name.IsSupported)
                {
                    value = propertyValues.Name.Value;
                }

                if (value == null && patternValues.LegacyIAccessible.IsSupported)
                {
                    value = patternValues.LegacyIAccessible.Pattern.Name.Value;
                }
                properties.Add(new DesktopData(propertyName, value));
                break;

            case ProcessId:
                if (propertyValues.ProcessId.IsSupported)
                {
                    properties.Add(new DesktopData(propertyName, propertyValues.ProcessId.ToString()));
                }
                break;

            case NativeWindowHandle:
                if (propertyValues.NativeWindowHandle.IsSupported)
                {
                    properties.Add(new DesktopData(propertyName, propertyValues.NativeWindowHandle.ToString()));
                }
                break;

            case AutomationId:
                CheckProperty(propertyName, propertyValues.AutomationId, ref properties);
                break;

            case ClassName:
                CheckProperty(propertyName, propertyValues.ClassName, ref properties);
                break;

            case HelpText:
                CheckProperty(propertyName, propertyValues.HelpText, ref properties);
                break;

            case ItemStatus:
                CheckProperty(propertyName, propertyValues.ItemStatus, ref properties);
                break;

            case ItemType:
                CheckProperty(propertyName, propertyValues.ItemType, ref properties);
                break;

            case AriaRole:
                CheckProperty(propertyName, propertyValues.AriaRole, ref properties);
                break;

            case AriaProperties:
                CheckProperty(propertyName, propertyValues.AriaProperties, ref properties);
                break;

            case AcceleratorKey:
                CheckProperty(propertyName, propertyValues.AcceleratorKey, ref properties);
                break;

            case AccessKey:
                CheckProperty(propertyName, propertyValues.AccessKey, ref properties);
                break;

            case IsEnabled:
                properties.Add(new DesktopData(propertyName, element.Properties.IsEnabled));
                break;

            case IsPassword:
                properties.Add(new DesktopData(propertyName, isPassword));
                break;

            case IsVisible:
                properties.Add(new DesktopData(propertyName, isVisible));
                break;

            case RowCount:
                properties.Add(new DesktopData(propertyName, element.AsGrid().RowCount));
                break;

            case ColumnCount:
                properties.Add(new DesktopData(propertyName, element.AsGrid().ColumnCount));
                break;

            case Text:
                if (patternValues.Text2.IsSupported)
                {
                    properties.Add(new DesktopData(propertyName, patternValues.Text2.Pattern.DocumentRange.GetText(999999999)));
                }
                else if (patternValues.Text.IsSupported)
                {
                    properties.Add(new DesktopData(propertyName, patternValues.Text.Pattern.DocumentRange.GetText(999999999)));
                }
                break;

            case Value:
                if (isPassword)
                {
                    properties.Add(new DesktopData(propertyName, "#PASSWORD_VALUE#"));
                }
                else if (patternValues.Value.IsSupported)
                {
                    properties.Add(new DesktopData(propertyName, patternValues.Value.Pattern.Value.ValueOrDefault));
                }
                else if (patternValues.LegacyIAccessible.IsSupported)
                {
                    properties.Add(new DesktopData(propertyName, patternValues.LegacyIAccessible.Pattern.Value.ValueOrDefault));
                }
                break;

            case IsReadOnly:
                if (patternValues.Value.IsSupported)
                {
                    properties.Add(new DesktopData(propertyName, patternValues.Value.Pattern.IsReadOnly));
                }
                break;

            case SelectedItems:
                if (patternValues.Selection.IsSupported)
                {
                    List <string> items = new List <string>();
                    foreach (AutomationElement item in patternValues.Selection.Pattern.Selection.ValueOrDefault)
                    {
                        if (item.Patterns.SelectionItem.IsSupported && item.Properties.Name.IsSupported)
                        {
                            items.Add(item.Name);
                        }
                    }
                    properties.Add(new DesktopData(propertyName, String.Join(",", items)));
                }
                break;

            case IsSelected:

                if (patternValues.SelectionItem.IsSupported)
                {
                    properties.Add(new DesktopData(propertyName, patternValues.SelectionItem.Pattern.IsSelected));
                }
                break;

            case Toggle:
                if (patternValues.Toggle.IsSupported)
                {
                    properties.Add(new DesktopData(propertyName, patternValues.Toggle.Pattern.ToggleState.ToString()));
                }
                break;

            case RangeValue:
                if (patternValues.RangeValue.IsSupported)
                {
                    properties.Add(new DesktopData(propertyName, Convert.ToInt32(patternValues.RangeValue.Pattern.Value)));
                }
                break;

            case HorizontalScrollPercent:
                if (patternValues.Scroll.IsSupported)
                {
                    properties.Add(new DesktopData(propertyName, Convert.ToInt32(patternValues.Scroll.Pattern.HorizontalScrollPercent.ValueOrDefault)));
                }
                break;

            case VerticalScrollPercent:
                if (patternValues.Scroll.IsSupported)
                {
                    properties.Add(new DesktopData(propertyName, Convert.ToInt32(patternValues.Scroll.Pattern.VerticalScrollPercent.ValueOrDefault)));
                }
                break;

            case FillColor:
                if (patternValues.Styles.IsSupported)
                {
                    properties.Add(new DesktopData(propertyName, patternValues.Styles.Pattern.FillColor.ValueOrDefault));
                }
                break;

            case FillPatternColor:
                if (patternValues.Styles.IsSupported)
                {
                    properties.Add(new DesktopData(propertyName, patternValues.Styles.Pattern.FillPatternColor.ValueOrDefault));
                }
                break;

            case FillPatternStyle:
                if (patternValues.Styles.IsSupported)
                {
                    properties.Add(new DesktopData(propertyName, patternValues.Styles.Pattern.FillPatternStyle.ValueOrDefault));
                }
                break;

            case AnnotationTypeName:
                if (patternValues.Annotation.IsSupported && patternValues.Annotation.Pattern.AnnotationTypeName.IsSupported)
                {
                    properties.Add(new DesktopData(propertyName, patternValues.Annotation.Pattern.AnnotationTypeName));
                }
                break;

            case Author:
                if (patternValues.Annotation.IsSupported && patternValues.Annotation.Pattern.Author.IsSupported)
                {
                    properties.Add(new DesktopData(propertyName, patternValues.Annotation.Pattern.Author));
                }
                break;

            case DateTime:
                if (patternValues.Annotation.IsSupported && patternValues.Annotation.Pattern.DateTime.IsSupported)
                {
                    properties.Add(new DesktopData(propertyName, patternValues.Annotation.Pattern.DateTime));
                }
                break;

            case ChildId:
                if (patternValues.LegacyIAccessible.IsSupported && patternValues.LegacyIAccessible.Pattern.ChildId.IsSupported)
                {
                    properties.Add(new DesktopData(propertyName, patternValues.LegacyIAccessible.Pattern.ChildId));
                }
                break;

            case Description:
                if (patternValues.LegacyIAccessible.IsSupported && patternValues.LegacyIAccessible.Pattern.Description.IsSupported)
                {
                    properties.Add(new DesktopData(propertyName, patternValues.LegacyIAccessible.Pattern.Description));
                }
                break;

            case Help:
                if (patternValues.LegacyIAccessible.IsSupported && patternValues.LegacyIAccessible.Pattern.Help.IsSupported)
                {
                    properties.Add(new DesktopData(propertyName, patternValues.LegacyIAccessible.Pattern.Help));
                }
                break;
            }
        }