// Verifies that each superstate has an initial state and that its // initial state is known. private void VerifyInitialStates(StateRowCollection col) { foreach (StateRow row in col) { if (row.InitialState == null || row.InitialState == string.Empty) { if (row.Substates.Count > 0) { throw new StateMachineBuilderException( "Initial state missing from " + row.Name + " state."); } } else { bool found = false; foreach (StateRow childRow in row.Substates) { if (row.InitialState == childRow.Name) { found = true; break; } } if (!found) { throw new StateMachineBuilderException( "No substate match for initial state."); } } VerifyInitialStates(row.Substates); } }
// Reads all of the state machine's state history types. private void ReadStateHistoryTypes(StateRowCollection col, IDictionary stateHistoryTypes) { foreach (StateRow row in col) { stateHistoryTypes.Add(row.Name, row.HistoryType); ReadStateHistoryTypes(row.Substates, stateHistoryTypes); } }
// Reads all of the state machine's states' initial state. private void ReadStateInitialStates(StateRowCollection col, IDictionary stateInitialStates) { foreach (StateRow row in col) { if (row.InitialState != null && row.InitialState != string.Empty) { stateInitialStates.Add(row.Name, row.InitialState); } ReadStateInitialStates(row.Substates, stateInitialStates); } }
// Reads all of the state machine's substate/superstate relationships. private void ReadStateRelationships(StateRowCollection col, IDictionary stateRelationships) { foreach (StateRow row in col) { foreach (StateRow childRow in row.Substates) { stateRelationships.Add(childRow.Name, row.Name); } ReadStateRelationships(row.Substates, stateRelationships); } }
// Reads all of the state machine's state transitions. private void ReadStateTransitions(StateRowCollection col, IDictionary stateTransitions) { foreach (StateRow row in col) { if (row.Transitions.Count > 0) { stateTransitions.Add(row.Name, row.Transitions); } ReadStateTransitions(row.Substates, stateTransitions); } }
// Reads all of the state machine's guards. private void ReadGuards(StateRowCollection col, ArrayList guards) { foreach (StateRow row in col) { foreach (TransitionRow transRow in row.Transitions) { if (transRow.Guard != null && transRow.Guard != string.Empty && !guards.Contains(transRow.Guard)) { guards.Add(transRow.Guard); } } ReadGuards(row.Substates, guards); } }
// Verifies that all of the targets are known. private void VerifyTargets(StateRowCollection col, ArrayList states) { foreach (StateRow row in col) { foreach (TransitionRow transRow in row.Transitions) { if (transRow.Target != null && transRow.Target != string.Empty && !states.Contains(transRow.Target)) { throw new StateMachineBuilderException( "Unknown target state: " + transRow.Target); } } VerifyTargets(row.Substates, states); } }
// Reads all of the state machine's actions. private void ReadActions(StateRowCollection col, ArrayList actions) { foreach (StateRow row in col) { foreach (TransitionRow transRow in row.Transitions) { foreach (ActionRow actionRow in transRow.Actions) { if (!actions.Contains(actionRow.Name)) { actions.Add(actionRow.Name); } } } ReadActions(row.Substates, actions); } }
// Verifies that the initial state is known. private void VerifyInitialState(StateRowCollection col) { bool found = false; foreach (StateRow row in col) { if (row.Name == InitialState) { found = true; break; } } if (!found) { throw new StateMachineBuilderException( "Initial state is missing or is not a top state."); } }
// Reads all of the state machine's states. private void ReadStates(StateRowCollection col, ArrayList states) { foreach (StateRow row in col) { if (row.Name == null || row.Name == string.Empty) { throw new StateMachineBuilderException( "State name cannot be null or empty."); } else if (states.Contains(row.Name)) { throw new StateMachineBuilderException("Duplicate states not allowed."); } states.Add(row.Name); ReadStates(row.Substates, states); } }
// Reads all of the state machine's events. private void ReadEvents(StateRowCollection col, ArrayList events) { foreach (StateRow row in col) { foreach (TransitionRow transRow in row.Transitions) { if (transRow.Event == null || transRow.Event == string.Empty) { throw new StateMachineBuilderException( "Event cannot be null or empty."); } if (!events.Contains(transRow.Event)) { events.Add(transRow.Event); } } ReadEvents(row.Substates, events); } }