private TaxiAutorization FromBucarestCSV(BucarestCSV bucarestLine) { if (bucarestLine == null) { return(null); } var city = City.FromName("Bucuresti"); var taxi = new TaxiAutorization(); taxi.Location = city; taxi.NumberAutorization = bucarestLine.NrAutTaxi; taxi.OtherDetails = bucarestLine.Observatii; var state = bucarestLine.StareAutTaxi; switch (state) { case var s when s.Contains("NEVALIDA"): taxi.State = LicenceState.NotValid; break; case var s when s.Contains("VALIDA"): taxi.State = LicenceState.Valid; break; case var s when s.Contains("ANALIZA"): taxi.State = LicenceState.ToBeAnalyzed; break; default: taxi.State = LicenceState.Unknown; break; } var car = new Car(); car.ManufacturingDate = bucarestLine.AnFabricatieAuto; car.Name = bucarestLine.MarcaAuto; car.PlateNumber = bucarestLine.NrInmatriculareAuto; taxi.CarLicensed = car; taxi.PersonLicensedTo = new Licensee() { Name = bucarestLine.NumeTransportator }; return(taxi); }
public async Task <TaxiAutorizations> TaxiFromPlateSqliteAll() { TaxiAutorizations ret = new TaxiAutorizations(); using (var con = new SqliteConnection()) { con.ConnectionString = "Data Source=taxis.sqlite3;"; await con.OpenAsync(); using (var cmd = con.CreateCommand()) { cmd.CommandText = "select * from bucuresti"; using (var rd = await cmd.ExecuteReaderAsync()) { while (await rd.ReadAsync()) { // just first record Func <object, string> empty = (rec) => { if (rec == null) { return(""); } if (rec == DBNull.Value) { return(""); } string value = rec.ToString(); if (string.IsNullOrWhiteSpace(value)) { return(""); } return(value); }; string line = ""; line += empty(rd["Nr. Aut. Taxi"]); line += "|"; line += empty(rd["Stare Aut. Taxi"]); line += "|"; line += empty(rd["Nume Transportator"]); line += "|"; line += empty(rd["Marca Auto"]); line += "|"; line += empty(rd["An Fabricatie Auto"]); line += "|"; line += empty(rd["Nr. Inmatriculare Auto"]); line += "|"; line += empty(rd["Expirare Valabilitate"]); line += "|"; line += empty(rd["Observatii"]); var bucarestCSV = new BucarestCSV(line); var err = bucarestCSV.Parse().FirstOrDefault(); if (err != null) { throw new ArgumentException($"line:{line} ex:{ err.ErrorMessage}"); } ret.Add(FromBucarestCSV(bucarestCSV)); } } } return(ret); } }
public async Task <TaxiAutorization> TaxiFromPlateSqlite(string plateNumber) { if (string.IsNullOrWhiteSpace(plateNumber)) { return(null); } plateNumber = plateNumber.ToLower(); using (var con = new SqliteConnection()) { con.ConnectionString = "Data Source=taxis.sqlite3;"; //con.ConnectionString = "taxis.sqlite3"; await con.OpenAsync(); BucarestCSV bucarestCSV = null; using (var cmd = con.CreateCommand()) { cmd.CommandText = "select * from bucuresti where lower([Nr. Inmatriculare Auto])=@plate"; cmd.Parameters.AddWithValue("@plate", plateNumber); using (var rd = await cmd.ExecuteReaderAsync()) { while (await rd.ReadAsync()) { // just first record if (bucarestCSV != null) { break; } Func <object, string> empty = (rec) => { if (rec == null) { return(""); } if (rec == DBNull.Value) { return(""); } string value = rec.ToString(); if (string.IsNullOrWhiteSpace(value)) { return(""); } return(value); }; string line = ""; line += empty(rd["Nr. Aut. Taxi"]); line += "|"; line += empty(rd["Stare Aut. Taxi"]); line += "|"; line += empty(rd["Nume Transportator"]); line += "|"; line += empty(rd["Marca Auto"]); line += "|"; line += empty(rd["An Fabricatie Auto"]); line += "|"; line += empty(rd["Nr. Inmatriculare Auto"]); line += "|"; line += empty(rd["Expirare Valabilitate"]); line += "|"; line += empty(rd["Observatii"]); bucarestCSV = new BucarestCSV(line); var err = bucarestCSV.Parse().FirstOrDefault(); if (err != null) { throw new ArgumentException($"line:{line} ex:{ err.ErrorMessage}"); } } } } return(FromBucarestCSV(bucarestCSV)); } }