Skip to content

Commit bf8ba37

Browse files
committed
Improve performance
1 parent 72adb79 commit bf8ba37

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

ProxyDialogAutoFiller/ProxyDialogAutoFiller.cs

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,17 @@ internal static void LoginToProxy(RuntimeContext context, AutomationElement targ
106106
var proxyDialogNameCondition = new PropertyCondition(AutomationElement.NameProperty, dialogDefinition.DialogTitleName);
107107
var targetControlTypeCondition = new OrCondition(
108108
new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Window),
109-
new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Pane));
109+
new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Custom));
110110
var proxyDialogCondition = new AndCondition(
111-
proxyDialogNameCondition,
112-
targetControlTypeCondition);
111+
targetControlTypeCondition,
112+
proxyDialogNameCondition);
113113
var proxyDialogElement = targetRootElement.FindFirst(TreeScope.Subtree, proxyDialogCondition);
114114
if (proxyDialogElement == null)
115115
{
116116
return;
117117
}
118118
context.Logger.Log($"Found proxy dialog.");
119-
var textTypeDescendants = proxyDialogElement.FindAll(TreeScope.Subtree, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Text));
119+
var textTypeDescendants = proxyDialogElement.FindAll(TreeScope.Descendants, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Text));
120120

121121
bool isTargetProxy = false;
122122
string userName = "";
@@ -155,7 +155,7 @@ internal static void LoginToProxy(RuntimeContext context, AutomationElement targ
155155
var userNameEditCondition = new AndCondition(
156156
new PropertyCondition(AutomationElement.NameProperty, dialogDefinition.UserNameInputName),
157157
new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit));
158-
var userNameEditElement = proxyDialogElement.FindFirst(TreeScope.Subtree, userNameEditCondition);
158+
var userNameEditElement = proxyDialogElement.FindFirst(TreeScope.Descendants, userNameEditCondition);
159159
if (userNameEditElement == null)
160160
{
161161
context.Logger.Log($"User name edit not found.");
@@ -167,7 +167,7 @@ internal static void LoginToProxy(RuntimeContext context, AutomationElement targ
167167
var passwordEditCondition = new AndCondition(
168168
new PropertyCondition(AutomationElement.NameProperty, dialogDefinition.PasswordInputName),
169169
new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit));
170-
var passwordEditElement = proxyDialogElement.FindFirst(TreeScope.Subtree, passwordEditCondition);
170+
var passwordEditElement = proxyDialogElement.FindFirst(TreeScope.Descendants, passwordEditCondition);
171171
if (passwordEditElement == null)
172172
{
173173
context.Logger.Log($"Password edit not found.");
@@ -179,7 +179,7 @@ internal static void LoginToProxy(RuntimeContext context, AutomationElement targ
179179
var loginButtonCondition = new AndCondition(
180180
loginButtonNameCondition,
181181
new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button));
182-
var loginButtonElement = proxyDialogElement.FindFirst(TreeScope.Subtree, loginButtonCondition);
182+
var loginButtonElement = proxyDialogElement.FindFirst(TreeScope.Descendants, loginButtonCondition);
183183
if (loginButtonElement == null)
184184
{
185185
context.Logger.Log($"Login button not found.");
@@ -204,19 +204,26 @@ internal static void LoginToProxy(RuntimeContext context, AutomationElement targ
204204
{
205205
Task.Delay(500).Wait();
206206
// ログインボタンが消えていたらダイアログも消えていると判断する。
207-
// このあとログインボタンを押すことから、ログインボタンを再利用している。
208-
try
207+
proxyDialogElement = targetRootElement.FindFirst(TreeScope.Descendants, proxyDialogCondition);
208+
if (proxyDialogElement == null)
209209
{
210-
_ = loginButtonElement.Current.ItemType;
211-
_ = loginButtonElement.Current.Name;
212-
_ = loginButtonElement.Current.IsOffscreen;
210+
isProxyDialogClosed = true;
211+
break;
213212
}
214-
catch
213+
loginButtonElement = proxyDialogElement.FindFirst(TreeScope.Descendants, loginButtonCondition);
214+
if (loginButtonElement == null)
215215
{
216-
context.Logger.Log($"login button closed.");
216+
context.Logger.Log($"Login button not found.");
217217
isProxyDialogClosed = true;
218218
break;
219219
}
220+
loginButton = loginButtonElement.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern;
221+
if (loginButton == null)
222+
{
223+
isProxyDialogClosed = true;
224+
break;
225+
}
226+
220227
// ChromeでloginButton.Invoke()の実行までが早すぎて応答しないことがあるので
221228
// ここで二回までリトライする。
222229
if (i < 2)

0 commit comments

Comments
 (0)