/// <summary>Proceed input sequence through FSM</summary> /// <param name="inputSequence">Input sequence of '0' and '1' symbols</param> /// <returns>Sequence of the FSM execution</returns> public string Process(string inputSequence) { char currentState = '$'; var statesSequence = new List <char>(); statesSequence.Add(currentState); foreach (var symbol in inputSequence.ToArray()) { currentState = TransitionsTable.Single(t => t.State == currentState).GetNewState(symbol); statesSequence.Add(currentState); } return(new string(statesSequence.ToArray())); }
/// <summary> /// Initializes a new instance of the <see cref="Context"/> class. /// </summary> /// <param name="transitionsTable">The transitions table, which holds the structure of the inner states</param> /// <exception cref="ArgumentNullException">transitionsTable</exception> /// <exception cref="InvalidConfigException"></exception> public Context(TransitionsTable transitionsTable) { if (transitionsTable == null) throw new ArgumentNullException(nameof(transitionsTable)); //Find inital state foreach (var transitionEntry in transitionsTable) { this.transitionsDict.Add(transitionEntry.Transition, stateFactory.CreateState(transitionEntry.StateType, transitionEntry.StateName)); #if NET35 if (transitionEntry.Transition.ToString().Contains("Initial")) this.InitialState = this.transitionsDict[transitionEntry.Transition]; #else if (transitionEntry.Transition.ToString().Contains("Initial", StringComparison.Ordinal)) this.InitialState = this.transitionsDict[transitionEntry.Transition]; #endif } if (this.InitialState == null) throw new InvalidConfigException(EM.EMSm.Properties.Resources.NoInitialStateDefinedMessage); this.CurrentState = this.InitialState; }