Example #1
0
        /// <summary>
        /// Instantiates a XmasTimer
        /// </summary>
        /// <param name="actman">The ActionManager of the engine</param>
        /// <param name="owner">The XmasAction that owns the timer</param>
        /// <param name="action">The action that is queued onto the engine when the timer expires</param>
        public XmasTimer(ActionManager actman, XmasAction owner, Action action)
        {
            this.owner = owner;
            this.actman = actman;
            this.action = action;
            timer.AutoReset = false;

            timer.Elapsed += timer_Elapsed;
        }
Example #2
0
 internal HandShake( XmasAction action)
 {
     this.Action = action;
 }
Example #3
0
 private void raiseEventForAction(XmasAction act, XmasEvent evt)
 {
     var envact = act as EnvironmentAction;
     var entact = act as EntityXmasAction;
     if (entact != null)
     {
         entact.Source.Raise(evt);
     }
     else
     {
         evtman.Raise(evt);
         if (envact != null)
         {
             foreach (var xuni in envact.RaiseActionEvtOn)
             {
                 xuni.RaiseNonRecursive(evt);
             }
         }
     }
 }
Example #4
0
 internal void QueueAction(XmasAction action)
 {
     lock (this)
     {
         if (ActionQueuing != null)
             ActionQueuing(this, new UnaryValueEvent<XmasAction>(action));
         awaitingActions.Enqueue(action);
         if (ActionQueued != null)
             ActionQueued(this, new UnaryValueEvent<XmasAction>(action));
     }
 }
Example #5
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));

                }
            }
        }
Example #6
0
 /// <summary>
 /// Creates a specially designed timer that queues its action to the engine when the timer has expired, thus this timer is threadsafe
 /// </summary>
 /// <param name="owner">The action that is owner of the timer</param>
 /// <param name="action">The action that the timer executes</param>
 /// <returns>The timer</returns>
 public XmasTimer CreateTimer(XmasAction owner, Action action)
 {
     XmasTimer gt = new XmasTimer(actman, owner, action);
     return gt;
 }
 public UnacceptableActionException(XmasAction action, XmasEntity xmasEntity)
     : base("XmasEntity: [" + xmasEntity.GetType().Name + "] can't accept action: [" + action.GetType().Name + "]")
 {
     this.action = action;
     this.xmasEntity = xmasEntity;
 }
Example #8
0
 protected void MakeActionChild(XmasAction child)
 {
     child.SetParent(this);
     lock (this)
     {
         this.subactions.Add(child);
     }
     child.Resolved += child_Resolved;
 }
Example #9
0
 internal void SetParent(XmasAction parent)
 {
     this.parentAction = parent;
 }