public override sealed async Task RunAsync(IInteractionProvider provider) { OnSubActionStartedOrStopped(0); try { for (int i = 0; !count.HasValue || i < count.Value; i++) { for (;;) { try { provider.EnsureNotCanceled(); OnActionInformationUpdated($"Iteration {i + 1}/{count}"); await action.RunAsync(provider); } catch (Exception ex) when (!(ex is SimulatorCanceledException)) { await provider.CheckRetryForExceptionAsync(ExceptionDispatchInfo.Capture(ex)); continue; } break; } } } finally { OnSubActionStartedOrStopped(null); } }
public override sealed async Task RunAsync(IInteractionProvider provider) { OnSubActionStartedOrStopped(0); try { for (int i = 0; !this.count.HasValue || i < this.count.Value; i++) { while (true) { try { provider.EnsureNotCanceled(); OnActionInformationUpdated($"Iteration {i + 1}/{this.count?.ToString() ?? "∞"}"); await this.action.RunAsync(provider); } catch (Exception ex) when(!(ex is SimulatorCanceledException)) { await provider.CheckRetryForExceptionAsync(ex); continue; } break; } } } finally { OnSubActionStartedOrStopped(null); } }
public override sealed async Task RunAsync(IInteractionProvider provider) { // Run the actions. int currentIdx = -1; var randomOrder = null as int[]; Func <int> getNextActionIndex; if (this.type == CompoundActionType.Sequential) { getNextActionIndex = () => (!this.loop && currentIdx + 1 == this.actionList.Count) ? -1 : currentIdx = (currentIdx + 1) % this.actionList.Count; } else if (this.type == CompoundActionType.RandomIndex) { getNextActionIndex = () => this.rng.Next(this.actionList.Count); } else { randomOrder = new int[this.actionList.Count]; getNextActionIndex = () => { if (!this.loop && currentIdx + 1 == this.actionList.Count) { return(-1); } currentIdx = (currentIdx + 1) % this.actionList.Count; if (currentIdx == 0) { // Generate a new order array. for (int i = 0; i < randomOrder.Length; i++) { randomOrder[i] = i; } for (int i = 0; i < randomOrder.Length; i++) { int rIdx = this.rng.Next(randomOrder.Length - i); int tmp = randomOrder[i]; randomOrder[i] = randomOrder[i + rIdx]; randomOrder[i + rIdx] = tmp; } } return(randomOrder[currentIdx]); }; } while (true) { int nextIdx = getNextActionIndex(); if (nextIdx == -1) { break; } OnActionInformationUpdated($"Running action {nextIdx + 1}"); while (true) { try { // Check if the simulator has already been canceled. provider.EnsureNotCanceled(); OnSubActionStartedOrStopped(nextIdx); try { await this.actionList[nextIdx].RunAsync(provider); } finally { OnSubActionStartedOrStopped(null); } // After running an action, wait. int waitInterval = this.rng.Next(this.minimumPauseDuration, this.maximumPauseDuration); OnActionInformationUpdated($"Pausing {waitInterval} ms"); await provider.WaitAsync(waitInterval); } catch (Exception ex) when(!(ex is SimulatorCanceledException)) { await provider.CheckRetryForExceptionAsync(ex); continue; } break; } } }
public override sealed async Task RunAsync(IInteractionProvider provider) { // Run the actions. int currentIdx = -1; int[] randomOrder = null; Func<int> getNextActionIndex; if (type == CompoundActionType.Sequential) getNextActionIndex = () => (!loop && currentIdx + 1 == actionList.Count) ? -1 : currentIdx = (currentIdx + 1) % actionList.Count; else if (type == CompoundActionType.RandomIndex) getNextActionIndex = () => rng.Next(actionList.Count); else { randomOrder = new int[actionList.Count]; getNextActionIndex = () => { if (!loop && currentIdx + 1 == actionList.Count) return -1; currentIdx = (currentIdx + 1) % actionList.Count; if (currentIdx == 0) { // Generate a new order array. for (int i = 0; i < randomOrder.Length; i++) randomOrder[i] = i; for (int i = 0; i < randomOrder.Length; i++) { int rIdx = rng.Next(randomOrder.Length - i); int tmp = randomOrder[i]; randomOrder[i] = randomOrder[i + rIdx]; randomOrder[i + rIdx] = tmp; } } return randomOrder[currentIdx]; }; } while (true) { int nextIdx = getNextActionIndex(); if (nextIdx == -1) break; OnActionInformationUpdated($"Running action {nextIdx + 1}"); for (;;) { try { // Check if the simulator has already been canceled. provider.EnsureNotCanceled(); OnSubActionStartedOrStopped(nextIdx); try { IAction action = actionList[nextIdx]; await action.RunAsync(provider); } finally { OnSubActionStartedOrStopped(null); } // After running an action, wait. int waitInterval = rng.Next(minimumPauseDuration, maximumPauseDuration); OnActionInformationUpdated($"Pausing {waitInterval} ms"); await provider.WaitAsync(waitInterval); } catch (Exception ex) when (!(ex is SimulatorCanceledException)) { await provider.CheckRetryForExceptionAsync(ExceptionDispatchInfo.Capture(ex)); continue; } break; } } }