예제 #1
0
        /// <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);
        }
예제 #2
0
 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");
 }
예제 #3
0
 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");
 }
예제 #4
0
 /// <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);
     }
 }
예제 #5
0
 /// <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;
     });
 }
예제 #6
0
        /// <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);
        }
예제 #7
0
 /// <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();
         }
     });
 }
예제 #8
0
        /// <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();
            }
        }
예제 #9
0
        /// <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();
 }
예제 #12
0
 /// <summary>
 /// Stop the periodic timer
 /// </summary>
 public void Stop()
 {
     WrapErr.ChkDisposed(this.disposed, 50005);
     this.DisposeTimer();
 }
예제 #13
0
 /// <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");
 }
예제 #14
0
 /// <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");
 }