/// <summary>Tick current state to execute the action based on the inputed message</summary> /// <param name="msg">The inputed message</param> /// <returns>The return message from the action</returns> public ISpEventMessage Tick([NotNull] ISpEventMessage?msg) { WrapErr.ChkDisposed(this.disposed, 50176); WrapErr.ChkParam(msg, "msg", 50172); // First tick to drive it from entry to regular ISpStateTransition <TMsgId>?tr = null; bool tmpIsStarted = this.isStarted; //Log.Debug("SpMachine", "Tick", String.Format("isStarted:{0}", this.isStarted)); if (!this.isStarted) { // The OnEntry must be called directly from the state machine for the first state. Subsequent // state transitions will insure that the OnEntry for the new state is called this.isStarted = true; tr = this.state.OnEntry(msg); } else { tr = this.state.OnTick(msg); } WrapErr.ChkVar(tr, 50177, () => String.Format( "The State '{0}' {1} Returned a Null Transition", this.state.FullName, tmpIsStarted ? "OnTick" : "OnEntry")); WrapErr.ChkVar(tr.ReturnMessage, 9999, "Null ReturnMessage"); return(tr.ReturnMessage); }
public void Disposed_Valid() { WrapErr.ToErrReport(out ErrReport err, 1111, "Validate arg", () => { WrapErr.ChkDisposed(false, 8888); }); Assert.AreEqual(0, err.Code, "Should not have been an error"); }
public void Disposed_Fail() { WrapErr.ToErrReport(out ErrReport err, 1111, "Validate arg", () => { WrapErr.ChkDisposed(true, 8888); }); this.Validate(err, 8888, "Disposed_Fail", "Attempting to use Disposed Object"); }
/// <summary> /// Add and event object to the store /// </summary> /// <param name="msg">The message event</param> public void Add(ISpEventMessage msg) { WrapErr.ChkDisposed(this.disposed, 50111); WrapErr.ChkParam(msg, "msg", 50112); lock (this.queueLock) { this.AddEvent(msg); } }
/// <summary> /// Set the interval in for wakeup for the next Start /// </summary> /// <param name="interval">The interval in </param> public void SetInterval(TimeSpan interval) { WrapErr.ChkDisposed(this.disposed, 50002); WrapErr.ChkTrue(interval.TotalMilliseconds > 0, 50000, "The interval cannot be 0 milliseconds total"); WrapErr.ToErrorReportException(50001, () => { this.timespan = interval; }); }
/// <summary> /// Pop the next event object from the store /// </summary> /// <returns>The T object</returns> public ISpEventMessage Get() { WrapErr.ChkDisposed(this.disposed, 50113); // Make stack variable and only lock the queue for the duration of the copy to // free it up for other threads to add events ISpEventMessage eventCopy = null; lock (this.queueLock) { eventCopy = this.GetEvent(); } return(eventCopy == null ? this.defaultTick : eventCopy); }
/// <summary> /// Start the periodic timer /// </summary> public void Start() { WrapErr.ChkDisposed(this.disposed, 50003); WrapErr.ToErrorReportException(50004, () => { lock (this.timerLock) { this.Stop(); this.timer = new Timer(this.timespan.TotalMilliseconds); this.timer.Elapsed += this.onTimerWakeup; this.timer.AutoReset = true; this.timer.Start(); } }); }
/// <summary> /// Wait indefinitely until behavior is satisfied /// </summary> public void WaitOnEvent() { WrapErr.ChkDisposed(this.disposed, 50082); lock (this.busyLock) { this.isBusy = false; } this.wakeEvent.WaitOne(); // Reset lock so it will wait on next call lock (this.busyLock) { this.isBusy = true; this.wakeEvent.Reset(); } }
/// <summary> /// Invoked when an event is received /// </summary> /// <param name="eventType">The type of event received</param> public void EventReceived(BehaviorResponseEventType eventType) { WrapErr.ChkDisposed(this.disposed, 50080); switch (eventType) { case BehaviorResponseEventType.MsgArrived: // We ignore messages received and depend only on the periodic timer break; case BehaviorResponseEventType.PeriodicWakeup: this.OnPeriodicTimer(); break; case BehaviorResponseEventType.TerminateRequest: this.wakeEvent.Set(); break; default: Log.Error(50081, String.Format("The Behavior Response Event Type '{0}' is not Supported", eventType)); break; } }
/// <summary> /// Start up the Engine /// </summary> public void Start() { WrapErr.ChkDisposed(this.disposed, 50056); this.timer.Start(); }
/// <summary> /// Stop the Engine /// </summary> public void Stop() { WrapErr.ChkDisposed(this.disposed, 50057); this.timer.Stop(); }
/// <summary> /// Stop the periodic timer /// </summary> public void Stop() { WrapErr.ChkDisposed(this.disposed, 50005); this.DisposeTimer(); }
/// <summary> /// Post an ISpMessage response to an ISpMessage. This will raise the /// ResponseReceived event /// </summary> /// <param name="msg">The reponse to post</param> public void PostResponse(ISpEventMessage msg) { WrapErr.ChkDisposed(this.disposed, 50033); this.RaiseEvent(this.ResponseReceived, msg, "Response"); }
/// <summary> /// Post an ISpMessage to those listening. This will raise the /// MsgReceived event /// </summary> /// <param name="msg">The message to post</param> public void PostMessage(ISpEventMessage msg) { WrapErr.ChkDisposed(this.disposed, 50032); this.RaiseEvent(this.MsgReceived, msg, "Message"); }