提交 aefa753e 编写于 作者: S Sam Harwell

Updates from code review feedback

上级 1d5c75e3
...@@ -13,7 +13,18 @@ namespace Microsoft.VisualStudio.IntegrationTest.Utilities ...@@ -13,7 +13,18 @@ namespace Microsoft.VisualStudio.IntegrationTest.Utilities
public static class AutomationElementExtensions public static class AutomationElementExtensions
{ {
private const int UIA_E_ELEMENTNOTAVAILABLE = unchecked((int)0x80040201); private const int UIA_E_ELEMENTNOTAVAILABLE = unchecked((int)0x80040201);
private const int AutomationRetryCount = 3;
/// <summary>
/// The number of times to retry a UI automation operation that failed with
/// <see cref="UIA_E_ELEMENTNOTAVAILABLE"/>, not counting the initial call. A value of 2 means the operation
/// will be attempted a total of three times.
/// </summary>
private const int AutomationRetryCount = 2;
/// <summary>
/// The delay between retrying a UI automation operation that failed with
/// <see cref="UIA_E_ELEMENTNOTAVAILABLE"/>.
/// </summary>
private static readonly TimeSpan AutomationRetryDelay = TimeSpan.FromMilliseconds(100); private static readonly TimeSpan AutomationRetryDelay = TimeSpan.FromMilliseconds(100);
/// <summary> /// <summary>
...@@ -334,6 +345,7 @@ private static string GetNameForExceptionMessage(this IUIAutomationElement eleme ...@@ -334,6 +345,7 @@ private static string GetNameForExceptionMessage(this IUIAutomationElement eleme
private static void RetryIfNotAvailable<T>(Action<T> action, T state) private static void RetryIfNotAvailable<T>(Action<T> action, T state)
{ {
// NOTE: The loop termination condition if exceptions are thrown is in the exception filter
for (var i = 0; true; i++) for (var i = 0; true; i++)
{ {
try try
...@@ -341,7 +353,7 @@ private static void RetryIfNotAvailable<T>(Action<T> action, T state) ...@@ -341,7 +353,7 @@ private static void RetryIfNotAvailable<T>(Action<T> action, T state)
action(state); action(state);
return; return;
} }
catch (COMException e) when (e.HResult == UIA_E_ELEMENTNOTAVAILABLE && i < AutomationRetryCount - 1) catch (COMException e) when (e.HResult == UIA_E_ELEMENTNOTAVAILABLE && i < AutomationRetryCount)
{ {
Thread.Sleep(AutomationRetryDelay); Thread.Sleep(AutomationRetryDelay);
continue; continue;
...@@ -351,13 +363,14 @@ private static void RetryIfNotAvailable<T>(Action<T> action, T state) ...@@ -351,13 +363,14 @@ private static void RetryIfNotAvailable<T>(Action<T> action, T state)
private static TResult RetryIfNotAvailable<T, TResult>(Func<T, TResult> function, T state) private static TResult RetryIfNotAvailable<T, TResult>(Func<T, TResult> function, T state)
{ {
// NOTE: The loop termination condition if exceptions are thrown is in the exception filter
for (var i = 0; true; i++) for (var i = 0; true; i++)
{ {
try try
{ {
return function(state); return function(state);
} }
catch (COMException e) when (e.HResult == UIA_E_ELEMENTNOTAVAILABLE && i < AutomationRetryCount - 1) catch (COMException e) when (e.HResult == UIA_E_ELEMENTNOTAVAILABLE && i < AutomationRetryCount)
{ {
Thread.Sleep(AutomationRetryDelay); Thread.Sleep(AutomationRetryDelay);
continue; continue;
......
...@@ -288,7 +288,7 @@ public string[] GetLightBulbActions() ...@@ -288,7 +288,7 @@ public string[] GetLightBulbActions()
var view = GetActiveTextView(); var view = GetActiveTextView();
var broker = GetComponentModel().GetService<ILightBulbBroker>(); var broker = GetComponentModel().GetService<ILightBulbBroker>();
return (await GetLightBulbActionsAsync(broker, view)).Select(a => a.DisplayText).ToArray(); return (await GetLightBulbActionsAsync(broker, view).ConfigureAwait(false)).Select(a => a.DisplayText).ToArray();
}); });
} }
...@@ -312,7 +312,7 @@ private async Task<IEnumerable<ISuggestedAction>> GetLightBulbActionsAsync(ILigh ...@@ -312,7 +312,7 @@ private async Task<IEnumerable<ISuggestedAction>> GetLightBulbActionsAsync(ILigh
actionSets = Array.Empty<SuggestedActionSet>(); actionSets = Array.Empty<SuggestedActionSet>();
} }
return await SelectActionsAsync(actionSets); return await SelectActionsAsync(actionSets).ConfigureAwait(false);
} }
public void ApplyLightBulbAction(string actionName, FixAllScope? fixAllScope, bool blockUntilComplete) public void ApplyLightBulbAction(string actionName, FixAllScope? fixAllScope, bool blockUntilComplete)
...@@ -323,7 +323,7 @@ public void ApplyLightBulbAction(string actionName, FixAllScope? fixAllScope, bo ...@@ -323,7 +323,7 @@ public void ApplyLightBulbAction(string actionName, FixAllScope? fixAllScope, bo
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
var activeTextView = GetActiveTextView(); var activeTextView = GetActiveTextView();
await lightBulbAction(activeTextView); await lightBulbAction(activeTextView).ConfigureAwait(false);
}); });
if (blockUntilComplete) if (blockUntilComplete)
...@@ -400,7 +400,7 @@ private async Task<IEnumerable<ISuggestedAction>> SelectActionsAsync(IEnumerable ...@@ -400,7 +400,7 @@ private async Task<IEnumerable<ISuggestedAction>> SelectActionsAsync(IEnumerable
foreach (var action in actionSet.Actions) foreach (var action in actionSet.Actions)
{ {
actions.Add(action); actions.Add(action);
actions.AddRange(await SelectActionsAsync(await action.GetActionSetsAsync(CancellationToken.None))); actions.AddRange(await SelectActionsAsync(await action.GetActionSetsAsync(CancellationToken.None).ConfigureAwait(false)).ConfigureAwait(false));
} }
} }
} }
...@@ -426,8 +426,8 @@ private static async Task<FixAllSuggestedAction> GetFixAllSuggestedActionAsync(I ...@@ -426,8 +426,8 @@ private static async Task<FixAllSuggestedAction> GetFixAllSuggestedActionAsync(I
if (action.HasActionSets) if (action.HasActionSets)
{ {
var nestedActionSets = await action.GetActionSetsAsync(CancellationToken.None); var nestedActionSets = await action.GetActionSetsAsync(CancellationToken.None).ConfigureAwait(false);
fixAllSuggestedAction = await GetFixAllSuggestedActionAsync(nestedActionSets, fixAllScope); fixAllSuggestedAction = await GetFixAllSuggestedActionAsync(nestedActionSets, fixAllScope).ConfigureAwait(false);
if (fixAllSuggestedAction != null) if (fixAllSuggestedAction != null)
{ {
return fixAllSuggestedAction; return fixAllSuggestedAction;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册