コード例 #1
0
ファイル: SmppConnection.cs プロジェクト: raedayyad/sharp-sms
        public void BeginBind(SmppBindResHandler Callback, object State)
        {
            if ((_InternalConnection != null) && _InternalConnection.Connected)
            {
                throw new SmppException("Error Connecting: The connection is already Open.");
            }
            switch (_Settings.Recycling.Method)
            {
            case SmppSettings.RecyclingMethod.Pooling:
                _InternalConnection = SmppPoolManager.GetConnection(_Settings);
                break;

            case SmppSettings.RecyclingMethod.Sharing:
                _InternalConnection = SmppShareManager.GetConnection(_Settings);
                break;

            default:
                _InternalConnection = new SmppInternalConnection(_Settings);
                break;
            }
            SetEvents();
            if ((_InternalConnection.Connected && (_InternalConnection.LastBindRes != null)) &&
                ((_InternalConnection.LastBindRes.Header != null) &&
                 (_InternalConnection.LastBindRes.Header.CommandStatus == 0)))
            {
                Callback(this, new SmppAsyncBindResEventArgs(_InternalConnection.LastBindRes));
            }
            else
            {
                _InternalConnection.BeginBind(Callback, State);
            }
        }
コード例 #2
0
        SmppInternalConnection GetPooledConnection()
        {
            SmppInternalConnection connection = null;

            lock (idlePool.SyncRoot) {
                lock (inUsePool.SyncRoot) {
                    if ((idlePool.Count == 0) && (inUsePool.Count == _Settings.Recycling.MaxSize))
                    {
                        return(null);
                    }
                    if (idlePool.Count > 0)
                    {
                        int index = idlePool.Count - 1;
                        while (index >= 0)
                        {
                            connection = idlePool[index] as SmppInternalConnection;
                            inUsePool.Add(connection);
                            idlePool.RemoveAt(index);
                            return(connection);
                        }
                        return(connection);
                    }
                    connection = new SmppInternalConnection(_Settings);
                    inUsePool.Add(connection);
                    return(connection);
                }
            }
            return(connection);
        }
コード例 #3
0
ファイル: SmppConnection.cs プロジェクト: raedayyad/sharp-sms
        public SmppBindRes Bind()
        {
            if ((_InternalConnection != null) && _InternalConnection.Connected)
            {
                throw new SmppException("Error Connecting: The connection is already Open.");
            }
            switch (_Settings.Recycling.Method)
            {
            case SmppSettings.RecyclingMethod.Pooling:
                _InternalConnection = SmppPoolManager.GetConnection(_Settings);
                break;

            case SmppSettings.RecyclingMethod.Sharing:
                _InternalConnection = SmppShareManager.GetConnection(_Settings);
                break;

            default:
                _InternalConnection = new SmppInternalConnection(_Settings);
                break;
            }
            SetEvents();
            SmppBindRes res = null;

            if ((_InternalConnection.Connected && (_InternalConnection.LastBindRes != null)) &&
                ((_InternalConnection.LastBindRes.Header != null) &&
                 (_InternalConnection.LastBindRes.Header.CommandStatus == 0)))
            {
                return(_InternalConnection.LastBindRes);
            }
            res = _InternalConnection.Bind();
            _InternalConnection.LastBindRes = res;
            return(res);
        }
コード例 #4
0
ファイル: SmppShare.cs プロジェクト: pesaply/sharp-sms
 public SmppShare(SmppSettings Settings) {
   this.Settings = Settings;
   availablePool = new SmppInternalConnection[Settings.Recycling.MaxSize];
   for (int i = 0; i < availablePool.Length; i++)
     availablePool[i] = new SmppInternalConnection(Settings);
   tmCheckIdleConn.AutoReset = false;
   tmCheckIdleConn.Enabled = true;
   tmCheckIdleConn.Elapsed += tmCheckIdleConn_Elapsed;
 }
コード例 #5
0
ファイル: SmppPoolManager.cs プロジェクト: pesaply/sharp-sms
 internal static void ReleaseConnection(SmppInternalConnection connection) {
   SmppPool pool = null;
   lock (Pools.SyncRoot) {
     string connectionString = connection.Settings.ConnectionString;
     pool = (SmppPool) Pools[connectionString];
     if (pool == null)
       throw new SmppException("Pooling exception: Unable to find original pool for connection");
   }
   pool.ReleaseConnection(connection);
 }
コード例 #6
0
ファイル: SmppPool.cs プロジェクト: pesaply/sharp-sms
 public void ReleaseConnection(SmppInternalConnection connection) {
   if (connection != null)
     lock (idlePool.SyncRoot) {
       lock (inUsePool.SyncRoot) {
         connection.ReleasedDateTime = DateTime.Now;
         inUsePool.Remove(connection);
         idlePool.Add(connection);
       }
     }
 }
コード例 #7
0
 public SmppShare(SmppSettings Settings)
 {
     this.Settings = Settings;
     availablePool = new SmppInternalConnection[Settings.Recycling.MaxSize];
     for (int i = 0; i < availablePool.Length; i++)
     {
         availablePool[i] = new SmppInternalConnection(Settings);
     }
     tmCheckIdleConn.AutoReset = false;
     tmCheckIdleConn.Enabled   = true;
     tmCheckIdleConn.Elapsed  += tmCheckIdleConn_Elapsed;
 }
コード例 #8
0
 public void ReleaseConnection(SmppInternalConnection connection)
 {
     if (connection != null)
     {
         lock (idlePool.SyncRoot) {
             lock (inUsePool.SyncRoot) {
                 connection.ReleasedDateTime = DateTime.Now;
                 inUsePool.Remove(connection);
                 idlePool.Add(connection);
             }
         }
     }
 }
コード例 #9
0
        internal static void ReleaseConnection(SmppInternalConnection connection)
        {
            SmppPool pool = null;

            lock (Pools.SyncRoot) {
                string connectionString = connection.Settings.ConnectionString;
                pool = (SmppPool)Pools[connectionString];
                if (pool == null)
                {
                    throw new SmppException("Pooling exception: Unable to find original pool for connection");
                }
            }
            pool.ReleaseConnection(connection);
        }
コード例 #10
0
ファイル: SmppPool.cs プロジェクト: pesaply/sharp-sms
 public SmppPool(SmppSettings Settings) {
   _Settings = Settings;
   inUsePool = new ArrayList();
   idlePool = new ArrayList(Settings.Recycling.MinSize);
   lock (idlePool.SyncRoot) {
     lock (inUsePool.SyncRoot) {
       for (int i = 0; i < Settings.Recycling.MinSize; i++) {
         var connection = new SmppInternalConnection(Settings);
         idlePool.Add(connection);
       }
     }
   }
   tmCheckIdleConn.AutoReset = false;
   tmCheckIdleConn.Enabled = true;
   tmCheckIdleConn.Elapsed += tmCheckIdleConn_Elapsed;
 }
コード例 #11
0
 public SmppPool(SmppSettings Settings)
 {
     _Settings = Settings;
     inUsePool = new ArrayList();
     idlePool  = new ArrayList(Settings.Recycling.MinSize);
     lock (idlePool.SyncRoot) {
         lock (inUsePool.SyncRoot) {
             for (int i = 0; i < Settings.Recycling.MinSize; i++)
             {
                 var connection = new SmppInternalConnection(Settings);
                 idlePool.Add(connection);
             }
         }
     }
     tmCheckIdleConn.AutoReset = false;
     tmCheckIdleConn.Enabled   = true;
     tmCheckIdleConn.Elapsed  += tmCheckIdleConn_Elapsed;
 }
コード例 #12
0
        public SmppInternalConnection GetConnection()
        {
            SmppInternalConnection pooledConnection = null;
            int tickCount = Environment.TickCount;
            int timeout   = _Settings.Timeout;

            while ((pooledConnection == null) && ((Environment.TickCount - tickCount) < timeout))
            {
                pooledConnection = GetPooledConnection();
                if (pooledConnection == null)
                {
                    Thread.Sleep(new TimeSpan(0x2710L));
                }
            }
            if (pooledConnection == null)
            {
                throw new Exception(
                          "error connecting: Timeout expired.  The timeout period elapsed prior to obtaining a connection from the pool.  This may have occurred because all pooled connections were in use and max pool size was reached.");
            }
            return(pooledConnection);
        }
コード例 #13
0
ファイル: SmppPool.cs プロジェクト: pesaply/sharp-sms
 SmppInternalConnection GetPooledConnection() {
   SmppInternalConnection connection = null;
   lock (idlePool.SyncRoot) {
     lock (inUsePool.SyncRoot) {
       if ((idlePool.Count == 0) && (inUsePool.Count == _Settings.Recycling.MaxSize))
         return null;
       if (idlePool.Count > 0) {
         int index = idlePool.Count - 1;
         while (index >= 0) {
           connection = idlePool[index] as SmppInternalConnection;
           inUsePool.Add(connection);
           idlePool.RemoveAt(index);
           return connection;
         }
         return connection;
       }
       connection = new SmppInternalConnection(_Settings);
       inUsePool.Add(connection);
       return connection;
     }
   }
   return connection;
 }
コード例 #14
0
ファイル: SmppConnection.cs プロジェクト: pesaply/sharp-sms
    public void BeginBind(SmppBindResHandler Callback, object State) {
      if ((_InternalConnection != null) && _InternalConnection.Connected)
        throw new SmppException("Error Connecting: The connection is already Open.");
      switch (_Settings.Recycling.Method) {
        case SmppSettings.RecyclingMethod.Pooling:
          _InternalConnection = SmppPoolManager.GetConnection(_Settings);
          break;

        case SmppSettings.RecyclingMethod.Sharing:
          _InternalConnection = SmppShareManager.GetConnection(_Settings);
          break;

        default:
          _InternalConnection = new SmppInternalConnection(_Settings);
          break;
      }
      SetEvents();
      if ((_InternalConnection.Connected && (_InternalConnection.LastBindRes != null)) &&
          ((_InternalConnection.LastBindRes.Header != null) &&
           (_InternalConnection.LastBindRes.Header.CommandStatus == 0)))
        Callback(this, new SmppAsyncBindResEventArgs(_InternalConnection.LastBindRes));
      else
        _InternalConnection.BeginBind(Callback, State);
    }
コード例 #15
0
ファイル: SmppConnection.cs プロジェクト: pesaply/sharp-sms
    public SmppBindRes Bind() {
      if ((_InternalConnection != null) && _InternalConnection.Connected)
        throw new SmppException("Error Connecting: The connection is already Open.");
      switch (_Settings.Recycling.Method) {
        case SmppSettings.RecyclingMethod.Pooling:
          _InternalConnection = SmppPoolManager.GetConnection(_Settings);
          break;

        case SmppSettings.RecyclingMethod.Sharing:
          _InternalConnection = SmppShareManager.GetConnection(_Settings);
          break;

        default:
          _InternalConnection = new SmppInternalConnection(_Settings);
          break;
      }
      SetEvents();
      SmppBindRes res = null;
      if ((_InternalConnection.Connected && (_InternalConnection.LastBindRes != null)) &&
          ((_InternalConnection.LastBindRes.Header != null) &&
           (_InternalConnection.LastBindRes.Header.CommandStatus == 0)))
        return _InternalConnection.LastBindRes;
      res = _InternalConnection.Bind();
      _InternalConnection.LastBindRes = res;
      return res;
    }
コード例 #16
0
 void CheckOutConnection(SmppInternalConnection conn)
 {
 }
コード例 #17
0
ファイル: SmppPool.cs プロジェクト: pesaply/sharp-sms
 void CheckOutConnection(SmppInternalConnection conn) {}