示例#1
0
        private string ReadBrandName(BinaryReader sw)
        {
            var brandNameSize = sw.ReadInt32();
            var brandName     = BinFormatterHelper.ReadStr(sw.ReadBytes(brandNameSize * 2));

            return(brandName);
        }
示例#2
0
 private void WriteCars(ICarEntity[] cars, BinaryWriter sw)
 {
     sw.Write(BinFormatterHelper.IntToBytes(cars.Length));
     for (var i = 0; i < cars.Length; i++)
     {
         WriteCar(cars[i], sw);
     }
 }
示例#3
0
        private void WriteDate(DateTime date, BinaryWriter sw)
        {
            var day   = date.Day.ToString();
            var month = date.Month.ToString();
            var year  = date.Year.ToString();

            var dateStr = day.PadLeft(2, '0') + month.PadLeft(2, '0') + year.PadLeft(4);
            var bytes   = BinFormatterHelper.StringOfIntToAsciiByte(dateStr);

            sw.Write(bytes);
        }
示例#4
0
        private void WriteBinDate(int d, int m, int y, BinaryWriter sw)
        {
            var day   = d.ToString();
            var month = m.ToString();
            var year  = y.ToString();

            var dateStr = day.PadLeft(2, '0') + month.PadLeft(2, '0') + year.PadLeft(4);
            var bytes   = BinFormatterHelper.StringOfIntToAsciiByte(dateStr);

            sw.Write(bytes);
        }
示例#5
0
        private void WriteTestCars(CarEntityWithoutConstraits[] cars, BinaryWriter sw, int overrideCount = -1)
        {
            var count = overrideCount == -1 ? cars.Length : overrideCount;

            sw.Write(BinFormatterHelper.IntToBytes(count));
            for (var i = 0; i < count; i++)
            {
                var car = cars[i];
                WriteBinDate(car.Day, car.Month, car.Year, sw);
                WriteBinBrand(car.BrandName, sw);
                WriteBinPrice(car.Price, sw);
            }
        }
示例#6
0
        private DateTime ReadDate(BinaryReader sw)
        {
            var dateStr = BinFormatterHelper.AsciiByteToStringOfInt(sw.ReadBytes(8));

            var day = Convert.ToInt32(dateStr.Substring(0, 2));


            var month = Convert.ToInt32(dateStr.Substring(2, 2));
            var year  = Convert.ToInt32(dateStr.Substring(4, 4));

            try
            {
                return(new DateTime(year, month, day));
            }
            catch (Exception)
            {
                throw new Exception("Date is incorrect");
            }
        }
示例#7
0
 private void WriteBrand(string brand, BinaryWriter sw)
 {
     sw.Write(BinFormatterHelper.IntToBytes(brand.Length));
     sw.Write(BinFormatterHelper.StrToBytes(brand));
 }
示例#8
0
 private void WritePrice(int price, BinaryWriter sw)
 {
     sw.Write(BinFormatterHelper.IntToBytes(price));
 }
示例#9
0
 private void WriteHeader(BinaryWriter sw)
 {
     sw.Write(BinFormatterHelper.CharToBytes((char)0x2526));
 }