Esempio n. 1
0
        static void Main(string[] args)
        {
            string version = typeof(Program).Assembly.GetName().Version.ToString();

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

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

            if (op.Valid)
            {
                DroneFlightLogDbContext context = new DroneFlightLogDbContextFactory().CreateDbContext(null);
                DroneFlightLogFactory <DroneFlightLogDbContext> factory = new DroneFlightLogFactory <DroneFlightLogDbContext>(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.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} update");
            }
        }
        public void TestInitialize()
        {
            DroneFlightLogDbContext context = new DroneFlightLogDbContextFactory().CreateDbContext(null);

            _factory = new DroneFlightLogFactory <DroneFlightLogDbContext>(context);

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

            _factory.Context.SaveChanges();
            _userId = user.Id;
        }
        public void TestInitialize()
        {
            DroneFlightLogDbContext context = new DroneFlightLogDbContextFactory().CreateDbContext(null);

            _factory = new DroneFlightLogFactory <DroneFlightLogDbContext>(context);

            Location location = _factory.Locations.AddLocation(Name);

            _factory.Context.SaveChanges();
            _locationId = location.Id;
        }
Esempio n. 4
0
        public void TestInitialize()
        {
            DroneFlightLogDbContext context = new DroneFlightLogDbContextFactory().CreateDbContext(null);

            _factory = new DroneFlightLogFactory <DroneFlightLogDbContext>(context);

            Manufacturer manufacturer = _factory.Manufacturers.AddManufacturer(Name);

            _factory.Context.SaveChanges();
            _manufacturerId = manufacturer.Id;
        }
Esempio n. 5
0
        public void TestInitialize()
        {
            DroneFlightLogDbContext context = new DroneFlightLogDbContextFactory().CreateDbContext(null);

            _factory = new DroneFlightLogFactory <DroneFlightLogDbContext>(context);

            Address address = _factory.Addresses.AddAddress(Number, Street, Town, County, Postcode, Country);

            _factory.Context.SaveChanges();
            _addressId = address.Id;
        }
Esempio n. 6
0
        public void TestInitialize()
        {
            DroneFlightLogDbContext context = new DroneFlightLogDbContextFactory().CreateDbContext(null);

            _factory = new DroneFlightLogFactory <DroneFlightLogDbContext>(context);

            Address address = _factory.Addresses.AddAddress(Number, Street, Town, County, Postcode, Country);

            _factory.Context.SaveChanges();

            Operator op = _factory.Operators.AddOperator(FirstNames, Surname, DoB, FlyerNumber, OperatorNumber, address.Id);

            _factory.Context.SaveChanges();

            Location location = _factory.Locations.AddLocation(LocationName);

            _factory.Context.SaveChanges();

            Manufacturer manufacturer = _factory.Manufacturers.AddManufacturer(ManufacturerName);

            _factory.Context.SaveChanges();

            Model model = _factory.Models.AddModel(ModelName, manufacturer.Id);

            _factory.Context.SaveChanges();

            Drone drone = _factory.Drones.AddDrone(DroneName, DroneSerialNumber, model.Id);

            _factory.Context.SaveChanges();

            Flight flight = _factory.Flights.AddFlight(op.Id, drone.Id, location.Id, DateTime.Now, DateTime.Now);

            _factory.Context.SaveChanges();
            _flightId = flight.Id;

            FlightProperty property = _factory.Properties.AddProperty(PropertyName, PropertyType, true);

            _factory.Context.SaveChanges();
            _propertyId = property.Id;

            FlightPropertyValue value = _factory.Properties.AddPropertyValue(_flightId, _propertyId, PropertyValue);

            _factory.Context.SaveChanges();
            _propertyValueId = value.Id;
        }
        public void TestInitialize()
        {
            DroneFlightLogDbContext context = new DroneFlightLogDbContextFactory().CreateDbContext(null);

            _factory = new DroneFlightLogFactory <DroneFlightLogDbContext>(context);

            Address firstAddress  = _factory.Addresses.AddAddress(Number, Street, Town, County, Postcode, Country);
            Address secondAddress = _factory.Addresses.AddAddress(Number, Street, Town, County, SecondPostcode, Country);

            _factory.Context.SaveChanges();
            _firstAddressId  = firstAddress.Id;
            _secondAddressId = secondAddress.Id;

            Operator op = _factory.Operators.AddOperator(FirstNames, Surname, DoB, FlyerNumber, OperatorNumber, _firstAddressId);

            _factory.Context.SaveChanges();
            _operatorId = op.Id;
        }
        public void TestInitialize()
        {
            DroneFlightLogDbContext context = new DroneFlightLogDbContextFactory().CreateDbContext(null);

            _factory = new DroneFlightLogFactory <DroneFlightLogDbContext>(context);

            Address address = _factory.Addresses.AddAddress(Number, Street, Town, County, Postcode, Country);

            _factory.Context.SaveChanges();

            Operator op       = _factory.Operators.AddOperator(FirstNames, Surname, DoB, FlyerNumber, OperatorNumber, address.Id);
            Operator secondOp = _factory.Operators.AddOperator(SecondFirstNames, Surname, DoB, FlyerNumber, OperatorNumber, address.Id);

            _factory.Context.SaveChanges();
            _operatorId       = op.Id;
            _secondOperatorId = secondOp.Id;

            Location location       = _factory.Locations.AddLocation(LocationName);
            Location secondLocation = _factory.Locations.AddLocation(SecondLocationName);

            _factory.Context.SaveChanges();
            _locationId       = location.Id;
            _secondLocationId = secondLocation.Id;

            Manufacturer manufacturer = _factory.Manufacturers.AddManufacturer(ManufacturerName);

            _factory.Context.SaveChanges();

            Model model = _factory.Models.AddModel(ModelName, manufacturer.Id);

            _factory.Context.SaveChanges();

            Drone drone       = _factory.Drones.AddDrone(DroneName, DroneSerialNumber, model.Id);
            Drone secondDrone = _factory.Drones.AddDrone(SecondDroneName, SecondDroneSerialNumber, model.Id);

            _factory.Context.SaveChanges();
            _droneId       = drone.Id;
            _secondDroneId = secondDrone.Id;

            Flight flight = _factory.Flights.AddFlight(op.Id, drone.Id, location.Id, StartDate, EndDate);

            _factory.Context.SaveChanges();
            _flightId = flight.Id;
        }
        static void Main(string[] args)
        {
            if (args.Length == 1)
            {
                // Read the application settings
                IConfiguration configuration = new ConfigurationBuilder()
                                               .AddJsonFile("appsettings.json")
                                               .Build();

                IConfigurationSection section  = configuration.GetSection("AppSettings");
                AppSettings           settings = section.Get <AppSettings>();

                // Create the factory for acessing the SQLite database
                DroneFlightLogDbContext context = new DroneFlightLogDbContextFactory().CreateDbContext(null);
                IDroneFlightLogFactory <DroneFlightLogDbContext> factory = new DroneFlightLogFactory <DroneFlightLogDbContext>(context);

                CsvReader <DroneFlightLogDbContext> reader = null;
                try
                {
                    //  Use the CSV reader to read the flights
                    reader = new CsvReader <DroneFlightLogDbContext>(settings, factory);
                    IList <Flight> flights = reader.Read(args[0]);

                    // Store the flights in the database
                    FlightWriter <DroneFlightLogDbContext> writer = new FlightWriter <DroneFlightLogDbContext>(factory);
                    writer.Save(flights);
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"{ex.Message}");
                    if ((reader != null) && (reader.LastError != null))
                    {
                        Console.WriteLine($"Record {reader.LastError.Record} : {reader.LastError.Message}");
                    }
                }
            }
            else
            {
                string executable = AppDomain.CurrentDomain.FriendlyName;
                Console.WriteLine($"Usage : {executable} path_to_csv_file");
            }
        }
Esempio n. 10
0
        public void TestInitialize()
        {
            DroneFlightLogDbContext context = new DroneFlightLogDbContextFactory().CreateDbContext(null);

            _factory = new DroneFlightLogFactory <DroneFlightLogDbContext>(context);

            Manufacturer manufacturer = _factory.Manufacturers.AddManufacturer(ManufacturerName);

            _factory.Context.SaveChanges();
            _manufacturerId = manufacturer.Id;

            Model model = _factory.Models.AddModel(ModelName, manufacturer.Id);

            _factory.Context.SaveChanges();
            _modelId = model.Id;

            Drone drone = _factory.Drones.AddDrone(DroneName, DroneSerialNumber, _modelId);

            _factory.Context.SaveChanges();
            _droneId = drone.Id;
        }
Esempio n. 11
0
        static void Main(string[] args)
        {
            DroneFlightLogDbContext context = new DroneFlightLogDbContextFactory().CreateDbContext(null);

            context.Database.Migrate();
        }