예제 #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ColumnAccessor" /> class.
 /// </summary>
 /// <param name="cursor">The cursor.</param>
 /// <param name="isamSession">The session.</param>
 /// <param name="tableid">The tableid.</param>
 /// <param name="grbit">The grbit.</param>
 internal ColumnAccessor(Cursor cursor, IsamSession isamSession, JET_TABLEID tableid, RetrieveColumnGrbit grbit)
 {
     this.cursor      = cursor;
     this.isamSession = isamSession;
     this.tableid     = tableid;
     this.grbit       = grbit;
 }
예제 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ColumnAccessor" /> class.
 /// </summary>
 /// <param name="cursor">The cursor.</param>
 /// <param name="isamSession">The session.</param>
 /// <param name="tableid">The tableid.</param>
 /// <param name="grbit">The grbit.</param>
 internal ColumnAccessor(Cursor cursor, IsamSession isamSession, JET_TABLEID tableid, RetrieveColumnGrbit grbit)
 {
     this.cursor = cursor;
     this.isamSession = isamSession;
     this.tableid = tableid;
     this.grbit = grbit;
 }
예제 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DatabaseCommon"/> class.
 /// </summary>
 /// <param name="isamSession">The session.</param>
 internal DatabaseCommon(IsamSession isamSession)
 {
     lock (isamSession)
     {
         this.isamSession = isamSession;
         this.cleanup     = true;
     }
 }
예제 #4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="dbPath">dbFilePath must point to the DIT file on the local computer.</param>
 /// <param name="logPath">The path should point to a writeable folder on the local computer, where ESE log files will be created. If not specified, then temp folder will be used.</param>
 public DirectoryContext(string dbFilePath, bool readOnly, string logDirectoryPath = null)
 {
     if (!File.Exists(dbFilePath))
     {
         // TODO: Extract as resource
         throw new FileNotFoundException("The specified database file does not exist.", dbFilePath);
     }
     int pageSize = DirectoryContext.GetDBPageSize(dbFilePath);
     string dbDirectoryPath = Path.GetDirectoryName(dbFilePath);
     string checkpointDirectoryPath = dbDirectoryPath;
     string tempDirectoryPath = dbDirectoryPath;
     if (logDirectoryPath != null)
     {
         if (!Directory.Exists(logDirectoryPath))
         {
             // TODO: Extract as resource
             throw new FileNotFoundException("The specified log directory does not exist.", logDirectoryPath);
         }
     }
     else
     {
         logDirectoryPath = dbDirectoryPath;
     }
     // TODO: Exception handling?
     // HACK: IsamInstance constructor throws AccessDenied Exception when the path does not end with a backslash.
     // TODO: Const isam instance name
     string instanceName = "DSInternals";
     this.instance = new IsamInstance(AddPathSeparator(checkpointDirectoryPath), AddPathSeparator(logDirectoryPath), AddPathSeparator(tempDirectoryPath), ADConstants.EseBaseName, instanceName, readOnly, pageSize);
     try
     {
         var isamParameters = this.instance.IsamSystemParameters;
         // TODO: Add param explanations
         isamParameters.LogFileSize = ADConstants.EseLogFileSize;
         isamParameters.DeleteOutOfRangeLogs = true;
         isamParameters.EnableIndexChecking = 1;
         isamParameters.EnableIndexCleanup = true;
         isamParameters.CircularLog = true;
         // TODO: Configure additional ISAM parameters
         // this.instance.IsamSystemParameters.EnableOnlineDefrag = false;
         // JET_paramDeleteOldLogs =  1
         this.session = this.instance.CreateSession();
         this.session.AttachDatabase(dbFilePath);
         this.attachedDatabasePath = dbFilePath;
         this.database = this.session.OpenDatabase(dbFilePath);
         this.Schema = new DirectorySchema(this.database);
         this.SecurityDescriptorRersolver = new SecurityDescriptorRersolver(this.database);
         this.DistinguishedNameResolver = new DistinguishedNameResolver(this.database, this.Schema);
         this.LinkResolver = new LinkResolver(this.database, this.Schema);
         this.DomainController = new DomainController(this);
     }
     catch
     {
         // Free resources if anything failed
         this.Dispose();
         throw;
     }
 }
예제 #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="IsamDatabase"/> class.
 /// </summary>
 /// <param name="isamSession">The session.</param>
 /// <param name="databaseName">Name of the database.</param>
 internal IsamDatabase(IsamSession isamSession, string databaseName)
     : base(isamSession)
 {
     lock (isamSession)
     {
         Api.JetOpenDatabase(isamSession.Sesid, databaseName, null, out this.dbid, OpenDatabaseGrbit.None);
         this.cleanup         = true;
         this.tableCollection = new TableCollection(this);
     }
 }
예제 #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="IsamDatabase"/> class.
 /// </summary>
 /// <param name="isamSession">The session.</param>
 /// <param name="databaseName">Name of the database.</param>
 internal IsamDatabase(IsamSession isamSession, string databaseName)
     : base(isamSession)
 {
     lock (isamSession)
     {
         Api.JetOpenDatabase(isamSession.Sesid, databaseName, null, out this.dbid, OpenDatabaseGrbit.None);
         this.cleanup = true;
         this.tableCollection = new TableCollection(this);
     }
 }
예제 #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TemporaryDatabase"/> class.
 /// </summary>
 /// <param name="isamSession">The session.</param>
 internal TemporaryDatabase(IsamSession isamSession)
     : base(isamSession)
 {
     lock (isamSession)
     {
         this.cleanup                   = true;
         this.tableCollection           = new TableCollection();
         this.tempTableHandleCollection = new TempTableHandleCollection(false);
     }
 }
예제 #8
0
 /// <summary>
 /// Checks the engine version.
 /// </summary>
 /// <param name="isamSession">The session.</param>
 /// <param name="versionESENT">The version esent.</param>
 /// <param name="versionESE">The version ese.</param>
 /// <param name="e">The e.</param>
 internal static void CheckEngineVersion(
     IsamSession isamSession,
     long versionESENT,
     long versionESE,
     System.Exception e)
 {
     if (!CheckEngineVersion(isamSession, versionESENT, versionESE))
     {
         throw e;
     }
 }
예제 #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="IsamTransaction"/> class. 
 /// Begin a transaction on the given session.
 /// </summary>
 /// <param name="isamSession">
 /// The session we will use for the transaction.
 /// </param>
 /// <remarks>
 /// If this transaction is not committed before this object is disposed
 /// then the transaction will automatically be aborted.
 /// </remarks>
 public IsamTransaction(IsamSession isamSession)
 {
     lock (isamSession)
     {
         this.isamSession = isamSession;
         this.isamSession.BeginTransaction();
         this.transactionLevel = isamSession.TransactionLevel;
         this.transactionLevelID = isamSession.TransactionLevelID(isamSession.TransactionLevel);
         this.cleanup = true;
     }
 }
예제 #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="IsamTransaction"/> class.
 /// Begin a transaction on the given session.
 /// </summary>
 /// <param name="isamSession">
 /// The session we will use for the transaction.
 /// </param>
 /// <remarks>
 /// If this transaction is not committed before this object is disposed
 /// then the transaction will automatically be aborted.
 /// </remarks>
 public IsamTransaction(IsamSession isamSession)
 {
     lock (isamSession)
     {
         this.isamSession = isamSession;
         this.isamSession.BeginTransaction();
         this.transactionLevel   = isamSession.TransactionLevel;
         this.transactionLevelID = isamSession.TransactionLevelID(isamSession.TransactionLevel);
         this.cleanup            = true;
     }
 }
예제 #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="IsamTransaction"/> class.
 /// Joins the current transaction on the given session.  If the session
 /// is not currently in a transaction then a new transaction will be
 /// begun.
 /// </summary>
 /// <param name="isamSession">
 /// The session we will use for the transaction.
 /// </param>
 /// <param name="join">
 /// If true, the current transaction on the session will be joined.  If false or if there is no current transaction then a new transaction will be begun.
 /// </param>
 /// <remarks>
 /// If an existing transaction is joined, then committing or aborting
 /// this transaction will have no effect on the joined transaction.  If
 /// a new transaction was begun then these actions will work normally.
 /// <para>
 /// If this transaction is not committed before this object is disposed
 /// then the transaction will automatically be aborted.
 /// </para>
 /// </remarks>
 public IsamTransaction(IsamSession isamSession, bool join)
 {
     lock (isamSession)
     {
         this.isamSession = isamSession;
         if (!join || isamSession.TransactionLevel == 0)
         {
             this.isamSession.BeginTransaction();
             this.transactionLevel   = isamSession.TransactionLevel;
             this.transactionLevelID = isamSession.TransactionLevelID(isamSession.TransactionLevel);
             this.cleanup            = true;
         }
     }
 }
예제 #12
0
        /// <summary>
        /// Checks the engine version.
        /// </summary>
        /// <param name="isamSession">The session.</param>
        /// <param name="versionESENT">The minimum ESENT version required.</param>
        /// <param name="versionESE">The minimum ESE version required.</param>
        /// <returns>Whether the current engine is greater than or equal to the required version.</returns>
        internal static bool CheckEngineVersion(
            IsamSession isamSession,
            long versionESENT,
            long versionESE)
        {
#if (ESENT)
            long version = versionESENT;
#else
            long version = versionESE;
#endif

            uint engineVersion;
            Api.JetGetVersion(isamSession.Sesid, out engineVersion);
            return(engineVersion >= version);
        }
예제 #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="IsamTransaction"/> class. 
 /// Joins the current transaction on the given session.  If the session
 /// is not currently in a transaction then a new transaction will be
 /// begun.
 /// </summary>
 /// <param name="isamSession">
 /// The session we will use for the transaction.
 /// </param>
 /// <param name="join">
 /// If true, the current transaction on the session will be joined.  If false or if there is no current transaction then a new transaction will be begun.
 /// </param>
 /// <remarks>
 /// If an existing transaction is joined, then committing or aborting
 /// this transaction will have no effect on the joined transaction.  If
 /// a new transaction was begun then these actions will work normally.
 /// <para>
 /// If this transaction is not committed before this object is disposed
 /// then the transaction will automatically be aborted.
 /// </para>
 /// </remarks>
 public IsamTransaction(IsamSession isamSession, bool join)
 {
     lock (isamSession)
     {
         this.isamSession = isamSession;
         if (!join || isamSession.TransactionLevel == 0)
         {
             this.isamSession.BeginTransaction();
             this.transactionLevel = isamSession.TransactionLevel;
             this.transactionLevelID = isamSession.TransactionLevelID(isamSession.TransactionLevel);
             this.cleanup = true;
         }
     }
 }
예제 #14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Cursor"/> class.
        /// </summary>
        /// <param name="isamSession">The session.</param>
        /// <param name="database">The database.</param>
        /// <param name="tableName">Name of the table.</param>
        /// <param name="tableid">The tableid.</param>
        /// <param name="inInsertMode">if set to <c>true</c> [in insert mode].</param>
        internal Cursor(
            IsamSession isamSession,
            TemporaryDatabase database,
            string tableName,
            JET_TABLEID tableid,
            bool inInsertMode)
        {
            lock (isamSession)
            {
                this.isamSession = isamSession;
                this.database = database;
                this.tableName = tableName;
                this.tableid = tableid;
                this.cleanup = true;
                this.record = new ColumnAccessor(this, isamSession, tableid, RetrieveColumnGrbit.None);
                this.editRecord = new ColumnAccessor(this, isamSession, tableid, RetrieveColumnGrbit.RetrieveCopy);
                this.indexRecord = new ColumnAccessor(this, isamSession, tableid, RetrieveColumnGrbit.RetrieveFromIndex);
                this.isSort = database.Tables[tableName].Type == TableType.Sort;
                this.isSortOrPreSort = database.Tables[tableName].Type == TableType.Sort
                                       || database.Tables[tableName].Type == TableType.PreSortTemporary;
                this.isTempTable = database.Tables[tableName].Type == TableType.Sort
                                   || database.Tables[tableName].Type == TableType.PreSortTemporary
                                   || database.Tables[tableName].Type == TableType.Temporary;
                this.inInsertMode = this.isSortOrPreSort && inInsertMode;
                this.inRetrieveMode = this.isSort && !inInsertMode;
                this.onBeforeFirst = this.isSort && !inInsertMode;

                if (!(this.isSort || (this.isSortOrPreSort && inInsertMode)))
                {
                    this.MoveBeforeFirst();
                }
            }
        }
예제 #15
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Cursor"/> class.
        /// </summary>
        /// <param name="isamSession">The session.</param>
        /// <param name="database">The database.</param>
        /// <param name="tableName">Name of the table.</param>
        /// <param name="grbit">The grbit.</param>
        internal Cursor(IsamSession isamSession, IsamDatabase database, string tableName, OpenTableGrbit grbit)
        {
            lock (isamSession)
            {
                this.isamSession = isamSession;
                this.database = database;
                this.tableName = tableName;
                Api.JetOpenTable(isamSession.Sesid, database.Dbid, tableName, null, 0, grbit, out this.tableid);
                this.cleanup = true;
                this.record = new ColumnAccessor(this, isamSession, this.tableid, RetrieveColumnGrbit.None);
                this.editRecord = new ColumnAccessor(this, isamSession, this.tableid, RetrieveColumnGrbit.RetrieveCopy);
                this.indexRecord = new ColumnAccessor(this, isamSession, this.tableid, RetrieveColumnGrbit.RetrieveFromIndex);

                this.MoveBeforeFirst();
            }
        }
예제 #16
0
 protected virtual void Dispose(bool disposing)
 {
     if (!disposing)
     {
         // Do nothing
         return;
     }
     if(this.LinkResolver != null)
     {
         this.LinkResolver.Dispose();
         this.LinkResolver = null;
     }
     if (this.SecurityDescriptorRersolver != null)
     {
         this.SecurityDescriptorRersolver.Dispose();
         this.SecurityDescriptorRersolver = null;
     }
     if (this.DistinguishedNameResolver != null)
     {
         this.DistinguishedNameResolver.Dispose();
         this.DistinguishedNameResolver = null;
     }
     if (this.DomainController != null)
     {
         this.DomainController.Dispose();
         this.DomainController = null;
     }
     if (this.database != null)
     {
         this.database.Dispose();
         this.database = null;
     }
     if (this.session != null)
     {
         if (this.attachedDatabasePath != null)
         {
             this.session.DetachDatabase(this.attachedDatabasePath);
             this.attachedDatabasePath = null;
         }
         this.session.Dispose();
         this.session = null;
     }
     if (this.instance != null)
     {
         this.instance.Dispose();
         this.instance = null;
     }
 }