Example #1
0
        internal void ExecuteAction(XmasAction action)
        {
            if (!action.HandShakeCompleted)
            {
                if (PreActionExecution != null)
                    PreActionExecution(this, new UnaryValueEvent<XmasAction>(action));
                runningActions.Add(action);
                action.Resolved += action_Resolved;
                action.Completed += action_Completed;

                var handshakeInquryevt = (XmasEvent)Generics.InstantiateGenericClass(typeof(ActionHandShakeInqueryEvent<>), new Type[] { action.GetType() }, action);
                raiseEventForAction(action, handshakeInquryevt);

                var startingevent = (ActionStartingEvent)Generics.InstantiateGenericClass(typeof(ActionStartingEvent<>), new Type[] { action.GetType() }, action.Clone());
                if (action.HandShakeRequired)
                {
                    startingevent.HandShakeNeeded = true;
                    startingevent.HandShake = action.ObtainHandShake();
                    this.awaitingHandShake.Add(action);
                }
                raiseEventForAction(action, startingevent);
            }

            if (!action.HandShakeRequired || action.HandShakeCompleted)
            {
                try
                {
                    action.Fire();

                }
                catch (ForceStopEngineException e)
                {
                    throw e;
                }
                catch (Exception e)
                {
                    action.Fail(e);
                    this.evtman.Raise(new ActionFailedEvent(action,e));

                }
            }
        }