private string ReadBrandName(BinaryReader sw) { var brandNameSize = sw.ReadInt32(); var brandName = BinFormatterHelper.ReadStr(sw.ReadBytes(brandNameSize * 2)); return(brandName); }
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); } }
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); }
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); }
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); } }
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"); } }
private void WriteBrand(string brand, BinaryWriter sw) { sw.Write(BinFormatterHelper.IntToBytes(brand.Length)); sw.Write(BinFormatterHelper.StrToBytes(brand)); }
private void WritePrice(int price, BinaryWriter sw) { sw.Write(BinFormatterHelper.IntToBytes(price)); }
private void WriteHeader(BinaryWriter sw) { sw.Write(BinFormatterHelper.CharToBytes((char)0x2526)); }