Exemple #1
0
 protected void RaiseStateChange(EventHandler handler, ILQHsm hsm, LogStateEventArgs logEvent)
 {
     if (handler != null)
     {
         handler(hsm, logEvent);
     }
 }
 protected void DoLifeCycleChange(IQHsmLifeCycleManager lifeCycleManager, ILQHsm hsm, QHsmLifeCycleChangeType lifeCycleChangeType)
 {
     if (OnLifeCycleChange (lifeCycleManager, hsm, lifeCycleChangeType))
     {
         RaiseLifeCycleChange (LifeCycleChange, lifeCycleManager, hsm, lifeCycleChangeType);
     }
 }
Exemple #3
0
 protected void DoLifeCycleChange(IQHsmLifeCycleManager lifeCycleManager, ILQHsm hsm, QHsmLifeCycleChangeType lifeCycleChangeType)
 {
     if (OnLifeCycleChange(lifeCycleManager, hsm, lifeCycleChangeType))
     {
         RaiseLifeCycleChange(LifeCycleChange, lifeCycleManager, hsm, lifeCycleChangeType);
     }
 }
Exemple #4
0
        private void _Hsm_StateChange_Internal(ILQHsm hsm, LogStateEventArgs ea)
        {
            string currentStateName      = null;
            string currentTransitionName = null;

            switch (ea.LogType)
            {
            case StateLogType.EventTransition:
            {
                currentStateName      = ea.State.Method.Name;
                currentTransitionName = ea.EventDescription;
            }
            break;

            case StateLogType.Init:
            {
                currentStateName = ea.NextState.Method.Name;
            } break;

            case StateLogType.Restored:
            case StateLogType.Entry:
            case StateLogType.Final:
            {
                currentStateName = ea.State.Method.Name;
            } break;
            }

            if (currentStateName != null)
            {
                RefreshCurrentStateView(currentStateName, currentTransitionName);
            }
        }
        private void _Hsm_StateChange(object sender, EventArgs e)
        {
            ILQHsm            hsm = (ILQHsm)sender;
            LogStateEventArgs sa  = (LogStateEventArgs)e;

            switch (sa.LogType)
            {
            case StateLogType.Init:
            case StateLogType.Entry:
            case StateLogType.Exit:
            {
                Logger.Info("StateChange: [{0} - {1}] {2} {3}", hsm.Id, hsm, sa.LogType, StateNameFrom(sa.State));
            }
            break;

            case StateLogType.EventTransition:
            {
                Logger.Info("StateChange: [{0} - {1}] {2} {3} {4} {5}",
                            hsm.Id,
                            hsm,
                            sa.LogType,
                            StateNameFrom(sa.State),
                            StateNameFrom(sa.NextState), sa.EventDescription);
            }
            break;

            default:
            {
                Logger.Info("StateChange(defaultHandler): [{0} - {1}] {2} {3}", hsm.Id, hsm, sa.LogType, StateNameFrom(sa.State));
            } break;
            }
        }
Exemple #6
0
        private void _Hsm_StateChange(object sender, EventArgs e)
        {
            ILQHsm            hsm = (ILQHsm)sender;
            LogStateEventArgs ea  = (LogStateEventArgs)e;

            _Hsm_StateChange_RunInViewThread(hsm, ea);
        }
Exemple #7
0
 public void RegisterHsm(ILQHsm hsm)
 {
     lock (_HsmCollection.SyncRoot)
     {
         _HsmCollection.Add(hsm.Id, hsm);
     }
     DoLifeCycleChange(this, hsm, QHsmLifeCycleChangeType.Added);
 }
Exemple #8
0
        public StateProtoViewAnimator(ILQHsm hsm, StateDiagramView view)
        {
            _Hsm  = hsm;
            _View = view;
            _Hsm_StateChange_RunInViewThread_Handler = new HsmStateChangeHander(_Hsm_StateChange_RunInViewThread);

            RegisterEvents();
        }
        private void SetupHsmEvents(ILQHsm hsm)
        {
            StateProtoViewAnimator animator = new StateProtoViewAnimator(hsm, _View);

            animator.TransitionDelay = 0;
            // hook events
            new ConsoleStateEventHandler(hsm);
        }
        public StateProtoViewAnimator(ILQHsm hsm, StateDiagramView view)
        {
            _Hsm = hsm;
            _View = view;
            _Hsm_StateChange_RunInViewThread_Handler = new HsmStateChangeHander(_Hsm_StateChange_RunInViewThread);

            RegisterEvents ();
        }
 public void RegisterHsm(ILQHsm hsm)
 {
     lock (_HsmCollection.SyncRoot)
     {
         _HsmCollection.Add (hsm.Id, hsm);
     }
     DoLifeCycleChange (this, hsm, QHsmLifeCycleChangeType.Added);
 }
Exemple #12
0
 public void DoFinalStateReached(ILQHsm hsm, QState state)
 {
     if (OnFinalStateReached(hsm, state))
     {
         LogStateEvent(StateLogType.Final, state);
         RaiseFinalStateReached(FinalStateReached, hsm, state);
     }
 }
Exemple #13
0
        private void DoStateChange(ILQHsm hsm)
        {
            EventHandler handler = StateChange;

            if (null != handler)
            {
                handler(hsm, new EventArgs());
            }
        }
		public void Dispose()
		{
			if (_Hsm != null)
			{
				_Hsm.EventManager.Runner.Stop ();
				_Hsm.EventManager.Runner = null;
				_Hsm = null;
			}
		}
 protected override IQEventManager GetEventManager(ILQHsm hsm)
 {
     string name = string.Format ("{0}", hsm.GroupId);
     int hashCode = GetHashCode (name);
     int index = hashCode % _EventManagers.Length;
     Logger.Debug ("HashCode returned for: {0} is {1} results in index: {2}", name, hashCode, index);
     index = Math.Abs (index);
     return _EventManagers [index];
 }
            public ComponentContext(object hsm, IComponentGlyph comp)
            {
                _Component = comp;

                _Hsm = hsm as ILQHsm;
                if (_Hsm == null)
                {
                    throw new NullReferenceException("Hsm created using " + _Component.TypeName + " is null");
                }
            }
Exemple #17
0
 public virtual void RaiseFinalStateReached(EventHandler handler, ILQHsm hsm, QState state)
 {
     if (handler != null)
     {
         LogStateEventArgs logEvent = new LogStateEventArgs();
         logEvent.LogType = StateLogType.Final;
         logEvent.State   = state;
         handler(hsm, logEvent);
     }
 }
        protected override IQEventManager GetEventManager(ILQHsm hsm)
        {
            string name     = string.Format("{0}", hsm.GroupId);
            int    hashCode = GetHashCode(name);
            int    index    = hashCode % _EventManagers.Length;

            Logger.Debug("HashCode returned for: {0} is {1} results in index: {2}", name, hashCode, index);
            index = Math.Abs(index);
            return(_EventManagers [index]);
        }
Exemple #19
0
        private void buttonCreateWatch_Click(object sender, System.EventArgs e)
        {
            _SampleWatch = new Samples.SampleWatch(_EventManager);
            _Hsm         = _SampleWatch; // use it as a straight on state machine
            _HsmSignals  = _SampleWatch; // use it as a source of signals -- instead of calling AsyncDispatch() on _Hsm

            SetupHsmEvents(_Hsm);
            _Hsm.Init();

            EnableEvents();
        }
Exemple #20
0
 private void _Hsm_StateChange_RunInViewThread(ILQHsm hsm, LogStateEventArgs ea)
 {
     if (_View.InvokeRequired)
     {
         object[] args = new object[] { hsm, ea };
         _View.Invoke(_Hsm_StateChange_RunInViewThread_Handler, args);
     }
     else
     {
         _Hsm_StateChange_Internal(hsm, ea);
     }
 }
 protected void RaiseLifeCycleChange(QHsmLifeCycleChangeHandler handler, IQHsmLifeCycleManager lifeCycleManager, ILQHsm hsm, QHsmLifeCycleChangeType lifeCycleChangeType)
 {
     try
     {
         if (handler != null)
         {
             handler (lifeCycleManager, hsm, lifeCycleChangeType);
         }
     } catch (Exception ex)
     {
         Logger.Error (ex, "LifeCycleChange event handler raised an exception.");
     }
 }
		protected void InitInstrumentation (ILQHsm hsm)
		{
			// Use QStateChangeListener to minimise exposure to this execution controller - I do not want the controller
			// ref to be passed along.
			_Listener = new QStateChangeListenerBase (this);

			if (_Hsm != null)
			{
				_Hsm.StateChange -= new EventHandler (_Listener.HandleStateChange);
			}
			_Hsm = hsm;
			_Hsm.StateChange += new EventHandler(_Listener.HandleStateChange);
		}
        private void buttonStartWatch_Click(object sender, System.EventArgs e)
        {
            buttonStartWatch.Enabled = false;

            _SampleWatch = _ExecutionModel.CreateHsm(_Id);
            _Hsm         = _SampleWatch;                    // use it as a straight on state machine
            _HsmSignals  = _Hsm as Samples.ISigSampleWatch; // use it as a source of signals -- instead of calling AsyncDispatch() on _Hsm

            SetupHsmEvents(_Hsm);
            _Hsm.Init();

            EnableEvents();
        }
		public void Execute (ILQHsm hsm) 
		{
			Prepare ();

			InitInstrumentation (hsm);

			_Hsm.Init ();

			if (_Hsm.EventManager.Runner == null)
			{
				new QGUITimerEventManagerRunner (_Hsm.EventManager, 200);
				_Hsm.EventManager.Runner.Start ();
			}
		}
 protected override bool OnLifeCycleChange(IQHsmLifeCycleManager lifeCycleManager, ILQHsm hsm, QHsmLifeCycleChangeType lifeCycleChangeType)
 {
     if (lifeCycleChangeType == QHsmLifeCycleChangeType.Added)
     {
         ILQHsmAdmin admin = hsm as ILQHsmAdmin;
         if (admin == null)
         {
             throw new InvalidOperationException ("Hsm must support ILQHsmAdmin interface");
         }
         IQEventManager eventManager = GetEventManager (hsm);
         admin.EventManager = eventManager;
     }
     return base.OnLifeCycleChange (lifeCycleManager, hsm, lifeCycleChangeType);
 }
 public void UnregisterHsm(ILQHsm hsm)
 {
     bool contains = false;
     lock (_HsmCollection.SyncRoot)
     {
         contains = _HsmCollection.Contains (hsm.Id);
         if (contains)
         {
             _HsmCollection.Remove (hsm.Id);
         }
     }
     if (contains)
     {
         DoLifeCycleChange (this, hsm, QHsmLifeCycleChangeType.Removed);
     }
 }
 protected override bool OnLifeCycleChange(IQHsmLifeCycleManager lifeCycleManager, ILQHsm hsm, QHsmLifeCycleChangeType lifeCycleChangeType)
 {
     switch (lifeCycleChangeType)
     {
         case QHsmLifeCycleChangeType.Added:
         {
             RegisterEvents (hsm);
         } break;
         case QHsmLifeCycleChangeType.Removed:
         {
             UnRegisterEvents (hsm);
         } break;
         default: break; // not really interested in any other events.
     }
     return base.OnLifeCycleChange (lifeCycleManager, hsm, lifeCycleChangeType);
 }
Exemple #28
0
        public void UnregisterHsm(ILQHsm hsm)
        {
            bool contains = false;

            lock (_HsmCollection.SyncRoot)
            {
                contains = _HsmCollection.Contains(hsm.Id);
                if (contains)
                {
                    _HsmCollection.Remove(hsm.Id);
                }
            }
            if (contains)
            {
                DoLifeCycleChange(this, hsm, QHsmLifeCycleChangeType.Removed);
            }
        }
		protected void hsm_StateChange(object sender, EventArgs e)
		{
			LogStateEventArgs args = e as LogStateEventArgs;
			ILQHsm hsm = sender as ILQHsm;

			if (args.LogType == StateLogType.Log)
			{
				return;
			}

			string stateName = QStateNameFrom (args.State);
			switch (args.LogType)
			{
				case StateLogType.Init: 
				{
					SetCurrentStateName (stateName);
				} break;
				case StateLogType.Entry:
				{
					SetCurrentStateName (stateName);
				} break;
				case StateLogType.Exit:			
				{
					CurrentState = null;
				} break;
				case StateLogType.EventTransition: 
				{
					CurrentTransition = null;
					DoRefresh ();
					SetCurrentStateName (stateName);
					SetCurrentTransitionName (stateName, args.EventDescription);
					DoRefresh ();
				} break;
				case StateLogType.Log: 
				{
				} break;
				default: throw new NotSupportedException ("StateLogType." + args.LogType.ToString ());
			}

			DoRefresh ();
		}
 protected override bool OnLifeCycleChange(IQHsmLifeCycleManager lifeCycleManager, ILQHsm hsm, QHsmLifeCycleChangeType lifeCycleChangeType)
 {
     if (lifeCycleChangeType == QHsmLifeCycleChangeType.Added)
     {
         ILQHsmAdmin admin = hsm as ILQHsmAdmin;
         if (admin == null)
         {
             throw new InvalidOperationException("Hsm must support ILQHsmAdmin interface");
         }
         IQEventManager eventManager = GetEventManager(hsm);
         admin.EventManager = eventManager;
     }
     return(base.OnLifeCycleChange(lifeCycleManager, hsm, lifeCycleChangeType));
 }
 public void Add(string name, ILQHsm hsm)
 {
     InnerHashtable.Add (name, hsm);
 }
        private void _Hsm_DispatchException(Exception ex, IQHsm hsm, System.Reflection.MethodInfo stateMethod, IQEvent ev)
        {
            ILQHsm qhsm = (ILQHsm)hsm;

            Logger.Error(ex, "DispatchException: [{0} - {1}] {2} {3}", qhsm.Id, hsm, stateMethod.Name, ev);
        }
        public void Execute(ILQHsm hsm)
        {
            Prepare ();

            InitInstrumentation (hsm);

            _Hsm.Init ();

            if (_Hsm.EventManager.Runner == null)
            {
                new QGUITimerEventManagerRunner (_Hsm.EventManager, 200);
                _Hsm.EventManager.Runner.Start ();
            }
        }
 private void managerEvents_LifeCycleChange(IQHsmLifeCycleManager lifeCycleManager, ILQHsm hsm, QHsmLifeCycleChangeType lifeCycleChangeType)
 {
     DoLifeCycleChange (lifeCycleManager, hsm, lifeCycleChangeType);
 }
Exemple #35
0
 protected virtual bool OnFinalStateReached(ILQHsm hsm, QState state)
 {
     return true;
 }
 private void _Hsm_StateChange_RunInViewThread(ILQHsm hsm, LogStateEventArgs ea)
 {
     if(_View.InvokeRequired)
     {
         object[] args = new object[] {hsm, ea};
         _View.Invoke (_Hsm_StateChange_RunInViewThread_Handler, args);
     }
     else
     {
         _Hsm_StateChange_Internal (hsm, ea);
     }
 }
 public void UnregisterHsm(ILQHsm hsm)
 {
     throw new NotSupportedException ("This Proxy is only for forwarding IQHsmLifeCycleManagerEvents");
 }
        protected void InitInstrumentation(ILQHsm hsm)
        {
            // Use QStateChangeListener to minimise exposure to this execution controller - I do not want the controller
            // ref to be passed along.
            _Listener = new QStateChangeListenerBase (this);

            if (_Hsm != null)
            {
                _Hsm.StateChange -= new EventHandler (_Listener.HandleStateChange);
            }
            _Hsm = hsm;
            _Hsm.StateChange += new EventHandler(_Listener.HandleStateChange);
        }
Exemple #39
0
 protected virtual bool OnFinalStateReached(ILQHsm hsm, QState state)
 {
     return(true);
 }
 public void Dispose()
 {
     if (_Hsm != null)
     {
         _Hsm.EventManager.Runner.Stop ();
         _Hsm.EventManager.Runner = null;
         _Hsm = null;
     }
 }
 protected override IQEventManager GetEventManager(ILQHsm hsm)
 {
     return _EventManager;
 }
Exemple #42
0
 public void Add(string name, ILQHsm hsm)
 {
     InnerHashtable.Add(name, hsm);
 }
Exemple #43
0
 public RestoreCmd(ILQHsm hsm, ILQHsmMemento memento)
     : base(hsm)
 {
     _Memento = memento;
 }
 protected virtual bool OnLifeCycleChange(IQHsmLifeCycleManager lifeCycleManager, ILQHsm hsm, QHsmLifeCycleChangeType lifeCycleChangeType)
 {
     return true;
 }
Exemple #45
0
 protected virtual void RaiseFinalStateReached(EventHandler handler, ILQHsm hsm, QState state)
 {
     if (handler != null)
     {
         LogStateEventArgs logEvent = new LogStateEventArgs ();
         logEvent.LogType = StateLogType.Final;
         logEvent.State = state;
         handler (hsm, logEvent);
     }
 }
Exemple #46
0
 protected void DoFinalStateReached(ILQHsm hsm, QState state)
 {
     if (OnFinalStateReached (hsm, state))
     {
         LogStateEvent (StateLogType.Final, state);
         RaiseFinalStateReached (FinalStateReached, hsm, state);
     }
 }
 public static void FillMementoWithStateName(ILQHsmMemento memento, ILQHsm hsm, string currentStateName)
 {
     FillMementoWithStateName (memento, hsm.GetType (), currentStateName, hsm);
 }
Exemple #48
0
        protected override bool OnLifeCycleChange(IQHsmLifeCycleManager lifeCycleManager, ILQHsm hsm, QHsmLifeCycleChangeType lifeCycleChangeType)
        {
            switch (lifeCycleChangeType)
            {
            case QHsmLifeCycleChangeType.Added:
            {
                RegisterEvents(hsm);
            } break;

            case QHsmLifeCycleChangeType.Removed:
            {
                UnRegisterEvents(hsm);
            } break;

            default: break;     // not really interested in any other events.
            }
            return(base.OnLifeCycleChange(lifeCycleManager, hsm, lifeCycleChangeType));
        }
 public ConsoleStateEventHandler(ILQHsm hsm)
 {
     _Hsm = hsm;
     RegisterEvents();
 }
Exemple #50
0
 protected void RaiseStateChange(EventHandler handler, ILQHsm hsm, LogStateEventArgs logEvent)
 {
     if (handler != null)
     {
         handler (hsm, logEvent);
     }
 }
        private void _Hsm_UnhandledTransition(IQHsm hsm, System.Reflection.MethodInfo stateMethod, IQEvent ev)
        {
            ILQHsm qhsm = (ILQHsm)hsm;

            Logger.Info("UnhandledTransition: [{0} - {1}] {2} {3}", qhsm.Id, hsm, stateMethod.Name, ev);
        }
 protected abstract IQEventManager GetEventManager(ILQHsm hsm);
            public ComponentContext(object hsm, IComponentGlyph comp)
            {
                _Component = comp;

                _Hsm = hsm as ILQHsm;
                if (_Hsm == null)
                {
                    throw new NullReferenceException ("Hsm created using " + _Component.TypeName + " is null");
                }
            }
 protected virtual void UnRegisterEvents(ILQHsm hsm)
 {
     hsm.StateChange -= new EventHandler(hsm_StateChange);
     hsm.UnhandledTransition -= new DispatchUnhandledTransitionHandler(hsm_UnhandledTransition);
     hsm.DispatchException -= new DispatchExceptionHandler(hsm_DispatchException);
 }
 protected abstract IQEventManager GetEventManager(ILQHsm hsm);
        private void _Hsm_StateChange_Internal(ILQHsm hsm, LogStateEventArgs ea)
        {
            string currentStateName = null;
            string currentTransitionName = null;
            switch (ea.LogType)
            {
                case StateLogType.EventTransition:
                {
                    currentStateName = ea.State.Method.Name;
                    currentTransitionName = ea.EventDescription;
                }
                    break;
                case StateLogType.Init:
                {
                    currentStateName = ea.NextState.Method.Name;
                } break;
                case StateLogType.Restored:
                case StateLogType.Entry:
                case StateLogType.Final:
                {
                    currentStateName = ea.State.Method.Name;
                } break;
            }

            if(currentStateName != null)
            {
                RefreshCurrentStateView (currentStateName, currentTransitionName);
            }
        }