public void Dispose() { if (sessionCallback != null) { CallbacksHolder.Instance().Remove(sessionCallback); } }
//assuming the airplane is already in a station... public void MoveToNextStation(Object o) { Flight flight = (Flight)o; Station nextStation; if (flight.State == Models.State.Landing) { nextStation = GetShortestQueue(flight.CurrentStation.NextLandingStations); } else { nextStation = GetShortestQueue(flight.CurrentStation.NextFlyingStations); } if (nextStation == null || nextStation.EnqueueFlight(flight)) { Station prevStation = flight.CurrentStation; flight.CurrentStation = nextStation; if (nextStation != null) { CallbacksHolder.Instance().StationStateUpdate(nextStation); new Timer(MoveToNextStation, flight, rnd.Next(10000, 60000), 0); } else { // add to history... } HandlePrevStation(prevStation); } }
public static CallbacksHolder Instance() { if (self == null) { self = new CallbacksHolder(); } return(self); }
private void InitCallback() { sessionCallback = null; OperationContext opCtx = OperationContext.Current; if (opCtx != null) { sessionCallback = opCtx.GetCallbackChannel <IAirportDuplexCallback>(); CallbacksHolder.Instance().Add(sessionCallback); } }
public void StartTakingOff(Flight flight) { Station st; st = GetShortestQueue(airport.FirstFlyingStations); // if this is the only flight in station if (st.EnqueueFlight(flight)) { CallbacksHolder.Instance().StationStateUpdate(st); flight.CurrentStation = st; Timer timer = new Timer(MoveToNextStation, flight, rnd.Next(10000, 60000), 0); } }
private Flight GetFlight() { if (flights.Count == 0) { return(null); } DTOs.FlightDTO flightDTO = flights.First(); Flight flight = new Flight() { ID = flightDTO.ID, State = (Models.State)Enum.Parse(typeof(Models.State), flightDTO.State.ToString()), CurrentStation = null, StartRouteTime = flightDTO.StartRouteTime }; flights.Remove(flightDTO); CallbacksHolder.Instance().FlightRemove(flightDTO); return(flight); }
private void HandlePrevStation(Station station) { if (station == null) { return; } // pops the flight currently in the station and get the next one Flight flight = station.DequeueFlight(); CallbacksHolder.Instance().StationStateUpdate(station); // if there's a next flight if (flight != null) { Station prevStation = flight.CurrentStation; flight.CurrentStation = station; new Timer(MoveToNextStation, flight, rnd.Next(10000, 60000), 0); HandlePrevStation(prevStation); } }
public bool ScheduleNewFlight(DTOs.FlightDTO flightDTO) { //add new flight to the db schedule table and get it back with unique id DTOs.FlightDTO newFlight = repo.AddFlightToSchedule(flightDTO); DTOs.FlightDTO firstFlight = flights.Count == 0 ? null : flights.First(); if (newFlight == null) { return(false); } if (!flights.Add(newFlight)) { return(false); } CallbacksHolder.Instance().FlightAdd(newFlight); if (firstFlight == null || newFlight.StartRouteTime < firstFlight.StartRouteTime) { TimeSpan timeUntilNextFlight = GetNextTimeSpan(); scheduleTimer.Change(timeUntilNextFlight, timeUntilNextFlight); } return(true); }