Exemplo n.º 1
0
        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);
                }
            }
        }
Exemplo n.º 2
0
        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);
                }
            }
        }
Exemplo n.º 3
0
 protected Voyage(VoyageState initialState)
 {
     if (null == initialState)
     {
         throw new ArgumentNullException("initialState");
     }
     CurrentState = initialState;
 }
Exemplo n.º 4
0
        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));
        }
Exemplo n.º 5
0
        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));
        }