private void RefreshCurrentVariables() { try { Logger.Debug("Refreshing current variables and their values."); WatchVariables = TclUtils.GetVariableValues(_interpreter, true); } catch (Exception e) { Logger.Error(e, "Error while refreshing current variables."); } }
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 string InsertBreakpoints(string text) { var sb = new StringBuilder(text.Length * 2); int lineNumber = 1; foreach (string line in new LineReader(() => new StringReader(text))) { if (!String.IsNullOrWhiteSpace(line) && !TclUtils.IsCommentLine(line)) { sb.AppendLine(CreateBeakpointText(lineNumber)); } sb.AppendLine(line); lineNumber++; } return(sb.ToString()); }
private ReturnCode ExecuteRaiseEvent(Interpreter interpreter, ArgumentList arguments, ref Result result) { var raisedEvent = arguments[2]; InternalLogger.Info($"Executing {raisedEvent} event."); if (!CiscoTclEvents.All.Contains(raisedEvent.String)) { var unknownEvent = $"Event {raisedEvent} is not valid Cisco TCL event.\nValid CiscoTcl events are: [{string.Join(", ", CiscoTclEvents.All)}]"; ErrorLogger.Error(unknownEvent); result = unknownEvent; return(ReturnCode.Error); } var transition = DetermineCurrentTransition(raisedEvent); if (transition == null) { var transitionNotDefined = $"Transition for event {raisedEvent} is not defined in FSM."; ErrorLogger.Warn(transitionNotDefined); result = transitionNotDefined; //transition is not defined, but it's not an error, just don't perform any transitions return(ReturnCode.Ok); } InternalLogger.Info($"Found transition for event {raisedEvent} is {transition}."); if (!TclUtils.ProcedureExists(interpreter, transition.Procedure)) { var procedureNotExists = $"Procedure {transition.Procedure} which is defined in transition {transition} does not exist."; ErrorLogger.Error(procedureNotExists); result = procedureNotExists; return(ReturnCode.Error); } var code = interpreter.EvaluateScript($"{transition.Procedure}", ref result); if (code != ReturnCode.Ok) { var error = $"Error occured while executing procedure {transition.Procedure}. Error: {result.String}"; ErrorLogger.Error(error); result = error; return(ReturnCode.Error); } var nextStateToSet = DetermineNextState(transition); if (!ContainsState(nextStateToSet)) { var notDefinedState = $"Target state {nextStateToSet} defined in transition is not defined in FSM transitions."; ErrorLogger.Error(notDefinedState); result = notDefinedState; return(ReturnCode.Error); } CurrentState = nextStateToSet; //unset overridden state no matter if it was or was not used _overriddenNextState = string.Empty; ResultLogger.Info($"Successfully raised {raisedEvent} and set FSM to state {nextStateToSet}"); return(ReturnCode.Ok); }