public void Flight_D1908_20170408_Partial()
        {
            FlightContext fc = new FlightContext("6770");

            int callbacks = 0;

            fc.OnRadarContact += (sender, args) =>
            {
                Assert.AreEqual(null, ((FlightContext)sender).Flight.DepartureTime);
                Assert.AreEqual(false, ((FlightContext)sender).Flight.DepartureInfoFound);
                Assert.AreEqual(0, ((FlightContext)sender).Flight.DepartureHeading);
                callbacks++;
            };

            fc.OnLanding += (sender, args) =>
            {
                Assert.AreEqual(636272628474023926, ((FlightContext)sender).Flight.ArrivalTime?.Ticks);
                Assert.AreEqual(250, ((FlightContext)sender).Flight.ArrivalHeading);
                callbacks++;
            };

            // These events should NOT be fired
            fc.OnTakeoff             += (sender, args) => Assert.Fail();
            fc.OnCompletedWithErrors += (sender, e) => Assert.Fail();

            fc.Process(Common.ReadFlightPoints("2017-04-08_D-1908.csv").Skip(500));

            Assert.AreEqual(2, callbacks);
        }
示例#2
0
        public static bool IsValid(string email, bool isExistingPilot)
        {
            var cleanEmail = ParseEmail(email);
            var valid      = false;

            try
            {
                var addr = new System.Net.Mail.MailAddress(cleanEmail);
                if (addr.Address == cleanEmail)
                {
                    valid = true;
                }
            }
            catch
            {
                return(false);
            }

            if (valid)
            {
                if (!isExistingPilot)
                {
                    return(true);
                }
                else
                {
                    using (var shortDb = new FlightContext())
                    {
                        return(shortDb.Pilots.Any(d => d.Email == cleanEmail));
                    }
                }
            }
            return(false);
        }
 public IEnumerable <Flight> QueryFlights(Expression <Func <Flight, bool> > queryExpression)
 {
     using (FlightContext dbContext = new FlightContext())
     {
         return(dbContext.Flights.Where(queryExpression).Where(_ => _.IsValid));
     }
 }
示例#4
0
 public bool IsValid(string club)
 {
     using (var shortDb = new FlightContext())
     {
         return(shortDb.Clubs.Any(d => d.ShortName == club));
     }
 }
 public Flight QueryFlightByFlightNumber(string flightNumber)
 {
     using (FlightContext dbContext = new FlightContext())
     {
         return(dbContext.Flights.Where(_ => _.FlightNumber == flightNumber && _.IsValid == true).FirstOrDefault());
     }
 }
示例#6
0
        public async Task <ActionResult> RemovePilotBinding(string currentPilotIdBinding)
        {
            ManageMessageId?message = ManageMessageId.Error;
            var             user    = await UserManager.FindByIdAsync(User.Identity.GetUserId());

            if (user != null)
            {
                using (var context = new FlightContext())
                {
                    if (user.BoundToPilotId != null)
                    {
                        var userPilotBinding = context.Pilots.Find(Convert.ToInt32(user.BoundToPilotId));
                        if (userPilotBinding.PilotId.ToString(CultureInfo.InvariantCulture) == currentPilotIdBinding)
                        {
                            using (var db = new ApplicationDbContext())
                            {
                                var dbUser = db.Users.Find(user.Id);
                                if (dbUser != null)
                                {
                                    dbUser.BoundToPilotId = null;
                                    db.SaveChanges();
                                    message = ManageMessageId.RemovePilotBindingSuccess;
                                }
                            }
                        }
                    }
                }
            }
            return(RedirectToAction("ManagePilotBinding", new { Message = message }));
        }
示例#7
0
 public AuthUsersController(FlightContext context, UserManager <AuthUser> userManager, SignInManager <AuthUser> signManager, RoleManager <ApplicationRole> roleManager)
 {
     _context     = context;
     _userManager = userManager;
     _signManager = signManager;
     _roleManager = roleManager;
 }
示例#8
0
        public async Task <ActionResult> LinkPilot(string pilot)
        {
            ManageMessageId?message = ManageMessageId.Error;
            var             user    = await UserManager.FindByIdAsync(User.Identity.GetUserId());

            if (user != null)
            {
                using (var context = new FlightContext())
                {
                    var userPilotBinding = context.Pilots.Find(Convert.ToInt32(pilot));
                    if (userPilotBinding != null)
                    {
                        // Validate User and Pilot have Email or Phone Number in Common

                        using (var db = new ApplicationDbContext())
                        {
                            var dbUser = db.Users.Find(user.Id);
                            if (dbUser != null)
                            {
                                dbUser.BoundToPilotId = userPilotBinding.PilotId.ToString(CultureInfo.InvariantCulture);
                                db.SaveChanges();
                                message = ManageMessageId.BindToPilotSuccess;
                            }
                        }
                    }
                }
            }
            return(RedirectToAction("ManagePilotBinding", new { Message = message }));
        }
示例#9
0
 //Makes a list that contains all Flights in the Database
 public List <Flight> GetAll()
 {
     using (context = new FlightContext())
     {
         return(context.Flights.ToList());
     }
 }
示例#10
0
 public static List <Pilot> FindPilotsByEmail(string email)
 {
     email = ParseEmail(email);
     using (var shortDb = new FlightContext())
     {
         return(shortDb.Pilots.Where(d => d.Email == email).ToList());
     }
 }
示例#11
0
 public void UpdateFlight(Flight flight)
 {
     using (FlightContext dbContext = new FlightContext())
     {
         dbContext.Update <Flight>(flight);
         dbContext.SaveChanges();
     }
 }
示例#12
0
 public FlightsController(
     FlightContext dbContext,
     FlightExtentions flights
     )
 {
     _dbContext = dbContext;
     _flights   = flights;
 }
 public FlightPlansController(FlightContext flightContext, IFlightManager flightManager,
                              IFlightPlanManager flightPlanManager, IHttpClientFactory clientFactory)
 {
     _flightContext     = flightContext;
     _flightPlanManager = flightPlanManager;
     _flightManager     = flightManager;
     _clientFactory     = clientFactory;
 }
 public IEnumerable < Flight >> GetAllFlights()
 {
     using (var flightContext = new FlightContext())
     {
         var flights = flightContext.Flights.ToList();
         return(flights);
     }
 }
示例#15
0
 public void FlightUpdate(Flight flight)
 {
     using (FlightContext db = new FlightContext())
     {
         db.Entry(flight).State = EntityState.Modified;
         db.SaveChanges();
     }
 }
示例#16
0
 public void PassEdit(Passenger passenger)
 {
     using (FlightContext db = new FlightContext())
     {
         db.Entry(passenger).State = EntityState.Modified;
         db.SaveChanges();
     }
 }
示例#17
0
 public void FlightAdd(Flight flight)
 {
     using (FlightContext db = new FlightContext())
     {
         db.Flights.Add(flight);
         db.SaveChanges();
     }
 }
 public static List <Pilot> FindPilotsByMobilNumber(string mobilNumber)
 {
     mobilNumber = ParseMobilNumber(mobilNumber);
     using (var shortDb = new FlightContext())
     {
         return(shortDb.Pilots.Where(d => d.MobilNumber == mobilNumber).ToList());
     }
 }
示例#19
0
 public void PassAdd(Passenger passenger)
 {
     using (FlightContext db = new FlightContext())
     {
         db.Passengers.Add(passenger);
         db.SaveChanges();
     }
 }
示例#20
0
 public IEnumerable <Flight> GetAllFlights()
 {
     using (var flightContext = new FlightContext())
     {
         var flights = flightContext.Flights.Include(f => f.Travelers).ToList();
         return(flights);
     }
 }
示例#21
0
 public void PassDelete(Passenger passenger)
 {
     using (FlightContext db = new FlightContext())
     {
         db.Passengers.Attach(passenger);
         db.Entry(passenger).State = EntityState.Deleted;
         db.SaveChanges();
     }
 }
        public FlightsControllerTests()
        {
            string[] args = { };
            var      d    = new DbContextOptionsBuilder <FlightContext>();
            var      h    = Program.CreateHostBuilder(args);

            d.UseInMemoryDatabase("DBName");
            _FlightDBContextMock = new FlightContext(d.Options);
            fpc = new FlightPlanController(_FlightDBContextMock);
        }
示例#23
0
        static void Main(string[] args)
        {
            var flightContext = new FlightContext("");

            Console.Write(flightContext.ToDotGraph());

            TextCopy.ClipboardService.SetText(flightContext.ToDotGraph());

            Console.ReadKey();
        }
示例#24
0
 public ActionResult RemoveFlight(Flight flight)
 {
     using (flightContext = new FlightContext())
     {
         Flight toRemove = flightContext.Flights.Find(flight.Id);
         flightContext.Flights.Remove(toRemove);
         flightContext.SaveChanges();
         return(View("~/Views/Admin/Home.cshtml"));
     }
 }
示例#25
0
 public void Delete(Flight flight)
 {
     using (FlightContext dbContext = new FlightContext())
     {
         flight.IsValid    = false;
         flight.UpdateTime = DateTime.Now;
         dbContext.Update <Flight>(flight);
         dbContext.SaveChanges();
     }
 }
示例#26
0
 public void FlightDelete(Flight flight)
 {
     using (FlightContext db = new FlightContext())
     {
         db.Flights.Attach(flight);
         db.Passengers.RemoveRange(flight.Passengers);
         db.Entry(flight).State = EntityState.Deleted;
         db.SaveChanges();
     }
 }
示例#27
0
 /// <summary>
 /// Method that reads from file all airports and saves in appropriate table.
 /// </summary>
 /// <param name="FlightContext">EntityFramework Flights Context</param>
 public static void SeedAirports(FlightContext context, ILogger logger)
 {
     if (!context.Airports.Any())
     {
         var airportData = System.IO.File.ReadAllText("Migrations/SeedData/airports.json");
         var airports    = JsonConvert.DeserializeObject <IList <Airport> >(airportData);
         context.AddRange(airports);
         context.SaveChanges();
     }
 }
示例#28
0
        // ToDo: Add information about the aircrafts climbrate and so on, if possible
        internal static PositionUpdate NormalizeData(FlightContext context, PositionUpdate position)
        {
            if (position == null ||
                context.Flight.PositionUpdates.Count < 2 ||
                (!double.IsNaN(position.Heading) && !double.IsNaN(position.Speed)))
            {
                return(position);
            }

            var previousPosition =
                context.Flight.PositionUpdates.LastOrDefault();

            if (previousPosition == null)
            {
                return(position);
            }

            double?heading = null;
            double?speed   = null;

            if (double.IsNaN(position.Heading))
            {
                heading = Geo.DegreeBearing(previousPosition.Location, position.Location);
            }

            if (double.IsNaN(position.Speed))
            {
                // 1. Get the distance (meters)
                // 2. Calculate the time difference (seconds)
                // 3. Convert to knots (1.94384449 is a constant)
                var    distance       = previousPosition.Location.DistanceTo(position.Location);
                double timeDifference = (position.TimeStamp - previousPosition.TimeStamp).Milliseconds;

                if (timeDifference < 50)
                {
                    return(null);
                }

                if (distance != 0)
                {
                    speed = distance / (timeDifference / 1000) * 1.94384449;
                }
                else
                {
                    speed = 0;
                }
            }

            position.Speed   = speed ?? position.Speed;
            position.Heading = heading ?? position.Heading;

            return(position);
        }
示例#29
0
 public ActionResult RemoveFlight(int id = 0)
 {
     using (FlightContext flightContext = new FlightContext())
     {
         Flight flight = flightContext.Flights.First(x => x.Id == id);
         if (flight == null)
         {
             return(View("~/Views/Home/Index.cshtml"));
         }
         return(View(flight));
     }
 }
示例#30
0
 public void BookFlight(int flightId, [FromBody] IEnumerable <Traveler> travelers)
 {
     using (var flightContext = new FlightContext())
     {
         var flight = flightContext.Flights.FirstOrDefault(f => f.FlightId == flightId);
         if (flight != null)
         {
             flight.Travelers = travelers.ToList();
             flightContext.SaveChanges();
         }
     }
 }