/// <summary>
        /// Initializes a new instance of the PersistentDictionaryCursor class.
        /// </summary>
        /// <param name="instance">The instance to use.</param>
        /// <param name="database">The database to open.</param>
        /// <param name="converters">ESENT conversion functions.</param>
        /// <param name="config">The database meta-data config.</param>
        public PersistentDictionaryCursor(
            Instance instance,
            string database,
            PersistentDictionaryConverters <TKey, TValue> converters,
            IPersistentDictionaryConfig config)
        {
            this.instance   = instance;
            this.converters = converters;
            this.config     = config;
            this.database   = database;
            Api.JetBeginSession(this.instance, out this.sesid, String.Empty, String.Empty);

            this.AttachDatabase();
            //try
            //{
            //    this.AttachDatabase();
            //}
            //catch (EsentPrimaryIndexCorruptedException)
            //{
            //    this.RetryAttachDatabase();
            //}
            //catch (EsentSecondaryIndexCorruptedException)
            //{
            //    this.RetryAttachDatabase();
            //}
        }
Exemple #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PersistentDictionaryCursorCache{TKey,TValue}"/>
 /// class.
 /// </summary>
 /// <param name="instance">The ESENT instance to use when opening a cursor.</param>
 /// <param name="database">The database to open the cursors on.</param>
 /// <param name="converters">The converters the cursors should use.</param>
 /// <param name="config">The configuration for the cursors.</param>
 public PersistentDictionaryCursorCache(
     Instance instance,
     string database,
     PersistentDictionaryConverters <TKey, TValue> converters,
     IPersistentDictionaryConfig config)
 {
     this.instance   = instance;
     this.converters = converters;
     this.config     = config;
     this.database   = database;
     this.cursors    = new PersistentDictionaryCursor <TKey, TValue> [MaxCachedCursors];
 }
Exemple #3
0
 /// <summary>
 /// Initializes a new instance of the PersistentDictionaryCursor class.
 /// </summary>
 /// <param name="instance">The instance to use.</param>
 /// <param name="database">The database to open.</param>
 /// <param name="converters">ESENT conversion functions.</param>
 /// <param name="config">The database meta-data config.</param>
 public PersistentDictionaryCursor(
     Instance instance,
     string database,
     PersistentDictionaryConverters <TKey, TValue> converters,
     IPersistentDictionaryConfig config)
 {
     this.instance   = instance;
     this.converters = converters;
     this.config     = config;
     this.database   = database;
     Api.JetBeginSession(this.instance, out this.sesid, String.Empty, String.Empty);
     this.AttachDatabase();
 }
        /// <summary>
        /// Initializes a new instance of the PersistentDictionary class.
        /// </summary>
        /// <param name="directory">
        /// The directory to create the database in.
        /// </param>
        public PersistentDictionary(string directory)
        {
            if (null == directory)
            {
                throw new ArgumentNullException("directory");
            }

            Globals.Init();
            this.converters        = new PersistentDictionaryConverters <TKey, TValue>();
            this.config            = new PersistentDictionaryConfig();
            this.databaseDirectory = directory;
            this.databasePath      = Path.Combine(directory, this.config.Database);

            this.updateLocks = new object[NumUpdateLocks];
            for (int i = 0; i < this.updateLocks.Length; ++i)
            {
                this.updateLocks[i] = new object();
            }

            this.instance = new Instance(Guid.NewGuid().ToString());
            this.instance.Parameters.SystemDirectory  = directory;
            this.instance.Parameters.LogFileDirectory = directory;
            this.instance.Parameters.TempDirectory    = directory;

            // If the database has been moved while inconsistent recovery
            // won't be able to find the database (logfiles contain the
            // absolute path of the referenced database). Set this parameter
            // to indicate a directory which contains any databases that couldn't
            // be found by recovery.
            this.instance.Parameters.AlternateDatabaseRecoveryDirectory = directory;

            this.instance.Parameters.CreatePathIfNotExist = true;
            this.instance.Parameters.BaseName             = this.config.BaseName;
            this.instance.Parameters.EnableIndexChecking  = false;      // TODO: fix unicode indexes
            this.instance.Parameters.CircularLog          = true;
            this.instance.Parameters.CheckpointDepthMax   = 64 * 1024 * 1024;
            this.instance.Parameters.LogFileSize          = 1024; // 1MB logs
            this.instance.Parameters.LogBuffers           = 1024; // buffers = 1/2 of logfile
            this.instance.Parameters.MaxTemporaryTables   = 0;
            this.instance.Parameters.MaxVerPages          = 1024;
            this.instance.Parameters.NoInformationEvent   = true;
            this.instance.Parameters.WaypointLatency      = 1;
            this.instance.Parameters.MaxSessions          = 256;
            this.instance.Parameters.MaxOpenTables        = 256;

            InitGrbit grbit = EsentVersion.SupportsWindows7Features
                                  ? Windows7Grbits.ReplayIgnoreLostLogs
                                  : InitGrbit.None;

            this.instance.Init(grbit);

            try
            {
                if (!File.Exists(this.databasePath))
                {
                    this.CreateDatabase(this.databasePath);
                }
                else
                {
                    this.CheckDatabaseMetaData(this.databasePath);
                }

                this.cursors = new PersistentDictionaryCursorCache <TKey, TValue>(
                    this.instance, this.databasePath, this.converters, this.config);
            }
            catch (Exception)
            {
                // We have failed to initialize for some reason. Terminate
                // the instance.
                this.instance.Term();
                throw;
            }
        }