Esempio n. 1
0
        private static DataEntity ArrangeDataEntity(int len)
        {
            var data = new DataEntity();

            for (var i = 0; i < len; i++)
            {
                var car = data.AddCar();
                car.SetBrandName("Test " + i);
            }
            return(data);
        }
Esempio n. 2
0
        private void ReadCars(DataEntity data, BinaryReader sr)
        {
            var carsCount = BitConverter.ToInt32(sr.ReadBytes(4), 0);

            if (carsCount < 0)
            {
                throw new Exception("Car count can not be lesser than 0. File Incorrect.");
            }

            for (var i = 0; i < carsCount; i++)
            {
                var car = data.AddCar();
                ReadCar(car, sr);
            }
        }
Esempio n. 3
0
        private DataEntity CreateDataStub()
        {
            var dataStub = new DataEntity();
            var len      = 5;

            for (var i = 0; i < len; i++)
            {
                var car = dataStub.AddCar();
                car.SetDate(DateByIterator(i));
                car.SetBrandName(BrandByIterator(i));
                car.SetPrice(PriceByIterator(i));
            }

            return(dataStub);
        }
Esempio n. 4
0
        private IDataEntity XmlToDataEntity(XDocument doc)
        {
            var entity = new DataEntity();

            var cars = doc.Descendants("Car");

            foreach (var carFromFile in cars)
            {
                var car = entity.AddCar();

                var at = GetElement(carFromFile, "Date");
                car.SetDate(Convert.ToDateTime(at));

                at = GetElement(carFromFile, "BrandName");
                car.SetBrandName(at);

                at = GetElement(carFromFile, "Price");
                car.SetPrice(Convert.ToInt32(at));
            }

            return(entity);
        }