public void StopOverAt(ILocation location) { if (null == location) { throw new ArgumentNullException("location"); } // Thread safe, lock free sincronization VoyageState stateBeforeTransition; VoyageState previousState = CurrentState; do { stateBeforeTransition = previousState; VoyageState newValue = stateBeforeTransition.StopOverAt(location); previousState = Interlocked.CompareExchange <VoyageState>(ref this.CurrentState, newValue, stateBeforeTransition); }while (previousState != stateBeforeTransition); if (!previousState.Equals(this.CurrentState)) { VoyageEventArgs args = new VoyageEventArgs(previousState.LastKnownLocation, previousState.NextExpectedLocation); EventHandler <VoyageEventArgs> handler = Stopped; if (null != handler) { handler(this, args); } } }
public void DepartFrom(ILocation location) { if (null == location) { throw new ArgumentNullException("location"); } VoyageState stateBeforeTransition; VoyageState previousState = CurrentState; do { stateBeforeTransition = previousState; VoyageState newValue = stateBeforeTransition.DepartFrom(location); previousState = Interlocked.CompareExchange <VoyageState>(ref this.CurrentState, newValue, stateBeforeTransition); }while (previousState != stateBeforeTransition); if (!previousState.Equals(this.CurrentState)) { VoyageEventArgs args = new VoyageEventArgs(CurrentState.LastKnownLocation, CurrentState.NextExpectedLocation); EventHandler <VoyageEventArgs> handler = Departed; if (null != handler) { handler(this, args); } } }
protected Voyage(VoyageState initialState) { if (null == initialState) { throw new ArgumentNullException("initialState"); } CurrentState = initialState; }
public override bool Equals(VoyageState other) { if (object.ReferenceEquals(this, other)) { return(true); } CompletedVoyage voyage = other as CompletedVoyage; if (null == voyage) { return(false); } return(Number.Equals(voyage.Number) && Schedule.Equals(voyage.Schedule)); }
public override bool Equals(VoyageState other) { if (object.ReferenceEquals(this, other)) { return(true); } StoppedVoyage voyage = other as StoppedVoyage; if (null == voyage) { return(false); } return(Number.Equals(voyage.Number) && _movementIndex == voyage._movementIndex && Schedule.Equals(voyage.Schedule)); }