public ApartmentHouseMemento(ApartmentHouse apartmentHouse)
 {
     _number = apartmentHouse.Number;
     _adress = apartmentHouse.Adress;
     _mementoApartments = new ApartmentMemento[apartmentHouse.Apartments.Count];
     var i = 0;
     foreach (var apartment in apartmentHouse)
     {
         _mementoApartments[i] = apartment.CreateMemento();
         i++;
     }
 }
        public void TestReadWriteCompressedToStream()
        {
            var fileStream = new FileStream("compressed.rar", FileMode.Create);
            var apartmentsArray = new[]
            {
                new Apartment(1, "Lalkin", new[] {new Room(6, 3, 2), new Room(3, 2, 2), new Room(3, 2, 2)}),
                new Apartment(2, "Petsf2", new[] {new Room(1, 3, 2), new Room(3, 2, 2)})
            };
            var apartmentHouse = new ApartmentHouse(1, "Улица Пушкина, Дом колотушкина", apartmentsArray);
            apartmentHouse.WriteCompressedToStream(fileStream);
            fileStream.Close();

            fileStream = new FileStream("compressed.rar", FileMode.Open);
            var newApartmentHouse = new ApartmentHouse();
            newApartmentHouse.ReadCompressedFromStream(fileStream);

            Assert.AreEqual(apartmentHouse, newApartmentHouse);
        }
        public void TestReadWriteToBinaryStream()
        {
            var fileStream = new FileStream("binary.bin", FileMode.Create);
            var apartmentsArray = new[]
            {
                new Apartment(1, "Kiselyov", new[] {new Room(6, 3, 2), new Room(3, 2, 2), new Room(3, 2, 2)}),
                new Apartment(2, "Petrov", new[] {new Room(1, 3, 2), new Room(3, 2, 2)})
            };
            var apartmentHouse = new ApartmentHouse(1, "Улица Пушкина, Дом колотушкина", apartmentsArray);
            apartmentHouse.WriteBinaryToStream(fileStream);
            fileStream.Close();

            fileStream = new FileStream("binary.bin", FileMode.Open);
            var newApartmentHouse = new ApartmentHouse();
            newApartmentHouse.ReadBinaryFromStream(fileStream);

            Assert.AreEqual(apartmentHouse, newApartmentHouse);
        }
Example #4
0
        // -------------------------------------------------        OnLoad
        private void OnLoad (object sender, EventArgs e)
        {
            Auxi_Colours .VisibleFrame (this);

            plot = new MSPlot (this, new Rectangle (50, 60, 350, 290), Side .S, 0.0, 4 * Math .PI, GridOrigin .ByStep, Math .PI,
                                                                       Side .E, 1.0, -1.0, GridOrigin .ByStep, 0.5);
            plot .AddComment (0.5, -14, "Sin (x) * Cos (12x)", 
                              new Font ("Times New Roman", 11, FontStyle .Bold | FontStyle .Italic), 0, Color .Blue);

            piechart = new PieChart (this, new Point (500, 330), 140, Auxi_Common .RandomArray (1000, Auxi_Common .strDays .Length));
            piechart .SectorTexts = Auxi_Common .strDays;

            Font fnt = new Font ("Times New Roman", 14, FontStyle.Bold | FontStyle.Italic);
            house9 = new ApartmentHouse (new Rectangle (690, 110, 120, 210));
            house9 .HouseColor = Color .White;
            house9 .RoofColor = Color .Red;
            house9 .DoorColor = Color .Brown;
            house9 .WindowColor = Color .Cyan;

            house23 = new ApartmentHouse (new Rectangle (580, 90, 130, 110));
            house23 .HouseColor = Color .Yellow;
            house23 .RoofColor = Color .Green;

            Point ptC = new Point (100, 440);
            int radius = 50;
            Color [] clrs = Auxi_Colours .SmoothChangedColors (4, Auxi_Colours .ColorPredefined (4), Auxi_Colours .ColorPredefined (5));
            poly4 = new ChatoyantPolygon (Auxi_Geometry .RegularPolygon (4, ptC, radius, 0), ptC, clrs, Auxi_Colours .ColorPredefined (6));
            ptC = new Point (260, 460);
            radius = 75;
            clrs = Auxi_Colours .SmoothChangedColors (7, Auxi_Colours .ColorPredefined (7), Auxi_Colours .ColorPredefined (8));
            poly7 = new ChatoyantPolygon (Auxi_Geometry .RegularPolygon (7, ptC, radius, 0), ptC, clrs, Auxi_Colours .ColorPredefined (9));

            info = new TextM (this, new Point (plot .MainArea .Area .Right + 30, Convert .ToInt32 (poly4 .Center .Y) + 20), strInfo);
            info .BackColor = Color .FromArgb (255, 255, 128);

            ClientSize = new Size (Math .Max (info .Area .Right, house9 .Area .Right) + 20, info .Area .Bottom + 12);

            timerStart .Enabled = true;
            timerStart .Start ();

            RenewMover ();
        }
        public void TestReadWriteTextToStream()
        {
            var fileStream = new FileStream("text.ini", FileMode.Create);
            var streamWriter = new StreamWriter(fileStream);
            var apartmentsArray = new[]
            {
                new Apartment(1, "EdwardHal", new[] {new Room(6111, 3, 1), new Room(3, 2, 2), new Room(3, 2, 2)}),
                new Apartment(2, "Petrov", new[] {new Room(21, 3, 2), new Room(3, 2, 2)})
            };
            var apartmentHouse = new ApartmentHouse(2, "lOLtoWN", apartmentsArray);
            apartmentHouse.WriteTextToStream(streamWriter);
            fileStream.Close();

            fileStream = new FileStream("text.ini", FileMode.Open);
            var streamReader = new StreamReader(fileStream);
            var newApartmentHouse = new ApartmentHouse();
            newApartmentHouse.ReadTextFromStream(streamReader);

            Assert.AreEqual(apartmentHouse, newApartmentHouse);
        }
 public void TestDataContractJsonSerialization()
 {
     var apartmentsArray = new[]
     {
         new Apartment(1, "Kiselyov", new[] {new Room(6, 3, 2), new Room(3, 2, 2), new Room(3, 2, 2)}),
         new Apartment(2, "Petrov", new[] {new Room(1, 3, 2), new Room(3, 2, 2)})
     };
     var apartmentHouse = new ApartmentHouse(1, "Улица Пушкина, Дом колотушкина", apartmentsArray);
     var serializer = new DataContractJsonSerializer(typeof(ApartmentHouse));
     using (var fileStream = new FileStream("DCSerialization.json", FileMode.Create))
     {
         serializer.WriteObject(fileStream, apartmentHouse);
     }
     ApartmentHouse apartmentHouse2;
     using (var fileStream = new FileStream("DCSerialization.json", FileMode.Open))
     {
         apartmentHouse2 = (ApartmentHouse)serializer.ReadObject(fileStream);
     }
     Assert.AreEqual(apartmentHouse, apartmentHouse2);
 }
        public void TestRuntimeSerialization()
        {
            var apartmentsArray = new[]
            {
                new Apartment(1, "Kiselyov", new[] {new Room(6, 3, 2), new Room(3, 2, 2), new Room(3, 2, 2)}),
                new Apartment(2, "Petrov", new[] {new Room(1, 3, 2), new Room(3, 2, 2)})
            };
            var apartmentHouse = new ApartmentHouse(1, "Улица Пушкина, Дом колотушкина", apartmentsArray);
            var memntoApartmentHouse = apartmentHouse.CreateMemento();
            var apartmentHouse2 = new ApartmentHouse();

            using (var fileStream = new FileStream("RTSerialization.dat", FileMode.Create))
            {
                MementoRuntimeSerialization<ApartmentHouseMemento>.RuntimeSerialize(fileStream, memntoApartmentHouse);
            }
            using (var fileStream = new FileStream("RTSerialization.dat", FileMode.Open))
            {
                memntoApartmentHouse = MementoRuntimeSerialization<ApartmentHouseMemento>.RuntimeDeserealize(fileStream);
            }
            apartmentHouse2.SetMemento(memntoApartmentHouse);
            Assert.AreEqual(apartmentHouse, apartmentHouse2);
        }
 public void TestLinqToXmlConverter()
 {
     var apartmentsArray = new[]
     {
         new Apartment(1, "Kiselyov", new[] {new Room(6, 3, 2), new Room(3, 2, 2), new Room(3, 2, 2)}),
         new Apartment(2, "Petrov", new[] {new Room(1, 3, 2), new Room(3, 2, 2)})
     };
     var apartmentHouse = new ApartmentHouse(1, "Улица Пушкина, Дом колотушкина", apartmentsArray);
     using (var fileStream = new FileStream("LinqToXml.xml", FileMode.Create))
     {
         ObjectLinqToXmlConverter<ApartmentHouse>.ToXmlTextStream(fileStream, apartmentHouse);
     }
     ApartmentHouse apartmentHouse2;
     using (var fileStream = new FileStream("LinqToXml.xml", FileMode.Open))
     {
         apartmentHouse2 = ObjectLinqToXmlConverter<ApartmentHouse>.Parse(fileStream);
     }
     Assert.AreEqual(apartmentHouse, apartmentHouse2);
 }