/// <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; }
internal HandShake( XmasAction action) { this.Action = action; }
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); } } } }
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)); } }
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)); } } }
/// <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; }
protected void MakeActionChild(XmasAction child) { child.SetParent(this); lock (this) { this.subactions.Add(child); } child.Resolved += child_Resolved; }
internal void SetParent(XmasAction parent) { this.parentAction = parent; }