public void AddNewFlightPlan(FlightPlan flightPlan)
 {
     //add flight plan to DB
     if (flightPlan == null || flightPlan.IsNull() ||
         !TimeFunc.ValidStringDate(flightPlan.InitialLocation.DateTime))
     {
         throw new Exception();
     }
     db.AddFlightPlan(flightPlan, CreateId());
 }
Exemple #2
0
 public bool IsNull()
 {
     //check validation
     if (DateTime == null || Longitude > 180 ||
         Longitude < -180 || Latitude > 90 || Latitude < -90 ||
         !TimeFunc.ValidStringDate(DateTime))
     {
         return(true);
     }
     return(false);
 }
Exemple #3
0
        private void UpdateFlight(List <DateTime> dateTimes, DateTime requestTime,
                                  FlightPlanId fid, List <Segment> segments, List <Flight> currentFlight)
        {
            FlightPlan f = fid.FlightP;
            //find current segment of flight
            int numSegment = FindSpecificSegment(dateTimes, requestTime);

            double   longStart, longEnd, latStart, latEnd;
            DateTime startSegment = dateTimes[numSegment];
            DateTime endSegment   = dateTimes[numSegment + 1];
            //num seconds passed from the beginning of the segment
            double secondsPast = (requestTime - startSegment).TotalSeconds;
            //total seconds that left in segment
            double secondLeft = (endSegment - requestTime).TotalSeconds;

            //calculate current place
            if (numSegment == 0)
            {
                longStart = f.InitialLocation.Longitude;
                longEnd   = segments[numSegment].Longitude;

                latStart = f.InitialLocation.Latitude;
                latEnd   = segments[numSegment].Latitude;
            }
            else
            {
                longStart = segments[numSegment - 1].Longitude;
                longEnd   = segments[numSegment].Longitude;

                latStart = segments[numSegment - 1].Latitude;
                latEnd   = segments[numSegment].Latitude;
            }
            double newX = (longStart * secondLeft + longEnd * secondsPast) /
                          (secondsPast + secondLeft);
            double newY = (latStart * secondLeft + latEnd * secondsPast) /
                          (secondsPast + secondLeft);

            //add the new Flight to list
            currentFlight.Add(new Flight(fid.ID, newX, newY,
                                         f.Passengers, f.CompanyName, TimeFunc.ConvertDate(requestTime), false));
        }
Exemple #4
0
        public List <Flight> GetFlightsFromServer(string relative_to)
        {
            //interuplation of flight place
            List <Flight>       currentFlight = new List <Flight>();
            List <FlightPlanId> flightPlan    = db.GetFlightPlans();

            foreach (FlightPlanId fid in flightPlan)
            {
                FlightPlan f           = fid.FlightP;
                DateTime   requestTime =
                    TimeFunc.CreateDateTimeFromString(relative_to);
                List <Segment>  segments  = f.Segments;
                List <DateTime> dateTimes = CreateAllDataTimeClient(segments,
                                                                    TimeFunc.CreateDateTimeFromString(f.InitialLocation.DateTime));
                //if flight is now
                if (FlightIsNow(requestTime, dateTimes[0], dateTimes[dateTimes.Count - 1]))
                {
                    //get the new place of flight
                    UpdateFlight(dateTimes, requestTime, fid, segments, currentFlight);
                }
            }
            return(currentFlight);
        }