/// <summary>
 /// Closes the connection to the database. This is the preferred method of closing any open connection.
 /// </summary>
 public override void Close()
 {
     _session      = null;
     _loginInfoObj = null;
     _clientx      = null;
     _client       = null;
     state         = ConnectionState.Closed;
 }
        /// <summary>
        /// Releases the unmanaged resources used by the <see cref="T:System.ComponentModel.Component" /> and optionally releases the managed resources.
        /// </summary>
        /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
        protected override void Dispose(bool disposing)
        {
            //File.AppendAllText("DqlConnect.log", sessionId + " Dispose\r\n");
            base.Dispose(disposing);

            if (disposing)
            {
                this._client       = null;
                this._clientx      = null;
                this._session      = null;
                this._loginInfoObj = null;
                state = ConnectionState.Closed;
                //   FreeDllsNow(0);
                GC.Collect();
                // GC.WaitForPendingFinalizers();
            }
        }
        /// <summary>
        /// AUTHOR: Ashok Kolwal
        /// COMPANY: VITRANA
        /// Version: 1.0
        /// Description: This method is used for get the session variable based on documentum server info.
        /// Last Modified date: 11 Jul,2017
        /// </summary>
        /// <param name="sessionVariableObject"></param>
        /// <returns></returns>
        public object GetSessionManager(GetSessionEntity sessionVariableObject)
        {
            object sessionVariable = null;

            try
            {
                IDfClientX clientX = new DfClientX();
                // Console.WriteLine("[GetSessionManager] IDfClientX instance created");
                IDfClient client = clientX.getLocalClient();
                // Console.WriteLine("[GetSessionManager] IDfClient instance created");
                IDfSessionManager sMgr = client.newSessionManager();
                // Console.WriteLine("[GetSessionManager] IDfSessionManager instance created");
                IDfLoginInfo loginInfo = clientX.getLoginInfo();
                // Console.WriteLine("[GetSessionManager] IDfLoginInfo instance created");
                loginInfo.setUser(sessionVariableObject.UserName);
                loginInfo.setPassword(sessionVariableObject.Password);
                loginInfo.setDomain("");
                sMgr.setIdentity(sessionVariableObject.RepositoryName, loginInfo);
                // Console.WriteLine("[GetSessionManager] LoginInfo identity is set");
                IDfSession session = sMgr.getSession(sessionVariableObject.RepositoryName);
                // Console.WriteLine("[GetSessionManager] IDfSession instance created");
                switch (sessionVariableObject.SessionVariableType)
                {
                case IDFSessionVariableType.IDfSession:
                    sessionVariable = session;
                    break;

                case IDFSessionVariableType.IDfSessionManager:
                    sessionVariable = sMgr;
                    break;
                }
                ;
            }
            catch (Exception ex)
            {
                throw new Exception("Error in [GetSessionManager] ", ex);
            }

            return(sessionVariable);
        }
        /// <summary>
        /// Opens a database connection with the settings specified by the <see cref="P:System.Data.Common.DbConnection.ConnectionString" />.
        /// </summary>
        /// <exception cref="System.Exception">Failed conecting to Documentum</exception>
        public override void Open()
        {
            if (state == ConnectionState.Open || state == ConnectionState.Connecting)
            {
                return;
            }

            state = ConnectionState.Connecting;

            if (builder == null)
            {
                builder = new DqlConnectionStringBuilder();
                builder.ConnectionString = this.ConnectionString;
            }

            _loginInfoObj = _clientx.getLoginInfo();
            _loginInfoObj.setUser(builder.UserId);
            _loginInfoObj.setPassword(builder.Password);
            //File.AppendAllText("DqlConnect.log", sessionId + " login success\r\n");

            try
            {
                // Create a new session to the requested DocBase
                _session = _client.newSession(builder.Repository, _loginInfoObj);
                if (_session == null && !_session.isConnected())
                {
                    state = ConnectionState.Closed;
                    throw new DqlSessionException("Failed conecting to Documentum");
                }
                state = ConnectionState.Open;
            }
            catch (Exception ex)
            {
                state = ConnectionState.Closed;
                throw new DqlSessionException("Unable to create session. Make sure the repository is available.\r\n" + connectionString, ex);
            }
        }