Exemplo n.º 1
0
 public static async Task <VatsimClientPilotV1> FindPilotAsync(string cid, string callsign, string timelogon)
 {
     using (var db = new VatsimDbContext())
     {
         return(await db.Pilots.FindAsync(cid, callsign, timelogon));
     }
 }
Exemplo n.º 2
0
        public static async void UpdateOrCreatePilot(VatsimClientPilot pilot)
        {
            using (var db = new VatsimDbContext())
            {
                var _pilot = await db.Pilots.FindAsync(pilot.Cid, pilot.Callsign, pilot.TimeLogon);

                // didn't find the pilot
                if (_pilot == null)
                {
                    db.Add(pilot);
                    db.SaveChanges();
                    Log.Information($"Added Pilot: {pilot} to DB");
                }
                else
                {
                    DateTime old_time = VatsimDataState.GetDateTimeFromVatsimTimeStamp(_pilot.TimeLogon);
                    DateTime new_time = VatsimDataState.GetDateTimeFromVatsimTimeStamp(pilot.TimeLogon);
                    if (new_time > old_time)
                    {
                        db.Add(pilot);
                        db.SaveChanges();
                        Log.Information($"Added Pilot: {pilot} to DB");
                    }
                    else
                    {
                        _pilot.Update(pilot);
                        db.Update(_pilot);
                        db.SaveChanges();
                        Log.Information($"Updated Pilot: {pilot} in DB");
                    }
                }
            }
        }
Exemplo n.º 3
0
 public static async Task <VatsimClientATCV1> FindControllerAsync(string cid, string callsign, string timelogon)
 {
     using (var db = new VatsimDbContext())
     {
         return(await db.Controllers.FindAsync(cid, callsign, timelogon));
     }
 }
Exemplo n.º 4
0
        public static async void UpdateOrCreateATC(VatsimClientATC controller)
        {
            using (var db = new VatsimDbContext())
            {
                var _controller = await db.Controllers.FindAsync(controller.Cid, controller.Callsign, controller.TimeLogon);

                // didn't find the pilot
                if (_controller == null)
                {
                    db.Add(controller);
                    db.SaveChanges();
                    Log.Information($"Added Controller: {controller} to DB");
                }
                else
                {
                    DateTime old_time = VatsimDataState.GetDateTimeFromVatsimTimeStamp(_controller.TimeLogon);
                    DateTime new_time = VatsimDataState.GetDateTimeFromVatsimTimeStamp(controller.TimeLogon);
                    if (new_time > old_time)
                    {
                        db.Add(controller);
                        Log.Information($"Added Controller: {controller} to DB");
                        db.SaveChanges();
                    }
                    else
                    {
                        _controller.Update(controller);
                        db.Update(_controller);
                        db.SaveChanges();
                        Log.Information($"Updated Controller: {controller} in DB");
                    }
                }
            }
        }
Exemplo n.º 5
0
 public static async void UpdateControllersFromListAsync(IEnumerable <VatsimClientATCV1> controllers)
 {
     using (var db = new VatsimDbContext())
     {
         db.Controllers.UpdateRange(controllers);
         await db.SaveChangesAsync();
     }
 }
Exemplo n.º 6
0
 public static async void UpdateFlightsFromListAsync(IEnumerable <VatsimClientPlannedFlightV1> flights)
 {
     using (var db = new VatsimDbContext())
     {
         db.Flights.UpdateRange(flights);
         await db.SaveChangesAsync();
     }
 }
Exemplo n.º 7
0
 public static async void UpdatePilotsFromListAsync(IEnumerable <VatsimClientPilotV1> pilots)
 {
     using (var db = new VatsimDbContext())
     {
         db.Pilots.UpdateRange(pilots);
         await db.SaveChangesAsync();
     }
 }
Exemplo n.º 8
0
        public static async void CreatePositionsFromListAsync(IEnumerable <VatsimClientPilotSnapshotV1> positions)
        {
            using (var db = new VatsimDbContext())
            {
                await db.Positions.AddRangeAsync(positions);

                await db.SaveChangesAsync();
            }
        }
Exemplo n.º 9
0
        public static async void CreateATCFromListAsync(IEnumerable <VatsimClientATCV1> controllers)
        {
            using (var db = new VatsimDbContext())
            {
                await db.Controllers.AddRangeAsync(controllers);

                await db.SaveChangesAsync();
            }
        }
Exemplo n.º 10
0
 /// <summary>
 /// Save a position to the database
 /// </summary>
 /// <param name="position">position snapshot information</param>
 public static void CreatePosition(VatsimClientPilotSnapshot position)
 {
     using (var db = new VatsimDbContext())
     {
         // make sure we have a position to write
         if (position != null)
         {
             db.Add(position);
             db.SaveChanges();
             Log.Information($"Added Position: {position} to DB");
         }
     }
 }
Exemplo n.º 11
0
 public static async Task <VatsimClientPlannedFlightV1> FindFlightAsync(
     string cid,
     string callsign,
     string timelogon,
     string dep,
     string dest)
 {
     using (var db = new VatsimDbContext())
     {
         return(await db.Flights.FindAsync(cid,
                                           callsign,
                                           timelogon,
                                           dep,
                                           dest));
     }
 }
Exemplo n.º 12
0
        public static async void UpdateOrCreateFlightAsync(VatsimClientPlannedFlightV1 flight)
        {
            using (var db = new VatsimDbContext())
            {
                var _flight = await FindFlightAsync(flight.Cid,
                                                    flight.Callsign,
                                                    flight.TimeLogon,
                                                    flight.PlannedDepairport,
                                                    flight.PlannedDestairport);

                // didn't find the pilot
                if (_flight == null)
                {
                    await db.AddAsync(flight);

                    await db.SaveChangesAsync();

                    Log.Information($"Added Flight: {flight} to DB");
                }
                else
                {
                    // log.Info($"Flight found in DB: {_flight.ToString()}");
                    // DateTime old_time = VatsimDataState.GetDateTimeFromVatsimTimeStamp(_flight.TimeLogon);
                    // DateTime new_time = VatsimDataState.GetDateTimeFromVatsimTimeStamp(flight.TimeLogon);
                    if (LogonTimeIsMoreRecent(_flight.TimeLogon, flight.TimeLogon))
                    {
                        await db.AddAsync(flight);

                        await db.SaveChangesAsync();

                        Log.Information($"Added Flight: {flight} to DB");
                    }
                    else
                    {
                        _flight.Update(flight);
                        db.Update(_flight);
                        await db.SaveChangesAsync();

                        Log.Information($"Updated Flight: {flight} in DB");
                    }
                }
            }
        }