コード例 #1
0
        /// <summary>
        /// The flight's checkpoint promotion evaluation method
        /// </summary>
        /// <param name="sender">the proxy caller</param>
        /// <param name="flight">the current flight object</param>
        void SimProxy_OnPromotionEvaluationEvent(object sender, FlightDTO flight)
        {
            //a request is being made to the service in order to calculate the flight's next checkpoint
            RequestFlightPosition reqPosition = new RequestFlightPosition()
            {
                //a hash of all the checkpoints flight serial
                TxtblckNameFlightNumberHash = SetTxtblckHash(txtblckCheckpoints),
                //a hash of the the stand-by flight serial list
                LstvwNameFlightsListHash = SetLstvwHash(lstvwsCheckpoints),
                //the cuurent flight's serial
                FlightSerial = flight.FlightSerial.ToString(),
                //bool value for is flight boarding
                IsBoarding = EvaluateTerminalState(flight)
            };

            //the service retrieves all the data for the flight's next checkpoint & updates database
            ResponseFlightPosition resPosition = simProxy.GetFlightPosition(reqPosition);

            /**simproxy flight_timer hash update**/
            //values to remove from the simproxy flight_timer hash
            KeyValuePair <FlightDTO, Timer> keyToRemove = new KeyValuePair <FlightDTO, Timer>(flight, simProxy.flightsTimers[flight]);
            //flight object with values in 'FlightSerial' property only
            FlightDTO previousFlightObject = flight;

            //flight object with full properties
            flight = simProxy.GetFlight(flight.FlightSerial);
            //values to replace the current flight_timer values in the simproxy hash
            KeyValuePair <FlightDTO, Timer> keyToAdd = new KeyValuePair <FlightDTO, Timer>(flight, simProxy.flightsTimers[previousFlightObject]);

            simProxy.UpdateflightsTimersHash(flight, keyToRemove, keyToAdd);

            if (resPosition.IsSuccess)
            {
                /**current flight's timer's interval set to next checkpoint's duration**/
                //if the next checkpoint in not to land or depart,
                if (flight.Checkpoint != null && resPosition.NextCheckpointName != "Departed!")
                {
                    //set timer's interval to updated flight's checkpoint's duration
                    double duration = flight.Checkpoint.Duration;
                    simProxy.flightsTimers[flight].Interval = duration;
                }
                //if the next checkpoint serial & type has values,
                else if (resPosition.CheckpointSerial != -1 && resPosition.CheckpointType != null)
                {
                    //request is made to service to retrieve the next checkpoint object
                    RequestCheckpointDuration reqDur = new RequestCheckpointDuration()
                    {
                        CheckpointSerial = resPosition.CheckpointSerial.ToString()
                    };
                    ResponseCheckpointDuration resDur = simProxy.GetCheckpointDuration(reqDur);
                    //and set timer's interval to next checkpoint duration
                    if (resDur.IsSuccess)
                    {
                        simProxy.flightsTimers[flight].Interval = resDur.CheckpointDuration;
                    }
                }

                /**binding data update**/
                //if the last flight's position was in terminal
                if (resPosition.LastCheckpointPosition == "txtblckFlightTerminal1" || resPosition.LastCheckpointPosition == "txtblckFlightTerminal2")
                {
                    //update the binding data by next checkpoint serial
                    SwitchOnCheckpointSerial(airportUserControl.Dispatcher, resPosition.CheckpointSerial, resPosition.CheckpointType,
                                             resPosition.NextCheckpointName, resPosition.LastCheckpointPosition, flight);
                    return;
                }
                //update binding data by next checkpoint's textblock or listview name property
                bool?isFound = SwitchOnNextCheckpointName(airportUserControl.Dispatcher, resPosition.NextCheckpointName, flight);
                //if last switch returns null,
                if (isFound == null)
                {
                    //check if the flight's next checkpoint is to cercle around or depart
                    if (resPosition.NextCheckpointName == "Departed!" || resPosition.NextCheckpointName == "No access to field!")
                    {
                        //dispose flight
                        simProxy.OnDispose(flight.FlightSerial);
                        KeyValuePair <FlightDTO, Timer> keyToDispose = new KeyValuePair <FlightDTO, Timer>(flight, simProxy.flightsTimers[flight]);
                        //dispose timer
                        simProxy.UpdateflightsTimersHash(null, keyToDispose, new KeyValuePair <FlightDTO, Timer>());
                    }
                    return;
                }
                //if the last switch returns false,
                if (isFound == false)
                {
                    //update the binding data by next checkpoint serial for all other checkpoints
                    SwitchOnCheckpointSerial(airportUserControl.Dispatcher, resPosition.CheckpointSerial, resPosition.CheckpointType,
                                             resPosition.NextCheckpointName, resPosition.LastCheckpointPosition, flight);
                }
            }
        }
コード例 #2
0
 public ResponseFlightPosition GetFlightPosition(RequestFlightPosition req)
 {
     return(simService.GetFlightPosition(req));
 }
コード例 #3
0
        /// <summary>
        /// The current flight promotion evaluation method
        /// </summary>
        /// <param name="req">the request from the user side</param>
        /// <returns>the response to the user side</returns>
        public ResponseFlightPosition GetFlightPosition(RequestFlightPosition req)
        {
            //the next checkpoint's control name
            string newCheckpointName = default(string);
            //the current flight's checkpoint's control name
            string lastCheckpointPosition = default(string);
            //the next checkpoint's serial
            int newCheckpointSerial = default(int);
            //the current checkpoint's serial
            int       lastCheckpointSerial = default(int);
            FlightDTO flight = null;

            try
            {
                //get the flight object from DB by serial
                flight = ctRepo.GetFlightObject(int.Parse(req.FlightSerial));
                if (flight == null)
                {
                    throw new Exception("Flight serial was not found.");
                }
                //retrieves the current flight's serial & checkpoint's control name from DB
                lastCheckpointPosition = ctRepo.GetFlightCheckpoint(req.TxtblckNameFlightNumberHash, req.LstvwNameFlightsListHash,
                                                                    req.FlightSerial, req.IsBoarding, out lastCheckpointSerial);
                //the simulator class calulates the next checkpoint's serial & control name
                newCheckpointName = timingSim.GetFlightPosition(req.TxtblckNameFlightNumberHash, req.LstvwNameFlightsListHash, flight, req.IsBoarding, out newCheckpointSerial);
            }
            catch (Exception e)
            {
                throw new Exception($"Flight #{req.FlightSerial} new position was not computed. {e.Message}");
            }
            //the next checkpoint's type enum
            string checkpointType = default(string);

            //if the next checkpoint is outside the airport, no DB update accurs in this method (will accure later by the dispose request)
            if (newCheckpointName == "Departed!")
            {
            }
            //if the last checkpoint is a terminal
            else if (lastCheckpointPosition == "txtblckFlightTerminal1" || lastCheckpointPosition == "txtblckFlightTerminal2")
            {
                //the next checkpoint is the current position
                newCheckpointName = lastCheckpointPosition;
                //updates checkpoint entities in DB with the new checkpoint credencials only, retrieves the checkpoint's type enum
                checkpointType = ctRepo.UpdateCheckpoints(newCheckpointSerial, newCheckpointName, lastCheckpointSerial, flight);
                //updates the flight entity in DB with the new & last checkpoint's serial,
                //indicates if the flight is starting the landing process
                ctRepo.UpdateFlightObject(flight, newCheckpointSerial, lastCheckpointSerial, false);
            }
            //if the new checkpoint doesn't holds one of the following actions
            else if (newCheckpointName != "Stay in checkpoint!" && newCheckpointName != "No access to field!")
            {
                //updates checkpoint entities in DB with new & last checkpoint's credencials
                checkpointType = ctRepo.UpdateCheckpoints(newCheckpointSerial, lastCheckpointPosition, lastCheckpointSerial, flight);
                //if the last checkpoint doesn't holds the following action
                if (lastCheckpointPosition != "none")
                {
                    //updates the flight entity in DB
                    ctRepo.UpdateFlightObject(flight, newCheckpointSerial, lastCheckpointSerial, false);
                }
            }

            //returns all the necessary data to the user side
            return(new ResponseFlightPosition()
            {
                IsSuccess = true,
                Message = $"Flight #{req.FlightSerial} new position retrieved.",
                NextCheckpointName = newCheckpointName,
                CheckpointSerial = newCheckpointSerial,
                CheckpointType = checkpointType,
                LastCheckpointPosition = lastCheckpointPosition
            });
        }