/// <summary> /// The flight object creation request method /// </summary> /// <param name="req">the request from the user side</param> /// <returns>the response to the user side</returns> public ResponseFlightObject CreateFlightObject(RequestFlightObject req) { int flightSerial = default(int); FlightDTO flight = null; try { //gets a random serial flightSerial = arrivalSim.CreateFlightSerial(); //creates a flight object in DB with a serial property only. //flight 'isAlive' prperty set to false flight = ctRepo.CreateFlightObject(flightSerial); } catch (Exception e) { throw new Exception($"Flight serial OR Flight object could not bet created. {e.Message}"); } return(new ResponseFlightObject { Flight = flight, IsSuccess = true, Message = $"Flight #{flight.FlightSerial} has been created." }); }
/// <summary> /// the simulator timer's elapsed event /// </summary> /// <param name="sender">the timer caller</param> /// <param name="e">the event arguments of the event</param> void CreateFlight_ArrivalTimerElapsed(object sender, ElapsedEventArgs e) { //the timer pauses until the current flight is created fully if (sender is Timer) { (sender as Timer).Stop(); } ResponseFlightObject resFlight = null; try { //a request is being made to the service to create a flight objest RequestFlightObject reqFlight = new RequestFlightObject() { CurrentFlights = simProxy.GetFlightsCollection().Flights }; resFlight = simProxy.CreateFlightObject(reqFlight); } catch (Exception ex) { throw new Exception($"Could not retrieve collection OR create flight object. {ex.Message}"); } //if the fligts has been created successfully if (resFlight.IsSuccess) { //the first interval is retreived by the proxy from the first checkpoint double initialDuration = simProxy.GetCheckpointDuration(new RequestCheckpointDuration() { CheckpointSerial = "1", CheckpointType = CheckpointType.Landing.ToString() }).CheckpointDuration; //the current flight & a new timer, for checkpoint promotion, are being saved into the simproxy hash simProxy.flightsTimers[resFlight.Flight] = new Timer(initialDuration); simProxy.flightsTimers[resFlight.Flight].Elapsed += PromotionTimer_Elapsed; simProxy.flightsTimers[resFlight.Flight].Start(); } else { throw new Exception("No success retrieving flight response."); } //the object creation timer unpauses (sender as Timer).Start(); }
public ResponseFlightObject CreateFlightObject(RequestFlightObject req) { return(simService.CreateFlightObject(req)); }