Пример #1
0
        //internal void ReadRecord(GenericFormRecord record, bool lazyLoading)
        //{
        //    ChangeState(States.Reading, s => s == States.Indexing);

        //    DoReadRecord(record, lazyLoading);

        //    ChangeState(States.Indexing);
        //}

        internal void ReadRecordAt(long position, GenericFormRecord record, bool lazyLoading)
        {
            ChangeState(States.Reading, s => s != States.Reading);

            if (segmentStack.Count > 0)
            {
                Log.Warning("Cleared unfinished stack left from previous reading");
                segmentStack.Clear();
            }

            BaseStream.Position = position;

            RecordMetadata recordMetaData = context.CreateRecordMetaData();

            NextSegment(recordMetaData);

            record.RawFlags = recordMetaData.Flags;
            record.Version  = recordMetaData.Version;

            DoReadRecord(record, lazyLoading);

            // Prevent segment errors due no reading all record content
            // during selective property reading
            if (lazyLoading)
            {
                SeekEndOfSegment();
            }

            EndSegment();

            ChangeState(States.Ready);
        }
Пример #2
0
        internal void WriteRecord(GenericFormRecord record, uint formId)
        {
            if (header == null)
            {
                throw new InvalidOperationException("Header not yet written");
            }

            FormKind formKind = (FormKind)InfoProvider.GetRecordInfo(record.GetType()).Signature;

            if (formKind != currentGroupFormKind)
            {
                // End existing group if one has begun
                if (currentGroupFormKind != FormKind.Any)
                {
                    EndSegment();
                }

                currentGroupFormKind = formKind;
                BeginGroupSegment(currentGroupFormKind);
                numRecords++;
            }

            // Convert global context Form ID to local relative Form ID
            uint localFormId = ReferenceMapper.ContexToLocal(formId);

            DoWriteRecord(record, localFormId);
            numRecords++;
        }
Пример #3
0
        private void DoReadRecord(GenericFormRecord record, bool lazyLoading)
        {
            RecordInfo recinf = InfoProvider.GetRecordInfo(record.GetType());

            if (record.GetType() != typeof(DummyRecord) && recinf.Signature != CurrentSegment.Signature)
            {
                throw new InvalidOperationException("Record signature mismatch.");
            }

            if (record.IsRecordCompressed)
            {
                // TODO: Intermediate MomeryStream may not be needed here
                long   decompressedSize = ReadUInt32();
                byte[] compressedData   = ReadBytesToEnd();
                Stream compressedStream = new MemoryStream(compressedData);
                Stream deflateStream    = new CustomDeflateStream(compressedStream, decompressedSize);
                using (RecordReader deflateReader = context.CreateReader(deflateStream))
                {
                    deflateReader.CurrentState = States.Reading;

                    // Copy flags etc to the deflate reader
                    deflateReader.PluginFlags     = PluginFlags;
                    deflateReader.ReferenceMapper = ReferenceMapper;
                    deflateReader.StringLocator   = StringLocator;

                    // Read record form the deflate reader
                    deflateReader.CurrentRecord = record;
                    record.ReadRecord(deflateReader, lazyLoading);
                    deflateReader.CurrentRecord = null;
                }
            }
            else
            {
                // Read record form the current reader
                CurrentRecord = record;
                record.ReadRecord(this, lazyLoading);
                CurrentRecord = null;
            }
        }