示例#1
0
        /// <summary>
        /// Stops this region.
        /// </summary>
        public void Stop()
        {
            Debug.WriteLine("Stop region '{0}'.", Name);

            ActiveVertex.OnExit();

            if (!HasHistory)
            {
                Debug.WriteLine("Region '{0}' has no history. Set active vertex to initial state again.", Name);

                ActiveVertex = Vertices[0];
            }
            else
            {
                Debug.WriteLine("Region '{0}' has history. Save vertex '{1}' as history state.", Name, ActiveVertex.GetType().Name);
            }
        }
示例#2
0
        /// <summary>
        /// Starts running this region.
        /// </summary>
        public void Start(string trigger = null)
        {
            Debug.WriteLine("Start region '{0}' from state '{1}' by trigger '{2}'.", Name, ActiveVertex.GetType().Name, trigger);

            if (ActiveVertex is InitialState)
            {
                var next = ActiveVertex.MoveNext(null);

                if (ActiveVertex != next)
                {
                    var currentVertex = ActiveVertex;
                    ActiveVertex = next;
                    OnTravelled(new TravelledEventArgs(null, currentVertex, next));

                    ActiveVertex.OnActive(null);
                }
            }
            else
            {
                // Saved history state
                OnTravelled(new TravelledEventArgs(trigger, Vertices[0], ActiveVertex));

                ActiveVertex.OnEntry();
                ActiveVertex.OnActive(trigger);
            }
        }