Exemplo n.º 1
0
        public void Initialize(String host, String userId, String userPwd, String dbName)
        {
            if (_cancelTasks != null)
                throw new AegisException(AegisResult.AlreadyInitialized);


            //  Connection Test
            try
            {
                DBConnector dbc = new DBConnector();
                dbc.Connect(host, userId, userPwd, dbName);
                dbc.Close();
            }
            catch (Exception e)
            {
                throw new AegisException(AegisResult.MySqlConnectionFailed, e, "Invalid MySQL connection.");
            }


            HostAddress = host;
            UserId = userId;
            UserPwd = userPwd;
            DBName = dbName;


            _cancelTasks = new CancellationTokenSource();
        }
Exemplo n.º 2
0
        public void QueryNoReader()
        {
            if (_dbConnector != null || Reader != null)
                throw new AegisException(AegisResult.DataReaderNotClosed, "There is already an open DataReader associated with this Connection which must be closed first.");


            _dbConnector = _pool.GetDBC();
            _command.Connection = _dbConnector.Connection;
            _command.CommandText = CommandText.ToString();

            Prepare();
            _command.ExecuteNonQuery();
            _dbConnector.QPS.Add(1);
            EndQuery();
        }
Exemplo n.º 3
0
        public void IncreasePool(Int32 count)
        {
            while (count-- > 0)
            {
                DBConnector dbc = new DBConnector();
                dbc.Connect(HostAddress, UserId, UserPwd, DBName);


                using (_lock.WriterLock)
                {
                    _listPoolDBC.Add(dbc);
                }
            }
        }
Exemplo n.º 4
0
 internal void ReturnDBC(DBConnector dbc)
 {
     using (_lock.WriterLock)
     {
         _listActiveDBC.Remove(dbc);
         _listPoolDBC.Add(dbc);
     }
 }
Exemplo n.º 5
0
        internal DBConnector GetDBC()
        {
            DBConnector dbc;


            using (_lock.WriterLock)
            {
                if (_listPoolDBC.Count == 0)
                {
                    dbc = new DBConnector();
                    dbc.Connect(HostAddress, UserId, UserPwd, DBName);
                }
                else
                {
                    dbc = _listPoolDBC.ElementAt(0);
                    _listPoolDBC.RemoveAt(0);
                    _listActiveDBC.Add(dbc);
                }
            }

            return dbc;
        }
Exemplo n.º 6
0
        public void EndQuery()
        {
            CommandText.Clear();
            _prepareBindings.Clear();
            _command.Parameters.Clear();
            _command.Connection = null;

            if (Reader != null)
            {
                Reader.Dispose();
                Reader = null;
            }

            if (_dbConnector != null)
            {
                _pool.ReturnDBC(_dbConnector);
                _dbConnector = null;
            }
        }