public void Process(CarDatabase cars) { var car = cars.Get(m_vin); if (car == null) { throw new Exception(String.Format("The car with specified VIN \"{0}\" is not found in the database", m_vin)); } if (m_newDateTime.HasValue) { car.IssueDate = m_newDateTime.Value; } if (m_newCarTypeInitialized) { car.CarType = m_newCarType; } if (m_newVendor != null) { car.Vendor = m_newVendor; } if (m_newModel != null) { car.Model = m_newModel; } }
public void Process(CarDatabase cars) { if (ReadAll) { var carsArray = cars.GetCars(); for (int n = 1; n <= carsArray.Length; n++) { Console.WriteLine(String.Format("{0}. {1}", n, carsArray[n - 1])); } } else { for (int n = 1; n <= Vins.Length; n++) { Car car = cars.Get(Vins[n - 1]); if (car != null) { Console.WriteLine(String.Format("{0}. {1}", n, car)); } else { Console.WriteLine(String.Format("{0}. The car with specified VIN \"{1}\" is not found in the database", n, Vins[n - 1])); } } } }
public void Process(CarDatabase cars) { Console.WriteLine("Valid values for the car type:"); foreach (var name in Enum.GetNames(typeof(CarType))) { Console.WriteLine(name); } }
public void Process(CarDatabase cars) { Console.WriteLine("Possible operations:"); Console.WriteLine("-add -vin VIN_NUMBER -year YEAR -vendor VENDOR -model MODEL -type TYPE: To add a new car. All parameters are required but can be set in any order."); Console.WriteLine("-delete VIN1 VIN2 VIN-n: To delete one or more cars from the database."); Console.WriteLine("-help (or -h) : To display help for all available operations."); Console.WriteLine("-quit (or -q) : To exit the application."); Console.WriteLine("-get all: To display a list of registered cars."); Console.WriteLine("-get VIN1 VIN2 VIN-n: To display one or more cars by specified VIN-s."); Console.WriteLine("-modify -vin VIN_NUMBER -year YEAR -vendor VENDOR -model MODEL -type TYPE: To modify a car with VIN=VIN_NUMBER. You can change any properties exept VIN-number."); Console.WriteLine("-types : To display valid car types."); }
public static void Save(string fileName, CarDatabase db) { XmlSerializer serializer = new XmlSerializer(typeof(List <Car>)); var list = new List <Car>(db.m_cars.Count); foreach (var item in db.m_cars) { list.Add(item.Value); } using (FileStream fs = new FileStream(fileName, FileMode.Create)) serializer.Serialize(fs, list); }
public void Process(CarDatabase cars) { for (int n = 1; n <= Vins.Length; n++) { if (cars.Remove(Vins[n - 1])) { Console.WriteLine(String.Format("{0}. The car with specified VIN \"{1}\" has been removed from the database.", n, Vins[n - 1])); } else { Console.WriteLine(String.Format("{0}. The car with specified VIN \"{1}\" is not found in the database", n, Vins[n - 1])); } } }
static void Main(string[] args) { CarDatabase carsDatabase = CarDatabase.Load(DATABASE_FILE); try { Console.WriteLine("Введите -h для справки по командам. -q для выхода из приложения."); string inputStr; while (true) { Console.WriteLine(); try { inputStr = Console.ReadLine().Trim(); var command = ParseLine(inputStr); if (command == null) { Console.WriteLine("Ошибка ввода. Введите -h для справки по командам. -q для выхода из приложения."); } else if (command is QuitCommand) { break; } else { command.Process(carsDatabase); } } catch (Exception error) { Console.WriteLine(error.Message); } } } finally { CarDatabase.Save(DATABASE_FILE, carsDatabase); } }
public static CarDatabase Load(string fileName) { CarDatabase db = new CarDatabase(); if (!File.Exists(fileName)) { db.InitDefault(); } else { XmlSerializer serializer = new XmlSerializer(typeof(List <Car>)); using (FileStream fs = new FileStream(fileName, FileMode.Open)) { List <Car> list = (List <Car>)serializer.Deserialize(fs); foreach (var entry in list) { db.Add(entry); } } } return(db); }
public void Process(CarDatabase cars) { }
public void Process(CarDatabase cars) { cars.Add(m_newCar); }