public void _50005_Start_Disposed() { TestHelpers.CatchExpected(50005, "WinSimpleTimer", "Stop", "Attempting to use Disposed Object", () => { WrapErr.ChkVar(this.timer, 9, ""); this.timer.Dispose(); this.timer.Stop(); }); }
public void _0_Stop_Multi() { TestHelpers.CatchUnexpected(() => { WrapErr.ChkVar(this.timer, 9, ""); this.timer.Stop(); this.timer.Stop(); this.timer.Stop(); }); }
private void TickAndValidateState(ISpEventMessage msg, ISpStateMachine sm, string expected) { ISpEventMessage?ret = this.Tick(msg, sm); Thread.Sleep(0); this.ValidateState(sm, expected); WrapErr.ChkVar(ret, 9999, ""); this.ValidateReturn(msg, ret); }
public void Var_ValidArg_FaultException() { string zork = "Zorker"; WrapErr.ToErrReport(out ErrReport err, 1111, "Validate arg", () => { WrapErr.ChkVar(zork, 8888, "zork error"); }); Assert.AreEqual(0, err.Code, "Should not have been an error"); }
public void MultiDispose() { WrapErr.ChkVar(this.timer, 9, ""); Assert.DoesNotThrow(() => { this.timer.Dispose(); this.timer.Dispose(); this.timer.Dispose(); }); }
public void Var_NullArg() { ErrReport err; WrapErr.ToErrReport(out err, 1111, "Validate arg", () => { WrapErr.ChkVar(null, 8888, "zork error"); }); this.Validate(err, 8888, "Var_NullArg", "zork error"); }
public void OnWakeup_noSubscribers() { WrapErr.ChkVar(this.timer, 9, ""); Assert.DoesNotThrow(() => { this.timer.SetInterval(new TimeSpan(0, 0, 0, 0, 25)); this.timer.Start(); Thread.Sleep(200); this.timer.Stop(); }); }
/// <summary>Raise an event to request credentials from user</summary> /// <param name="dataModel">The network info data model</param> /// <returns>WifiErrorCode.Success on success, otherwise and error</returns> private WifiErrorCode GetUserCredentials(WifiNetworkInfo dataModel, ref bool save) { save = false; this.log.Info("********************************", "Comm Wrapper - GetUserCredentials"); // TODO - implement. Could also use the wifi GUID WifiCredentials cred = new WifiCredentials() { SSID = dataModel.SSID, RemoteHostName = dataModel.RemoteHostName, RemoteServiceName = dataModel.RemoteServiceName, }; WrapErr.ChkVar(this.CredentialsRequestedEvent, 9999, "No subscribers to CredentialsRequestedEvent"); this.CredentialsRequestedEvent?.Invoke(this, cred); if (cred.IsUserCanceled) { this.log.Info("********************************", "Comm Wrapper - GetUserCredentials Canceled"); return(WifiErrorCode.UserCanceled); } if (cred.SSID.Trim().Length == 0) { this.log.Info("********************************", "Comm Wrapper - GetUserCrendentials Empty SSID"); return(WifiErrorCode.EmptySsid); } else if (cred.RemoteHostName.Trim().Length == 0) { this.log.Info("********************************", "Comm Wrapper - GetUserCrendentials Empty host name"); return(WifiErrorCode.EmptyHostName); } else if (cred.RemoteServiceName.Trim().Length == 0) { this.log.Info("********************************", "Comm Wrapper - GetUserCrendentials Empty port name"); return(WifiErrorCode.EmptyServiceName); } else if (cred.WifiPassword.Trim().Length == 0) { this.log.Info("********************************", "Comm Wrapper - GetUserCrendentials Empty password"); return(WifiErrorCode.EmptyPassword); } this.log.Info("GetUserCredentials", () => string.Format("User request save:{0}", cred.IsUserSaveRequest)); save = cred.IsUserSaveRequest; dataModel.RemoteHostName = cred.RemoteHostName; dataModel.RemoteServiceName = cred.RemoteServiceName; dataModel.Password = cred.WifiPassword; return(WifiErrorCode.Success); }
/// <summary>Safely execute function and transfer the GUID to the response</summary> /// <param name="msg">The incoming message</param> /// <param name="func">The function to invoke to generate the response message</param> /// <returns>A correlated response message</returns> private ISpEventMessage GetMsg(ISpEventMessage msg, Func <ISpEventMessage> func) { WrapErr.ChkParam(msg, "msg", 9999); return(WrapErr.ToErrorReportException(9999, () => { ISpEventMessage ret = func.Invoke(); WrapErr.ChkVar(ret, 9999, "The Provider Returned a Null Message"); // Transfer the GUID for correlation ret.Uid = msg.Uid; return ret; })); }
/// <summary>Return single instance of the object requested</summary> /// <typeparam name="T">The type to return</typeparam> /// <returns>A singleton of the requested object</returns> protected override T ReturnObj <T>() { if (this.singleton == null) { this.singleton = this.objBuilder(); WrapErr.ChkVar(this.singleton, 9999, () => string.Format("Class {0} constructor returned a null object", typeof(T).Name)); } T?result = this.singleton as T; WrapErr.ChkVar(result, 9999, () => string.Format("Singleton is type {0} rather than type {1}", this.singleton.GetType().Name, typeof(T).Name)); return(result); }
/// <summary> /// Retrieve the transition object from the OnResults queue of the super state /// </summary> /// <param name="msg"></param> /// <returns></returns> private ISpStateTransition GetSuperStateOnResultTransition(ISpEventMessage msg) { // Check super state registered result transitions against Sub State event id ISpStateTransition tr = this.GetOnResultTransition(msg); WrapErr.ChkVar(tr, 9999, () => { return(String.Format( "State {0} Specified Exit but SuperState {1} has no handlers for that event id:{2}", this.currentState.FullName, this.FullName, this.GetCachedEventId(msg.EventId))); }); tr.ReturnMessage = this.MsgFactory.GetResponse(msg, tr.ReturnMessage); return(tr); }
/// <summary> /// Initialise the state id chain from ancestors to this state /// </summary> /// <param name="parent"></param> /// <param name="id"></param> private void InitStateIds(ISpState parent, int id) { // Add any ancestor state ids to the chain WrapErr.ToErrorReportException(50207, () => { if (parent != null) { WrapErr.ChkVar(parent.IdChain, 50206, "The Parent has a Null Id Chain"); this.idChain.Clear(); parent.IdChain.ForEach((item) => this.idChain.Add(item)); } // This state id is the leaf this.idChain.Add(id); this.BuildName(); }); }
/// <summary> /// Handle the NextState Transition type by setting the next state as /// </summary> /// <param name="tr"></param> /// <param name="msg"></param> /// <returns></returns> private ISpStateTransition HandleNextStateTransitionType(ISpStateTransition tr, ISpEventMessage msg) { Log.Info(this.className, "HandleNextStateTransitionType", String.Format("'{0}' State", this.FullName)); WrapErr.ChkTrue(tr.TransitionType == SpStateTransitionType.NextState, 9999, () => { return(String.Format("{0} is not NextState", tr.TransitionType)); }); WrapErr.ChkVar(tr.NextState, 9999, () => { return (String.Format( "State {0} Specified Next State on Event {1} but Next State Null", this.currentState.FullName, this.GetCachedEventId(msg.EventId))); }); this.currentState.OnExit(); this.currentState = tr.NextState; return(this.currentState.OnEntry(this.MsgFactory.GetDefaultResponse(msg))); }
/// <summary> /// Execute on each tick period /// </summary> /// <param name="msg">The incoming message with event</param> /// <returns>The return transition object with result information</returns> public sealed override ISpStateTransition OnTick(ISpEventMessage msg) { //Log.Info(this.className, "OnTick", String.Format("'{0}' State", this.FullName)); WrapErr.ChkVar(this.entryState, 9999, "The 'SetEntryState() Must be Called in the Constructor"); WrapErr.ChkVar(this.currentState, 9999, "Current state is not set"); WrapErr.ChkTrue(this.IsEntryExcecuted, 9999, "Tick Being Called before OnEntry"); // If there are OnEvent transitions registered at the superstate level return immediately ISpStateTransition tr = GetSuperStateOnEventTransition(msg); if (tr != null) { return(tr); } return(this.GetTransition(this.currentState.OnTick, msg)); }
/// <summary> /// Execute logic on entry into this superstate /// </summary> /// <param name="msg">The incoming message with event</param> /// <returns>The return transition object with result information</returns> public sealed override ISpStateTransition OnEntry(ISpEventMessage msg) { Log.Info(this.className, "OnEntry", String.Format("'{0}' State Event {1}", this.FullName, this.GetCachedEventId(msg.EventId))); WrapErr.ChkVar(this.entryState, 9999, "The 'SentEntryState() Must be Called in the Constructor"); // Find if there are exit conditions OnEntry at the SuperState level and excecute them first // This will check OnEvent transitions queue and transitions from the overriden ExecOnEntry ISpStateTransition t = base.OnEntry(msg); if (t.TransitionType != SpStateTransitionType.SameState) { return(t); } // return transition this.currentState = this.entryState; return(this.currentState.OnEntry(msg)); }
public void OnWakeup_PulseCount() { WrapErr.ChkVar(this.timer, 9, ""); int count = 0; this.timer.SetInterval(new TimeSpan(0, 0, 0, 0, 100)); this.timer.OnWakeup += new Action(() => { count++; Trace.WriteLine(string.Format("Wakeup {0}", count)); }); this.timer.Start(); Thread.Sleep(1000); this.timer.Stop(); Thread.Sleep(500); Assert.IsTrue(count >= 9 && count <= 11, String.Format("pulse count:{0} was not between 9 & 11", count)); Console.WriteLine("Pulse Count on every 100ms for 1 second is {0}", count); }
public string IconSource(UIIcon code) { ErrReport report; string source = WrapErr.ToErrReport(out report, 9999, () => string.Format(""), () => { string tmp = ""; this.IconInfo(code, (info) => { tmp = info.IconSource as string; WrapErr.ChkVar(tmp, 9999, () => string.Format("No source string for {0}", code)); WrapErr.ChkTrue(tmp.Length > 0, 9999, () => string.Format("0 length source string for {0}", code)); }, (msg) => { tmp = ""; }); return(tmp); }); return(report.Code == 0 ? source : ""); }
/// <summary> /// Read the transition object to determine behavior /// </summary> /// <param name="tr">The transition object</param> /// <param name="msg">the current event message</param> /// <param name="superStateLevelEvent"> /// true if the transition object is from the current substate, false if the transition was generated /// by the superstate based on a previous Defered Transition type generated from the substate. This /// prevents infinite recursion. /// </param> /// <returns>A Transtion object with the results of the state processing</returns> ISpStateTransition ReadTransitionType(ISpStateTransition tr, ISpEventMessage msg, bool superStateLevelEvent) { WrapErr.ChkVar(tr, 9999, "The transition is null"); switch (tr.TransitionType) { case SpStateTransitionType.SameState: return(tr); case SpStateTransitionType.NextState: return(this.HandleNextStateTransitionType(tr, msg)); case SpStateTransitionType.ExitState: return(this.HandleExitStateTransitionType(msg)); case SpStateTransitionType.Defered: return(this.HandleDeferedStateTransitionType(tr, msg, superStateLevelEvent)); default: WrapErr.ChkTrue(false, 9999, String.Format("Transition Type {0} not Handled", tr.TransitionType)); return(tr); } }
/// <summary> /// Handle the substate ExitState Transition Type by using the event msg passed to it to do a lookup /// of this super state's transitions. The super state should have a transition that has been /// registered to the same id /// </summary> /// <param name="msg"></param> /// <returns></returns> private ISpStateTransition HandleExitStateTransitionType(ISpEventMessage msg) { Log.Info(this.className, "HandleExitStateTransitionType", String.Format("'{0}' State", this.FullName)); // TODO - this is really only another kind of defered. The difference is that the superstate does not // TODO called at runtime to handle the event. Rather the event is passed to the super state's // TODO registered events. In this scenario it may not actually exit the super state but process // the event id to something else. The difference is that the results are being determined // by the registrations at the superstate level rather than the sub state level // Check super state registered result transitions against Sub State event id ISpStateTransition tr = this.GetSuperStateOnResultTransition(msg); WrapErr.ChkVar(tr, 9999, () => { return(String.Format( "State {0} Specified Exit but SuperState {1} has no handlers for that event id:{2}", this.currentState.FullName, this.FullName, this.GetCachedEventId(msg.EventId))); }); // At this point, the transition registered to the superstate should have everything set in it return(tr); }
public void ExceptionType_Regular_Var() { CheckExceptionType(() => { WrapErr.ChkVar(null, 8888, "Bad var"); }); }
public ObjCreator(Func <object> constructor) { WrapErr.ChkVar(constructor, 9999, "Constructor passed in is null"); this.objBuilder = constructor; }