protected override void OnReadRecordBuffer(byte[] mBuffer, Record result) { mRecordWriter.Read(this, mBuffer, (TRecord)result); }
protected override void OnInitialize(Stream stream) { Byte[] headerBuff = new byte[mDbfHeaderWriter.RecordWidth]; mDbfHeader = new DbfHeader(); int read = stream.Read(headerBuff, 0, headerBuff.Length); if (read > 0) { mDbfHeaderWriter.Read(this, headerBuff, mDbfHeader); //File size reported by the operating system must match the logical file size. Logical file size = ( Length of header + ( Number of records * Length of each record ) ) //mHeaderSerializer.mQuickWriteMethod(this, headerBuff, header); var nbColumns = ((mDbfHeader.HeaderWidth - mDbfHeaderWriter.RecordWidth) / mDbfColumnWriter.RecordWidth) + 1; var totalLength = stream.Length; mRecordWidth = mDbfHeader.RecordWidth; var recordsLength = totalLength - mDbfHeader.HeaderWidth; if (mRecordWidth > 0) { var columns = new List <ColumnDefinition>(nbColumns); mRecordCount = (UInt32)(recordsLength / mRecordWidth); Byte[] columnHeaderBuff = new byte[mDbfColumnWriter.RecordWidth]; DbfColumnHeader dbfColumnHeader = new DbfColumnHeader(); ColumnDefinition columnDefinition = null; //new ColumnDefinition(); //columnDefinition.Initialize(DbfVersion.dBaseIII, 0, typeof(DbfRecord).GetField("DeletedFlag", // BindingFlags.Instance // | BindingFlags.Public // | BindingFlags.NonPublic // | BindingFlags.DeclaredOnly), 0, null); //columns.Add(columnDefinition); for (int i = 1; i < nbColumns; i++) { read = stream.Read(columnHeaderBuff, 0, columnHeaderBuff.Length); mDbfColumnWriter.Read(this, columnHeaderBuff, dbfColumnHeader); System.Diagnostics.Trace.WriteLine(string.Format("{0},{1},{2},{3}", dbfColumnHeader.ColumnName, dbfColumnHeader.ColumnType, dbfColumnHeader.ColumnWidth, dbfColumnHeader.Decimals)); columnDefinition = new ColumnDefinition(); columnDefinition.Initialize(dbfColumnHeader.ColumnName, dbfColumnHeader.ColumnType, dbfColumnHeader.ColumnWidth, dbfColumnHeader.Decimals); columns.Add(columnDefinition); } int lastByte = stream.ReadByte(); if (lastByte == END_OF_COLUMN_DEFINITIONS) { mColumns = columns; mHeaderWidth = mDbfHeader.HeaderWidth; } } } mRecordWriter = new QuickSerializer( typeof(TRecord), mVersion, mColumns, mRecordWidth, false, true); if (mColumns == null) { mColumns = mRecordWriter.Columns; mRecordWidth = mRecordWriter.RecordWidth; mDbfHeader.VerNumber = 131; mDbfHeader.LastUpdate = DateTime.Now; mDbfHeader.NbRecords = 0; var nbColumns = mColumns.Count; mDbfHeader.HeaderWidth = (UInt16)(mDbfHeaderWriter.RecordWidth + mDbfColumnWriter.RecordWidth * nbColumns + 1); mDbfHeader.RecordWidth = (UInt16)mRecordWriter.RecordWidth; mDbfHeader.Zero = 0; mDbfHeader.IncompleteTransaction = 0; mDbfHeader.EncryptionFlag = 0; //mDbfHeader.LanOnly = []; mDbfHeader.Indexed = 0; mDbfHeader.Language = 0; mDbfHeader.Zero2 = 0; WriteHeader(stream, /*withColumns*/ true); } }