Esempio n. 1
0
 public void Free(SdeConnection sdeConnection)
 {
     if (sdeConnection == null)
     {
         return;
     }
     lock (_thisLock)
     {
         if (_usedConnections.IndexOf(sdeConnection) != -1)
         {
             _usedConnections.Remove(sdeConnection);
             if (sdeConnection.Pooling == true)
             {
                 _freeConnections.Add(sdeConnection);
                 sdeConnection.LastUse = DateTime.Now;
             }
             else
             {
                 if (sdeConnection.SeConnection.handle != IntPtr.Zero)
                 {
                     CloseConnection(sdeConnection);
                 }
             }
         }
     }
 }
Esempio n. 2
0
 public SdeStream(SdeConnection connection)
 {
     if (connection.SeConnection.handle != IntPtr.Zero)
     {
         Wrapper10.SE_stream_create(connection.SeConnection, ref _stream);
     }
 }
Esempio n. 3
0
 public void Close()
 {
     if (_pool == null || _sdeConnection == null)
     {
         return;
     }
     _pool.Free(_sdeConnection);
     _sdeConnection = null;
 }
Esempio n. 4
0
 private void CloseConnection(SdeConnection sdeConnection)
 {
     //sdeConnection.FreeStream();
     if (sdeConnection.SeConnection.handle != IntPtr.Zero)
     {
         Wrapper10.SE_connection_free(sdeConnection.SeConnection);
         sdeConnection.SeConnection.handle = IntPtr.Zero;
     }
     sdeConnection.Dataset = null;
 }
Esempio n. 5
0
        private bool OpenConnection(SdeConnection sdeConnection, IDataset dataset)
        {
            _errMsg = "";

            if (sdeConnection.SeConnection.handle != IntPtr.Zero)
            {
                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");
            string pooling  = ConfigTextStream.ExtractValue(_connectionString, "pooling");

            if (!String.IsNullOrWhiteSpace(pooling) &&
                (pooling.ToLower() == "false" || pooling.ToLower() == "no"))
            {
                sdeConnection.Pooling = false;
            }
            else
            {
                sdeConnection.Pooling = true;
            }

            sdeConnection.Dataset = dataset;

            SE_ERROR error = new SE_ERROR();

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

            return(true);
        }
Esempio n. 6
0
        /*
         * public SE_STREAM SeStream
         * {
         *  get
         *  {
         *      if (_sdeConnection == null) return new SE_STREAM();
         *      return _sdeConnection.SeStream;
         *  }
         * }
         *
         *
         * public void ResetStream()
         * {
         *  if (_sdeConnection == null) return;
         *
         *  _sdeConnection.ResetStream();
         * }
         * */

        public bool Open(IDataset dataset)
        {
            _errMsg = "";
            _pool   = Globals.ConnectionManager[_connectionString];
            if (_pool == null)
            {
                return(true);
            }
            _sdeConnection = _pool.Alloc(dataset);
            _errMsg        = _pool.LastErrorMessage;

            return(_sdeConnection != null);
        }
Esempio n. 7
0
        public SdeConnection Alloc(IDataset dataset)
        {
            lock (_thisLock)
            {
                // Freie Connection suchen...
                foreach (SdeConnection seConnection in ListOperations <SdeConnection> .Clone(_freeConnections))
                {
                    if (seConnection.SeConnection.handle != IntPtr.Zero)
                    {
                        _freeConnections.Remove(seConnection);
                        _usedConnections.Add(seConnection);
                        seConnection.Dataset = dataset;
                        return(seConnection);
                    }
                }

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

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

                return(null);
            }
        }