private void OnNewState(State newState) { if (NewState != null) { NewState(this, new EventArgs<State>(newState)); } }
public StateMachine(State initialState, IEnumerable inputAlphabet) { this.initialState = initialState; this.inputAlphabet = new ArrayList(); foreach (object o in inputAlphabet) { this.inputAlphabet.Add(o); } }
private void OnStateWaitingForInput(State state) { if (this.syncContext != null && this.syncContext.InvokeRequired) { this.syncContext.BeginInvoke(new Procedure<State>(OnStateWaitingForInput), new object[] { state }); } else { if (StateWaitingForInput != null) { StateWaitingForInput(this, new EventArgs<State>(state)); } } }
private void SetCurrentState(State newState) { if (this.currentState != null && this.currentState.IsFinalState) { throw new InvalidOperationException("state machine is already in a final state"); } this.currentState = newState; this.currentState.StateMachine = this; OnNewState(this.currentState); this.currentState.OnEnteredState(); if (!this.currentState.IsFinalState) { ProcessQueuedInput(); } }
public override void ProcessInput(object input, out State newState) { if (input.Equals(PrivateInput.GoToReadyToInstall)) { newState = new ReadyToInstallState(this.installerPath, this.newVersionInfo); } else if (input.Equals(PrivateInput.GoToError)) { string errorMessage = PdnResources.GetString("Updates.ExtractingState.GenericError"); newState = new ErrorState(this.exception, errorMessage); } else if (input.Equals(PrivateInput.GoToAborted)) { newState = new AbortedState(); } else { throw new ArgumentException(); } }
public abstract void ProcessInput(object input, out State newState);
public override void ProcessInput(object input, out State newState) { if (input.Equals(PrivateInput.GoToExtracting)) { newState = new ExtractingState(this.zipTempName, this.downloadMe); } else if (input.Equals(PrivateInput.GoToError)) { string errorMessage; if (this.exception is WebException) { errorMessage = Utility.WebExceptionToErrorMessage((WebException)this.exception); } else { errorMessage = PdnResources.GetString("Updates.DownloadingState.GenericError"); } newState = new ErrorState(this.exception, errorMessage); } else if (input.Equals(PrivateInput.GoToAborted)) { newState = new AbortedState(); } else { throw new ArgumentException(); } }