Beispiel #1
0
        /// <summary>
        /// Loads meta information into this instance of <see cref="RecordStream"/>.
        /// If you have called <c>UnloadInfo</c>,
        /// the status of this <see cref="RecordStream"/> instance will be restored where it was right before the last time UnloadInfo was called.
        /// </summary>
        public virtual void LoadInfo()
        {
            //reads info from <paramref name="infoStream" />
            if (_rinfo != null)
            {
                return;
            }
            if (_infoPos >= 0)
            {
                _infoStream.SeekTo(_infoPos);

                if (_infoStream.Check(IOChecks.RecordStream))
                {
                    _rinfo              = new _rinfo();
                    _rinfo._metaNum     = _infoStream.ReadInt32();
                    _metaNumRetrieved   = true;
                    _rinfo._blockLength = _infoStream.ReadInt32();
                    _rinfo._totalLength = _infoStream.ReadInt64();

                    if (ReadMoreInfo != null)
                    {
                        ReadMoreInfo(_infoStream);
                    }

                    _rinfo._list = new List <long>();
                    _infoStream.ReadList(_rinfo._list);
                }
                else
                {
                    throw new InvalidDataException(IOResources.ERR_StreamExtension_DataIrrecognizable);
                }
            }
        }
Beispiel #2
0
 /// <summary>
 /// Unloads the meta information of this <see cref="RecordStream"/> instance and release some memory.
 /// Before calling this method, you must make a decision to save or discard the changes to the data blocks.
 /// Later you are able to reload the meta information by calling LoadInfo again.
 /// </summary>
 public virtual void UnloadInfo()
 {
     if (_rinfo == null)
     {
         throw new InvalidOperationException(IOResources.ERR_IRecord_NotLoaded);
     }
     if (_rinfo._infoModified1)
     {
         throw new InvalidOperationException(IOResources.ERR_RecordStream_UpdateNotSaved);
     }
     if (_rinfo._list != null)
     {
         _rinfo._list.Clear();
         _rinfo._list = null;
     }
     _rinfo = null;
 }
Beispiel #3
0
        /// <summary>
        /// Makes this <see cref="RecordStream"/> represent a new record without eliminating the data
        /// of the previous record in the underlying stream.
        /// If you have already loaded an existing record into this instance and made changes to the data blocks,
        /// and you call this method again before you call <c>SaveInfo</c>, and then these new changes will be lost.
        /// </summary>
        /// <param name="blockLength">The length of each data block in this record stream.</param>
        public void CreateNew(int blockLength)
        {
            if (blockLength <= 0)
            {
                throw new ArgumentOutOfRangeException("blockLength", GeneralResources.ERR_PositiveValueRequired.Scan("blockLength"));
            }

            if (_infoPos == -1 && _rinfo == null)
            {
                _rinfo                = new _rinfo();
                _rinfo._list          = new List <long>();
                _rinfo._totalLength   = 0;
                _rinfo._blockLength   = blockLength;
                _currPos              = -1;
                _rinfo._infoModified1 = true;
                _rinfo._infoModified2 = true;
            }
            else
            {
                throw new InvalidOperationException(IOResources.ERR_RecordStream_InvalidCreation);
            }
        }