private ReturnCode ExecuteDefine(Interpreter interpreter, ArgumentList arguments, ref Result result) { var fsmArray = arguments[2]; var initialState = arguments[3]; InternalLogger.Info($"Defining FSM with array {fsmArray} to initial state {initialState}"); if (!TclUtils.ArrayExists(interpreter, fsmArray)) { var fsmTransArrayError = $"Array of fsm states with name: {fsmArray} does not exist (is not defined)."; ErrorLogger.Error(fsmTransArrayError); result = fsmTransArrayError; return(ReturnCode.Error); } InternalLogger.Debug($"Retrieving all FSM transitions from {fsmArray} FSM array."); IReadOnlyList <FsmTransition> fsmTransitions; if (!FsmUtils.TryGetFsmTransitions(interpreter, fsmArray, out fsmTransitions)) { var transitionsFailed = $"Failed to retrieve FSM transition from {fsmArray} array."; ErrorLogger.Error(transitionsFailed); result = transitionsFailed; return(ReturnCode.Error); } InternalLogger.Info($"Assigning all {fsmTransitions.Count} into internal transitions set."); _transitions.Clear(); foreach (var fsmTransition in fsmTransitions) { InternalLogger.Debug($"Adding FSM transition: {fsmTransition}"); _transitions.Add(fsmTransition); } InternalLogger.Info($"Checking whether {initialState} state is defined in transition set."); if (!ContainsState(initialState)) { var stateNotFound = $"State {initialState} was not found in defined transitions. Known states are:\n{string.Join(",", DumpStates())}"; ErrorLogger.Error(stateNotFound); result = stateNotFound; return(ReturnCode.Error); } CurrentState = initialState; ResultLogger.Info($"FSM successfully defined to initial state: {initialState}"); return(ReturnCode.Ok); }
private ReturnCode ExecuteSetState(ArgumentList arguments, ref Result result) { var fsmState = arguments[2]; InternalLogger.Info($"Executing FSM setstate with next state to be {fsmState}"); if (!ContainsState(fsmState)) { var stateNotFound = $"State {fsmState} was not found in defined transitions. Known states are:\n{string.Join(",", DumpStates())}"; ErrorLogger.Error(stateNotFound); result = stateNotFound; return(ReturnCode.Error); } _overriddenNextState = fsmState; ResultLogger.Info($"Next FSM state successfully set to be {fsmState}."); return(ReturnCode.Ok); }