示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
        public bool InsertRecord(RowRecord record, int recordSize)
        {
            if (CountRealRecords * recordSize + recordSize > Data.Length)
            {
                return(false);
            }

            SaveRecord(record, CountRealRecords, recordSize);
            CountRealRecords++;
            CountNotDeletedRecords++;
            return(true);
        }
示例#4
0
        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);
        }
示例#5
0
        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)));
        }
示例#6
0
 public bool UpdateRecord(RowRecord newRecord, int pos, int recordSize)
 {
     SaveRecord(newRecord, pos, recordSize);
     return(true);
 }