コード例 #1
0
        /// <summary>
        /// Initialize database
        /// </summary>
        public async Task OpenAsync()
        {
            LOG("start initializing", "ENGINE");

            try
            {
                // open async stream
                if (_stream is IAsyncInitialize s)
                {
                    await s.InitializeAsync();
                }

                // initialize disk service (will create database if needed)
                _disk = await DiskService.CreateAsync(_stream, _collation, MEMORY_SEGMENT_SIZES, MAX_EXTENDS);

                // get header page from disk service
                _header = _disk.Header;

                // test for same collation
                if (_collation.ToString() != _header.Pragmas.Collation.ToString())
                {
                    throw new LiteException(0, $"Datafile collation '{_header.Pragmas.Collation}' is different from engine settings. Use Rebuild database to change collation.");
                }

                // initialize wal-index service
                _walIndex = new WalIndexService(_disk);

                // restore wal index references, if exists
                await _walIndex.RestoreIndex(_header);

                // register system collections
                // this.InitializeSystemCollections();
                _disposed = false;

                LOG("initialization completed", "ENGINE");
            }
            catch (Exception ex)
            {
                LOG(ex.Message, "ERROR");

                // explicit dispose (but do not run shutdown operation)
                await this.DisposeAsync();

                throw;
            }
        }