예제 #1
0
        public static void DeserializeBin()
        {
            var binIoManager = new IoManager();

            IEnumerable <Car> cars = null;
            FileStream        fs   = new FileStream("DataFile.dat", FileMode.Open);

            try
            {
                BinaryFormatter formatter = new BinaryFormatter();

                cars = (List <Car>)formatter.Deserialize(fs);
            }
            catch (SerializationException e)
            {
                Console.WriteLine("Failed to deserialize. Reason: " + e.Message);
                throw;
            }
            finally
            {
                fs.Close();
            }
            binIoManager.ShowTable(cars);
        }
예제 #2
0
파일: CarWorker.cs 프로젝트: volhadl/ol
        public void ParkMenu()
        {
            var parkIoManager = new IoManager();

            try
            {
                var carPark = GetDefaultCarPark();

                parkIoManager.WriteStepMessage("Park Menu");
                parkIoManager.ParkMenu();
                while (true)
                {
                    string menuStepResp = parkIoManager.ReadMenuStep();
                    parkIoManager.Write(menuStepResp);

                    if (menuStepResp == "CREATE")
                    {
                        parkIoManager.WriteStepMessage("Taxi park is created:");
                        parkIoManager.ShowTable(carPark.Cars);
                    }
                    else if (menuStepResp == "PRICE")
                    {
                        parkIoManager.WriteStepMessage("Car park price:");
                        parkIoManager.WritePrice(carPark.GetPrice());
                    }
                    else if (menuStepResp == "SORT")
                    {
                        parkIoManager.WriteStepMessage("Cars sorted by Fuel Consumption:");
                        parkIoManager.ShowTable(carPark.Cars.OrderBy(car => car.FuelConsumption));
                    }
                    else if (menuStepResp == "SEARCH")
                    {
                        ShowSerchResultByYear(carPark.Cars);
                    }
                    else if (menuStepResp == "SAVEBIN")
                    {
                        ReadWriteDataManager.SerializeBin(carPark.Cars);
                    }
                    else if (menuStepResp == "OPENBIN")
                    {
                        if (!File.Exists(@"D:\\lol.xml"))
                        {
                            throw new OpenFileException("File doesn't exist...");
                        }
                        ReadWriteDataManager.DeserializeBin();
                    }
                    else if (menuStepResp == "XML")
                    {
                        parkIoManager.WriteStepMessage("XML fail is created:");
                        ReadWriteDataManager.SerializeXml(carPark);
                    }
                    else if (menuStepResp == "OPENXML")
                    {
                        if (!File.Exists(@"D:\\lol.xml"))
                        {
                            throw new OpenFileException("File doesn't exist...");
                        }

                        var result = ReadWriteDataManager.DeserializeXml();
                        parkIoManager.ShowTable(result.Cars);
                    }
                    else if (menuStepResp == "EXIT")
                    {
                        break;
                    }
                    else
                    {
                        parkIoManager.Write("There is no such command... Try again or write EXITE for return to Main menu. ");
                    }
                }
            }
            catch (Exception ex)
            {
                parkIoManager.Write("Somthing went wrong...\n" + ex);
            }
        }