コード例 #1
0
        public void SpecifyNewRoute(IRouteSpecification routeSpecification)
        {
            // Thread safe, lock free sincronization
            CargoState stateBeforeTransition;
            CargoState previousState = CurrentState;

            do
            {
                stateBeforeTransition = previousState;
                CargoState newValue = stateBeforeTransition.SpecifyNewRoute(routeSpecification);
                previousState = Interlocked.CompareExchange <CargoState>(ref this.CurrentState, newValue, stateBeforeTransition);
            }while (previousState != stateBeforeTransition);

            if (!previousState.Equals(this.CurrentState))
            {
                ChangeEventArgs <IRouteSpecification> args = new ChangeEventArgs <IRouteSpecification>(previousState.RouteSpecification, CurrentState.RouteSpecification);

                EventHandler <ChangeEventArgs <IRouteSpecification> > handler = NewRouteSpecified;
                if (null != handler)
                {
                    handler(this, args);
                }
            }
        }
コード例 #2
0
        public void AssignToRoute(IItinerary itinerary)
        {
            // Thread safe, lock free sincronization
            CargoState stateBeforeTransition;
            CargoState previousState = CurrentState;

            do
            {
                stateBeforeTransition = previousState;
                CargoState newValue = stateBeforeTransition.AssignToRoute(itinerary);
                previousState = Interlocked.CompareExchange <CargoState>(ref this.CurrentState, newValue, stateBeforeTransition);
            }while (previousState != stateBeforeTransition);

            if (!previousState.Equals(this.CurrentState))
            {
                ChangeEventArgs <IItinerary> args = new ChangeEventArgs <IItinerary>(previousState.Itinerary, CurrentState.Itinerary);

                EventHandler <ChangeEventArgs <IItinerary> > handler = ItineraryChanged;
                if (null != handler)
                {
                    handler(this, args);
                }
            }
        }
コード例 #3
0
        public void Unload(Voyage.IVoyage voyage, DateTime date)
        {
            // Thread safe, lock free sincronization
            CargoState stateBeforeTransition;
            CargoState previousState = CurrentState;

            do
            {
                stateBeforeTransition = previousState;
                CargoState newValue = stateBeforeTransition.Unload(voyage, date);
                previousState = Interlocked.CompareExchange <CargoState>(ref this.CurrentState, newValue, stateBeforeTransition);
            }while (previousState != stateBeforeTransition);

            if (!previousState.Equals(this.CurrentState))
            {
                HandlingEventArgs args = new HandlingEventArgs(CurrentState, CurrentState.CalculationDate);

                EventHandler <HandlingEventArgs> handler = Unloaded;
                if (null != handler)
                {
                    handler(this, args);
                }
            }
        }