Beispiel #1
0
        static void Main(string[] args)
        {
            Author          author    = new Author("Adam", "Mickiewicz", 50, "Warszawa");
            Person          person    = new Person("Antek", "Nowak", 15, "Krakow");
            Book            book1     = new Book("Dziady", author, 200, "PWN");
            Book            book2     = new Book("Przedwiosnie", author, 250, "Sowa");
            BookDescription bookDscp1 = new BookDescription(book1, "dziwna ksiazka", DateTime.Now, Purpose.All, Kind.Fantasy);
            BookDescription bookDscp2 = new BookDescription(book2, "fajne", DateTime.Now, Purpose.Teenagers, Kind.Moral);
            Rental          rental1   = new Rental(bookDscp1, person, DateTime.Now);
            Rental          rental2   = new Rental(bookDscp1, person, DateTime.Now);
            Rental          rental3   = new Rental(bookDscp2, person, DateTime.Now);

            DataContext dataCtx = new DataContext();

            dataCtx.PeopleCatalog.Add(author);
            dataCtx.PeopleCatalog.Add(person);
            dataCtx.ItemsCatalog.Add(book1.Id, book1);
            dataCtx.ItemsCatalog.Add(book2.Id, book2);
            dataCtx.StatesCatalog.Add(bookDscp1);
            dataCtx.StatesCatalog.Add(bookDscp2);
            dataCtx.EventsCatalog.Add(rental1);
            dataCtx.EventsCatalog.Add(rental2);
            dataCtx.EventsCatalog.Add(rental3);

            OwnSerializer.Serialize(dataCtx, "DataCtxSerialized.data");

            DataContext newDataCtx = OwnSerializer.Deserialize("DataCtxSerialized.data");
        }
Beispiel #2
0
        public void SameDataAfterDeserializing()
        {
            IDataFiller    filler   = new DataFillerImpl();
            DataRepository dataRepo = new DataRepository(filler);

            dataRepo.setDataContext();
            var dataCtxOriginal = dataRepo.getDataContext();

            OwnSerializer.Serialize(dataCtxOriginal, FILENAME);

            var dataCtxDeserialized = OwnSerializer.Deserialize(FILENAME);

            Assert.AreEqual(dataCtxOriginal.EventsCatalog[1].Person.LastName, dataCtxDeserialized.EventsCatalog[1].Person.LastName);
        }
        public void performanceTest()
        {
            Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.High;
            Thread.CurrentThread.Priority = ThreadPriority.Highest;

            var watch = new Stopwatch();

            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();

            watch.Start();
            dataFiller1 = new LargeDataFillerImpl();
            dataFiller1.GetPeopleList();
            dataFiller1.GetItemsList();
            dataFiller1.GetStatesList();
            dataFiller1.GetEventsList();
            watch.Stop();

            Console.WriteLine("LargeDataFiller time = {0}", watch.Elapsed.TotalMilliseconds);

            watch.Reset();

            watch.Start();
            dataFiller2 = new LargeJsonDataFillerImpl();
            dataFiller2.GetPeopleList();
            dataFiller2.GetItemsList();
            dataFiller2.GetStatesList();
            dataFiller2.GetEventsList();
            watch.Stop();

            Console.WriteLine("LargeJsonDataFiller time = {0}", watch.Elapsed.TotalMilliseconds);

            watch.Reset();

            watch.Start();
            XMLObjectSerializer <DataContext> .Deserialize("XmlData/DataContextData.xml");

            watch.Stop();

            Console.WriteLine("XmlSerializer time = {0}", watch.Elapsed.TotalMilliseconds);

            watch.Reset();

            watch.Start();
            OwnSerializer.Deserialize("OwnSerializerData/SerializedData.data");
            watch.Stop();

            Console.WriteLine("OwnSerializer time = {0}", watch.Elapsed.TotalMilliseconds);
        }
Beispiel #4
0
        public void SerializeReferenceTest()
        {
            IDataFiller    filler = new DataFillerImpl();
            DataRepository repo   = new DataRepository(filler);

            repo.setDataContext();
            OwnSerializer.Serialize(repo.getDataContext(), FILENAME);
            var originalDataCtx = repo.getDataContext();

            Assert.IsTrue(originalDataCtx.StatesCatalog[0].Item == originalDataCtx.ItemsCatalog[originalDataCtx.StatesCatalog[0].Item.Id]);

            var deserializedDataCtx = OwnSerializer.Deserialize(FILENAME);

            Assert.IsTrue(deserializedDataCtx.StatesCatalog[0].Item == deserializedDataCtx.ItemsCatalog[originalDataCtx.StatesCatalog[0].Item.Id]);
        }