Ejemplo n.º 1
0
 public void False_Valid()
 {
     WrapErr.ToErrReport(out ErrReport err, 1111, "Validate arg", () => {
         WrapErr.ChkFalse(false, 8888, "zork error");
     });
     Assert.AreEqual(0, err.Code, "Should not have been an error");
 }
Ejemplo n.º 2
0
 public void False_Fail()
 {
     WrapErr.ToErrReport(out ErrReport err, 1111, "Validate arg", () => {
         WrapErr.ChkFalse(true, 8888, "zork error");
     });
     this.Validate(err, 8888, "False_Fail", "zork error");
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Excecuted once when the state becomes the current state
 /// </summary>
 /// <param name="msg">The incoming message</param>
 /// <returns>A state transition object</returns>
 public virtual ISpStateTransition OnEntry(ISpEventMessage msg)
 {
     Log.Info(this.className, "OnEntry", String.Format("'{0}' State {1} - Event", this.FullName, this.GetCachedEventId(msg.EventId)));
     WrapErr.ChkFalse(this.IsEntryExcecuted, 50201, "OnEntry Cannot be Executed More Than Once Until OnExit is Called");
     return(WrapErr.ToErrorReportException(9999, () => {
         return this.GetTransition(true, this.ExecOnEntry, msg);
     }));
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Register a state transition for an event
        /// </summary>
        /// <param name="eventId">The id converter of the event type</param>
        /// <param name="transition">The transition object</param>
        public static void RegisterTransition(string type, ISpToInt eventId, ISpStateTransition transition, Dictionary <int, ISpStateTransition> store)
        {
            WrapErr.ChkParam(eventId, "eventId", 51004);
            WrapErr.ChkParam(transition, "transition", 51005);
            WrapErr.ChkParam(store, "store", 51006);

            // Wrap the id converter separately
            int tmp = WrapErr.ToErrorReportException(51007,
                                                     () => { return(String.Format("Error on Event Id Converter for '{0}' Event Type", type)); },
                                                     () => { return(eventId.ToInt()); });

            // Duplicate transitions on same Event is a no no.
            WrapErr.ChkFalse(store.Keys.Contains(tmp), 51008,
                             () => { return(String.Format("Already Contain a '{0}' Transition for Id:{1}", type, tmp)); });
            store.Add(tmp, transition);
        }
Ejemplo n.º 5
0
        /// <summary>Register a transition for a state</summary>
        /// <param name="type">string of transition type</param>
        /// <typeparam name="TMsgId">Event id</typeparam>
        /// <param name="msgId">The event message id</param>
        /// <param name="transition">Transition object</param>
        /// <param name="store">Transition store</param>
        public static void RegisterTransition <TMsgId>(string type, TMsgId msgId, ISpStateTransition <TMsgId>?transition, Dictionary <int, ISpStateTransition <TMsgId> >?store) where TMsgId : struct
        {
            //WrapErr.ChkParam(eventId, "msgId", 51004);
            WrapErr.ChkParam(transition, "transition", 51005);
            WrapErr.ChkParam(store, "store", 51006);

            WrapErr.ChkTrue(typeof(TMsgId).IsEnum, 9999, () => string.Format("Transition type {0} must be Enum", msgId.GetType().Name));
            WrapErr.ChkTrue(typeof(TMsgId).GetEnumUnderlyingType() == typeof(Int32), 9999,
                            () => string.Format("Transition type enum {0} must be derived from int", msgId.GetType().Name));

            int tmp = Convert.ToInt32(msgId);

            // 51007 - failure of conversion number

            // Duplicate transitions on same Event is a no no.
            WrapErr.ChkFalse(store.Keys.Contains(tmp), 51008,
                             () => { return(String.Format("Already Contain a '{0}' Transition for Id:{1}", type, tmp)); });
            store.Add(tmp, transition);
        }