public void AddTransitionNameMap(GQHSMTransition transition) { string tName = transition.GetFullName(); // find state this transition is associated with GQHSMState state = GetState(transition.GetSourceStateID()); if (state != null) { tName = state.GetFullName() + "." + tName; } if (transition.GuardCondition.Length == 0) { if (!_nameToTransitionMap.ContainsKey(tName)) { _nameToTransitionMap.Add(tName, transition); } else { Logger.Error("Duplicate name in transitions {0}\n", tName); } } else { _nameToGuardedTransitionMultiMap.Add(tName, transition); } }
/// <summary> /// Parse Timeout Expressions /// single float (i.e. 1.0, 0.1, etc converts to TimeSpan.FromSeconds(value) /// every float (i.e. "every 1.0") repeats timeout every TimeSpan.FromSeconds(value) /// at DateTime (i.e. "at Sat, 01 Nov 2008 19:35:00 GMT") does single at DateTime.Parse(value) /// </summary> /// <param name="transition"></param> /// <param name="expression"></param> public void RegisterTimeOutExpression(GQHSMTransition transition, string expression) { string timeOutExpression = expression.Trim(); string eventSignal = transition.EventSignal; if (transition.EventSignal.Length > 0) { eventSignal = transition.EventSignal; } else { eventSignal = transition.Name; } if (timeOutExpression.IndexOf(" ") == -1) { double timeOut = 0.0f; GQHSMAction action = null; if (!Double.TryParse(timeOutExpression, out timeOut)) { action = new GQHSMAction(this, timeOutExpression); } RegisterTimeOutExpression(transition.GetSourceStateID(), new GQHSMTimeOut(transition.State[0].Name + "." + transition.GetFullName(), TimeSpan.FromSeconds(timeOut), new QEvent(eventSignal), action)); } else { string[] strList = timeOutExpression.Split(' '); string timeOutValue = strList [strList.Length - 1].Trim(); TimeOutType flag = TimeOutType.Single; if (timeOutExpression.StartsWith("every")) { flag = TimeOutType.Repeat; } if (timeOutExpression.StartsWith("at")) { flag = TimeOutType.Single; DateTime dt; GQHSMAction action = null; if (!DateTime.TryParse(timeOutValue, out dt)) { action = new GQHSMAction(this, timeOutValue); } RegisterTimeOutExpression(transition.GetSourceStateID(), new GQHSMTimeOut(transition.State[0].Name + "." + transition.GetFullName(), dt, new QEvent(eventSignal), action)); } else { Double timeOut = 0.0f; GQHSMAction action = null; if (!Double.TryParse(timeOutValue, out timeOut)) { action = new GQHSMAction(this, timeOutValue); } RegisterTimeOutExpression(transition.GetSourceStateID(), new GQHSMTimeOut(transition.State[0].Name + "." + transition.GetFullName(), TimeSpan.FromSeconds(timeOut), new QEvent(eventSignal), flag, action)); } } }