Exemplo n.º 1
0
        internal void ReadRecord(RecordReader reader, bool lazyLoading)
        {
            var compinfo = InfoProvider.GetCompoundInfo(GetType());
            var recinfo  = InfoProvider.GetRecordInfo(GetType());

            BeforeRead(reader);

            reader.BeginReadFields(0);

            HashSet <string> remainingPropertiesToLoad = lazyLoading ? new HashSet <string>(compinfo.Members.Values.Where(m => m.IsLazy).SelectMany(m => m.FieldNames)) : null;

            foreach (string propertyName in reader.FindFields())
            {
                MemberInfo meminf = compinfo.FindMember(propertyName);
                if (meminf != null)
                {
                    reader.ReadField(this, propertyName, meminf, 0);

                    if (remainingPropertiesToLoad != null)
                    {
                        if (!meminf.IsListType && !meminf.IsDynamic)
                        {
                            remainingPropertiesToLoad.Remove(propertyName);
                        }

                        if (!remainingPropertiesToLoad.Any())
                        {
                            // Loaded all properties that were supposed to
                            reader.CancelFindFields();
                            break;
                        }
                    }
                }
                else if (lazyLoading || recinfo.IsDummyRecord)
                {
                    // Prevent segment errors when not all properties were expected to be consumed
                    reader.SeekEndOfSegment();
                }
                else
                {
                    Log.Warning("Unexpected record property: {0}", propertyName);
                }
            }

            reader.EndReadFields(0);

            //// Make sure list properties that were supposed to be loaded are not null
            //foreach (MemberInfo meminfo in members.Where(m => m.Value.IsListType && (fieldsToLoad == null || fieldsToLoad.Contains(m.Key))).Select(m => m.Value))
            //{
            //    meminfo.EnsureListCreated(this);
            //}

            AfterRead(reader);
        }
Exemplo n.º 2
0
        internal virtual void ReadCompoundField(RecordReader reader, string fieldName, int depth)
        {
            var members = InfoProvider.GetCompoundInfo(GetType()).Members;

            if (!members.ContainsKey(fieldName))
            {
                throw new InvalidProgramException("Unexpected field name while reading a compound field: " + fieldName);
            }

            var meminf = members[fieldName];

            reader.ReadField(this, fieldName, meminf, depth);
        }
Exemplo n.º 3
0
        internal void OnComplete(RecordReader reader, int depth)
        {
            reader.EndReadFields(depth);

            // Make sure list fields that were supposed to be loaded are not null
            var members = InfoProvider.GetCompoundInfo(GetType()).Members;

            foreach (MemberInfo meminfo in members.Where(m => m.Value.IsListType).Select(m => m.Value))
            {
                meminfo.EnsureListCreated(this);
            }

            AfterRead(reader);
        }
Exemplo n.º 4
0
        public override void ReadMetaData(RecordReader reader)
        {
            if (Signature == "GRUP")
            {
                throw new InvalidOperationException("Group signature was not expected now");
            }

            Length   = reader.ReadUInt32();
            Flags    = reader.ReadUInt32();
            FormId   = reader.ReadUInt32();
            Revision = reader.ReadUInt32();
            Version  = reader.ReadUInt16();
            Unknown  = reader.ReadUInt16();
        }
Exemplo n.º 5
0
                public Worker(RecordReader reader, Options options)
                {
                    if (options.RecordCacheSize < 1)
                    {
                        throw new InvalidOperationException("Record cache size must be at least 1");
                    }

                    this.reader  = reader;
                    this.options = options;

                    int recordsToCreate = options.RecordCacheSize;

                    while (recordsToCreate-- > 0)
                    {
                        idleRecords.Push(new RecordEntry());
                    }
                }
Exemplo n.º 6
0
        public override void ReadMetaData(RecordReader reader)
        {
            if (Signature == "XXXX")
            {
                // Segment length is always 4 which not interesting so skip 2 bytes
                reader.Seek(2);

                // Read lenght of the next segment
                uint nextSegmentLength = reader.ReadUInt32();

                // Load the actual signature (segment after XXXX)
                Signature = reader.ReadStringFixedLength(4);

                // Length is ZERO so skip 2 bytes and use value from the previous segment
                reader.Seek(2);
                Length = nextSegmentLength;
            }
            else
            {
                Length = reader.ReadUInt16();
            }
        }
Exemplo n.º 7
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;
            }
        }
Exemplo n.º 8
0
 internal abstract void ReadField(RecordReader reader);
Exemplo n.º 9
0
 internal sealed override void ReadField(RecordReader reader)
 {
     // Method replaced with one that provides the Field name that is being read and the depth as well
     throw new NotImplementedException("Not implemented for compound fields");
 }
Exemplo n.º 10
0
 protected virtual void AfterRead(RecordReader reader)
 {
 }
Exemplo n.º 11
0
 protected virtual void BeforeRead(RecordReader reader)
 {
 }
Exemplo n.º 12
0
        internal void OnCreate(RecordReader reader, int depth)
        {
            BeforeRead(reader);

            reader.BeginReadFields(depth);
        }
Exemplo n.º 13
0
 public abstract void ReadMetaData(RecordReader reader);
Exemplo n.º 14
0
 internal void ReadRecord(RecordReader reader)
 {
     ReadRecord(reader, false);
 }
Exemplo n.º 15
0
 public Enumerator(RecordReader reader, Options options)
 {
     this.reader  = reader;
     this.options = options;
 }
Exemplo n.º 16
0
 private AsyncRecordFinder(RecordReader reader, Options options)
 {
     this.reader  = reader;
     this.options = options;
 }