Ejemplo n.º 1
0
        public void TestInitialize()
        {
            FlightRecorderDbContext context = new FlightRecorderDbContextFactory().CreateInMemoryDbContext();

            _factory = new FlightRecorderFactory(context);
            _factory.Aircraft.Add(Registration, SerialNumber, YearOfManufacture, ModelName, ManufacturerName);
        }
Ejemplo n.º 2
0
        public void TestInitialize()
        {
            FlightRecorderDbContext context = new FlightRecorderDbContextFactory().CreateInMemoryDbContext();

            _factory = new FlightRecorderFactory(context);
            _factory.Flights.Add(FlightNumber, Embarkation, Destination, AirlineName);
        }
        public void TestInitialize()
        {
            FlightRecorderDbContext context = new FlightRecorderDbContextFactory().CreateInMemoryDbContext();

            _factory = new FlightRecorderFactory(context);
            _factory.Locations.Add(EntityName);
        }
        public void TestInitialize()
        {
            FlightRecorderDbContext context = new FlightRecorderDbContextFactory().CreateInMemoryDbContext();

            _factory = new FlightRecorderFactory(context);
            _factory.Models.Add(ModelName, ManufacturerName);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Import the contents of the CSV file
        /// </summary>
        /// <param name="file"></param>
        /// <param name="context"></param>
        public void Import(string file, FlightRecorderFactory factory)
        {
            Regex regex = new Regex(FlattenedSighting.CsvRecordPattern, RegexOptions.Compiled);

            using (StreamReader reader = new StreamReader(file))
            {
                int count = 0;
                while (!reader.EndOfStream)
                {
                    string line = reader.ReadLine();
                    count++;

                    if (count > 1)
                    {
                        // Check the line matches the pattern required for successful import
                        bool matches = regex.Matches(line).Any();
                        if (!matches)
                        {
                            Console.WriteLine(line);
                            string message = $"Invalid record format at line {count} of {file}";
                            throw new InvalidRecordFormatException(message);
                        }

                        // Inflate the CSV record to a sighting and store it in the database
                        FlattenedSighting sighting = FlattenedSighting.FromCsv(line);
                        factory.Sightings.Add(sighting);

                        RecordImport?.Invoke(this, new SightingDataExchangeEventArgs {
                            RecordCount = count - 1, Sighting = sighting
                        });
                    }
                }
            }
        }
Ejemplo n.º 6
0
        public void TestInitialize()
        {
            FlightRecorderDbContext context = new FlightRecorderDbContextFactory().CreateInMemoryDbContext();

            _factory = new FlightRecorderFactory(context);

            _locationId = _factory.Locations.Add(LocationName).Id;
            _flightId   = _factory.Flights.Add(FlightNumber, Embarkation, Destination, AirlineName).Id;
            _aircraftId = _factory.Aircraft.Add(Registration, SerialNumber, YearOfManufacture, ModelName, ManufacturerName).Id;
            _sightingId = _factory.Sightings.Add(Altitude, SightingDate, _locationId, _flightId, _aircraftId).Id;
        }
        public void TestInitialize()
        {
            FlightRecorderDbContext context = new FlightRecorderDbContextFactory().CreateInMemoryDbContext();

            _factory = new FlightRecorderFactory(context);

            User user = _factory.Users.AddUser(UserName, Password);

            _factory.Context.SaveChanges();
            _userId = user.Id;
        }
        public void TestInitialize()
        {
            FlightRecorderDbContext context = new FlightRecorderDbContextFactory().CreateInMemoryDbContext();

            _factory    = new FlightRecorderFactory(context);
            _sightingId = _factory.Sightings.Add(new FlattenedSighting
            {
                FlightNumber = FlightNumber,
                Airline      = AirlineName,
                Registration = Registration,
                SerialNumber = SerialNumber,
                Manufacturer = ManufacturerName,
                Model        = ModelName,
                Age          = Age,
                Embarkation  = Embarkation,
                Destination  = Destination,
                Altitude     = Altitude,
                Date         = SightingDate,
                Location     = LocationName
            }).Id;
        }
 public AirlinesController(FlightRecorderFactory factory)
 {
     _factory = factory;
 }
Ejemplo n.º 10
0
 public SightingsController(FlightRecorderFactory factory)
 {
     _factory = factory;
 }
Ejemplo n.º 11
0
 public ManufacturersController(FlightRecorderFactory factory)
 {
     _factory = factory;
 }
Ejemplo n.º 12
0
 internal SightingManager(FlightRecorderFactory factory)
 {
     _factory = factory;
 }
Ejemplo n.º 13
0
 public UserService(FlightRecorderFactory factory, IOptions <AppSettings> settings)
 {
     _factory  = factory;
     _settings = settings.Value;
 }
 public ModelsController(FlightRecorderFactory factory)
 {
     _factory = factory;
 }
Ejemplo n.º 15
0
 public AircraftController(FlightRecorderFactory factory)
 {
     _factory = factory;
 }
Ejemplo n.º 16
0
 internal AircraftManager(FlightRecorderFactory factory)
 {
     _factory = factory;
 }
Ejemplo n.º 17
0
 internal FlightManager(FlightRecorderFactory factory)
 {
     _factory = factory;
 }
Ejemplo n.º 18
0
        static void Main(string[] args)
        {
            string version = typeof(Program).Assembly.GetName().Version.ToString();

            Console.WriteLine($"Flight Recorder Database Management {version}");

            Operation op = new CommandParser().ParseCommandLine(args);

            if (op.Valid)
            {
                FlightRecorderDbContext context = new FlightRecorderDbContextFactory().CreateDbContext(null);
                FlightRecorderFactory   factory = new FlightRecorderFactory(context);

                try
                {
                    switch (op.Type)
                    {
                    case OperationType.add:
                        factory.Users.AddUser(op.UserName, op.Password);
                        Console.WriteLine($"Added user {op.UserName}");
                        break;

                    case OperationType.setpassword:
                        factory.Users.SetPassword(op.UserName, op.Password);
                        Console.WriteLine($"Set password for user {op.UserName}");
                        break;

                    case OperationType.delete:
                        factory.Users.DeleteUser(op.UserName);
                        Console.WriteLine($"Deleted user {op.UserName}");
                        break;

                    case OperationType.import:
                        CsvImporter importer = new CsvImporter();
                        importer.Import(op.FileName, factory);
                        Console.WriteLine($"Imported data from {op.FileName}");
                        break;

                    case OperationType.export:
                        // The third parameter is an arbitrary large number intended to capture all
                        // sightings
                        IEnumerable <Sighting> sightings = factory.Sightings.List(null, 1, 99999999);
                        CsvExporter            exporter  = new CsvExporter();
                        exporter.Export(sightings, op.FileName);
                        Console.WriteLine($"Exported the database to {op.FileName}");
                        break;

                    case OperationType.update:
                        context.Database.Migrate();
                        Console.WriteLine($"Applied the latest database migrations");
                        break;

                    default:
                        break;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Error : {ex.Message}");
                }
            }
            else
            {
                string executable = AppDomain.CurrentDomain.FriendlyName;
                Console.WriteLine("Usage:");
                Console.WriteLine($"[1] {executable} add username password");
                Console.WriteLine($"[2] {executable} setpassword username password");
                Console.WriteLine($"[3] {executable} delete username");
                Console.WriteLine($"[4] {executable} import csv_file_path");
                Console.WriteLine($"[5] {executable} export csv_file_path");
                Console.WriteLine($"[6] {executable} update");
            }
        }