Пример #1
0
 public void Close()
 {
     if (_pool == null || _sdeConnection == null)
     {
         return;
     }
     _pool.Free(_sdeConnection);
     _sdeConnection = null;
 }
Пример #2
0
 private void CloseConnection(SdeConnection sdeConnection)
 {
     sdeConnection.FreeStream();
     if (sdeConnection.SeConnection.handle != 0)
     {
         Wrapper92.SE_connection_free(sdeConnection.SeConnection);
         sdeConnection.SeConnection.handle = 0;
     }
 }
Пример #3
0
        public bool Open()
        {
            _errMsg = "";
            _pool   = Globals.ConnectionManager[_connectionString];
            if (_pool == null)
            {
                return(true);
            }
            _sdeConnection = _pool.Alloc();

            return(_sdeConnection != null);
        }
Пример #4
0
 public void Free(SdeConnection sdeConnection)
 {
     if (sdeConnection == null)
     {
         return;
     }
     lock (_thisLock)
     {
         if (_usedConnections.IndexOf(sdeConnection) != -1)
         {
             _usedConnections.Remove(sdeConnection);
             _freeConnections.Add(sdeConnection);
             sdeConnection.ResetStream();
             sdeConnection.LastUse = DateTime.Now;
         }
     }
 }
Пример #5
0
        public SdeConnection Alloc()
        {
            lock (_thisLock)
            {
                // Freie Connection suchen...
                foreach (SdeConnection SeConnection in ListOperations <SdeConnection> .Clone(_freeConnections))
                {
                    if (SeConnection.SeConnection.handle != 0)
                    {
                        _freeConnections.Remove(SeConnection);
                        _usedConnections.Add(SeConnection);
                        return(SeConnection);
                    }
                }

                // Freie Connection suchen, die bereits geschlossen wurde...
                foreach (SdeConnection SeConnection in ListOperations <SdeConnection> .Clone(_freeConnections))
                {
                    if (SeConnection.SeConnection.handle == 0)
                    {
                        if (OpenConnection(SeConnection))
                        {
                            _freeConnections.Remove(SeConnection);
                            _usedConnections.Add(SeConnection);
                            return(SeConnection);
                        }
                    }
                }

                // Neue Connection anlegen
                if (_usedConnections.Count + _freeConnections.Count < _maxConnections)
                {
                    SdeConnection SeConnection = new SdeConnection();
                    if (OpenConnection(SeConnection))
                    {
                        _usedConnections.Add(SeConnection);
                        return(SeConnection);
                    }
                }

                return(null);
            }
        }
Пример #6
0
        private bool OpenConnection(SdeConnection SdeConnection)
        {
            if (SdeConnection.SeConnection.handle != 0)
            {
                CloseConnection(SdeConnection);
            }

            string server   = ConfigTextStream.ExtractValue(_connectionString, "server");
            string instance = ConfigTextStream.ExtractValue(_connectionString, "instance");
            string database = ConfigTextStream.ExtractValue(_connectionString, "database");
            string username = ConfigTextStream.ExtractValue(_connectionString, "usr");
            string password = ConfigTextStream.ExtractValue(_connectionString, "pwd");

            SE_ERROR error = new SE_ERROR();

            try
            {
                if (Wrapper92.SE_connection_create(
                        server,
                        instance,
                        database,
                        username,
                        password,
                        ref error,
                        ref SdeConnection.SeConnection) != 0)
                {
                    _errMsg = Wrapper92.GetErrorMsg(SdeConnection.SeConnection, error);
                    return(false);
                }
            }
            catch (Exception ex)
            {
                _errMsg = "SDE ERROR: " + ex.Message;
                return(false);
            }

            return(true);
        }