예제 #1
0
        private IUIAutomationElement GetElement(IUIAutomationElement current, IEnumerable <string> pathItems)
        {
            foreach (string pathItem in pathItems)
            {
                bool foundChild = false;
                for (
                    IUIAutomationElement child = UIAManager.CurrentTreeWalker.GetFirstChildElement(current);
                    child != null;
                    child = UIAManager.CurrentTreeWalker.GetNextSiblingElement(child))
                {
                    if (string.CompareOrdinal(
                            Converter.RuntimeIdToString(child.GetRuntimeId()),
                            pathItem) == 0)
                    {
                        foundChild = true;
                        current    = child;
                        break;
                    }
                }

                if (!foundChild)
                {
                    return(null);
                }
            }

            return(current);
        }
예제 #2
0
        private void GetDescendantItems(IUIAutomationElement element, string path)
        {
            IUIAutomationTreeWalker w = UIAManager.CurrentTreeWalker;

            Queue <Tuple <IUIAutomationElement, string> > q = new Queue <Tuple <IUIAutomationElement, string> >();

            q.Enqueue(Tuple.Create(element, path));

            while (q.Count > 0)
            {
                Tuple <IUIAutomationElement, string> t = q.Dequeue();

                for (IUIAutomationElement e = w.GetFirstChildElement(t.Item1); e != null; e = w.GetNextSiblingElement(e))
                {
                    string p = JoinPath(t.Item2, Converter.RuntimeIdToString(e.GetRuntimeId()));

                    WriteItemObject(
                        item: UIElement.Wrap(e, p),
                        path: p,
                        isContainer: true);

                    q.Enqueue(Tuple.Create(e, p));
                }
            }
        }
예제 #3
0
        void IUIAutomationEventHandler.HandleAutomationEvent(
            IUIAutomationElement sender, int eventId)
        {
            AutomationEventArgs args;

            if (eventId != WindowPatternIdentifiers.WindowClosedEvent.Id)
            {
                args = new AutomationEventArgs(AutomationEvent.LookupById(eventId));
            }
            else
            {
                args = new WindowClosedEventArgs((int[])sender.GetRuntimeId());
            }
            _basicHandler(AutomationElement.Wrap(sender), args);
        }
예제 #4
0
        public static string GetPath(IUIAutomationElement element)
        {
            Stack <string> ids = new Stack <string>();

            for (; element != null; element = UIAManager.CurrentTreeWalker.GetParentElement(element))
            {
                ids.Push(Converter.RuntimeIdToString(element.GetRuntimeId()));
            }

            // remove runtime id of root element (represented by drive letter)
            ids.Pop();

            StringBuilder path = new StringBuilder(UIDriveProvider.driveName);

            while (ids.Count > 0)
            {
                path.Append(UIDriveProvider.pathSeparator).Append(ids.Pop());
            }

            return(path.ToString());
        }
예제 #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="path"></param>
        /// <param name="returnContainers"></param>
        /// <remarks>
        /// Must be implemented (base method throws PSNotSupportedException).
        /// </remarks>
        /// <example>
        /// cd path_to_page
        /// ls *
        ///		GetChildNames(path: path_to_page, returnContainers: ReturnContainers.ReturnMatchingContainers)
        ///
        /// </example>
        protected override void GetChildNames(string path, ReturnContainers returnContainers)
        {
            // Find out under what conditions a different value is being passed
            Debug.Assert(returnContainers == ReturnContainers.ReturnMatchingContainers);

            INode node = this.GetNode(path);

            foreach (INode child in GetIdentifiableChildren(node))
            {
                IList <INode> grandChildren = GetIdentifiableChildren(child);

                WriteItemObject(
                    item: ((IIdentifiableObject)child).ID,
                    path: path,                     //  + pathSeparator + item,
                    isContainer: true);
            }

#if YELLOWBOX_BONEYARD
            IList <string> pathItems = SplitPath(path);

            IUIAutomationElement parent = GetElement(UIAManager.RootElement, pathItems);
            if (parent == null)
            {
                return;
            }

            for (
                IUIAutomationElement child = UIAManager.CurrentTreeWalker.GetFirstChildElement(parent);
                child != null;
                child = UIAManager.CurrentTreeWalker.GetNextSiblingElement(child))
            {
                string item = Converter.RuntimeIdToString(child.GetRuntimeId());

                WriteItemObject(
                    item: item,
                    path: path,                     //  + pathSeparator + item,
                    isContainer: true);
            }
#endif
        }
예제 #6
0
 public int[] GetRuntimeId()
 {
     return(IUIAutomationElement.GetRuntimeId().ToTypedArray <int>());
 }
예제 #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="path"></param>
        /// <param name="recurse"></param>
        /// <remarks>
        /// Instead of returning objects, this method needs to pass the respective
        /// objects to the 'WriteItemObject' method.
        /// It could be that the <paramref name="path"/> argument is prefixed with the
        /// current drive's 'root' path.
        /// This method is called with commands like "ls abc". However, a command like
        /// "ls *" will invoke the 'GetChildNames' instead.
        /// </remarks>
        /// <example>
        /// ls on:
        ///     GetChildItems(path: @"ON:\", recurse: false)
        ///
        ///     The drive name has been capitalized and a trailing path separator has been appended
        ///     even though it was not specified in the 'ls' command.
        ///
        /// ls "ON:\{3496EC60-2025-4F0E-93EB-3F832AB9702C}{1}{B0}"
        ///     GetChildItems(path: @"ON:\{3496EC60-2025-4F0E-93EB-3F832AB9702C}{1}{B0}", recurse: false)
        ///
        ///     Note the absence of a trailing path separator.
        ///
        /// </example>
        protected override void GetChildItems(string path, bool recurse)
        {
            INode node = this.GetNode(path);

            if (node == null)
            {
                return;
            }

            uint maxDepth = recurse ? uint.MaxValue : 1;

            path = path.EndsWith(DriveProvider.pathSeparator) ? path : path + DriveProvider.pathSeparator;
            var queue = new Queue <Tuple <INode /* node */, string /* path */, uint /* depth */> >();

            queue.Enqueue(new Tuple <INode, string, uint>(node, path, 0));

            while (queue.Count > 0)
            {
                Tuple <INode, string, uint> current = queue.Dequeue();

                foreach (INode child in GetIdentifiableChildren(current.Item1))
                {
                    string childPath  = current.Item2 + ((IIdentifiableObject)child).ID;
                    uint   childDepth = current.Item3 + 1;

                    IList <INode> grandChildren = GetIdentifiableChildren(child);

                    WriteItemObject(
                        item: child,
                        path: childPath,
                        isContainer: true);

                    if (childDepth < maxDepth && grandChildren.Count > 0)
                    {
                        queue.Enqueue(new Tuple <INode, string, uint>(child, childPath, childDepth));
                    }
                }
            }

#if YELLOWBOX_BONEYARD
            IList <string> pathItems = SplitPath(path);

            IUIAutomationElement parent = GetElement(UIAManager.RootElement, pathItems);
            if (parent == null)
            {
                return;
            }

            if (recurse)
            {
                GetDescendantItems(parent, path);
            }
            else
            {
                for (
                    IUIAutomationElement child = UIAManager.CurrentTreeWalker.GetFirstChildElement(parent);
                    child != null;
                    child = UIAManager.CurrentTreeWalker.GetNextSiblingElement(child))
                {
                    string childPath = JoinPath(path, Converter.RuntimeIdToString(child.GetRuntimeId()));

                    using (var restoreCurrentPath = new AutoRestorer <string>(oldPath => { currentPath = oldPath; }, currentPath, childPath))
                    {
                        WriteItemObject(
                            item: UIElement.Wrap(child, childPath),
                            path: childPath,
                            isContainer: true);
                    }
                }
            }
#endif
        }