Skip to content

Commit 061dc60

Browse files
author
Darin Higgins
committed
Added a little more debugging code to the test app.
1 parent b9bd49c commit 061dc60

File tree

6 files changed

+115
-7
lines changed

6 files changed

+115
-7
lines changed

Disambiguator.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
77
ProjectSection(SolutionItems) = preProject
88
.gitignore = .gitignore
99
CreatePlgX.bat = CreatePlgX.bat
10+
notes.txt = notes.txt
1011
PackageRelease.bat = PackageRelease.bat
1112
PlgXExclude.txt = PlgXExclude.txt
1213
Readme.txt = Readme.txt

TestApp1/App.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
33
<startup>
4-
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6"/>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
55
</startup>
66
</configuration>

TestApp1/Properties/Settings.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

TestApp1/TestApp1.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<OutputType>WinExe</OutputType>
99
<RootNamespace>TestApp1</RootNamespace>
1010
<AssemblyName>TestApp1</AssemblyName>
11-
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
11+
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
1212
<FileAlignment>512</FileAlignment>
1313
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
1414
<Deterministic>true</Deterministic>
@@ -45,6 +45,8 @@
4545
<Reference Include="System.Net.Http" />
4646
<Reference Include="System.Windows.Forms" />
4747
<Reference Include="System.Xml" />
48+
<Reference Include="UIAutomationClient" />
49+
<Reference Include="UIAutomationTypes" />
4850
</ItemGroup>
4951
<ItemGroup>
5052
<Compile Include="frmTestApp1.cs">

TestApp1/frmTestApp1.Designer.cs

Lines changed: 47 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

TestApp1/frmTestApp1.cs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
using System.Linq;
77
using System.Text;
88
using System.Threading.Tasks;
9+
using System.Windows.Automation;
910
using System.Windows.Forms;
1011

12+
1113
namespace TestApp1
1214
{
1315
public partial class frmTestApp1 : Form
@@ -16,5 +18,65 @@ public frmTestApp1()
1618
{
1719
InitializeComponent();
1820
}
21+
22+
private void btnGo_Click(object sender, EventArgs e)
23+
{
24+
var root = AutomationElement.RootElement;
25+
26+
Recurse(root);
27+
}
28+
29+
private void Recurse(AutomationElement element)
30+
{
31+
int ec = 0;
32+
var elems = element.FindAll(TreeScope.Children, Condition.TrueCondition).Cast<AutomationElement>();
33+
34+
var e1 = elems.Where(e => Prop(e, "Name") == "Certify-Client Repos").FirstOrDefault();
35+
36+
elems = e1.FindAll(TreeScope.Children, Condition.TrueCondition).Cast<AutomationElement>();
37+
38+
e1 = elems.Where(e => Prop(e, "Name") == "Windows Security").FirstOrDefault();
39+
40+
elems = e1.FindAll(TreeScope.Subtree, Condition.TrueCondition).Cast<AutomationElement>();
41+
42+
var tc = elems.Count();
43+
foreach (AutomationElement e in elems)
44+
{
45+
ec++;
46+
try
47+
{
48+
var props = e.GetSupportedProperties();
49+
tbxOutput.Text += "\r\n";
50+
int pc = 0;
51+
foreach (var p in props)
52+
{
53+
pc++;
54+
tbxOutput.Text += $" {p.ProgrammaticName}-{e.GetCurrentPropertyValue(p)}\r\n";
55+
lblStatus.Text = $"{pc} prop in {ec} of {tc}";
56+
lblStatus.Refresh();
57+
}
58+
}
59+
catch
60+
{ }
61+
}
62+
}
63+
64+
65+
private string Prop(AutomationElement e, string propName)
66+
{
67+
try
68+
{
69+
var props = e.GetSupportedProperties();
70+
foreach (var p in props)
71+
{
72+
if (p.ProgrammaticName.Contains("." + propName + "Property"))
73+
{
74+
return $"{e.GetCurrentPropertyValue(p)}";
75+
}
76+
}
77+
}
78+
catch { }
79+
return "$$$UNKNOWN$$$";
80+
}
1981
}
2082
}

0 commit comments

Comments
 (0)