예제 #1
0
 private AndCondition GetConditionsWithoutStar()
 {
     using (var automation = AutomationUtil.getAutomation())
     {
         var cond = new List <ConditionBase>();
         foreach (var p in Properties.Where(x => x.Enabled == true && (x.Value != null && !x.Value.Contains("*"))))
         {
             //if (p == "ControlType") cond.Add(element.ConditionFactory.ByControlType((ControlType)Enum.Parse(typeof(ControlType), ControlType)));
             //if (p == "Name") cond.Add(element.ConditionFactory.ByName(Name));
             //if (p == "ClassName") cond.Add(element.ConditionFactory.ByClassName(ClassName));
             //if (p == "AutomationId") cond.Add(element.ConditionFactory.ByAutomationId(AutomationId));
             if (p.Name == "ControlType")
             {
                 ControlType ct = (ControlType)Enum.Parse(typeof(ControlType), ControlType);
                 cond.Add(new PropertyCondition(automation.PropertyLibrary.Element.ControlType, ct));
             }
             if (p.Name == "Name")
             {
                 cond.Add(new PropertyCondition(automation.PropertyLibrary.Element.Name, Name));
             }
             if (p.Name == "ClassName")
             {
                 cond.Add(new PropertyCondition(automation.PropertyLibrary.Element.ClassName, ClassName));
             }
             if (p.Name == "AutomationId")
             {
                 cond.Add(new PropertyCondition(automation.PropertyLibrary.Element.AutomationId, AutomationId));
             }
         }
         return(new AndCondition(cond));
     }
 }
예제 #2
0
        public void RunClangCompile(int aCommandId)
        {
            if (mCommandsController.Running)
            {
                return;
            }

            mCommandsController.Running = true;

            var task = System.Threading.Tasks.Task.Run(() =>
            {
                try
                {
                    if (VsServiceProvider.TryGetService(typeof(DTE), out object dte))
                    {
                        DocumentsHandler.SaveActiveDocuments();
                        AutomationUtil.SaveDirtyProjects((dte as DTE2).Solution);
                    }

                    CollectSelectedItems(false, ScriptConstants.kAcceptedFileExtensions);
                    RunScript(aCommandId);
                }
                catch (Exception exception)
                {
                    VsShellUtilities.ShowMessageBox(AsyncPackage, exception.Message, "Error",
                                                    OLEMSGICON.OLEMSGICON_CRITICAL, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
                }
            }).ContinueWith(tsk => mCommandsController.OnAfterClangCommand());
        }
예제 #3
0
        private AndCondition GetConditions(string[] properties)
        {
            var automation = AutomationUtil.getAutomation();
            var cond       = new List <ConditionBase>();

            foreach (var p in properties)
            {
                //if (p == "ControlType") cond.Add(element.ConditionFactory.ByControlType((ControlType)Enum.Parse(typeof(ControlType), ControlType)));
                //if (p == "Name") cond.Add(element.ConditionFactory.ByName(Name));
                //if (p == "ClassName") cond.Add(element.ConditionFactory.ByClassName(ClassName));
                //if (p == "AutomationId") cond.Add(element.ConditionFactory.ByAutomationId(AutomationId));
                if (p == "ControlType")
                {
                    ControlType ct = (ControlType)Enum.Parse(typeof(ControlType), ControlType);
                    cond.Add(new PropertyCondition(automation.PropertyLibrary.Element.ControlType, ct));
                }
                if (p == "Name")
                {
                    cond.Add(new PropertyCondition(automation.PropertyLibrary.Element.Name, Name));
                }
                if (p == "AutomationId")
                {
                    cond.Add(new PropertyCondition(automation.PropertyLibrary.Element.AutomationId, AutomationId));
                }
                if (p == "ClassName")
                {
                    cond.Add(new PropertyCondition(automation.PropertyLibrary.Element.ClassName, ClassName));
                }
            }
            return(new AndCondition(cond));
        }
예제 #4
0
파일: Recording.cs 프로젝트: zwunix/openrpa
        public static Interfaces.Selector.treeelement[] GetRootElements()
        {
            var result       = new List <Interfaces.Selector.treeelement>();
            var automation   = AutomationUtil.getAutomation();
            var _rootElement = automation.GetDesktop();
            var _treeWalker  = automation.TreeWalkerFactory.GetControlViewWalker();
            //result.Add(new WindowsTreeElement(null, true, automation, _rootElement, _treeWalker));

            var elementNode = _treeWalker.GetFirstChild(_rootElement);

            while (elementNode != null)
            {
                result.Add(new WindowsTreeElement(null, false, automation, elementNode, _treeWalker));
                try
                {
                    Console.WriteLine("Adding " + elementNode.ToString());
                    elementNode = _treeWalker.GetNextSibling(elementNode);
                }
                catch (Exception)
                {
                    elementNode = null;
                }
            }
            return(result.ToArray());
        }
        public void Start()
        {
            var automation = AutomationUtil.getAutomation();

            desktop = automation.GetDesktop();
            StructureChangedEventHandler = desktop.RegisterStructureChangedEvent(FlaUI.Core.Definitions.TreeScope.Descendants, DetectorCheck);
        }
예제 #6
0
        public static treeelement[] _GetRootElements(Selector anchor)
        {
            if (CurrentProcessId == 0)
            {
                CurrentProcessId = Process.GetCurrentProcess().Id;
            }

            var result = new List <treeelement>();

            Task.Run(() =>
            {
                var automation   = AutomationUtil.getAutomation();
                var _rootElement = automation.GetDesktop();
                var _treeWalker  = automation.TreeWalkerFactory.GetControlViewWalker();
                if (anchor != null)
                {
                    if (!(anchor is WindowsSelector Windowsselector))
                    {
                        Windowsselector = new WindowsSelector(anchor.ToString());
                    }
                    var elements = WindowsSelector.GetElementsWithuiSelector(Windowsselector, null, 5, null);
                    if (elements.Count() > 0)
                    {
                        foreach (var elementNode in elements)
                        {
                            result.Add(new WindowsTreeElement(null, false, automation, elementNode.RawElement, _treeWalker));
                        }
                        //_rootElement = elements[0].RawElement;
                        return;
                    }
                }
                if (_rootElement != null)
                {
                    var elementNode = _treeWalker.GetFirstChild(_rootElement);
                    while (elementNode != null)
                    {
                        if (!elementNode.Properties.ProcessId.IsSupported)
                        {
                            result.Add(new WindowsTreeElement(null, false, automation, elementNode, _treeWalker));
                        }
                        else if (elementNode.Properties.ProcessId.ValueOrDefault != CurrentProcessId)
                        {
                            result.Add(new WindowsTreeElement(null, false, automation, elementNode, _treeWalker));
                        }

                        try
                        {
                            elementNode = _treeWalker.GetNextSibling(elementNode);
                        }
                        catch (Exception)
                        {
                            elementNode = null;
                        }
                    }
                }
            }).Wait(5000);
            return(result.ToArray());
        }
예제 #7
0
        public void RunClangTidy(int aCommandId)
        {
            if (mCommandsController.Running)
            {
                return;
            }

            mCommandsController.Running = true;

            var task = System.Threading.Tasks.Task.Run(() =>
            {
                try
                {
                    DocumentsHandler.SaveActiveDocuments();

                    if (!VsServiceProvider.TryGetService(typeof(DTE), out object dte))
                    {
                        return;
                    }

                    var dte2 = dte as DTE2;
                    AutomationUtil.SaveDirtyProjects(dte2.Solution);

                    CollectSelectedItems(false, ScriptConstants.kAcceptedFileExtensions);

                    using (var silentFileController = new SilentFileChangerController())
                    {
                        using (var fileChangerWatcher = new FileChangerWatcher())
                        {
                            var tidySettings = SettingsProvider.GetSettingsPage(typeof(ClangTidyOptionsView)) as ClangTidyOptionsView;

                            if (CommandIds.kTidyFixId == aCommandId || tidySettings.AutoTidyOnSave)
                            {
                                fileChangerWatcher.OnChanged += FileOpener.Open;

                                string solutionFolderPath = dte2.Solution.FullName
                                                            .Substring(0, dte2.Solution.FullName.LastIndexOf('\\'));

                                fileChangerWatcher.Run(solutionFolderPath);

                                FilePathCollector fileCollector = new FilePathCollector();
                                var filesPath = fileCollector.Collect(mItemsCollector.GetItems).ToList();

                                silentFileController.SilentFiles(filesPath);
                                silentFileController.SilentFiles(dte2.Documents);
                            }
                            RunScript(aCommandId);
                        }
                    }
                }
                catch (Exception exception)
                {
                    VsShellUtilities.ShowMessageBox(AsyncPackage, exception.Message, "Error",
                                                    OLEMSGICON.OLEMSGICON_CRITICAL, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
                }
            }).ContinueWith(tsk => DispatcherHandler.Invoke(() => mCommandsController.OnAfterClangCommand(), DispatcherPriority.Background));
        }
예제 #8
0
        public void EnumNeededProperties(AutomationElement element, AutomationElement parent)
        {
            string name = null;

            if (element.Properties.Name.IsSupported)
            {
                name = element.Properties.Name.Value;
            }
            var props        = GetProperties();
            int i            = props.Length - 1;
            int matchcounter = 0;
            var automation   = AutomationUtil.getAutomation();
            var cacheRequest = new CacheRequest();

            cacheRequest.TreeScope = FlaUI.Core.Definitions.TreeScope.Element | FlaUI.Core.Definitions.TreeScope.Subtree;
            //cacheRequest.TreeScope = FlaUI.Core.Definitions.TreeScope.Element;
            cacheRequest.AutomationElementMode = FlaUI.Core.Definitions.AutomationElementMode.None;
            cacheRequest.Add(automation.PropertyLibrary.Element.AutomationId);
            cacheRequest.Add(automation.PropertyLibrary.Element.ProcessId);
            cacheRequest.Add(automation.PropertyLibrary.Element.Name);
            cacheRequest.Add(automation.PropertyLibrary.Element.ClassName);
            cacheRequest.Add(automation.PropertyLibrary.Element.ControlType);
            using (cacheRequest.Activate())
            {
                do
                {
                    var selectedProps = props.Take(i).ToArray();
                    foreach (var p in Properties)
                    {
                        p.Enabled = selectedProps.Contains(p.Name);
                    }
                    var c = GetConditions(props.Take(i).ToArray());
                    matchcounter = parent.FindAllChildren(c).Count();
                    if (matchcounter > 1)
                    {
                        break;
                    }
                    if (matchcounter != 1)
                    {
                        Log.Selector("EnumNeededProperties match with " + i + " gave more than 1 result");
                        ++i;
                        if (i >= props.Count())
                        {
                            break;
                        }
                    }
                } while (matchcounter != 1 && i < props.Count());

                //Log.Selector("EnumNeededProperties match with " + i + " gave " + matchcounter + " result");
                Properties.ForEach((e) => e.Enabled = false);
                foreach (var p in props.Take(i).ToArray())
                {
                    Properties.Where(x => x.Name == p).First().Enabled = true;
                }
            }
        }
예제 #9
0
 public static UIElement GetFromFocusedElement()
 {
     using (var automation = AutomationUtil.getAutomation())
     {
         if (automation.FocusedElement() is AutomationElement rawElement)
         {
             return(new UIElement(rawElement));
         }
     }
     return(null);
 }
예제 #10
0
 public static UIElement GetFromPoint(int X, int Y)
 {
     try
     {
         using (var automation = AutomationUtil.getAutomation())
         {
             try
             {
                 if (automation.FromPoint(new System.Drawing.Point(X, Y)) is AutomationElement rawElement)
                 {
                     return(new UIElement(rawElement));
                 }
             }
             catch (Exception ex)
             {
                 Log.Error(ex.ToString());
             }
             try
             {
                 var task = Task.Run(() =>
                 {
                     if (automation.FromPoint(new System.Drawing.Point(X, Y)) is AutomationElement rawElement)
                     {
                         return(new UIElement(rawElement));
                     }
                     return(null);
                 });
                 if (task.Wait(TimeSpan.FromMilliseconds(200)))
                 {
                     return(task.Result);
                 }
                 else
                 {
                     return(null);
                 }
             }
             catch (Exception ex)
             {
                 Log.Error(ex.ToString());
             }
         }
     }
     catch (Exception ex)
     {
         Log.Error(ex.ToString());
     }
     return(null);
 }
 public void Start()
 {
     if (string.IsNullOrEmpty(Selector))
     {
         return;
     }
     if (!PluginConfig.enable_windows_detector)
     {
         return;
     }
     Task.Run(() =>
     {
         var automation = AutomationUtil.getAutomation();
         desktop        = automation.GetDesktop();
         StructureChangedEventHandler = desktop.RegisterStructureChangedEvent(FlaUI.Core.Definitions.TreeScope.Descendants, DetectorCheck);
     });
 }
예제 #12
0
 public void Initialize(IOpenRPAClient client, IWorkflow workflow, IWorkflowInstance instance)
 {
     automation = AutomationUtil.getAutomation();
     //cache = new CacheRequest();
     //cache.TreeScope = FlaUI.Core.Definitions.TreeScope.Element | FlaUI.Core.Definitions.TreeScope.Subtree | FlaUI.Core.Definitions.TreeScope.Parent;
     ////cacheRequest.TreeScope = FlaUI.Core.Definitions.TreeScope.Element;
     //cache.AutomationElementMode = FlaUI.Core.Definitions.AutomationElementMode.None;
     //cache.Add(automation.PropertyLibrary.Element.AutomationId);
     //cache.Add(automation.PropertyLibrary.Element.ProcessId);
     //cache.Add(automation.PropertyLibrary.Element.Name);
     //cache.Add(automation.PropertyLibrary.Element.ClassName);
     //cache.Add(automation.PropertyLibrary.Element.ControlType);
     //cache.Add(automation.PropertyLibrary.Element.LocalizedControlType);
     //cache.Add(automation.PropertyLibrary.Element.FrameworkId);
     //cache.Add(automation.PropertyLibrary.Element.BoundingRectangle);
     //cache.Add(automation.PropertyLibrary.Element.IsPassword);
     //// cache.Add(automation.PropertyLibrary.Element.Parent);
     //cacheObject = cache.Activate();
 }
예제 #13
0
파일: Plugin.cs 프로젝트: sanser/carbuy
        public IElement LaunchBySelector(Selector selector, bool CheckRunning, TimeSpan timeout)
        {
            var    first   = selector[0];
            var    second  = selector[1];
            var    p       = first.Properties.Where(x => x.Name == "browser").FirstOrDefault();
            string browser = "";

            if (p != null)
            {
                browser = p.Value;
            }

            p = first.Properties.Where(x => x.Name == "url").FirstOrDefault();
            string url = "";

            if (p != null)
            {
                url = p.Value;
            }

            NMHook.openurl(browser, url);
            if (browser == "chrome")
            {
                foreach (var process in System.Diagnostics.Process.GetProcesses())
                {
                    string pname = process.ProcessName.ToLower();
                    if (pname.Contains("chrome"))
                    {
                        string title = process.MainWindowTitle;
                        Console.WriteLine(title);
                        if (!string.IsNullOrEmpty(title))
                        {
                            var exists     = NMHook.tabs.Where(x => x.title == title).FirstOrDefault();
                            var automation = AutomationUtil.getAutomation();
                            var _ele       = automation.FromHandle(process.MainWindowHandle);
                            return(new UIElement(_ele));
                        }
                    }
                }
            }
            return(null);
        }
예제 #14
0
        public WindowsSelector(AutomationElement element, WindowsSelector anchor, bool doEnum)
        {
            var sw = new System.Diagnostics.Stopwatch();

            sw.Start();
            Log.Selector(string.Format("windowsselector::begin {0:mm\\:ss\\.fff}", sw.Elapsed));

            AutomationElement root        = null;
            AutomationElement baseElement = null;
            var pathToRoot = new List <AutomationElement>();

            while (element != null)
            {
                // Break on circular relationship (should not happen?)
                //if (pathToRoot.Contains(element) || element.Equals(_rootElement)) { break; }
                // if (pathToRoot.Contains(element)) { break; }
                try
                {
                    if (element.Parent != null)
                    {
                        pathToRoot.Add(element);
                    }
                    if (element.Parent == null)
                    {
                        root = element;
                    }
                }
                catch (Exception)
                {
                    root = element;
                }
                try
                {
                    //element = _treeWalker.GetParent(element);
                    element = element.Parent;
                }
                catch (Exception ex)
                {
                    Log.Error(ex, "");
                    return;
                }
            }
            Log.Selector(string.Format("windowsselector::create pathToRoot::end {0:mm\\:ss\\.fff}", sw.Elapsed));
            pathToRoot.Reverse();
            if (anchor != null)
            {
                //var anchorlist = anchor.Where(x => x.Enabled && x.Selector == null).ToList();
                //for (var i = 0; i < anchorlist.Count(); i++)
                //{
                //    if(WindowsSelectorItem.Match(anchorlist[i], pathToRoot[0]))
                //    //if (((WindowsSelectorItem)anchorlist[i]).Match(pathToRoot[0]))
                //    {
                //        pathToRoot.Remove(pathToRoot[0]);
                //    }
                //    else
                //    {
                //        Log.Selector("Element does not match the anchor path");
                //        return;
                //    }
                //}
                var a   = anchor.Last();
                var idx = -1;
                for (var i = 0; i < pathToRoot.Count(); i++)
                {
                    if (WindowsSelectorItem.Match(a, pathToRoot[i]))
                    {
                        idx = i;
                        break;
                    }
                }
                pathToRoot.RemoveRange(0, idx);
            }
            WindowsSelectorItem item;

            if (PluginConfig.traverse_selector_both_ways)
            {
                Log.Selector(string.Format("windowsselector::create traverse_selector_both_ways::begin {0:mm\\:ss\\.fff}", sw.Elapsed));
                var temppathToRoot = new List <AutomationElement>();
                var newpathToRoot  = new List <AutomationElement>();
                foreach (var e in pathToRoot)
                {
                    temppathToRoot.Add(e);
                }
                Log.Selector(string.Format("windowsselector::traverse back to element from root::begin {0:mm\\:ss\\.fff}", sw.Elapsed));
                using (var automation = AutomationUtil.getAutomation())
                {
                    bool isDesktop           = true;
                    AutomationElement parent = null;
                    if (anchor != null)
                    {
                        parent = temppathToRoot[0].Parent; isDesktop = false;
                    }
                    else
                    {
                        automation.GetDesktop();
                    }
                    int count = temppathToRoot.Count;
                    while (temppathToRoot.Count > 0)
                    {
                        count--;
                        var i = temppathToRoot.First();
                        temppathToRoot.Remove(i);
                        item = new WindowsSelectorItem(i, false);
                        var m = item.matches(root, count, parent, 2, isDesktop, false);
                        if (m.Length > 0)
                        {
                            newpathToRoot.Add(i);
                            parent    = i;
                            isDesktop = false;
                        }
                        if (m.Length == 0 && Config.local.log_selector)
                        {
                            //var message = "needed to find " + Environment.NewLine + item.ToString() + Environment.NewLine + "but found only: " + Environment.NewLine;
                            //var children = parent.FindAllChildren();
                            //foreach (var c in children)
                            //{
                            //    try
                            //    {
                            //        message += new UIElement(c).ToString() + Environment.NewLine;
                            //    }
                            //    catch (Exception)
                            //    {
                            //    }
                            //}
                            //Log.Debug(message);
                        }
                    }
                }
                if (newpathToRoot.Count != pathToRoot.Count)
                {
                    Log.Information("Selector had " + pathToRoot.Count + " items to root, but traversing children only matched " + newpathToRoot.Count);
                    pathToRoot = newpathToRoot;
                }
                Log.Selector(string.Format("windowsselector::create traverse_selector_both_ways::end {0:mm\\:ss\\.fff}", sw.Elapsed));
            }
            if (pathToRoot.Count == 0)
            {
                Log.Error("Element has not parent, or is same as annchor");
                return;
            }
            baseElement = pathToRoot.First();
            element     = pathToRoot.Last();
            Clear();
            Log.Selector(string.Format("windowsselector::remove anchor if needed::end {0:mm\\:ss\\.fff}", sw.Elapsed));
            if (anchor == null)
            {
                Log.Selector(string.Format("windowsselector::create root element::begin {0:mm\\:ss\\.fff}", sw.Elapsed));
                item         = new WindowsSelectorItem(baseElement, true);
                item.Enabled = true;
                //item.canDisable = false;
                Items.Add(item);
                Log.Selector(string.Format("windowsselector::create root element::end {0:mm\\:ss\\.fff}", sw.Elapsed));
            }

            if (PluginConfig.search_descendants)
            {
                Log.Selector(string.Format("windowsselector::search_descendants::begin {0:mm\\:ss\\.fff}", sw.Elapsed));
                if (anchor == null)
                {
                    // Add window, we NEED to search from a window
                    item = new WindowsSelectorItem(pathToRoot[0], false, -1);
                    if (doEnum)
                    {
                        item.EnumNeededProperties(pathToRoot[pathToRoot.Count - 1], pathToRoot[pathToRoot.Count - 1].Parent);
                    }
                    item.canDisable = false;
                    Items.Add(item);


                    var FrameworkId = item.Properties.Where(x => x.Name == "FrameworkId").FirstOrDefault();
                    if (FrameworkId != null && (FrameworkId.Value == "XAML" || FrameworkId.Value == "WinForm"))
                    {
                        var itemname = item.Properties.Where(x => x.Name == "Name").FirstOrDefault();
                        if (itemname != null)
                        {
                            itemname.Enabled = false;
                        }
                    }
                }
                if (pathToRoot.Count > 2)
                {
                    item = new WindowsSelectorItem(pathToRoot[pathToRoot.Count - 2], false, -1);
                    if (doEnum)
                    {
                        item.EnumNeededProperties(pathToRoot[pathToRoot.Count - 2], pathToRoot[pathToRoot.Count - 2].Parent);
                    }
                    Items.Add(item);
                }
                if (pathToRoot.Count > 1)
                {
                    int IndexInParent = -1;
                    if (pathToRoot[pathToRoot.Count - 1].Parent != null)
                    {
                        var c = pathToRoot[pathToRoot.Count - 1].Parent.FindAllChildren();
                        for (var x = 0; x < c.Count(); x++)
                        {
                            if (pathToRoot[pathToRoot.Count - 1].Equals(c[x]))
                            {
                                IndexInParent = x;
                            }
                        }
                    }
                    item = new WindowsSelectorItem(pathToRoot[pathToRoot.Count - 1], false, IndexInParent);
                    if (doEnum)
                    {
                        item.EnumNeededProperties(pathToRoot[pathToRoot.Count - 1], pathToRoot[pathToRoot.Count - 1].Parent);
                    }
                    Items.Add(item);
                }
                Log.Selector(string.Format("windowsselector::search_descendants::end {0:mm\\:ss\\.fff}", sw.Elapsed));
            }
            else
            {
                bool isStartmenu = false;
                for (var i = 0; i < pathToRoot.Count(); i++)
                {
                    Log.Selector(string.Format("windowsselector::search_descendants::loop element " + i + ":begin {0:mm\\:ss\\.fff}", sw.Elapsed));
                    var o             = pathToRoot[i];
                    int IndexInParent = -1;
                    if (o.Parent != null && i > 0)
                    {
                        var c = o.Parent.FindAllChildren();
                        for (var x = 0; x < c.Count(); x++)
                        {
                            if (o.Equals(c[x]))
                            {
                                IndexInParent = x;
                            }
                        }
                    }

                    item = new WindowsSelectorItem(o, false, IndexInParent);
                    var _IndexInParent = item.Properties.Where(x => x.Name == "IndexInParent").FirstOrDefault();
                    if (_IndexInParent != null)
                    {
                        _IndexInParent.Enabled = false;
                    }
                    if (i == 0 || i == (pathToRoot.Count() - 1))
                    {
                        item.canDisable = false;
                    }
                    foreach (var p in item.Properties)
                    {
                        int idx = p.Value.IndexOf(".");
                        if (p.Name == "ClassName" && idx > -1)
                        {
                            var FrameworkId = item.Properties.Where(x => x.Name == "FrameworkId").FirstOrDefault();
                            //if (FrameworkId!=null && (FrameworkId.Value == "XAML" || FrameworkId.Value == "WinForm") && _IndexInParent != null)
                            //{
                            //    item.Properties.ForEach(x => x.Enabled = false);
                            //    _IndexInParent.Enabled = true;
                            //    p.Enabled = true;
                            //}
                            int idx2 = p.Value.IndexOf(".", idx + 1);
                            // if (idx2 > idx) p.Value = p.Value.Substring(0, idx2 + 1) + "*";
                            if (idx2 > idx && item.Properties.Count > 1)
                            {
                                p.Enabled = false;
                            }
                        }
                        //if (p.Name == "ClassName" && p.Value.StartsWith("WindowsForms10")) p.Value = "WindowsForms10*";
                        if (p.Name == "ClassName" && p.Value.ToLower() == "shelldll_defview")
                        {
                            item.Enabled = false;
                        }
                        if (p.Name == "ClassName" && (p.Value.ToLower() == "dv2vontrolhost" || p.Value.ToLower() == "desktopprogramsmfu"))
                        {
                            isStartmenu = true;
                        }
                        //if (p.Name == "ClassName" && p.Value == "#32770")
                        //{
                        //    item.Enabled = false;
                        //}
                        if (p.Name == "ControlType" && p.Value == "ListItem" && isStartmenu)
                        {
                            p.Enabled = false;
                        }
                    }
                    var hassyslistview32 = item.Properties.Where(p => p.Name == "ClassName" && p.Value.ToLower() == "syslistview32").ToList();
                    if (hassyslistview32.Count > 0)
                    {
                        var hasControlType = item.Properties.Where(p => p.Name == "ControlType").ToList();
                        if (hasControlType.Count > 0)
                        {
                            hasControlType[0].Enabled = false;
                        }
                    }

                    if (doEnum)
                    {
                        item.EnumNeededProperties(o, o.Parent);
                    }
                    Items.Add(item);
                    Log.Selector(string.Format("windowsselector::search_descendants::loop element " + i + ":end {0:mm\\:ss\\.fff}", sw.Elapsed));
                }
            }
            pathToRoot.Reverse();
            if (anchor != null)
            {
                var p = Items[0].Properties.Where(x => x.Name == "SearchDescendants").FirstOrDefault();
                if (p == null)
                {
                    Items[0].Properties.Add(new SelectorItemProperty("SearchDescendants", PluginConfig.search_descendants.ToString()));
                }
            }
            Log.Selector(string.Format("windowsselector::end {0:mm\\:ss\\.fff}", sw.Elapsed));
            OnPropertyChanged(new System.ComponentModel.PropertyChangedEventArgs("Count"));
            OnPropertyChanged(new System.ComponentModel.PropertyChangedEventArgs("Item[]"));
            OnCollectionChanged(new System.Collections.Specialized.NotifyCollectionChangedEventArgs(System.Collections.Specialized.NotifyCollectionChangedAction.Reset));
        }
예제 #15
0
        public static UIElement[] GetElementsWithuiSelector(WindowsSelector selector, IElement fromElement, int maxresults, WindowsCacheExtension ext)
        {
            TimeSpan timeout = TimeSpan.FromMilliseconds(5000);

            timeout = TimeSpan.FromMilliseconds(20000);
            var sw = new System.Diagnostics.Stopwatch();

            sw.Start();
            Log.Selector(string.Format("GetElementsWithuiSelector::begin {0:mm\\:ss\\.fff}", sw.Elapsed));

            UIElement _fromElement = fromElement as UIElement;
            // var selectors = selector.Where(x => x.Enabled == true && x.Selector == null).ToList();
            var selectors = selector.ToList();
            AutomationElement startfrom = null;

            if (_fromElement != null)
            {
                startfrom = _fromElement.RawElement;
            }


            var _current = new List <UIElement>();
            // var automation = AutomationUtil.getAutomation();
            AutomationBase automation = null;

            if (ext != null)
            {
                automation = ext.automation;
            }
            if (automation == null)
            {
                automation = AutomationUtil.getAutomation();
            }

            UIElement[] result = null;
            // AutomationElement ele = null;

            bool search_descendants = PluginConfig.search_descendants;
            var  v = selectors[0].Properties.Where(x => x.Name == "search_descendants").FirstOrDefault();

            if (v == null)
            {
                selectors[0].Properties.Where(x => x.Name == "SearchDescendants").FirstOrDefault();
            }
            if (v != null)
            {
                search_descendants = bool.Parse(v.Value);
            }

            if (startfrom == null)
            {
                startfrom = automation.GetDesktop();
            }
            _current.Add(new UIElement(startfrom));
            for (var i = 0; i < selectors.Count; i++)
            {
                var _sel    = selectors[i];
                var sel     = new WindowsSelectorItem(_sel);
                var current = _current.ToArray();
                _current.Clear();
                // if(i == 1 && current.Length == 1 && current.First().ControlType == sel.ControlType)
                if (i == 1)
                {
                    foreach (var e in current)
                    {
                        if (WindowsSelectorItem.Match(sel, e.RawElement))
                        {
                            _current.Add(e);
                        }
                    }
                    if (_current.Count > 0)
                    {
                        continue;
                    }
                    //_current = GetElementsWithuiSelectorItem(automation, sel, current, maxresults, i == (selectors.Count - 1)).ToList();
                    //if(_current.Count == 0) _current = current.ToList();
                    //_current = current.ToList();
                }
                _current = GetElementsWithuiSelectorItem(i, automation, sel, current, maxresults, i == (selectors.Count - 1), search_descendants).ToList();
                if (i == 0 && _current.Count == 0)
                {
                    _current = current.ToList();
                }
            }
            Log.Debug(string.Format("GetElementsWithuiSelector::completed with " + _current.Count + " results {0:mm\\:ss\\.fff}", sw.Elapsed));
            if (_current.Count > 0)
            {
                result = _current.ToArray();
                if (result.Count() > maxresults)
                {
                    Console.WriteLine("found " + result.Count() + " but only needed " + maxresults);
                    result = result.Take(maxresults).ToArray();
                }
                return(result);
            }
            if (result == null)
            {
                Log.Selector(string.Format("GetElementsWithuiSelector::ended with 0 results after {0:mm\\:ss\\.fff}", sw.Elapsed));
                return(new UIElement[] { });
            }
            if (result.Count() > maxresults)
            {
                result = result.Take(maxresults).ToArray();
            }
            Log.Selector(string.Format("GetElementsWithuiSelector::ended with " + result.Length + " results after {0:mm\\:ss\\.fff}", sw.Elapsed));
            return(result);
        }
예제 #16
0
        private void Open_Selector(object sender, RoutedEventArgs e)
        {
            string SelectorString = ModelItem.GetValue <string>("Selector");
            int    maxresult      = 1;

            if (string.IsNullOrEmpty(SelectorString))
            {
                SelectorString = "[{Selector: 'Windows'}]";
            }
            var selector   = new Interfaces.Selector.Selector(SelectorString);
            var pluginname = selector.First().Selector;
            var selectors  = new Interfaces.Selector.SelectorWindow(pluginname, selector, maxresult);

            if (selectors.ShowDialog() == true)
            {
                ModelItem.Properties["Selector"].SetValue(new InArgument <string>()
                {
                    Expression = new Literal <string>(selectors.vm.json)
                });
                var Plugin = Interfaces.Plugins.recordPlugins.Where(x => x.Name == pluginname).First();
                var _base  = Plugin.GetElementsWithSelector(selector, null, 10);
                if (_base == null || _base.Length == 0)
                {
                    return;
                }
                var ele = _base[0];
                if (ele != null && !(ele is UIElement))
                {
                    var automation = AutomationUtil.getAutomation();
                    var p          = new System.Drawing.Point(ele.Rectangle.X + 10, ele.Rectangle.Y + 10);
                    if (p.X > 0 && p.Y > 0)
                    {
                        var _temp = automation.FromPoint(p);
                        if (_temp != null)
                        {
                            ele = new UIElement(_temp);
                        }
                    }
                }
                if (ele is UIElement ui)
                {
                    var window = ui.GetWindow();
                    if (window == null)
                    {
                        return;
                    }
                    if (!string.IsNullOrEmpty(window.Name))
                    {
                        ModelItem.Properties["DisplayName"].SetValue(window.Name);
                    }
                    if (window.Properties.BoundingRectangle.IsSupported)
                    {
                        var bound = window.BoundingRectangle;
                        ModelItem.Properties["X"].SetValue(new InArgument <int>()
                        {
                            Expression = new Literal <int>(bound.X)
                        });
                        ModelItem.Properties["Y"].SetValue(new InArgument <int>()
                        {
                            Expression = new Literal <int>(bound.Y)
                        });
                        ModelItem.Properties["Width"].SetValue(new InArgument <int>()
                        {
                            Expression = new Literal <int>(bound.Width)
                        });
                        ModelItem.Properties["Height"].SetValue(new InArgument <int>()
                        {
                            Expression = new Literal <int>(bound.Height)
                        });
                    }
                }
            }
        }
예제 #17
0
        public void OnUserAction(Interfaces.IRecordPlugin sender, Interfaces.IRecordEvent e)
        {
            StopRecordPlugins();
            AutomationHelper.syncContext.Post(o =>
            {
                Interfaces.GenericTools.Restore();
                foreach (var p in Interfaces.Plugins.recordPlugins)
                {
                    if (p.Name != sender.Name)
                    {
                        if (p.ParseUserAction(ref e))
                        {
                            continue;
                        }
                    }
                }
                e.Selector.RemoveRange(2, e.Selector.Count - 2);
                ModelItem.Properties["Selector"].SetValue(new InArgument <string>()
                {
                    Expression = new Literal <string>(e.Selector.ToString())
                });
                var ele = e.Element;
                if (ele != null && !(ele is UIElement))
                {
                    var automation = AutomationUtil.getAutomation();
                    var p          = new System.Drawing.Point(ele.Rectangle.X + 10, ele.Rectangle.Y + 10);
                    if (p.X > 0 && p.Y > 0)
                    {
                        var _temp = automation.FromPoint(p);
                        if (_temp != null)
                        {
                            ele = new UIElement(_temp);
                        }
                    }
                }

                if (ele is UIElement ui)
                {
                    var window = ui.GetWindow();
                    if (window == null)
                    {
                        return;
                    }
                    if (!string.IsNullOrEmpty(window.Name))
                    {
                        ModelItem.Properties["DisplayName"].SetValue(window.Name);
                    }
                    if (window.Properties.BoundingRectangle.IsSupported)
                    {
                        var bound = window.BoundingRectangle;
                        ModelItem.Properties["X"].SetValue(new InArgument <int>()
                        {
                            Expression = new Literal <int>(bound.X)
                        });
                        ModelItem.Properties["Y"].SetValue(new InArgument <int>()
                        {
                            Expression = new Literal <int>(bound.Y)
                        });
                        ModelItem.Properties["Width"].SetValue(new InArgument <int>()
                        {
                            Expression = new Literal <int>(bound.Width)
                        });
                        ModelItem.Properties["Height"].SetValue(new InArgument <int>()
                        {
                            Expression = new Literal <int>(bound.Height)
                        });
                    }
                }
            }, null);
        }
예제 #18
0
        public static UIElement[] GetElementsWithuiSelector(WindowsSelector selector, IElement fromElement = null, int maxresults = 1)
        {
            var sw = new System.Diagnostics.Stopwatch();

            sw.Start();
            Log.Selector(string.Format("GetElementsWithuiSelector::begin {0:mm\\:ss\\.fff}", sw.Elapsed));

            UIElement _fromElement = fromElement as UIElement;
            var       selectors    = selector.Where(x => x.Enabled == true && x.Selector == null).ToList();

            var current    = new List <UIElement>();
            var automation = AutomationUtil.getAutomation();

            UIElement[] result = null;
            using (automation)
            {
                var _treeWalker             = automation.TreeWalkerFactory.GetControlViewWalker();
                AutomationElement startfrom = null;
                if (_fromElement != null)
                {
                    startfrom = _fromElement.RawElement;
                }
                Log.Selector("automation.GetDesktop");
                if (startfrom == null)
                {
                    startfrom = automation.GetDesktop();
                }

                current.Add(new UIElement(startfrom));
                for (var i = 0; i < selectors.Count; i++)
                {
                    var s        = new WindowsSelectorItem(selectors[i]);
                    var elements = new List <UIElement>();
                    elements.AddRange(current);
                    current.Clear();
                    int failcounter = 0;
                    do
                    {
                        foreach (var _element in elements)
                        {
                            var matches   = ((WindowsSelectorItem)s).matches(automation, _element.RawElement, _treeWalker, (i == 0 ? 1: maxresults));
                            var uimatches = new List <UIElement>();
                            foreach (var m in matches)
                            {
                                var ui   = new UIElement(m);
                                var list = selectors.Take(i).ToList();
                                list.Add(new WindowsSelectorItem(m, false));
                                uimatches.Add(ui);
                            }
                            current.AddRange(uimatches.ToArray());
                        }
                        if (current.Count == 0)
                        {
                            ++failcounter;
                            foreach (var element in elements)
                            {
                                var message  = "needed to find " + Environment.NewLine + selectors[i].ToString() + Environment.NewLine + "but found only: " + Environment.NewLine;
                                var children = element.RawElement.FindAllChildren();
                                foreach (var c in children)
                                {
                                    try
                                    {
                                        message += new UIElement(c).ToString() + Environment.NewLine;
                                    }
                                    catch (Exception)
                                    {
                                    }
                                }
                                Log.Selector(message);
                            }
                        }
                        else
                        {
                            Log.Selector(string.Format("Found " + current.Count + " hits for selector # " + i + " {0:mm\\:ss\\.fff}", sw.Elapsed));
                        }
                    } while (failcounter < 2 && current.Count == 0);

                    if (i == (selectors.Count - 1))
                    {
                        result = current.ToArray();
                    }
                    if (current.Count == 0)
                    {
                        var message = "needed to find " + Environment.NewLine + selectors[i].ToString() + Environment.NewLine + "but found only: " + Environment.NewLine;
                        foreach (var element in elements)
                        {
                            var children = element.RawElement.FindAllChildren();
                            foreach (var c in children)
                            {
                                try
                                {
                                    message += new UIElement(c).ToString() + Environment.NewLine;
                                }
                                catch (Exception)
                                {
                                }
                            }
                        }
                        Log.Warning(message);
                        return(new UIElement[] { });
                    }
                }
            }
            if (result == null)
            {
                Log.Selector(string.Format("GetElementsWithuiSelector::ended with 0 results after {0:mm\\:ss\\.fff}", sw.Elapsed));
                return(new UIElement[] { });
            }
            Log.Selector(string.Format("GetElementsWithuiSelector::ended with " + result.Count() + " results after {0:mm\\:ss\\.fff}", sw.Elapsed));
            return(result);
        }
예제 #19
0
        private void Open_Selector(object sender, RoutedEventArgs e)
        {
            string SelectorString = ModelItem.GetValue <string>("Selector");
            int    maxresult      = 1;

            if (string.IsNullOrEmpty(SelectorString))
            {
                SelectorString = "[{Selector: 'Windows'}]";
            }
            var selector   = new Interfaces.Selector.Selector(SelectorString);
            var pluginname = selector.First().Selector;
            var selectors  = new Interfaces.Selector.SelectorWindow(pluginname, selector, maxresult);

            // selectors.Owner = GenericTools.MainWindow;  -- Locks up and never returns ?
            if (selectors.ShowDialog() == true)
            {
                ModelItem.Properties["Selector"].SetValue(new InArgument <string>()
                {
                    Expression = new Literal <string>(selectors.vm.json)
                });
                var Plugin = Interfaces.Plugins.recordPlugins.Where(x => x.Name == pluginname).First();
                var _base  = Plugin.GetElementsWithSelector(selector, null, 10);
                if (_base == null || _base.Length == 0)
                {
                    return;
                }
                var ele = _base[0];
                if (ele != null && !(ele is UIElement))
                {
                    var automation = AutomationUtil.getAutomation();
                    var p          = new System.Drawing.Point(ele.Rectangle.X + 10, ele.Rectangle.Y + 10);
                    if (p.X > 0 && p.Y > 0)
                    {
                        var _temp = automation.FromPoint(p);
                        if (_temp != null)
                        {
                            ele = new UIElement(_temp);
                        }
                    }
                }
                if (ele is UIElement ui)
                {
                    var window = ui.GetWindow();
                    if (window == null)
                    {
                        return;
                    }
                    if (!string.IsNullOrEmpty(window.Name))
                    {
                        ModelItem.Properties["DisplayName"].SetValue(window.Name);
                    }
                    if (window.Properties.BoundingRectangle.IsSupported)
                    {
                        var bound      = window.BoundingRectangle;
                        var newbound   = new System.Drawing.Rectangle(bound.X, bound.Y, bound.Width, bound.Height);
                        var p          = new System.Drawing.Point(bound.X, bound.Y);
                        var allScreens = System.Windows.Forms.Screen.AllScreens.ToList();
                        int screen     = 0;
                        for (var i = 0; i < allScreens.Count; i++)
                        {
                            var work = allScreens[i].WorkingArea;
                            if (work.Contains(bound) || allScreens[i].WorkingArea.Contains(p))
                            {
                                screen     = i;
                                newbound.X = newbound.X - work.X;
                                newbound.Y = newbound.Y - work.Y;
                                break;
                            }
                        }
                        ModelItem.Properties["Screen"].SetValue(new InArgument <int>()
                        {
                            Expression = new Literal <int>(screen)
                        });
                        ModelItem.Properties["X"].SetValue(new InArgument <int>()
                        {
                            Expression = new Literal <int>(newbound.X)
                        });
                        ModelItem.Properties["Y"].SetValue(new InArgument <int>()
                        {
                            Expression = new Literal <int>(newbound.Y)
                        });
                        ModelItem.Properties["Width"].SetValue(new InArgument <int>()
                        {
                            Expression = new Literal <int>(newbound.Width)
                        });
                        ModelItem.Properties["Height"].SetValue(new InArgument <int>()
                        {
                            Expression = new Literal <int>(newbound.Height)
                        });
                    }
                }
            }
        }
예제 #20
0
        public static UIElement[] GetElementsWithuiSelector(WindowsSelector selector, IElement fromElement = null, int maxresults = 1)
        {
            TimeSpan timeout = TimeSpan.FromMilliseconds(1000);

            timeout = TimeSpan.FromMilliseconds(20000);
            var midcounter = 1;

            if (PluginConfig.allow_multiple_hits_mid_selector)
            {
                midcounter = 10;
            }
            var sw = new System.Diagnostics.Stopwatch();

            sw.Start();
            Log.Selector(string.Format("GetElementsWithuiSelector::begin {0:mm\\:ss\\.fff}", sw.Elapsed));

            UIElement _fromElement = fromElement as UIElement;
            var       selectors    = selector.Where(x => x.Enabled == true && x.Selector == null).ToList();

            var current    = new List <UIElement>();
            var automation = AutomationUtil.getAutomation();

            var search_descendants = false;
            var p = selector[0].Properties.Where(x => x.Name == "SearchDescendants").FirstOrDefault();

            if (p != null)
            {
                search_descendants = bool.Parse(p.Value);
            }


            UIElement[] result = null;
            using (automation)
            {
                var _treeWalker             = automation.TreeWalkerFactory.GetControlViewWalker();
                AutomationElement startfrom = null;
                if (_fromElement != null)
                {
                    startfrom = _fromElement.RawElement;
                }
                Log.SelectorVerbose("automation.GetDesktop");
                bool isDesktop = false;
                if (startfrom == null)
                {
                    startfrom = automation.GetDesktop();
                    isDesktop = true;
                }
                current.Add(new UIElement(startfrom));
                for (var i = 0; i < selectors.Count; i++)
                {
                    var s        = new WindowsSelectorItem(selectors[i]);
                    var elements = new List <UIElement>();
                    elements.AddRange(current);
                    current.Clear();
                    foreach (var _element in elements)
                    {
                        var count = maxresults;
                        //if (i == 0) count = midcounter;
                        //// if (i < selectors.Count) count = 500;
                        //if ((i + 1) < selectors.Count) count = 1;
                        if (i < selectors.Count)
                        {
                            count = 500;
                        }
                        var matches   = (s).matches(startfrom, i, _element.RawElement, count, isDesktop, search_descendants); // (i == 0 ? 1: maxresults)
                        var uimatches = new List <UIElement>();
                        foreach (var m in matches)
                        {
                            var ui = new UIElement(m);
                            uimatches.Add(ui);
                        }
                        current.AddRange(uimatches.ToArray());
                        if (sw.Elapsed > timeout)
                        {
                            Log.Selector(string.Format("GetElementsWithuiSelector::timed out {0:mm\\:ss\\.fff}", sw.Elapsed));
                            return(new UIElement[] { });
                        }
                    }
                    if (current.Count > 1)
                    {
                        //if (i < selectors.Count && maxresults == 1)
                        //{
                        //    Log.Warning("Selector had " + current.Count + " hits and not just one, at element " + i + " this selector will be slow!");
                        //}
                    }
                    if (i == (selectors.Count - 1))
                    {
                        result = current.ToArray();
                    }
                    isDesktop = false;
                    Log.Selector(string.Format("Found " + current.Count + " hits for selector # " + i + " {0:mm\\:ss\\.fff}", sw.Elapsed));
                }
            }
            if (result == null)
            {
                Log.Selector(string.Format("GetElementsWithuiSelector::ended with 0 results after {0:mm\\:ss\\.fff}", sw.Elapsed));
                return(new UIElement[] { });
            }
            Log.Selector(string.Format("GetElementsWithuiSelector::ended with " + result.Length + " results after {0:mm\\:ss\\.fff}", sw.Elapsed));
            return(result);
        }
예제 #21
0
        public static UIElement[] GetElementsWithuiSelector(WindowsSelector selector, IElement fromElement, int maxresults, WindowsCacheExtension ext)
        {
            TimeSpan timeout = TimeSpan.FromMilliseconds(5000);

            timeout = TimeSpan.FromMilliseconds(20000);
            var sw = new System.Diagnostics.Stopwatch();

            sw.Start();
            Log.Selector(string.Format("GetElementsWithuiSelector::begin {0:mm\\:ss\\.fff}", sw.Elapsed));

            UIElement _fromElement = fromElement as UIElement;
            // var selectors = selector.Where(x => x.Enabled == true && x.Selector == null).ToList();
            var selectors = selector.ToList();
            AutomationElement startfrom = null;

            if (_fromElement != null)
            {
                startfrom = _fromElement.RawElement;
            }


            var _current = new List <UIElement>();
            // var automation = AutomationUtil.getAutomation();
            AutomationBase automation = null;

            if (ext != null)
            {
                automation = ext.automation;
            }
            if (automation == null)
            {
                automation = AutomationUtil.getAutomation();
            }

            UIElement[] result = null;
            // AutomationElement ele = null;

            bool search_descendants = selectors[0].SearchDescendants();

            if (startfrom == null)
            {
                startfrom = automation.GetDesktop();
            }
            _current.Add(new UIElement(startfrom));
            for (var i = 0; i < selectors.Count; i++)
            {
                var _sel    = selectors[i];
                var sel     = new WindowsSelectorItem(_sel);
                var current = _current.ToArray();
                _current.Clear();
                // if(i == 1 && current.Length == 1 && current.First().ControlType == sel.ControlType)
                if (i == 1)
                {
                    foreach (var e in current)
                    {
                        if (WindowsSelectorItem.Match(sel, e.RawElement))
                        {
                            _current.Add(e);
                        }
                    }
                    if (_current.Count > 0)
                    {
                        continue;
                    }
                    //_current = GetElementsWithuiSelectorItem(automation, sel, current, maxresults, i == (selectors.Count - 1)).ToList();
                    //if(_current.Count == 0) _current = current.ToList();
                    //_current = current.ToList();
                }
                _current = GetElementsWithuiSelectorItem(i, automation, sel, current, maxresults, i == (selectors.Count - 1), search_descendants).ToList();
                if (i == 0 && _current.Count == 0)
                {
                    _current = current.ToList();
                }
                else if (i > 0 && _current.Count == 0 && current.Length > 0 && (PluginConfig.try_mouse_over_search || selector.mouse_over_search()))
                {
                    for (var z = 0; z < current.Length; z++)
                    {
                        current[z].Focus();
                        var x = current[z].Rectangle.X + 5; var y = current[z].Rectangle.Y + 5;
                        var screen = automation.FromPoint(new System.Drawing.Point(x, y));
                        Log.Selector("mouse point lookup at " + x + "," + y + " for " + sel.ToString());
                        var screenel = screen.Parent;
                        while (screenel != null)
                        {
                            var uiscreenel = new UIElement(screenel);

                            if (WindowsSelectorItem.Match(sel, screenel))
                            {
                                _current.Clear();
                                _current.Add(new UIElement(screenel));
                                Log.Selector("Mouse lookup found " + uiscreenel.ToString());
                                break;
                            }
                            else
                            {
                                screenel = screenel.Parent;
                            }
                            // only allow direct parents, or search for match in all child elements found ? ( like searching for a button inside a pane )
                            //else
                            //{
                            //    Log.Output("Lookup in " + uiscreenel.ToString());
                            //    _current = GetElementsWithuiSelectorItem(i, automation, sel, new UIElement[] { uiscreenel }, maxresults, i == (selectors.Count - 1), search_descendants).ToList();
                            //    if (_current.Count != 0) break;
                            //    screenel = screenel.Parent;
                            //}
                        }
                        if (_current.Count > 0)
                        {
                            break;
                        }
                    }
                }
            }
            Log.Debug(string.Format("GetElementsWithuiSelector::completed with " + _current.Count + " results {0:mm\\:ss\\.fff}", sw.Elapsed));
            if (_current.Count > 0)
            {
                result = _current.ToArray();
                if (result.Count() > maxresults)
                {
                    Console.WriteLine("found " + result.Count() + " but only needed " + maxresults);
                    result = result.Take(maxresults).ToArray();
                }
                return(result);
            }
            if (result == null)
            {
                Log.Selector(string.Format("GetElementsWithuiSelector::ended with 0 results after {0:mm\\:ss\\.fff}", sw.Elapsed));
                return(new UIElement[] { });
            }
            if (result.Count() > maxresults)
            {
                result = result.Take(maxresults).ToArray();
            }
            Log.Selector(string.Format("GetElementsWithuiSelector::ended with " + result.Length + " results after {0:mm\\:ss\\.fff}", sw.Elapsed));
            return(result);
        }
예제 #22
0
        public static UIElement[] GetElementsWithuiSelector(WindowsSelector selector, IElement fromElement = null, int maxresults = 1)
        {
            TimeSpan timeout = TimeSpan.FromMilliseconds(5000);

            timeout = TimeSpan.FromMilliseconds(20000);
            var midcounter = 1;

            if (PluginConfig.allow_multiple_hits_mid_selector)
            {
                midcounter = 10;
            }
            var sw = new System.Diagnostics.Stopwatch();

            sw.Start();
            Log.Selector(string.Format("GetElementsWithuiSelector::begin {0:mm\\:ss\\.fff}", sw.Elapsed));

            UIElement _fromElement = fromElement as UIElement;
            var       selectors    = selector.Where(x => x.Enabled == true && x.Selector == null).ToList();

            var current    = new List <UIElement>();
            var automation = AutomationUtil.getAutomation();

            var search_descendants = false;
            var p = selector[0].Properties.Where(x => x.Name == "SearchDescendants").FirstOrDefault();

            if (p != null)
            {
                search_descendants = bool.Parse(p.Value);
            }


            UIElement[] result = null;
            using (automation)
            {
                var _treeWalker             = automation.TreeWalkerFactory.GetControlViewWalker();
                AutomationElement startfrom = null;
                if (_fromElement != null)
                {
                    startfrom = _fromElement.RawElement;
                }
                Log.SelectorVerbose("automation.GetDesktop");
                bool isDesktop = false;
                if (startfrom == null)
                {
                    startfrom = automation.GetDesktop();
                    isDesktop = true;
                }
                current.Add(new UIElement(startfrom));
                for (var i = 0; i < selectors.Count; i++)
                {
                    var s        = new WindowsSelectorItem(selectors[i]);
                    var elements = new List <UIElement>();
                    elements.AddRange(current);
                    current.Clear();
                    int count = 0;
                    foreach (var _element in elements)
                    {
                        count = maxresults;
                        //if (i == 0) count = midcounter;
                        //// if (i < selectors.Count) count = 500;
                        //if ((i + 1) < selectors.Count) count = 1;
                        if (i < (selectors.Count - 1))
                        {
                            count = 500;
                        }
                        var matches   = (s).matches(startfrom, i, _element.RawElement, count, isDesktop, search_descendants); // (i == 0 ? 1: maxresults)
                        var uimatches = new List <UIElement>();
                        foreach (var m in matches)
                        {
                            var ui = new UIElement(m);
                            uimatches.Add(ui);
                        }
                        current.AddRange(uimatches.ToArray());
                        if (sw.Elapsed > timeout)
                        {
                            Log.Selector(string.Format("GetElementsWithuiSelector::timed out {0:mm\\:ss\\.fff}", sw.Elapsed));
                            return(new UIElement[] { });
                        }
                    }
                    if (i == (selectors.Count - 1))
                    {
                        result = current.ToArray();
                    }
                    Log.Selector(string.Format("Found " + current.Count + " hits for selector # " + i + " {0:mm\\:ss\\.fff}", sw.Elapsed));
                    if (i > 0 && elements.Count > 0 && current.Count == 0)
                    {
                        //var message = "needed to find " + Environment.NewLine + selectors[i].ToString() + Environment.NewLine + "but found only: " + Environment.NewLine;
                        //var children = elements[0].RawElement.FindAllChildren();
                        //foreach (var c in children)
                        //{
                        //    try
                        //    {
                        //        message += new UIElement(c).ToString() + Environment.NewLine;
                        //    }
                        //    catch (Exception)
                        //    {
                        //    }
                        //}
                        //Log.Selector(message);
                    }
                    if (i == 0 && isDesktop && current.Count > 0)
                    {
                        if (current[0].RawElement.Patterns.Window.TryGetPattern(out var winPattern))
                        {
                            if (winPattern.WindowVisualState.Value == FlaUI.Core.Definitions.WindowVisualState.Minimized)
                            {
                                IntPtr handle = current[0].RawElement.Properties.NativeWindowHandle.Value;
                                winPattern.SetWindowVisualState(FlaUI.Core.Definitions.WindowVisualState.Normal);
                            }
                        }
                    }
                    isDesktop = false;
                }
            }
            if (result == null)
            {
                Log.Selector(string.Format("GetElementsWithuiSelector::ended with 0 results after {0:mm\\:ss\\.fff}", sw.Elapsed));
                return(new UIElement[] { });
            }
            if (result.Count() > maxresults)
            {
                result = result.Take(maxresults).ToArray();
            }
            Log.Selector(string.Format("GetElementsWithuiSelector::ended with " + result.Length + " results after {0:mm\\:ss\\.fff}", sw.Elapsed));
            return(result);
        }
예제 #23
0
        public static UIElement[] GetElementsWithuiSelector(WindowsSelector selector, IElement fromElement = null, int maxresults = 1)
        {
            var midcounter = 1;

            if (PluginConfig.allow_multiple_hits_mid_selector)
            {
                midcounter = 10;
            }
            var sw = new System.Diagnostics.Stopwatch();

            sw.Start();
            Log.Selector(string.Format("GetElementsWithuiSelector::begin {0:mm\\:ss\\.fff}", sw.Elapsed));

            UIElement _fromElement = fromElement as UIElement;
            var       selectors    = selector.Where(x => x.Enabled == true && x.Selector == null).ToList();

            var current    = new List <UIElement>();
            var automation = AutomationUtil.getAutomation();

            // var search_descendants = PluginConfig.search_descendants;
            var search_descendants = false;
            var p = selector[0].Properties.Where(x => x.Name == "SearchDescendants").FirstOrDefault();

            if (p != null)
            {
                search_descendants = bool.Parse(p.Value);
            }


            UIElement[] result = null;
            using (automation)
            {
                var _treeWalker             = automation.TreeWalkerFactory.GetControlViewWalker();
                AutomationElement startfrom = null;
                if (_fromElement != null)
                {
                    startfrom = _fromElement.RawElement;
                }
                Log.SelectorVerbose("automation.GetDesktop");
                bool isDesktop = false;
                if (startfrom == null)
                {
                    startfrom = automation.GetDesktop();
                    isDesktop = true;
                }
                current.Add(new UIElement(startfrom));

                for (var i = 0; i < selectors.Count; i++)
                {
                    var s        = new WindowsSelectorItem(selectors[i]);
                    var elements = new List <UIElement>();
                    elements.AddRange(current);
                    current.Clear();
                    int failcounter = 0;
                    do
                    {
                        foreach (var _element in elements)
                        {
                            var count = maxresults;
                            if (i == 0)
                            {
                                count = midcounter;
                            }
                            // if (i < selectors.Count) count = 500;
                            if ((i + 1) < selectors.Count)
                            {
                                count = 1;
                            }
                            var matches   = ((WindowsSelectorItem)s).matches(automation, _element.RawElement, _treeWalker, count, isDesktop, TimeSpan.FromSeconds(250), search_descendants); // (i == 0 ? 1: maxresults)
                            var uimatches = new List <UIElement>();
                            foreach (var m in matches)
                            {
                                var ui   = new UIElement(m);
                                var list = selectors.Take(i).ToList();
                                list.Add(new WindowsSelectorItem(m, false));
                                uimatches.Add(ui);
                            }
                            current.AddRange(uimatches.ToArray());
                        }
                        if (current.Count > 1)
                        {
                            if (i < selectors.Count)
                            {
                                Log.Warning("Selector had " + current.Count + " hits and not just one, at element " + i + " this selector will be slow!");
                            }
                        }
                        if (current.Count == 0 && PluginConfig.allow_child_searching)
                        {
                            Log.Warning("Selector found not hits at element " + i + ", Try searching children, this selector will be slow!");
                            if ((i + 1) < selectors.Count && i > 0)
                            {
                                i++;
                                s = new WindowsSelectorItem(selectors[i]);
                                foreach (var _element in elements)
                                {
                                    var count = maxresults;
                                    if (i == 0)
                                    {
                                        count = 1;
                                    }
                                    if (i < selectors.Count)
                                    {
                                        count = 500;
                                    }
                                    var matches   = ((WindowsSelectorItem)s).matches(automation, _element.RawElement, _treeWalker, count, false, TimeSpan.FromSeconds(250), search_descendants); // (i == 0 ? 1 : maxresults)
                                    var uimatches = new List <UIElement>();
                                    foreach (var m in matches)
                                    {
                                        var ui   = new UIElement(m);
                                        var list = selectors.Take(i).ToList();
                                        list.Add(new WindowsSelectorItem(m, false));
                                        uimatches.Add(ui);
                                    }
                                    current.AddRange(uimatches.ToArray());
                                }
                                Console.WriteLine(current.Count());
                            }
                        }
                        if (current.Count == 0)
                        {
                            ++failcounter;
                        }
                        if (current.Count == 0 && Config.local.log_selector)
                        {
                            if (isDesktop)
                            {
                                var message = "needed to find " + Environment.NewLine + selectors[i].ToString() + Environment.NewLine + "but found only: " + Environment.NewLine;
                                var windows = Win32WindowUtils.GetTopLevelWindows(automation);
                                foreach (var c in windows)
                                {
                                    try
                                    {
                                        message += new UIElement(c).ToString() + Environment.NewLine;
                                    }
                                    catch (Exception)
                                    {
                                    }
                                }
                                // Log.Selector(message);
                                Log.Warning(message);
                            }
                            else
                            {
                                foreach (var element in elements)
                                {
                                    var message  = "needed to find " + Environment.NewLine + selectors[i].ToString() + Environment.NewLine + "but found only: " + Environment.NewLine;
                                    var children = element.RawElement.FindAllChildren();
                                    foreach (var c in children)
                                    {
                                        try
                                        {
                                            message += new UIElement(c).ToString() + Environment.NewLine;
                                        }
                                        catch (Exception)
                                        {
                                        }
                                    }
                                    // Log.Selector(message);
                                    Log.Warning(message);
                                }
                            }
                        }
                        else
                        {
                            Log.SelectorVerbose(string.Format("Found " + current.Count + " hits for selector # " + i + " {0:mm\\:ss\\.fff}", sw.Elapsed));
                        }
                    } while (failcounter < 2 && current.Count == 0);


                    if (i == (selectors.Count - 1))
                    {
                        result = current.ToArray();
                    }
                    if (current.Count == 0 && Config.local.log_selector)
                    {
                        if (isDesktop)
                        {
                            var message = "needed to find " + Environment.NewLine + selectors[i].ToString() + Environment.NewLine + "but found only: " + Environment.NewLine;
                            var windows = Win32WindowUtils.GetTopLevelWindows(automation);
                            foreach (var c in windows)
                            {
                                try
                                {
                                    message += new UIElement(c).ToString() + Environment.NewLine;
                                }
                                catch (Exception)
                                {
                                }
                            }
                            Log.Warning(message);
                        }
                        else
                        {
                            var message = "needed to find " + Environment.NewLine + selectors[i].ToString() + Environment.NewLine + "but found only: " + Environment.NewLine;
                            foreach (var element in elements)
                            {
                                var children = element.RawElement.FindAllChildren();
                                foreach (var c in children)
                                {
                                    try
                                    {
                                        message += new UIElement(c).ToString() + Environment.NewLine;
                                    }
                                    catch (Exception)
                                    {
                                    }
                                }
                            }
                            Log.Warning(message);
                        }
                        return(new UIElement[] { });
                    }
                    isDesktop = false;
                }
            }
            if (result == null)
            {
                Log.Selector(string.Format("GetElementsWithuiSelector::ended with 0 results after {0:mm\\:ss\\.fff}", sw.Elapsed));
                return(new UIElement[] { });
            }
            return(result);
        }
예제 #24
0
        public void OnUserAction(Interfaces.IRecordPlugin sender, Interfaces.IRecordEvent e)
        {
            StopRecordPlugins();
            AutomationHelper.syncContext.Post(o =>
            {
                Interfaces.GenericTools.Restore();
                foreach (var p in Interfaces.Plugins.recordPlugins)
                {
                    if (p.Name != sender.Name)
                    {
                        if (p.ParseUserAction(ref e))
                        {
                            continue;
                        }
                    }
                }
                e.Selector.RemoveRange(2, e.Selector.Count - 2);
                // ModelItem.Properties["Selector"].SetValue(new InArgument<string>() { Expression = new Literal<string>(e.Selector.ToString()) });
                var ele = e.Element;
                if (ele != null && !(ele is UIElement))
                {
                    var automation = AutomationUtil.getAutomation();
                    var p          = new System.Drawing.Point(ele.Rectangle.X + 10, ele.Rectangle.Y + 10);
                    if (p.X > 0 && p.Y > 0)
                    {
                        var _temp = automation.FromPoint(p);
                        if (_temp != null)
                        {
                            ele = new UIElement(_temp);
                        }
                    }
                }

                if (ele is UIElement ui)
                {
                    var window = ui.GetWindow();
                    if (window == null)
                    {
                        return;
                    }
                    if (!string.IsNullOrEmpty(window.Name))
                    {
                        ModelItem.Properties["DisplayName"].SetValue(window.Name);
                    }
                    if (window.Properties.BoundingRectangle.IsSupported)
                    {
                        var bound      = window.BoundingRectangle;
                        var newbound   = new System.Drawing.Rectangle(bound.X, bound.Y, bound.Width, bound.Height);
                        var p          = new System.Drawing.Point(bound.X, bound.Y);
                        var allScreens = System.Windows.Forms.Screen.AllScreens.ToList();
                        int screen     = 0;
                        for (var i = 0; i < allScreens.Count; i++)
                        {
                            var work = allScreens[i].WorkingArea;
                            if (work.Contains(bound) || allScreens[i].WorkingArea.Contains(p))
                            {
                                screen     = i;
                                newbound.X = newbound.X - work.X;
                                newbound.Y = newbound.Y - work.Y;
                                break;
                            }
                        }
                        ModelItem.Properties["Screen"].SetValue(new InArgument <int>()
                        {
                            Expression = new Literal <int>(screen)
                        });
                        ModelItem.Properties["X"].SetValue(new InArgument <int>()
                        {
                            Expression = new Literal <int>(newbound.X)
                        });
                        ModelItem.Properties["Y"].SetValue(new InArgument <int>()
                        {
                            Expression = new Literal <int>(newbound.Y)
                        });
                        ModelItem.Properties["Width"].SetValue(new InArgument <int>()
                        {
                            Expression = new Literal <int>(newbound.Width)
                        });
                        ModelItem.Properties["Height"].SetValue(new InArgument <int>()
                        {
                            Expression = new Literal <int>(newbound.Height)
                        });
                    }
                }
            }, null);
        }
예제 #25
0
        public static ProcessInfo GetProcessInfo(this AutomationElement element)
        {
            if (!element.Properties.ProcessId.IsSupported)
            {
                return(null);
            }
            ProcessInfo result    = new ProcessInfo();
            int         processId = -1;
            IntPtr      handle    = IntPtr.Zero;

            try
            {
                processId = element.Properties.ProcessId.Value;
                var p = System.Diagnostics.Process.GetProcessById(processId);
                handle             = p.Handle;
                result.processname = p.ProcessName;
                result.filename    = p.MainModule.FileName.replaceEnvironmentVariable();
            }
            catch (Exception)
            {
            }

            bool _isImmersiveProcess = false;

            try
            {
                if (handle != IntPtr.Zero)
                {
                    _isImmersiveProcess = IsImmersiveProcess(handle);
                }
            }
            catch (Exception)
            {
            }
            string ApplicationUserModelId = null;

            if (_isImmersiveProcess)
            {
                var automation = AutomationUtil.getAutomation();
                var pc         = new FlaUI.Core.Conditions.PropertyCondition(automation.PropertyLibrary.Element.ClassName, "Windows.UI.Core.CoreWindow");
                var _el        = element.FindFirstChild(pc);
                if (_el != null)
                {
                    processId = _el.Properties.ProcessId.Value;

                    IntPtr ptrProcess = OpenProcess(QueryLimitedInformation, false, processId);
                    if (IntPtr.Zero != ptrProcess)
                    {
                        uint          cchLen  = 130; // Currently APPLICATION_USER_MODEL_ID_MAX_LENGTH = 130
                        StringBuilder sbName  = new StringBuilder((int)cchLen);
                        Int32         lResult = GetApplicationUserModelId(ptrProcess, ref cchLen, sbName);
                        if (APPMODEL_ERROR_NO_APPLICATION == lResult)
                        {
                            _isImmersiveProcess = false;
                        }
                        else if (ERROR_SUCCESS == lResult)
                        {
                            ApplicationUserModelId = sbName.ToString();
                        }
                        else if (ERROR_INSUFFICIENT_BUFFER == lResult)
                        {
                            sbName = new StringBuilder((int)cchLen);
                            if (ERROR_SUCCESS == GetApplicationUserModelId(ptrProcess, ref cchLen, sbName))
                            {
                                ApplicationUserModelId = sbName.ToString();
                            }
                        }
                        CloseHandle(ptrProcess);
                    }
                }
                else
                {
                    _isImmersiveProcess = false;
                }
            }
            var arguments = GetCommandLine(processId);
            var arr       = parseCommandLine(arguments);

            if (arr.Length == 0)
            {
            }
            else if (arguments.Contains("\"" + arr[0] + "\""))
            {
                result.arguments = arguments.Replace("\"" + arr[0] + "\"", "");
            }
            else
            {
                result.arguments = arguments.Replace(arr[0], "");
            }
            if (result.arguments != null)
            {
                result.arguments = result.arguments.replaceEnvironmentVariable();
            }
            //if (arr.Length > 0)
            //{
            //    var resultarr = new string[arr.Length - 1];
            //    Array.Copy(arr, 1, resultarr, 0, arr.Length - 1);
            //    result.arguments = string.Join(" ", resultarr).replaceEnvironmentVariable();
            //}
            result.applicationUserModelId = ApplicationUserModelId;
            result.isImmersiveProcess     = _isImmersiveProcess;
            return(result);
        }
예제 #26
0
        protected override void StartLoop(NativeActivityContext context)
        {
            var result            = new List <UIElement>();
            var includeHidden     = false;
            var includeEmptyTitle = false;

            try
            {
                if (IncludeEmptyTitle != null)
                {
                    includeEmptyTitle = IncludeEmptyTitle.Get(context);
                }
                if (IncludeHidden != null)
                {
                    includeHidden = IncludeHidden.Get(context);
                }
            }
            catch (Exception)
            {
            }
            var windows = RuningWindows.GetOpenedWindows(includeHidden, includeEmptyTitle);

            using (var automation = AutomationUtil.getAutomation())
            {
                foreach (var window in windows)
                {
                    var _window = automation.FromHandle(window.Key);
                    result.Add(new UIElement(_window));
                }
            }
            WindowsCacheExtension ext = context.GetExtension <WindowsCacheExtension>();
            var sw = new Stopwatch();

            sw.Start();
            Log.Selector(string.Format("Windows.GetWindows::begin {0:mm\\:ss\\.fff}", sw.Elapsed));

            UIElement[] elements = result.ToArray();
            context.SetValue(Elements, elements);

            var lastelements = context.GetValue(_lastelements);

            if (lastelements == null)
            {
                lastelements = new UIElement[] { }
            }
            ;
            context.SetValue(_lastelements, elements);
            IEnumerator <UIElement> _enum = elements.ToList().GetEnumerator();
            bool more = _enum.MoveNext();

            if (lastelements.Length == elements.Length && lastelements.Length > 0)
            {
                more = !System.Collections.StructuralComparisons.StructuralEqualityComparer.Equals(lastelements, elements);
            }
            if (more)
            {
                context.SetValue(_elements, _enum);
                context.SetValue(_sw, sw);
                Log.Selector(string.Format("Windows.GetWindows::end:: call ScheduleAction: {0:mm\\:ss\\.fff}", sw.Elapsed));
                IncIndex(context);
                SetTotal(context, elements.Length);
                context.ScheduleAction <UIElement>(Body, _enum.Current, OnBodyComplete);
            }
            else
            {
                Log.Selector(string.Format("Windows.GetWindows:end {0:mm\\:ss\\.fff}", sw.Elapsed));
            }
        }
예제 #27
0
        public WindowsSelector(AutomationElement element, WindowsSelector anchor, bool doEnum)
        {
            var sw = new System.Diagnostics.Stopwatch();

            sw.Start();
            Log.Selector(string.Format("windowsselector::begin {0:mm\\:ss\\.fff}", sw.Elapsed));

            AutomationElement root        = null;
            AutomationElement baseElement = null;
            var pathToRoot = new List <AutomationElement>();

            while (element != null)
            {
                // Break on circular relationship (should not happen?)
                //if (pathToRoot.Contains(element) || element.Equals(_rootElement)) { break; }
                // if (pathToRoot.Contains(element)) { break; }
                try
                {
                    if (element.Parent != null)
                    {
                        pathToRoot.Add(element);
                    }
                    if (element.Parent == null)
                    {
                        root = element;
                    }
                }
                catch (Exception)
                {
                    root = element;
                }
                try
                {
                    //element = _treeWalker.GetParent(element);
                    element = element.Parent;
                }
                catch (Exception ex)
                {
                    Log.Error(ex, "");
                    return;
                }
            }
            Log.Selector(string.Format("windowsselector::create pathToRoot::end {0:mm\\:ss\\.fff}", sw.Elapsed));
            pathToRoot.Reverse();
            if (anchor != null)
            {
                var anchorlist = anchor.Where(x => x.Enabled && x.Selector == null).ToList();
                for (var i = 0; i < anchorlist.Count(); i++)
                {
                    if (WindowsSelectorItem.Match(anchorlist[i], pathToRoot[0]))
                    //if (((WindowsSelectorItem)anchorlist[i]).Match(pathToRoot[0]))
                    {
                        pathToRoot.Remove(pathToRoot[0]);
                    }
                    else
                    {
                        Log.Selector("Element does not match the anchor path");
                        return;
                    }
                }
            }
            WindowsSelectorItem item;
            var temppathToRoot = new List <AutomationElement>();
            var newpathToRoot  = new List <AutomationElement>();

            foreach (var e in pathToRoot)
            {
                temppathToRoot.Add(e);
            }
            Log.Selector(string.Format("windowsselector::traverse back to element from root::begin {0:mm\\:ss\\.fff}", sw.Elapsed));
            using (var automation = AutomationUtil.getAutomation())
            {
                var  _treeWalker = automation.TreeWalkerFactory.GetControlViewWalker();
                bool isDesktop   = true;
                var  parent      = automation.GetDesktop();
                if (anchor != null)
                {
                    parent = temppathToRoot[0].Parent; isDesktop = false;
                }
                while (temppathToRoot.Count > 0)
                {
                    var i = temppathToRoot.First();
                    temppathToRoot.Remove(i);
                    item = new WindowsSelectorItem(i, false);
                    var m = item.matches(automation, parent, _treeWalker, 2, isDesktop);
                    if (m.Length > 0)
                    {
                        newpathToRoot.Add(i);
                        parent    = i;
                        isDesktop = false;
                    }
                    if (m.Length == 0 && Config.local.log_selector)
                    {
                        var message  = "needed to find " + Environment.NewLine + item.ToString() + Environment.NewLine + "but found only: " + Environment.NewLine;
                        var children = parent.FindAllChildren();
                        foreach (var c in children)
                        {
                            try
                            {
                                message += new UIElement(c).ToString() + Environment.NewLine;
                            }
                            catch (Exception)
                            {
                            }
                        }
                        Log.Debug(message);
                        //if (i.Parent != null)
                        //{
                        //    var c = i.Parent.FindAllChildren();
                        //    var IndexInParent = -1;
                        //    for (var x = 0; x < c.Count(); x++)
                        //    {
                        //        if (i == c[x]) IndexInParent = x;
                        //    }
                        //}
                    }
                }
            }
            Log.Selector(string.Format("windowsselector::traverse back to element from root::end {0:mm\\:ss\\.fff}", sw.Elapsed));
            if (newpathToRoot.Count != pathToRoot.Count)
            {
                Log.Information("Selector had " + pathToRoot.Count + " items to root, but traversing children inly matched " + newpathToRoot.Count);
                pathToRoot = newpathToRoot;
            }



            if (pathToRoot.Count == 0)
            {
                Log.Error("Element has not parent, or is same as annchor");
                return;
            }
            baseElement = pathToRoot.First();
            element     = pathToRoot.Last();
            Clear();
            Log.Selector(string.Format("windowsselector::remove anchor if needed::end {0:mm\\:ss\\.fff}", sw.Elapsed));
            if (anchor == null)
            {
                item         = new WindowsSelectorItem(baseElement, true);
                item.Enabled = true;
                //item.canDisable = false;
                Items.Add(item);
            }
            bool isStartmenu = false;

            for (var i = 0; i < pathToRoot.Count(); i++)
            {
                var o = pathToRoot[i];
                item = new WindowsSelectorItem(o, false);
                if (i == 0 || i == (pathToRoot.Count() - 1))
                {
                    item.canDisable = false;
                }
                foreach (var p in item.Properties) // TODO: Ugly, ugly inzuBiz hack !!!!
                {
                    int idx = p.Value.IndexOf(".");
                    if (p.Name == "ClassName" && idx > -1)
                    {
                        int idx2 = p.Value.IndexOf(".", idx + 1);
                        if (idx2 > idx)
                        {
                            p.Value = p.Value.Substring(0, idx2 + 1) + "*";
                        }
                    }
                    //if (p.Name == "ClassName" && p.Value.StartsWith("WindowsForms10")) p.Value = "WindowsForms10*";
                    if (p.Name == "ClassName" && p.Value.ToLower() == "shelldll_defview")
                    {
                        item.Enabled = false;
                    }
                    if (p.Name == "ClassName" && (p.Value.ToLower() == "dv2vontrolhost" || p.Value.ToLower() == "desktopprogramsmfu"))
                    {
                        isStartmenu = true;
                    }
                    if (p.Name == "ClassName" && p.Value == "#32770")
                    {
                        item.Enabled = false;
                    }
                    if (p.Name == "ControlType" && p.Value == "ListItem" && isStartmenu)
                    {
                        p.Enabled = false;
                    }
                }
                var hassyslistview32 = item.Properties.Where(p => p.Name == "ClassName" && p.Value.ToLower() == "syslistview32").ToList();
                if (hassyslistview32.Count > 0)
                {
                    var hasControlType = item.Properties.Where(p => p.Name == "ControlType").ToList();
                    if (hasControlType.Count > 0)
                    {
                        hasControlType[0].Enabled = false;
                    }
                }

                if (doEnum)
                {
                    item.EnumNeededProperties(o, o.Parent);
                }
                Items.Add(item);
            }
            pathToRoot.Reverse();
            Log.Selector(string.Format("windowsselector::end {0:mm\\:ss\\.fff}", sw.Elapsed));
            OnPropertyChanged(new System.ComponentModel.PropertyChangedEventArgs("Count"));
            OnPropertyChanged(new System.ComponentModel.PropertyChangedEventArgs("Item[]"));
            OnCollectionChanged(new System.Collections.Specialized.NotifyCollectionChangedEventArgs(System.Collections.Specialized.NotifyCollectionChangedAction.Reset));
        }