public void Stop() { NetworkInformation.NetworkStatusChanged -= NetworkInformation_NetworkStatusChanged; Canceller?.Cancel(); Canceller = null; Started = false; }
protected override IEnumerator RespondToCommandInternal(string inputCommand) { if (!inputCommand.StartsWith("move ", StringComparison.InvariantCultureIgnoreCase)) { yield break; } inputCommand = inputCommand.Substring(5); MatchCollection matches = Regex.Matches(inputCommand, @"[udlr]", RegexOptions.IgnoreCase); if (matches.Count > 35) { yield return("elevator music"); } foreach (Match move in matches) { KeypadButton button = _buttons[buttonIndex[move.Value.ToLowerInvariant()]]; if (button != null) { yield return(move.Value); if (Canceller.ShouldCancel) { Canceller.ResetCancel(); yield break; } yield return(DoInteractionClick(button)); } } }
protected override IEnumerator RespondToCommandInternal(string inputCommand) { if (!inputCommand.StartsWith("press ", StringComparison.InvariantCultureIgnoreCase)) { yield break; } inputCommand = inputCommand.Substring(6); foreach (char buttonString in inputCommand) { int val = buttonString - '0'; if (val >= 0 && val <= 9) { MonoBehaviour button = (MonoBehaviour)_buttons.GetValue(val); yield return(buttonString); if (Canceller.ShouldCancel) { Canceller.ResetCancel(); yield break; } yield return(DoInteractionClick(button)); } } }
protected override IEnumerator RespondToCommandInternal(string inputCommand) { if (!inputCommand.StartsWith("press ", StringComparison.InvariantCultureIgnoreCase)) { yield break; } inputCommand = inputCommand.Substring(6); string sequence = "pressing "; foreach (Match move in Regex.Matches(inputCommand, @"(\b(red|blue|green|yellow)\b|[rbgy])", RegexOptions.IgnoreCase)) { SimonButton button = _buttons[buttonIndex[move.Value.Substring(0, 1).ToLowerInvariant()]]; if (button != null) { yield return(move.Value); sequence += move.Value + " "; if (Canceller.ShouldCancel) { Canceller.ResetCancel(); yield break; } yield return(DoInteractionClick(button, sequence)); } } }
protected override IEnumerator RespondToCommandInternal(string inputCommand) { inputCommand = inputCommand.ToLowerInvariant(); if (inputCommand.EqualsAny("submit", "check")) { yield return("Checking for leaks Kappa"); yield return(DoInteractionClick(_check)); yield break; } if (!inputCommand.StartsWith("rotate ")) { yield break; } inputCommand = inputCommand.Substring(6); string[] sequence = inputCommand.ToLowerInvariant().Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries); List <MonoBehaviour> pipes = new List <MonoBehaviour>(); bool elevator = false; foreach (string buttonString in sequence) { var letters = "abcdef"; var numbers = "123456"; if (buttonString.Length != 2 || letters.IndexOf(buttonString[0]) < 0 || numbers.IndexOf(buttonString[1]) < 0) { continue; } var row = numbers.IndexOf(buttonString[1]); var col = letters.IndexOf(buttonString[0]); MonoBehaviour button = _pipes[row][col]; pipes.Add(button); elevator |= pipes.FindAll(x => x == button).Count >= 4; } if (pipes.Count > 0) { yield return(inputCommand); if (elevator) { yield return("elevator music"); } } foreach (MonoBehaviour button in pipes) { if (Canceller.ShouldCancel) { Canceller.ResetCancel(); yield break; } yield return(DoInteractionClick(button)); } }
private IEnumerator SolveCoroutine(string word) { char[] characters = word.ToCharArray(); for (int characterIndex = 0; characterIndex < characters.Length; ++characterIndex) { if (Canceller.ShouldCancel) { Canceller.ResetCancel(); yield break; } CharSpinner spinner = _spinners[characterIndex]; IEnumerator subcoroutine = GetCharacterSpinnerToCharacterCoroutine(spinner, characters[characterIndex]); while (subcoroutine.MoveNext()) { yield return(subcoroutine.Current); } //Break out of the sequence if a column spinner doesn't have a matching character if (char.ToLowerInvariant(spinner.GetCurrentChar()) != char.ToLowerInvariant(characters[characterIndex])) { yield return("unsubmittablepenalty"); yield break; } } yield return(DoInteractionClick(_submitButton)); }
private IEnumerator ReleaseCoroutine(int second) { yield return("release"); TimerComponent timerComponent = BombCommander.Bomb.GetTimer(); string secondString = second.ToString(); float timeRemaining = float.PositiveInfinity; while (timeRemaining > 0.0f && _held) { if (Canceller.ShouldCancel) { Canceller.ResetCancel(); yield break; } timeRemaining = timerComponent.TimeRemaining; if (BombCommander.CurrentTimerFormatted.Contains(secondString)) { DoInteractionEnd(_button); _held = false; } yield return(null); } }
private IEnumerator ReleaseCoroutine(int second) { yield return("release"); MonoBehaviour timerComponent = (MonoBehaviour)CommonReflectedTypeInfo.GetTimerMethod.Invoke(BombCommander.Bomb, null); string secondString = second.ToString(); float timeRemaining = float.PositiveInfinity; while (timeRemaining > 0.0f) { if (Canceller.ShouldCancel) { Canceller.ResetCancel(); yield break; } timeRemaining = (float)CommonReflectedTypeInfo.TimeRemainingField.GetValue(timerComponent); string formattedTime = (string)CommonReflectedTypeInfo.GetFormattedTimeMethod.Invoke(null, new object[] { timeRemaining, true }); if (formattedTime.Contains(secondString)) { DoInteractionEnd(_button); _held = false; break; } yield return(null); } }
protected override IEnumerator RespondToCommandInternal(string inputCommand) { string[] commandParts = inputCommand.ToLowerInvariant().Split(' '); if (commandParts.Length != 2) { yield break; } if (!commandParts[0].EqualsAny("rotate", "turn")) { yield break; } if (!int.TryParse(commandParts[1], out int totalTurnCount)) { yield break; } totalTurnCount = totalTurnCount % 4; yield return("rotate"); for (int turnCount = 0; turnCount < totalTurnCount; ++turnCount) { if (Canceller.ShouldCancel) { Canceller.ResetCancel(); yield break; } yield return(DoInteractionClick(_pointingKnob)); } }
private IEnumerator SolveCoroutine(string word) { char[] characters = word.ToCharArray(); for (int characterIndex = 0; characterIndex < characters.Length; ++characterIndex) { if (Canceller.ShouldCancel) { Canceller.ResetCancel(); yield break; } MonoBehaviour spinner = GetCharSpinner(characterIndex); IEnumerator subcoroutine = GetCharacterSpinnerToCharacterCoroutine(spinner, characters[characterIndex]); while (subcoroutine.MoveNext()) { yield return(subcoroutine.Current); } //Break out of the sequence if a column spinner doesn't have a matching character if (GetCurrentChar(spinner) != characters[characterIndex]) { yield break; } } DoInteractionStart(_submitButton); yield return(new WaitForSeconds(0.1f)); DoInteractionEnd(_submitButton); }
protected override IEnumerator RespondToCommandInternal(string inputCommand) { if (!inputCommand.StartsWith("cut ", StringComparison.InvariantCultureIgnoreCase)) { yield break; } inputCommand = inputCommand.Substring(4); foreach (Match wireIndexString in Regex.Matches(inputCommand, @"[1-6]")) { if (!int.TryParse(wireIndexString.Value, out int wireIndex)) { continue; } wireIndex--; if (wireIndex >= 0 && wireIndex < _wires.Length) { if (_wires[wireIndex].Snipped) { continue; } yield return(wireIndexString.Value); if (Canceller.ShouldCancel) { Canceller.ResetCancel(); yield break; } VennSnippableWire wire = _wires[wireIndex]; yield return(DoInteractionClick(wire, string.Format("cutting wire {0}", wireIndexString.Value))); } } }
protected override IEnumerator RespondToCommandInternal(string inputCommand) { if (!inputCommand.StartsWith("press ", StringComparison.InvariantCultureIgnoreCase)) { yield break; } inputCommand = inputCommand.Substring(6); string[] sequence = inputCommand.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries); List <MonoBehaviour> buttons = new List <MonoBehaviour>(); foreach (string buttonString in sequence) { if (!int.TryParse(buttonString, out int val) || val < 1 || val > 8) { yield break; } MonoBehaviour button = (MonoBehaviour)_buttons.GetValue(val - 1); buttons.Add(button); } yield return(inputCommand); foreach (MonoBehaviour button in buttons) { if (Canceller.ShouldCancel) { Canceller.ResetCancel(); yield break; } yield return(DoInteractionClick(button)); } }
private IEnumerator ReleaseCoroutineVanilla(int second) { yield return("release"); TimerComponent timerComponent = BombCommander.Bomb.GetTimer(); string secondString = second.ToString(); float timeRemaining = float.PositiveInfinity; while (timeRemaining > 0.0f && _held) { if (Canceller.ShouldCancel) { Canceller.ResetCancel(); yield return(string.Format("sendtochat The button was not {0} due to a request to cancel.", _held ? "released" : "tapped")); yield break; } timeRemaining = timerComponent.TimeRemaining; if (BombCommander.CurrentTimerFormatted.Contains(secondString)) { DoInteractionEnd(_button); _held = false; } yield return(null); } }
private IEnumerator SolveCoroutine(string word) { char[] characters = word.ToCharArray(); for (int characterIndex = 0; characterIndex < characters.Length; ++characterIndex) { if (Canceller.ShouldCancel) { Canceller.ResetCancel(); yield break; } IEnumerator subcoroutine = GetCharacterSpinnerToCharacterCoroutine(characterIndex, characters[characterIndex].ToString()); while (subcoroutine.MoveNext()) { yield return(subcoroutine.Current); } //Break out of the sequence if a column spinner doesn't have a matching character if (!_display[characterIndex].text.Equals(characters[characterIndex].ToString(), StringComparison.InvariantCultureIgnoreCase)) { yield return("unsubmittablepenalty"); yield break; } } yield return(DoInteractionClick(_submitButton)); }
public void Stop() { ActualTimers.Stop(); Canceller.Cancel(); DisconnectOrWhatever(); IrcThread.Join(); }
protected override IEnumerator RespondToCommandInternal(string inputCommand) { if (ProcessMethod == null) { Debug.LogError("A declared TwitchPlays SimpleModComponentSolver process method is <null>, yet a component solver has been created; command invokation will not continue."); yield break; } KMSelectable[] selectableSequence = null; try { selectableSequence = (KMSelectable[])ProcessMethod.Invoke(CommandComponent, new object[] { inputCommand }); if (selectableSequence == null || selectableSequence.Length == 0) { yield break; } } catch (Exception ex) { Debug.LogErrorFormat("An exception occurred while trying to invoke {0}.{1}; the command invokation will not continue.", ProcessMethod.DeclaringType.FullName, ProcessMethod.Name); Debug.LogException(ex); yield break; } yield return("modsequence"); int beforeInteractionStrikeCount = StrikeCount; for (int selectableIndex = 0; selectableIndex < selectableSequence.Length; ++selectableIndex) { if (Canceller.ShouldCancel) { Canceller.ResetCancel(); yield break; } KMSelectable selectable = selectableSequence[selectableIndex]; if (selectable == null) { yield return(new WaitForSeconds(0.1f)); continue; } DoInteractionStart(selectable); yield return(new WaitForSeconds(0.1f)); DoInteractionEnd(selectable); //Escape the sequence if a part of the given sequence is wrong, or if part of the sequence solved the module. //This means it is no longer possible to death warp a bomb in twitch plays. Kappa Keepo if (StrikeCount != beforeInteractionStrikeCount || Solved) { yield break; } } }
protected override IEnumerator RespondToCommandInternal(string inputCommand) { string[] commandParts = inputCommand.Split(' '); if (commandParts.Length != 2) { yield break; } if (!commandParts[0].Equals("transmit", StringComparison.InvariantCultureIgnoreCase) && !commandParts[0].Equals("trans", StringComparison.InvariantCultureIgnoreCase) && !commandParts[0].Equals("xmit", StringComparison.InvariantCultureIgnoreCase) && !commandParts[0].Equals("tx", StringComparison.InvariantCultureIgnoreCase)) { yield break; } int targetFrequency = 0; if (!int.TryParse(commandParts[1].Substring(commandParts[1].Length - 3), out targetFrequency)) { yield break; } if (!Frequencies.Contains(targetFrequency)) { yield break; } int initialFrequency = CurrentFrequency; MonoBehaviour buttonToShift = targetFrequency < initialFrequency ? _downButton : _upButton; while (CurrentFrequency != targetFrequency && (CurrentFrequency == initialFrequency || Mathf.Sign(CurrentFrequency - initialFrequency) != Mathf.Sign(CurrentFrequency - targetFrequency))) { yield return("change frequency"); if (Canceller.ShouldCancel) { Canceller.ResetCancel(); yield break; } DoInteractionStart(buttonToShift); yield return(new WaitForSeconds(0.1f)); DoInteractionEnd(buttonToShift); } if (CurrentFrequency == targetFrequency) { yield return("transmit"); DoInteractionStart(_transmitButton); yield return(new WaitForSeconds(0.1f)); DoInteractionEnd(_transmitButton); } }
/// <summary> /// Cancels any current feed refresh attempt and clears the error state when the user starts changing the feed URI. /// </summary> private void LinkTextBox_TextChangedAfterFeedLinkChanged(object sender, TextChangedEventArgs e) { if (LinkTextBox.Text.Trim() == ViewModel.CurrentFeed.LinkAsString) { return; } LinkTextBox.TextChanged -= LinkTextBox_TextChangedAfterFeedLinkChanged; Canceller.Cancel(); ClearErrorState(); }
public void Finish() { NetworkInformation.NetworkStatusChanged -= NetworkInformation_NetworkStatusChanged; if (Canceller != null) { Canceller.Cancel(); Canceller = null; } Clear(); Started = false; }
protected override IEnumerator RespondToCommandInternal(string inputCommand) { if (inputCommand.Equals("submit", StringComparison.InvariantCultureIgnoreCase) || inputCommand.Equals("check", StringComparison.InvariantCultureIgnoreCase)) { yield return("Checking for leaks Kappa"); DoInteractionStart(_check); yield return(new WaitForSeconds(0.1f)); DoInteractionEnd(_check); yield break; } if (!inputCommand.StartsWith("rotate ", StringComparison.InvariantCultureIgnoreCase)) { yield break; } inputCommand = inputCommand.Substring(6); string[] sequence = inputCommand.ToLowerInvariant().Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries); foreach (string buttonString in sequence) { var letters = "abcdef"; var numbers = "123456"; if (buttonString.Length != 2 || letters.IndexOf(buttonString[0]) < 0 || numbers.IndexOf(buttonString[1]) < 0) { continue; } var row = numbers.IndexOf(buttonString[1]); var col = letters.IndexOf(buttonString[0]); MonoBehaviour button = _pipes[row][col]; yield return(buttonString); if (Canceller.ShouldCancel) { Canceller.ResetCancel(); yield break; } DoInteractionStart(button); yield return(new WaitForSeconds(0.1f)); DoInteractionEnd(button); } }
protected override IEnumerator RespondToCommandInternal(string inputCommand) { if (!inputCommand.StartsWith("cut ", StringComparison.InvariantCultureIgnoreCase)) { yield break; } inputCommand = inputCommand.Substring(4); int beforeButtonStrikeCount = StrikeCount; foreach (Match wireIndexString in Regex.Matches(inputCommand, @"[1-6]")) { int wireIndex = 0; if (!int.TryParse(wireIndexString.Value, out wireIndex)) { continue; } wireIndex--; if (wireIndex >= 0 && wireIndex < _wires.Length) { if (_cutWires[wireIndex]) { continue; } _cutWires[wireIndex] = true; yield return(wireIndexString.Value); if (Canceller.ShouldCancel) { Canceller.ResetCancel(); yield break; } MonoBehaviour wire = (MonoBehaviour)_wires.GetValue(wireIndex); DoInteractionStart(wire); yield return(new WaitForSeconds(0.1f)); DoInteractionEnd(wire); //Escape the sequence if a part of the given sequence is wrong if (StrikeCount != beforeButtonStrikeCount || Solved) { break; } } } }
protected override IEnumerator RespondToCommandInternal(string inputCommand) { string[] commandParts = inputCommand.ToLowerInvariant().Split(' '); if (commandParts.Length != 2) { yield break; } if (!commandParts[0].EqualsAny("transmit", "trans", "xmit", "tx", "submit")) { yield break; } if (!int.TryParse(commandParts[1].Substring(commandParts[1].Length - 3), out int targetFrequency)) { yield break; } if (!Frequencies.Contains(targetFrequency)) { yield break; } int initialFrequency = CurrentFrequency; MonoBehaviour buttonToShift = targetFrequency < initialFrequency ? _downButton : _upButton; while (CurrentFrequency != targetFrequency && (CurrentFrequency == initialFrequency || Mathf.Sign(CurrentFrequency - initialFrequency) != Mathf.Sign(CurrentFrequency - targetFrequency))) { yield return("change frequency"); if (Canceller.ShouldCancel) { Canceller.ResetCancel(); yield break; } yield return(DoInteractionClick(buttonToShift)); } if (CurrentFrequency == targetFrequency) { yield return("transmit"); yield return(DoInteractionClick(_transmitButton)); } }
protected override IEnumerator RespondToCommandInternal(string inputCommand) { if (ProcessMethod == null) { Debug.LogError("A declared TwitchPlays SimpleModComponentSolver process method is <null>, yet a component solver has been created; command invokation will not continue."); yield break; } KMSelectable[] selectableSequence = null; try { selectableSequence = (KMSelectable[])ProcessMethod.Invoke(CommandComponent, new object[] { inputCommand }); if (selectableSequence == null || selectableSequence.Length == 0) { yield break; } } catch (Exception ex) { Debug.LogErrorFormat("An exception occurred while trying to invoke {0}.{1}; the command invokation will not continue.", ProcessMethod.DeclaringType.FullName, ProcessMethod.Name); Debug.LogException(ex); yield break; } yield return "modsequence"; for(int selectableIndex = 0; selectableIndex < selectableSequence.Length; ++selectableIndex) { if (Canceller.ShouldCancel) { Canceller.ResetCancel(); yield break; } KMSelectable selectable = selectableSequence[selectableIndex]; if (selectable == null) { yield return new WaitForSeconds(0.1f); continue; } DoInteractionClick(selectable); yield return new WaitForSeconds(0.1f); } }
private IEnumerator SetDial(int pos, int value) { yield return("move dial " + pos + " by " + value + " clicks"); value = ((value % 12) + 12) % 12; for (int i = 0; i < value; i++) { yield return(DoInteractionClick(_buttons[pos])); if (Canceller.ShouldCancel) { yield return("sendtochat Setting the " + DialNames[pos] + " dial on safety safe was interrupted due to a request to cancel."); Canceller.ResetCancel(); yield break; } } }
private IEnumerator CycleCharacterSpinnerCoroutine(int index) { yield return("cycle"); KMSelectable downButton = _downButtons[index]; for (int hitCount = 0; hitCount < 6; ++hitCount) { if (Canceller.ShouldCancel) { Canceller.ResetCancel(); yield break; } yield return(DoInteractionClick(downButton)); yield return(new WaitForSeconds(1.0f)); } }
private IEnumerator CycleCharacterSpinnerCoroutine(CharSpinner spinner) { yield return("cycle"); KeypadButton downButton = spinner.DownButton; for (int hitCount = 0; hitCount < 6; ++hitCount) { if (Canceller.ShouldCancel) { Canceller.ResetCancel(); yield break; } yield return(DoInteractionClick(downButton)); yield return(new WaitForSeconds(1.0f)); } }
/// <summary> /// Runs a number of web services and then block until shutdown. /// </summary> public static async Task StartAsync() { var exitevt = new ManualResetEventSlim(false); // start all services // for (int i = 0; i < services.Count; i++) { var svc = services.ValueAt(i); await svc.StartAsync(Canceller.Token); } // handle SIGTERM and CTRL_C AppDomain.CurrentDomain.ProcessExit += (sender, eventArgs) => { Canceller.Cancel(false); exitevt.Set(); // release the Main thread }; Console.CancelKeyPress += (sender, eventArgs) => { Canceller.Cancel(false); exitevt.Set(); // release the Main thread // Don't terminate the process immediately, wait for the Main thread to exit gracefully. eventArgs.Cancel = true; }; Console.WriteLine("CTRL + C to shut down"); Lifetime.NotifyStarted(); // wait on the reset event exitevt.Wait(Canceller.Token); Lifetime.StopApplication(); for (int i = 0; i < services.Count; i++) { var svc = services.ValueAt(i); await svc.StopAsync(Canceller.Token); } Lifetime.NotifyStopped(); }
private IEnumerator CycleCharacterSpinnerCoroutine(MonoBehaviour spinner) { yield return("cycle"); MonoBehaviour downButton = (MonoBehaviour)_downButtonField.GetValue(spinner); for (int hitCount = 0; hitCount < 6; ++hitCount) { if (Canceller.ShouldCancel) { Canceller.ResetCancel(); yield break; } DoInteractionStart(downButton); yield return(new WaitForSeconds(0.1f)); DoInteractionEnd(downButton); yield return(new WaitForSeconds(1.0f)); } }
protected override IEnumerator RespondToCommandInternal(string inputCommand) { if (!inputCommand.StartsWith("press ", StringComparison.InvariantCultureIgnoreCase)) { yield break; } inputCommand = inputCommand.Substring(6); int beforeButtonStrikeCount = StrikeCount; string[] sequence = inputCommand.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries); foreach (string buttonString in sequence) { int val = -1; if (int.TryParse(buttonString, out val) && val >= 1 && val <= 8) { MonoBehaviour button = (MonoBehaviour)_buttons.GetValue(val - 1); yield return(buttonString); if (Canceller.ShouldCancel) { Canceller.ResetCancel(); yield break; } DoInteractionStart(button); yield return(new WaitForSeconds(0.1f)); DoInteractionEnd(button); //Escape the sequence if a part of the given sequence is wrong if (StrikeCount != beforeButtonStrikeCount || Solved) { yield break; } } } }
protected override IEnumerator RespondToCommandInternal(string inputCommand) { string[] commandParts = inputCommand.Split(' '); if (commandParts.Length != 2) { yield break; } if (!commandParts[0].Equals("rotate", StringComparison.InvariantCultureIgnoreCase) && !commandParts[0].Equals("turn", StringComparison.InvariantCultureIgnoreCase)) { yield break; } int totalTurnCount = 0; if (!int.TryParse(commandParts[1], out totalTurnCount)) { yield break; } totalTurnCount = totalTurnCount % 4; yield return("rotate"); for (int turnCount = 0; turnCount < totalTurnCount; ++turnCount) { if (Canceller.ShouldCancel) { Canceller.ResetCancel(); yield break; } DoInteractionStart(_pointingKnob); yield return(new WaitForSeconds(0.1f)); DoInteractionEnd(_pointingKnob); } }