private int CalculateRowRecordSize(Table table) { using var memStream = new MemoryStream(); var rowRecord = new RowRecord(table.CreateDefaultRow().Result); ZeroFormatterSerializer.Serialize(memStream, rowRecord); return((int)memStream.Length); }
public void SaveRecord(RowRecord record, int pos, int recordSize) { using var memStream = new MemoryStream(Data); memStream.Seek(pos * recordSize, SeekOrigin.Begin); var buffer = new byte[recordSize]; ZeroFormatterSerializer.Serialize(ref buffer, 0, record); memStream.Write(buffer, 0, buffer.Length); }
public bool InsertRecord(RowRecord record, int recordSize) { if (CountRealRecords * recordSize + recordSize > Data.Length) { return(false); } SaveRecord(record, CountRealRecords, recordSize); CountRealRecords++; CountNotDeletedRecords++; return(true); }
public void InsertRecord(RowRecord rowRecord) { var dataBlock = LoadDataBlock(metaInfDataStorage.HeadDataBlockList); if (dataBlock == null || !dataBlock.InsertRecord(rowRecord, metaInfDataStorage.RowRecordSize)) { MoveNewBlockToHead(); dataBlock = LoadDataBlock(metaInfDataStorage.HeadDataBlockList); dataBlock.InsertRecord(rowRecord, metaInfDataStorage.RowRecordSize); } SaveDataBlock(dataBlock, metaInfDataStorage.HeadDataBlockList); }
public OperationResult <Tuple <long, long> > InsertRow(Id tableName, Row fields) { if (!File.Exists(GetTableFileName(tableName))) { return(new OperationResult <Tuple <long, long> >(ExecutionState.failed, new Tuple <long, long>(0, 0), new TableNotExistError(FullTableName(tableName)))); } using var manager = new TableFileManager(new FileStream(GetTableFileName(tableName), FileMode.Open, FileAccess.ReadWrite, FileShare.Read, 4096)); var rowRecord = new RowRecord(fields); manager.InsertRecord(rowRecord); return(new OperationResult <Tuple <long, long> >(ExecutionState.performed, new Tuple <long, long>(manager.readCount, manager.writeCount))); }
public bool UpdateRecord(RowRecord newRecord, int pos, int recordSize) { SaveRecord(newRecord, pos, recordSize); return(true); }