Beispiel #1
0
        static void Main(string[] args)
        {
            try
            {
                var demoCars = CreateDefaultCarCollection();
                Console.WriteLine("Creating default Car Collection binary file " + BinaryDemoFileName);
                _carSupporter.Save(BinaryDemoFileName, CarFileFormat.Binary, true, demoCars);

                Console.WriteLine("Creating default Car Collection XML file " + XmlDemoFileName);
                _carSupporter.Save(XmlDemoFileName, CarFileFormat.Xml, true, demoCars);

                Console.WriteLine("Converting XML Car Collection file to a binary file " + BinaryFileName);
                _carSupporter.Convert(XMLFileName, BinaryFileName, CarFileFormat.Binary, true);

                Console.WriteLine("Reading Car Collection file " + XMLFileName);
                var cars = _carSupporter.Load(XMLFileName);

                Console.WriteLine("Adding a new record to the default Car Collection file");
                demoCars.CarRecords.Add(cars.CarRecords[0]);

                Console.WriteLine("Creating modified Car Collection binary file " + ModifiedBinaryFileName);
                _carSupporter.Save(ModifiedBinaryFileName, CarFileFormat.Binary, true, demoCars);

                Console.WriteLine("Updating the first record in the default Car Collection file (price = 99999)");
                demoCars.CarRecords[0].Price = 99999;

                Console.WriteLine("Creating modified Car Collection XML file " + ModifiedXMLFileName);
                _carSupporter.Save(ModifiedXMLFileName, CarFileFormat.Xml, true, demoCars);

                Console.WriteLine("Deleting the second record in the default Car Collection file");
                demoCars.CarRecords.RemoveAt(1);

                var jsonFormat = CarCollectionSupporter.AddFileFormat <CarCollectionJsonSerializer>();

                Console.WriteLine("Creating modified Car Collection JSON file " + ModifiedJsonFileName);
                _carSupporter.Save(ModifiedJsonFileName, jsonFormat, true, demoCars);
            }
            catch (IOException e)
            {
                Console.WriteLine("Cannot perform operation because of this error: " + e.Message);
            }

            Console.WriteLine("Press any key to continue");
            Console.ReadKey();
        }
Beispiel #2
0
 public static void BeforeTests()
 {
     _jsonFileFormat = CarCollectionSupporter.AddFileFormat <CarCollectionJsonSerializer>();
 }