Example #1
0
        protected override void ReadContent(ByteReader reader)
        {
            var info = reader.ReadString(HEADER_INFO.Length);
            var ver  = reader.ReadByte();

            if (info != HEADER_INFO)
            {
                throw LiteException.InvalidDatabase();
            }
            if (ver != FILE_VERSION)
            {
                throw LiteException.InvalidDatabaseVersion(ver);
            }

            ChangeID        = reader.ReadUInt16();
            FreeEmptyPageID = reader.ReadUInt32();
            LastPageID      = reader.ReadUInt32();
            DbParams.Read(reader);

            // read page collections references (position on end of page)
            var cols = reader.ReadByte();

            for (var i = 0; i < cols; i++)
            {
                CollectionPages.Add(reader.ReadString(), reader.ReadUInt32());
            }
        }
Example #2
0
 public HeaderPage()
     : base(0)
 {
     FreeEmptyPageID = uint.MaxValue;
     ChangeID        = 0;
     LastPageID      = 0;
     ItemCount       = 1; // fixed for header
     FreeBytes       = 0; // no free bytes on header
     DbParams        = new DbParams();
     CollectionPages = new Dictionary <string, uint>(StringComparer.OrdinalIgnoreCase);
 }
Example #3
0
        protected override void WriteContent(ByteWriter writer)
        {
            writer.Write(HEADER_INFO, HEADER_INFO.Length);
            writer.Write(FILE_VERSION);
            writer.Write(ChangeID);
            writer.Write(FreeEmptyPageID);
            writer.Write(LastPageID);
            DbParams.Write(writer);

            writer.Write((byte)CollectionPages.Count);
            foreach (var key in CollectionPages.Keys)
            {
                writer.Write(key);
                writer.Write(CollectionPages[key]);
            }
        }
Example #4
0
        /// <summary>
        /// Set a new dbversion
        /// </summary>
        public void SetParam(DbParams dbparams)
        {
            lock (_locker)
                try
                {
                    _transaction.Begin();
                    _transaction.AvoidDirtyRead();

                    var header = _pager.GetPage <HeaderPage>(0);

                    header.DbParams = dbparams;

                    _pager.SetDirty(header);

                    _transaction.Commit();
                }
                catch (Exception ex)
                {
                    _log.Write(Logger.ERROR, ex.Message);
                    _transaction.Rollback();
                    throw;
                }
        }
Example #5
0
        /// <summary>
        /// Set a new dbversion
        /// </summary>
        public void SetParam(DbParams dbparams)
        {
            lock (_locker)
            try
                {
                    _transaction.Begin();
                    _transaction.AvoidDirtyRead();

                    var header = _pager.GetPage<HeaderPage>(0);

                    header.DbParams = dbparams;

                    _pager.SetDirty(header);

                    _transaction.Commit();
                }
                catch (Exception ex)
                {
                    _log.Write(Logger.ERROR, ex.Message);
                    _transaction.Rollback();
                    throw;
                }
        }