コード例 #1
0
        private async Task <Location> GetFlightLocation(FlightPlan flightPlan, DateTime dateTime)
        {
            var flightInitialLocation = await _context.InitialLocation.FindAsync(flightPlan.FlightId);

            DateTime time         = flightInitialLocation.DateTime;
            DateTime prevTime     = time;
            Location prevLocation = new Location {
                Longitude = flightInitialLocation.Longitude, Latitude = flightInitialLocation.Latitude
            };
            //Location location = new Location();
            TimeSpan   flightTime  = dateTime - flightInitialLocation.DateTime;
            var        segments    = _context.Segments.Where(s => s.FlightId == flightPlan.FlightId);
            SegmentDto prevSegment = null;

            foreach (Segment segment in segments)
            {
                flightTime = flightTime - TimeSpan.FromSeconds(segment.TimeSpanSeconds);
                if (flightTime.TotalSeconds < 0 || flightTime.TotalSeconds == 0)
                {
                    return(CalculateLocation(flightInitialLocation, flightTime, prevSegment, segment));
                }
                prevSegment = new SegmentDto {
                    Latitude = segment.Latitude, Longitude = segment.Longitude, TimeSpanSeconds = segment.TimeSpanSeconds
                };
            }


            return(null);
        }
コード例 #2
0
        private async Task CreateFlight(DateTime dateTime, List <Flight> flights, FlightPlan fp)
        {
            InitialLocation initialLocation = await _context.InitialLocation.FindAsync(fp.FlightId);

            var landingTime = await LandingTime(fp);

            if (initialLocation != null && ((initialLocation.DateTime.CompareTo(dateTime) < 0 && landingTime.CompareTo(dateTime) > 0) || initialLocation.DateTime.CompareTo(dateTime) == 0))
            {
                Location location = await GetFlightLocation(fp, dateTime);

                if (location != null)
                {
                    flights.Add(new Flight
                    {
                        FlightId    = fp.FlightId,
                        Longitude   = location.Longitude,
                        Latitude    = location.Latitude,
                        Passengers  = fp.Passengers,
                        CompanyName = fp.CompanyName,
                        DateTime    = dateTime,
                        IsExternal  = false
                    });
                }
            }
        }
コード例 #3
0
        public async Task <ActionResult <FlightPlan> > AddFlightPlan(FlightPlanDto flightPlanDto)
        {
            string flightId   = CreateId(flightPlanDto.CompanyName);
            var    flightPlan = new FlightPlan
            {
                FlightId        = flightId,
                Passengers      = flightPlanDto.Passengers,
                CompanyName     = flightPlanDto.CompanyName,
                InitialLocation = new InitialLocation
                {
                    Id        = flightId,
                    Longitude = flightPlanDto.InitialLocation.Longitude,
                    Latitude  = flightPlanDto.InitialLocation.Latitude,
                    DateTime  = flightPlanDto.InitialLocation.DateTime
                }
            };

            FromSegmentsDtoToSegments(flightPlanDto.Segments, flightPlan.Segments, flightId);

            await _context.FlightsPlans.AddAsync(flightPlan);

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                throw;
            }

            return(flightPlan);
        }
コード例 #4
0
        // Create a FlightPlan object.
        private FlightPlan SetFlightPlan(object[] basicData, object[] initialLocation,
                                         List <object[]> segments)
        {
            FlightPlan flightPlan = new FlightPlan();

            if (basicData[0] == null)
            {
                return(null);
            }

            flightPlan.Passengers  = Convert.ToInt32(basicData[flightPlanPassangersE]);
            flightPlan.CompanyName = Convert.ToString(basicData[flightPlanCompanyNameE]);

            double   longitude = Convert.ToDouble(initialLocation[initialLocationLongitudeE]);
            double   latitude  = Convert.ToDouble(initialLocation[initialLocationLatitudeE]);
            DateTime dateTime  = Convert.ToDateTime(initialLocation[initalLocationDateTimeE]);
            Location location  = new Location(longitude, latitude, dateTime);

            flightPlan.InitialLocation = location;

            foreach (object[] segment in segments.ToArray())
            {
                double  longitudeS     = Convert.ToDouble(segment[segmentLongitudeE]);
                double  latitudeS      = Convert.ToDouble(segment[segmentLatitudeE]);
                int     TimespanSecond = Convert.ToInt32(segment[segmenTimespanSecondE]);
                Segment segment1       = new Segment(longitudeS, latitudeS, TimespanSecond);
                flightPlan.Segments.Add(segment1);
            }
            return(flightPlan);
        }
コード例 #5
0
        public FlightPlanDB FlightsPlanById(string id)
        {
            InitialLocation initialLocation;
            FlightPlanDB    flightPlanDB = null;
            FlightPlan      flightPlan;
            string          query = $"SELECT * FROM Flight WHERE id = '{id}'";

            SQLiteCommand myCommand = new SQLiteCommand(query, databaseObject.myConnection);
            ////databaseObject.OpenConnection();
            SQLiteDataReader result = myCommand.ExecuteReader();

            // Creating a List of integers

            if (result.HasRows)
            {
                while (result.Read())
                {
                    string company   = $"{result["company"]}";
                    int    passenger = Convert.ToInt32($"{result["passengers"]}");
                    //create initial location
                    initialLocation = new InitialLocation(Convert.ToDouble(
                                                              $"{result["start_longitude"]}"),
                                                          Convert.ToDouble($"{result["start_latitude"]}"),
                                                          FromStringToDate($"{result["start_time"]}"));
                    //create flightplan
                    flightPlan = new FlightPlan(passenger, company,
                                                initialLocation, SegmentList(id));
                    flightPlanDB = new FlightPlanDB(id, flightPlan);
                }
            }
            //databaseObject.CloseConnection();


            return(flightPlanDB);
        }
コード例 #6
0
 // Insert a FlightPlan into the data base.
 public void InsertFlightPlan(FlightPlan flightPlan, string id)
 {
     OpenConnection();
     InsertToFlightPlanTable(flightPlan, id);
     InsertToInitialLocationTable(flightPlan, id);
     InsertToSegmentsTable(flightPlan, id);
     CloseConncetion();
 }
コード例 #7
0
 public Flight(FlightPlan flightplan, bool is_external)
 {
     this.FlightID     = flightplan.ID;
     this.Longitude    = flightplan.Initial_Location.Longitude;
     this.Latitude     = flightplan.Initial_Location.Latitude;
     this.Passengers   = flightplan.Passengers;
     this.Company_name = flightplan.Company_Name;
     this.Date_time    = flightplan.Initial_Location.Date_Time;
     this.Is_external  = is_external;
 }
コード例 #8
0
 public Flight(FlightPlan f, string id)
 {
     FlightId    = id;
     Latitude    = f.InitialLocation.Latitude;
     Longitude   = f.InitialLocation.Longitude;
     Passengers  = f.Passengers;
     CompanyName = f.CompanyName;
     DateTime    = f.InitialLocation.DateTime;
     string temp = FlightId;
 }
コード例 #9
0
        public async Task <FlightPlan> GetFlightPlan(string id)
        {
            FlightPlan fp = null;

            foreach (FlightData x in internalFlights) // first search in internals
            {
                if (x.Id == id)
                {
                    fp = x.Fp;
                }
            }
            if (fp == null) // if not found search in externals
            {
                foreach (ServerInfo si in externalFlightsServers.ToList <ServerInfo>())
                {
                    // Create a New HttpClient object.
                    HttpClient client = new HttpClient();

                    // Call asynchronous network methods in a try/catch block to handle exceptions
                    try
                    {
                        HttpResponseMessage response = await client.GetAsync(si.ServerURL + "/api/FlightPlan/" + id);

                        response.EnsureSuccessStatusCode();
                        string responseBody = await response.Content.ReadAsStringAsync();

                        Console.WriteLine(responseBody);
                        fp = Newtonsoft.Json.JsonConvert.DeserializeObject <FlightPlan>(responseBody);
                    }
                    catch (HttpRequestException e)
                    {
                        Console.WriteLine("\nException Caught!");
                        Console.WriteLine("Message :{0} ", e.Message);
                    }

                    // Need to call dispose on the HttpClient object
                    // when done using it, so the app doesn't leak resources
                    client.Dispose();

                    //responseBody now holds info that came from server
                    //convert from Json to list:

                    if (fp.Company_name != null)
                    {
                        return(fp);
                    }
                }
            }
            else
            {
                return(fp);
            }
            return(null);
        }
コード例 #10
0
        public static TimeSpan TotalTime(this FlightPlan plan)
        {
            double total_seconds = 0;

            foreach (var segment in plan.segments)
            {
                total_seconds += segment.timespan_seconds;
            }

            return(TimeSpan.FromSeconds(total_seconds));
        }
コード例 #11
0
        private async Task <DateTime> LandingTime(FlightPlan flightPlan)
        {
            var initialLocation = await _context.InitialLocation.FindAsync(flightPlan.FlightId);

            DateTime landingDateTime = initialLocation.DateTime;
            var      segments        = _context.Segments.Where(s => s.FlightId == flightPlan.FlightId);

            foreach (Segment s in segments)
            {
                landingDateTime = landingDateTime.AddSeconds(s.TimeSpanSeconds);
            }
            return(landingDateTime);
        }
コード例 #12
0
        public static (double latitude, double longitude) InterpolateLocation
            (this FlightPlan plan, DateTime dateTime)
        {
            var startLoc = new Loc(
                plan.initial_location.latitude,
                plan.initial_location.longitude);

            var timeDiff  = dateTime - plan.initial_location.date_time;
            var totalTime = timeDiff.TotalSeconds;

            var loc = LinearInterpolation(startLoc, plan.segments, totalTime);

            return(loc.latitude, loc.longitude);
        }
コード例 #13
0
        public FlightData(FlightPlan fp)
        {
            Random rnd     = new Random();
            int    a       = rnd.Next(10);
            int    b       = rnd.Next(10);
            int    c       = rnd.Next(10);
            int    d       = rnd.Next(10);
            int    e       = rnd.Next(10);
            int    f       = rnd.Next(10);
            string serial1 = a.ToString() + b.ToString() + c.ToString() + d.ToString();
            string serial2 = e.ToString() + f.ToString();

            Id      = "FLY" + serial1 + "NM" + serial2;
            this.fp = fp;
        }
コード例 #14
0
        // Insert the given FlightPlan into the FlightPlanTable.
        private void InsertToFlightPlanTable(FlightPlan flightPlan, string id)
        {
            SqliteCommand insertCommand = new SqliteCommand();

            insertCommand.Connection = conn;

            insertCommand.CommandText = "INSERT INTO FlightPlanTable VALUES" +
                                        " (@Id , @Passengers, @CompanyName)";
            insertCommand.Parameters.AddWithValue("@Id", id);
            insertCommand.Parameters.AddWithValue("@Passengers", flightPlan.Passengers);
            insertCommand.Parameters.AddWithValue("@CompanyName", flightPlan.CompanyName);

            try
            {
                insertCommand.ExecuteReader();
            }
            catch { }
        }
コード例 #15
0
        // Insert the given FlightPlan's InitialLocation into the InitialLocationTable.
        private void InsertToInitialLocationTable(FlightPlan flightPlan, string id)
        {
            SqliteCommand insertCommand = new SqliteCommand();

            insertCommand.Connection = conn;

            insertCommand.CommandText = "INSERT INTO InitialLocationTable VALUES" +
                                        " (@Id , @Longitude , @Latitude , @DateTime)";
            insertCommand.Parameters.AddWithValue("@Id", id);
            insertCommand.Parameters.AddWithValue("@Longitude",
                                                  flightPlan.InitialLocation.Longitude);
            insertCommand.Parameters.AddWithValue("@Latitude",
                                                  flightPlan.InitialLocation.Latitude);
            insertCommand.Parameters.AddWithValue("@DateTime",
                                                  flightPlan.InitialLocation.DateTime);

            try
            {
                insertCommand.ExecuteReader();
            }
            catch { }
        }
コード例 #16
0
        // Insert the given FlightPlan's Segments into the SegmentsTable.
        private void InsertToSegmentsTable(FlightPlan flightPlan, string id)
        {
            int i, size = flightPlan.Segments.Count;

            for (i = 0; i < size; i++)
            {
                SqliteCommand insertCommand = new SqliteCommand();
                insertCommand.Connection  = conn;
                insertCommand.CommandText = "INSERT INTO SegmentsTable VALUES" +
                                            " (NULL, @FlightId, @Place, @Longitude , @Latitude, @TimespanSeconds)";
                insertCommand.Parameters.AddWithValue("@FlightId", id);
                insertCommand.Parameters.AddWithValue("@Place", i + 1);
                insertCommand.Parameters.AddWithValue("@Longitude", flightPlan.Segments[i].Longitude);
                insertCommand.Parameters.AddWithValue("@Latitude", flightPlan.Segments[i].Latitude);
                insertCommand.Parameters.AddWithValue("@TimespanSeconds",
                                                      flightPlan.Segments[i].TimespanSeconds);
                try
                {
                    insertCommand.ExecuteReader();
                }
                catch { }
            }
        }
コード例 #17
0
        //add plan to DB from the object we got from json
        public void AddPlan(FlightPlan flightPlan)
        {
            string     id    = CreateId();
            Coordinate coord = GetEndCoors(flightPlan.Segments);
            //get the end time of the flight
            DateTime endTime = GetEndTime(flightPlan.Segments,
                                          flightPlan.Initial_Location.Date_Time);
            DateTime statTime = TimeZoneInfo.ConvertTimeToUtc(
                flightPlan.Initial_Location.Date_Time);
            string statTimeString = statTime.ToString("u", DateTimeFormatInfo.InvariantInfo);

            endTime = TimeZoneInfo.ConvertTimeToUtc(endTime);
            string endTimeString = endTime.ToString("u", DateTimeFormatInfo.InvariantInfo);

            ////// INSERT INTO DATABASE
            using var myCommand = new SQLiteCommand(databaseObject.myConnection);
            string qurey = " VALUES(" + "\'" + id + "\',\'" + flightPlan.Company_Name
                           + "\'," + flightPlan.Passengers + ",\'" + statTimeString + "\'," +
                           flightPlan.Initial_Location.Longitude + ","
                           + flightPlan.Initial_Location.Latitude + ","
                           + coord.Lat + "," + coord.Lng + ",\'" + endTimeString + "\'" + ")";

            myCommand.CommandText = "INSERT INTO Flight(id, company, passengers," +
                                    "start_time,start_longitude, start_latitude,end_latitude, " +
                                    "end_longitude, end_time)" + qurey;
            int result = myCommand.ExecuteNonQuery();

            if (result > 0)
            {
                AddListSegmet(flightPlan, id);
                Console.WriteLine(result);
            }
            else
            {
                Console.WriteLine(result);
            }
        }
コード例 #18
0
        //add list of segment by id to the DB
        public void AddListSegmet(FlightPlan flightPlan, string id)
        {
            int length = flightPlan.Segments.Count;

            for (int i = 0; i < length; i++)
            {
                using var myCommand = new SQLiteCommand(databaseObject.myConnection);
                string qurey = " VALUES(" + "\'" + id + "\'," + i + "," +
                               flightPlan.Segments[i].Longitude + "," + flightPlan.Segments[i].Latitude
                               + "," + flightPlan.Segments[i].Timespan_Seconds + ")";
                myCommand.CommandText = "INSERT INTO Segments(id, serial, longitude, latitude," +
                                        " timespan)" + qurey;
                int result = myCommand.ExecuteNonQuery();
                if (result > 0)
                {
                    Console.WriteLine(result);
                }
                else
                {
                    Console.WriteLine(result);
                }
                //databaseObject.CloseConnection();
            }
        }
コード例 #19
0
 public void InsertFlightPlan(FlightPlan flightPlan)
 {
 }
コード例 #20
0
 public static void AddFlightPlan(FlightPlan flightPlan)
 {
     flightPlanDB.TryAdd(flightPlan.GetId(), flightPlan);
 }
コード例 #21
0
        public void addInternal(FlightPlan fp)
        {
            FlightData fd = new FlightData(fp);

            internalFlights.Add(fd);
        }