Beispiel #1
0
        /// <summary>
        /// After leaving the specified state
        /// </summary>
        /// <param name="state"></param>
        /// <param name="activityCallback"></param>
        /// <returns></returns>
        protected void AfterLeave(State state,
                                  Func <EventActivityBinder <TInstance, State>, EventActivityBinder <TInstance, State> > activityCallback)
        {
            State <TInstance> activityState = GetState(state.Name);

            EventActivityBinder <TInstance, State> binder = new DataEventActivityBinder <TInstance, State>(this, activityState.AfterLeave);

            binder = activityCallback(binder);

            During(state, binder);
        }
Beispiel #2
0
        public static EventActivityBinder <TInstance, TData> Try <TInstance, TData>(
            this EventActivityBinder <TInstance, TData> source,
            Func <EventActivityBinder <TInstance, TData>, EventActivityBinder <TInstance, TData> > context,
            Func <ExceptionActivityBinder <TInstance, TData>, ExceptionActivityBinder <TInstance, TData> > handlers)
            where TInstance : class
        {
            EventActivityBinder <TInstance, TData> contextBinder = new DataEventActivityBinder <TInstance, TData>(
                source.StateMachine, source.Event);

            contextBinder = context(contextBinder);

            ExceptionActivityBinder <TInstance, TData> exceptionBinder =
                new ExceptionActivityBinderImpl <TInstance, TData>(source.StateMachine, source.Event);

            exceptionBinder = handlers(exceptionBinder);

            return(source.Add(new TryActivity <TInstance, TData>(source.Event, contextBinder, exceptionBinder)));
        }
Beispiel #3
0
        void BindEveryTransitionEvent(Func <EventActivityBinder <TInstance, State>, EventActivityBinder <TInstance, State> > activityCallback,
                                      Func <State <TInstance>, Event <State> > eventProvider)
        {
            State <TInstance>[] states = _stateCache.Values.ToArray();

            ActivityBinder <TInstance>[] binders = states.Select(state =>
            {
                EventActivityBinder <TInstance, State> binder = new DataEventActivityBinder <TInstance, State>(this, eventProvider(state));

                return(activityCallback(binder));
            }).SelectMany(x => x.GetStateActivityBinders()).ToArray();

            foreach (var state in states)
            {
                foreach (var binder in binders)
                {
                    binder.Bind(state);
                }
            }
        }