/// <summary> /// Constructor for dialog /// </summary> /// <param name="coreProps"></param> public PropertyConfigDialog(IEnumerable <int> coreProps, TypeBase source, string title) { if (source == null) { throw new ArgumentNullException(nameof(source)); } InitializeComponent(); this.Title = string.Format(CultureInfo.InvariantCulture, Properties.Resources.PropertyConfigDialog_TitleFormat, title); this.ctrlPropertySelect.LeftColumnTitle = string.Format(CultureInfo.InvariantCulture, Properties.Resources.PropertyConfigDialog_AllItemsFormat, title); this.ctrlPropertySelect.RightColumnTitle = string.Format(CultureInfo.InvariantCulture, Properties.Resources.PropertyConfigDialog_SelectedItemsFormat, title); var list = (from kv in source.GetKeyValuePairList() where !DesktopElement.IsExcludedProperty(kv.Key, kv.Value) select new RecordEntitySetting { Id = kv.Key, Name = kv.Value, IsRecorded = coreProps.Contains(kv.Key), Type = RecordEntityType.Property }).ToList(); var selList = coreProps.Select(l => list.Where(r => r.Id == l).FirstOrDefault()).ToList(); CoreProperties = selList.ToList();// generate base list here. ctrlPropertySelect.SetLists(list.ToList(), selList); ((INotifyCollectionChanged)ctrlPropertySelect.lvRight.Items).CollectionChanged += lvRight_CollectionChanged; }
/// <summary> /// Populate siblings /// </summary> /// <param name="parentNode"></param> /// <param name="poiNode"></param> /// <param name="startId"></param> private int PopulateSiblingTreeNodes(A11yElement parentNode, A11yElement poiNode) { int childId = 1; IUIAutomationTreeWalker walker = this.TreeWalker; IUIAutomationElement child = null; if ((IUIAutomationElement)parentNode.PlatformObject != null) { try { child = walker.GetFirstChildElement((IUIAutomationElement)parentNode.PlatformObject); } #pragma warning disable CA1031 // Do not catch general exception types catch (Exception ex) { ex.ReportException(); child = null; System.Diagnostics.Trace.WriteLine("Tree walker exception: " + ex); } #pragma warning restore CA1031 // Do not catch general exception types while (child != null) { #pragma warning disable CA2000 // Use recommended dispose patterns var childNode = new DesktopElement(child, true, false); #pragma warning restore CA2000 // Use recommended dispose patterns childNode.PopulateMinimumPropertiesForSelection(); if (childNode.IsSameUIElement(poiNode) == false) { childNode.UniqueId = childId++; childNode.Parent = parentNode; childNode.TreeWalkerMode = this.TreeWalkerMode; this.Items.Add(childNode); } else { childNode = poiNode as DesktopElement; } parentNode.Children.Add(childNode); try { child = walker.GetNextSiblingElement(child); } #pragma warning disable CA1031 // Do not catch general exception types catch (Exception ex) { ex.ReportException(); child = null; System.Diagnostics.Trace.WriteLine("Tree walker exception: " + ex); } #pragma warning restore CA1031 // Do not catch general exception types } } return(childId); }
/// <summary> /// Do not call this function directly. Instead, call MoveTo(). /// </summary> /// <param name="getElementMethod"></param> private void _MoveTo(GetElementDelegate getElementMethod) { var element = GetNearbyElement(getElementMethod); if (element == null) { throw new TreeNavigationFailedException(); } #pragma warning disable CA2000 // Call IDisposable.Dispose() var desktopElement = new DesktopElement(element, true, false); #pragma warning restore CA2000 desktopElement.PopulateMinimumPropertiesForSelection(); if (desktopElement.IsRootElement() == false) { this.SelectAction?.SetCandidateElement(desktopElement); this.SelectAction?.Select(); } else { // if it is desktop, release it. desktopElement.Dispose(); throw new TreeNavigationFailedException(); } }
private IUIAutomationElement GetNearbyElement(GetElementDelegate getNextElement) { var currentElement = GetCurrentElement(); if (currentElement == null) { return(null); } var treeWalker = A11yAutomation.GetTreeWalker(this.TreeViewMode); var retVal = getNextElement?.Invoke(treeWalker, currentElement); // make sure that we skip an element from current process while walking tree. // this code should be hit only at App level. but for sure. if (DesktopElement.IsFromCurrentProcess(retVal)) { var tmp = retVal; retVal = getNextElement?.Invoke(treeWalker, retVal); // since element is not in use, release. Marshal.ReleaseComObject(tmp); } Marshal.ReleaseComObject(treeWalker); return(retVal); }
public void Add(string name, int type, string id, string id_shortcut = "") { if (type != -1) { var element = new DesktopElement(type, name, id); if (id_shortcut != String.Empty) { element.setShortCut(id_shortcut); } if (x + (int)element.width + 15 > FileManager.Graphics.Window.Width) { x = Configuration.startX; y += (int)(element.height + (element.height / 2)); } element.nameElement.setPosition((int)(x), (int)(y + (element.height - 25))); element.nameElement.setSize(9); element.setPosition(x, y); FileElement.Add(element); x += (int)element.width + 15; count++; element.Generate(); element.Display(canvas); } }
private void RemoveElement(DesktopElement element) { this.InvokeAsynchronouslyInBackground( () => { this.desktop.RemoveElement(element); }); }
/// <summary> /// Constructor with DesktopElement /// </summary> /// <param name="name"></param> /// <param name="Text"></param> /// <param name="e"></param> public TextAttributeViewModel(int id, string name, DesktopElement e) { this.Id = id; this.Name = name; this.Text = e.Glimpse; this.Element = e; this.DetailsVisibility = Visibility.Visible; this.Command = new CommandHandler(() => ShowElementInfo(), true); }
public TextRange RangeFromChild(DesktopElement child) { if (child == null) { throw new ArgumentNullException(nameof(child)); } return(new TextRange(this.Pattern.RangeFromChild(child.PlatformObject), this)); }
/// <summary> /// Get instance of EventMessage /// when sender is null, it is generally error case. /// /// if it returns null, it means that the sender is hosted in the process of running Recorder code. /// </summary> /// <param name="id"></param> /// <param name="sender"></param> /// <param name="comment"></param> /// <param name="isError"></param> /// <returns></returns> public static EventMessage GetInstance(int id, IUIAutomationElement sender) { if (sender == null || !DesktopElement.IsFromCurrentProcess(sender)) { return(new EventMessage(id, sender)); } return(null); }
public void Show(IDesktopElement element) { this.InvokeAsynchronously( () => { DesktopElement desktopElement = element as DesktopElement; this.desktop.AddElement(desktopElement); }); }
/// <summary> /// Populate tree by retrieving all children at once. /// </summary> /// <param name="rootNode"></param> private void PopulateChildrenTreeNode(A11yElement rootNode, int startId) { int childId = startId; IUIAutomationTreeWalker walker = A11yAutomation.GetTreeWalker(this.WalkerMode); IUIAutomationElement child = (IUIAutomationElement)rootNode.PlatformObject; if (child != null) { try { child = walker.GetFirstChildElement(child); } #pragma warning disable CA1031 // Do not catch general exception types catch (Exception ex) { ex.ReportException(); child = null; System.Diagnostics.Trace.WriteLine("Tree walker exception: " + ex); } #pragma warning restore CA1031 // Do not catch general exception types while (child != null) { #pragma warning disable CA2000 // childNode will be disposed by the parent node // Create child without populating basic property. it will be set all at once in parallel. var childNode = new DesktopElement(child, true, false) { UniqueId = childId++ }; #pragma warning restore CA2000 // childNode will be disposed by the parent node rootNode.Children.Add(childNode); childNode.Parent = rootNode; childNode.TreeWalkerMode = this.WalkerMode; this.Elements.Add(childNode); try { child = walker.GetNextSiblingElement(child); } #pragma warning disable CA1031 // Do not catch general exception types catch (Exception ex) { ex.ReportException(); child = null; System.Diagnostics.Trace.WriteLine("Tree walker exception: " + ex); } #pragma warning restore CA1031 // Do not catch general exception types } } Marshal.ReleaseComObject(walker); }
public DesktopElement GetContainingGrid() { var e = new DesktopElement(this.Pattern.CurrentContainingGrid); if (e.Properties != null && e.Properties.Count != 0) { return(e); } throw new ApplicationException("Pattern may not be valid any more."); }
/// <summary> /// Populate siblings /// </summary> /// <param name="parentNode"></param> /// <param name="poiNode"></param> /// <param name="startId"></param> private int PopulateSiblingTreeNodes(A11yElement parentNode, A11yElement poiNode) { int childId = 1; IUIAutomationTreeWalker walker = this.TreeWalker; IUIAutomationElement child = null; if ((IUIAutomationElement)parentNode.PlatformObject != null) { try { child = walker.GetFirstChildElement((IUIAutomationElement)parentNode.PlatformObject); } catch (Exception ex) { ex.ReportException(); child = null; System.Diagnostics.Trace.WriteLine("Tree walker exception: " + ex); } while (child != null) { var childNode = new DesktopElement(child, true, false); childNode.PopulateMinimumPropertiesForSelection(); if (childNode.IsSameUIElement(poiNode) == false) { childNode.UniqueId = childId++; childNode.Parent = parentNode; childNode.TreeWalkerMode = this.TreeWalkerMode; this.Items.Add(childNode); } else { childNode = poiNode as DesktopElement; } parentNode.Children.Add(childNode); try { child = walker.GetNextSiblingElement(child); } catch (Exception ex) { ex.ReportException(); child = null; System.Diagnostics.Trace.WriteLine("Tree walker exception: " + ex); } } } return(childId); }
public DesktopElement GetContainingGrid() { var e = new DesktopElement(this.Pattern.CurrentContainingGrid); if (e.Properties != null && e.Properties.Count != 0) { return(e); } throw new ApplicationException(ErrorMessages.PatternNoLongerValid); }
/// <summary> /// Populate tree by retrieving all children at once. /// </summary> /// <param name="rootNode"></param> /// <param name="parentNode"></param> /// <param name="startChildId"></param> private int PopulateChildrenTreeNode(A11yElement rootNode, A11yElement parentNode, int startChildId) { this.Elements.Add(rootNode); rootNode.Parent = parentNode; rootNode.TreeWalkerMode = this.WalkerMode; // set tree walker mode. IUIAutomationTreeWalker walker = A11yAutomation.GetTreeWalker(this.WalkerMode); IUIAutomationElement child = (IUIAutomationElement)rootNode.PlatformObject; if (child != null) { try { child = walker.GetFirstChildElement(child); } #pragma warning disable CA1031 // Do not catch general exception types catch (Exception ex) { ex.ReportException(); child = null; System.Diagnostics.Trace.WriteLine("Tree walker exception: " + ex); } #pragma warning restore CA1031 // Do not catch general exception types while (child != null && _elementCounter.TryIncrement()) { // Create child without populating basic property. it will be set all at once in parallel. var childNode = new DesktopElement(child, true, false); rootNode.Children.Add(childNode); childNode.Parent = rootNode; childNode.UniqueId = startChildId++; startChildId = PopulateChildrenTreeNode(childNode, rootNode, startChildId); try { child = walker.GetNextSiblingElement(child); } #pragma warning disable CA1031 // Do not catch general exception types catch (Exception ex) { ex.ReportException(); child = null; System.Diagnostics.Trace.WriteLine("Tree walker exception: " + ex); } #pragma warning restore CA1031 // Do not catch general exception types } } Marshal.ReleaseComObject(walker); return(startChildId); }
public void Show(IDesktopElement element, Point position) { this.InvokeAsynchronously( () => { DesktopElement desktopElement = element as DesktopElement; desktopElement.StartupLocation = StartupPosition.Manual; this.desktop.AddElement(desktopElement, position); }); }
/// <summary> /// Closes the element with the given Id /// </summary> /// <param name="id">The id.</param> public void Close(Guid id) { DesktopElement instance = this.desktop.Children.OfType <DesktopElement>().Where(x => x.Id == id).FirstOrDefault(); if (instance != null) { if (instance is WindowElement) { this.Windows.Remove((instance as WindowElement).DataContext as INavigationViewModel); } instance.Close(); } }
public DesktopManager() { DesktopRect = SystemInformation.VirtualScreen; DesktopWidth = DesktopRect.Width; DesktopHeight = DesktopRect.Height; uia3.ConnectionTimeout = new TimeSpan(0, 0, 30); uia3.TransactionTimeout = new TimeSpan(0, 1, 0); desktop = uia3.GetDesktop(); OnScreenProperty = new PropertyCondition(uia3.PropertyLibrary.Element.IsOffscreen, false); TopModalCondition = desktop.ConditionFactory.ByControlType(ControlType.Pane).And(desktop.ConditionFactory.ByClassName("Alternate Modal Top Most")); DesktopElement = new DesktopElement(desktop, DesktopRect); AutomationElement[] children = desktop.FindAllChildren(); foreach (AutomationElement child in children) { if (child.Properties.ProcessId.IsSupported && child.Patterns.Window.IsSupported && child.Properties.NativeWindowHandle.IsSupported) { AddHandle(child.Properties.ProcessId, child); } } var eventHandler = desktop.RegisterStructureChangedEvent(TreeScope.Children, (element, type, arg) => { if (type.Equals(StructureChangeType.ChildAdded)) { try { int pid = element.Properties.ProcessId; string className = element.Properties.ClassName; if (className != "SysShadow") { if (!element.Patterns.Window.IsSupported) { popups.Add(new PopupHandle(pid, element, popups)); } else if (element.Properties.NativeWindowHandle.IsSupported) { AddHandle(pid, element); } } } catch {} } }); }
/// <summary> /// Populate tree by retrieving all children at once. /// </summary> /// <param name="rootNode"></param> private void PopulateChildrenTreeNode(A11yElement rootNode, int startId) { int childId = startId; IUIAutomationTreeWalker walker = A11yAutomation.GetTreeWalker(this.WalkerMode); IUIAutomationElement child = (IUIAutomationElement)rootNode.PlatformObject; if (child != null) { try { child = walker.GetFirstChildElement(child); } catch (Exception ex) { child = null; System.Diagnostics.Trace.WriteLine("Tree walker exception: " + ex); } while (child != null) { // Create child without populating basic property. it will be set all at once in parallel. var childNode = new DesktopElement(child, true, false) { UniqueId = childId++ }; rootNode.Children.Add(childNode); childNode.Parent = rootNode; childNode.TreeWalkerMode = this.WalkerMode; this.Elements.Add(childNode); try { child = walker.GetNextSiblingElement(child); } catch (Exception ex) { child = null; System.Diagnostics.Trace.WriteLine("Tree walker exception: " + ex); } } } Marshal.ReleaseComObject(walker); }
/// <summary> /// Set Parent to build ancestry tree /// </summary> /// <param name="e"></param> /// <param name="uniqueId"></param> private void SetParent(A11yElement e, int uniqueId) { if (e == null || e.PlatformObject == null || e.IsRootElement()) { return; } try { var puia = this.TreeWalker.GetParentElement((IUIAutomationElement)e.PlatformObject); if (puia == null) { return; } #pragma warning disable CA2000 // Call IDisposable.Dispose() var parent = new DesktopElement(puia, true, SetMembers); parent.PopulateMinimumPropertiesForSelection(); // we need to avoid infinite loop of self reference as parent. // it is a probably a bug in UIA or the target app. if (e.IsSameUIElement(parent) == false) { parent.IsAncestorOfSelected = true; parent.Children.Add(e); e.Parent = parent; this.Items.Add(parent); parent.UniqueId = uniqueId; SetParent(parent, uniqueId - 1); } #pragma warning restore CA2000 } #pragma warning disable CA1031 // Do not catch general exception types catch (Exception ex) { ex.ReportException(); // ignore to show the best efforts. System.Diagnostics.Trace.WriteLine(ex); } #pragma warning restore CA1031 // Do not catch general exception types }
/// <summary> /// Constructor for dialog /// </summary> /// <param name="coreProps"></param> public PropertyConfigDialog(IEnumerable <int> coreProps, TypeBase source, string title) { InitializeComponent(); this.Title = $"{title} Configuration"; this.ctrlPropertySelect.LeftColumnTitle = $"All {title}"; this.ctrlPropertySelect.RightColumnTitle = $"Selected {title}"; var list = (from kv in source.GetKeyValuePairList() where !DesktopElement.IsExcludedProperty(kv.Key, kv.Value) select new RecordEntitySetting { Id = kv.Key, Name = kv.Value, IsRecorded = coreProps.Contains(kv.Key), Type = RecordEntityType.Property }).ToList(); var selList = coreProps.Select(l => list.Where(r => r.Id == l).FirstOrDefault()).ToList(); CoreProperties = selList.ToList();// generate base list here. ctrlPropertySelect.SetLists(list.ToList(), selList); ((INotifyCollectionChanged)ctrlPropertySelect.lvRight.Items).CollectionChanged += lvRight_CollectionChanged; }
internal List(IUIAutomationElement element, Application application, DesktopElement parent) : base(element, application, parent) { }
/// <summary> /// Create a new pattern for the provided element. /// </summary> /// <param name="element"> The element that supports the pattern. </param> /// <returns> The pattern if we could find one else null will be returned. </returns> public static ExpandCollapsePattern Create(DesktopElement element) { var pattern = element.NativeElement.GetCurrentPattern(UIA_PatternIds.UIA_ExpandCollapsePatternId) as IUIAutomationExpandCollapsePattern; return pattern == null ? null : new ExpandCollapsePattern(pattern); }
internal ProgressBar(IUIAutomationElement element, Application application, DesktopElement parent) : base(element, application, parent) { }
internal SemanticZoom(IUIAutomationElement element, Application application, DesktopElement parent) : base(element, application, parent) { }
internal HeaderItem(IUIAutomationElement element, Application application, DesktopElement parent) : base(element, application, parent) { }
internal TabControl(IUIAutomationElement element, Application application, DesktopElement parent) : base(element, application, parent) { }
public TextRange RangeFromChild(DesktopElement child) { return(new TextRange(this.Pattern.RangeFromChild(child.PlatformObject), this)); }
public ElementInfoDialog(DesktopElement e) : this(new List <DesktopElement>() { e }) { }
/// <summary> /// Create a new pattern for the provided element. /// </summary> /// <param name="element"> The element that supports the pattern. </param> /// <returns> The pattern if we could find one else null will be returned. </returns> public static ValuePattern Create(DesktopElement element) { var pattern = element.NativeElement.GetCurrentPattern(UIA_PatternIds.UIA_ValuePatternId) as IUIAutomationValuePattern; return pattern == null ? null : new ValuePattern(pattern); }
internal SplitButton(IUIAutomationElement element, Application application, DesktopElement parent) : base(element, application, parent) { }