コード例 #1
0
        private static void InitializeEvents()
        {
            Type machineType = typeof(T);

            foreach (PropertyInfo propertyInfo in machineType.GetProperties(BindingFlags.Static | BindingFlags.Public))
            {
                if (IsPropertyABasicEvent(propertyInfo))
                {
                    BasicEvent <T> value = SetPropertyValue(propertyInfo, x => new BasicEvent <T>(x.Name));

                    _events.Add(value.Name, value);
                }
                else if (IsPropertyATypedEvent(propertyInfo))
                {
                    Type eventType = typeof(DataEvent <,>).MakeGenericType(typeof(T), propertyInfo.PropertyType.GetGenericArguments()[0]);

                    ConstructorInfo ctor   = eventType.GetConstructors()[0];
                    var             name   = Expression.Parameter(typeof(string), "name");
                    var             newExp = Expression.New(ctor, name);

                    Func <string, object> creator = Expression.Lambda <Func <string, object> >(newExp, new[] { name }).Compile();

                    PropertyInfo eventProperty = propertyInfo;

                    SetPropertyValue(propertyInfo, x => creator(eventProperty.Name));
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Send an event within the current state
        /// </summary>
        /// <param name="raised">The event to raise</param>
        public virtual void RaiseEvent(Event raised)
        {
            BasicEvent <T> eevent = BasicEvent <T> .GetEvent(raised);

            _currentState.RaiseEvent(this as T, eevent, null);
            _anyState.RaiseEvent(this as T, eevent, null);
        }
コード例 #3
0
        public bool Inspect <T>(BasicEvent <T> state)
            where T : StateMachine <T>
        {
            Append(string.Format("When {0} Occurs", state.Name));

            return(true);
        }
コード例 #4
0
        public State(string name)
        {
            _name = name;

            _enter = new BasicEvent <T>(Name + ":Enter");
            _leave = new BasicEvent <T>(Name + ":Leave");

            _actions = new MultiDictionary <Event, StateEventAction <T> >(true);
        }
コード例 #5
0
        public bool Inspect <T>(BasicEvent <T> eevent)
            where T : StateMachine <T>
        {
            _currentEventVertex = GetEventVertex(eevent.Name, () => eevent.Name, typeof(Event), typeof(void));

            _edges.Add(new Edge(_currentStateVertex, _currentEventVertex, eevent.Name));

            return(true);
        }
コード例 #6
0
        public static BasicEvent <T> GetEvent(Event input)
        {
            BasicEvent <T> result = input as BasicEvent <T>;

            if (result == null)
            {
                throw new ArgumentException("The event is not valid for this state machine " + input.Name);
            }

            return(result);
        }
コード例 #7
0
        public void RaiseEvent(T instance, BasicEvent <T> eevent, object value)
        {
            if (!_actions.ContainsKey(eevent))
            {
                return;
            }

            foreach (var action in _actions[eevent])
            {
                action.Execute(instance, eevent, value);
            }
        }
コード例 #8
0
        private void BindEventAction(int all, int i, FastProperty <T, int> property)
        {
            var e      = _sources[i];
            var eevent = BasicEvent <T> .GetEvent(e);

            var eventAction = new BasicEventAction <T>(eevent);

            int flag = 1 << i;

            eventAction.Then(x =>
            {
                int value = property.Get(x) | flag;
                property.Set(x, value);

                if (value == all)
                {
                    x.RaiseEvent(_target);
                }
            });

            _bindEventAction(eventAction);
        }
コード例 #9
0
        /// <summary>
        /// Defines an actions to take when an event is raised within a state
        /// </summary>
        /// <param name="raised"></param>
        /// <returns></returns>
        protected static BasicEventAction <T> When(Event raised)
        {
            BasicEvent <T> eevent = BasicEvent <T> .GetEvent(raised);

            return(new BasicEventAction <T>(eevent));
        }