private CachedSocket _socketList; // linked list

        internal CachedSocketList(TimeSpan socketLifetime, SocketCachePolicy socketCachePolicy)
        {
            _socketCount       = 0;
            _socketLifetime    = socketLifetime;
            _socketCachePolicy = socketCachePolicy;
            _socketList        = null;
        } // CachedSocketList
        } // ReceiveCallback



        //
        // Properties
        //
        public override Object this[Object key]
        {
            get
            {
                String keyStr = key as String;
                if (keyStr == null)
                    return null;

                switch (keyStr.ToLower(CultureInfo.InvariantCulture))
                {
                case UserNameKey: return _securityUserName;
                case PasswordKey: return null; // Intentionally refuse to return password.
                case DomainKey: return _securityDomain;
                case SocketCacheTimeoutKey: return _socketCacheTimeout;
                case ReceiveTimeoutKey: return _receiveTimeout;
                case SocketCachePolicyKey: return _socketCachePolicy.ToString();
                case RetryCountKey: return _retryCount;
                case ConnectionGroupNameKey: return _connectionGroupName;
                case ProtectionLevelKey: 
                    if (authSet)
                        return _protectionLevel.ToString();
                    break;
                } // switch (keyStr.ToLower(CultureInfo.InvariantCulture))

                return null;
            }

            set
            {
                String keyStr = key as String;
                if (keyStr == null)
                    return;

                switch (keyStr.ToLower(CultureInfo.InvariantCulture))
                {
                case UserNameKey: _securityUserName = (String)value; break;
                case PasswordKey: _securityPassword = (String)value; break;
                case DomainKey: _securityDomain = (String)value; break;
                case SocketCacheTimeoutKey: 
                                                int timeout = Convert.ToInt32(value, CultureInfo.InvariantCulture);
                                                if (timeout < 0)
                                                    throw new RemotingException(
                                                            CoreChannel.GetResourceString(
                                                            "Remoting_Tcp_SocketTimeoutNegative"));
                                                _socketCacheTimeout = TimeSpan.FromSeconds(timeout);
                                                ClientSocketCache.SocketTimeout = _socketCacheTimeout;
                                                break;
                case ReceiveTimeoutKey: 
                                                _receiveTimeout = Convert.ToInt32(value, CultureInfo.InvariantCulture);
                                                ClientSocketCache.ReceiveTimeout = _receiveTimeout;
                                                break;
                case SocketCachePolicyKey:  _socketCachePolicy = (SocketCachePolicy)(value is SocketCachePolicy ?  value :
                                                                                            Enum.Parse(typeof(SocketCachePolicy),
                                                                                                       (String)value, true));
                                                ClientSocketCache.CachePolicy = _socketCachePolicy;
                                                break;
                case RetryCountKey: _retryCount = Convert.ToInt32(value, CultureInfo.InvariantCulture); break;
                case ConnectionGroupNameKey: _connectionGroupName = (String)value; break;
                case ProtectionLevelKey: _protectionLevel = (ProtectionLevel)(value is ProtectionLevel ? value :
                                                                                         Enum.Parse(typeof(ProtectionLevel),
                                                                                         (String)value, true));
                                           authSet = true;                                              
                                          break;
                case SPNKey: _spn =  (String)value; authSet = true; break;
                } // switch (keyStr.ToLower(CultureInfo.InvariantCulturey))
            }
        } // this[]
 internal CachedSocketList(TimeSpan socketLifetime, SocketCachePolicy socketCachePolicy)
 {
     this._socketLifetime = socketLifetime;
     this._socketCachePolicy = socketCachePolicy;
     this._socketList = null;
 }
        public override object this[object key]
        {
            get
            {
                string str = key as string;
                if (str != null)
                {
                    switch (str.ToLower(CultureInfo.InvariantCulture))
                    {
                    case "username":
                        return(this._securityUserName);

                    case "password":
                        return(null);

                    case "domain":
                        return(this._securityDomain);

                    case "socketcachetimeout":
                        return(this._socketCacheTimeout);

                    case "timeout":
                        return(this._receiveTimeout);

                    case "socketcachepolicy":
                        return(this._socketCachePolicy.ToString());

                    case "retrycount":
                        return(this._retryCount);

                    case "connectiongroupname":
                        return(this._connectionGroupName);

                    case "tokenimpersonationlevel":
                        if (!this.authSet)
                        {
                            break;
                        }
                        return(this._tokenImpersonationLevel.ToString());

                    case "protectionlevel":
                        if (!this.authSet)
                        {
                            break;
                        }
                        return(this._protectionLevel.ToString());
                    }
                }
                return(null);
            }
            set
            {
                string str = key as string;
                if (str != null)
                {
                    switch (str.ToLower(CultureInfo.InvariantCulture))
                    {
                    case "username":
                        this._securityUserName = (string)value;
                        return;

                    case "password":
                        this._securityPassword = (string)value;
                        return;

                    case "domain":
                        this._securityDomain = (string)value;
                        return;

                    case "socketcachetimeout":
                    {
                        int num = Convert.ToInt32(value, CultureInfo.InvariantCulture);
                        if (num < 0)
                        {
                            throw new RemotingException(CoreChannel.GetResourceString("Remoting_Tcp_SocketTimeoutNegative"));
                        }
                        this._socketCacheTimeout             = TimeSpan.FromSeconds((double)num);
                        this.ClientSocketCache.SocketTimeout = this._socketCacheTimeout;
                        return;
                    }

                    case "timeout":
                        this._receiveTimeout = Convert.ToInt32(value, CultureInfo.InvariantCulture);
                        this.ClientSocketCache.ReceiveTimeout = this._receiveTimeout;
                        return;

                    case "socketcachepolicy":
                        this._socketCachePolicy            = (value is SocketCachePolicy) ? ((SocketCachePolicy)value) : ((SocketCachePolicy)System.Enum.Parse(typeof(SocketCachePolicy), (string)value, true));
                        this.ClientSocketCache.CachePolicy = this._socketCachePolicy;
                        return;

                    case "retrycount":
                        this._retryCount = Convert.ToInt32(value, CultureInfo.InvariantCulture);
                        return;

                    case "connectiongroupname":
                        this._connectionGroupName = (string)value;
                        return;

                    case "tokenimpersonationlevel":
                        this._tokenImpersonationLevel = (value is TokenImpersonationLevel) ? ((TokenImpersonationLevel)value) : ((TokenImpersonationLevel)System.Enum.Parse(typeof(TokenImpersonationLevel), (string)value, true));
                        this.authSet = true;
                        return;

                    case "protectionlevel":
                        this._protectionLevel = (value is ProtectionLevel) ? ((ProtectionLevel)value) : ((ProtectionLevel)System.Enum.Parse(typeof(ProtectionLevel), (string)value, true));
                        this.authSet          = true;
                        return;

                    case "serviceprincipalname":
                        this._spn    = (string)value;
                        this.authSet = true;
                        return;
                    }
                }
            }
        }
 internal SocketCache(SocketHandlerFactory handlerFactory, SocketCachePolicy socketCachePolicy, 
                                                                 TimeSpan socketTimeout)
 {
     _handlerFactory = handlerFactory;
     _socketCachePolicy = socketCachePolicy; 
     _socketTimeout = socketTimeout;
 } // SocketCache 
        private CachedSocket _socketList; // linked list
 
        internal CachedSocketList(TimeSpan socketLifetime, SocketCachePolicy socketCachePolicy)
        { 
            _socketCount = 0; 
            _socketLifetime = socketLifetime;
            _socketCachePolicy = socketCachePolicy; 
            _socketList = null;
        } // CachedSocketList
        } // ReceiveCallback

        //
        // Properties
        //
        public override Object this[Object key]
        {
            get
            {
                String keyStr = key as String;
                if (keyStr == null)
                {
                    return(null);
                }

                switch (keyStr.ToLower(CultureInfo.InvariantCulture))
                {
                case UserNameKey: return(_securityUserName);

                case PasswordKey: return(null); // Intentionally refuse to return password.

                case DomainKey: return(_securityDomain);

                case SocketCacheTimeoutKey: return(_socketCacheTimeout);

                case ReceiveTimeoutKey: return(_receiveTimeout);

                case SocketCachePolicyKey: return(_socketCachePolicy.ToString());

                case RetryCountKey: return(_retryCount);

                case ConnectionGroupNameKey: return(_connectionGroupName);

                case ProtectionLevelKey:
                    if (authSet)
                    {
                        return(_protectionLevel.ToString());
                    }
                    break;
                } // switch (keyStr.ToLower(CultureInfo.InvariantCulture))

                return(null);
            }

            set
            {
                String keyStr = key as String;
                if (keyStr == null)
                {
                    return;
                }

                switch (keyStr.ToLower(CultureInfo.InvariantCulture))
                {
                case UserNameKey: _securityUserName = (String)value; break;

                case PasswordKey: _securityPassword = (String)value; break;

                case DomainKey: _securityDomain = (String)value; break;

                case SocketCacheTimeoutKey:
                    int timeout = Convert.ToInt32(value, CultureInfo.InvariantCulture);
                    if (timeout < 0)
                    {
                        throw new RemotingException(
                                  CoreChannel.GetResourceString(
                                      "Remoting_Tcp_SocketTimeoutNegative"));
                    }
                    _socketCacheTimeout             = TimeSpan.FromSeconds(timeout);
                    ClientSocketCache.SocketTimeout = _socketCacheTimeout;
                    break;

                case ReceiveTimeoutKey:
                    _receiveTimeout = Convert.ToInt32(value, CultureInfo.InvariantCulture);
                    ClientSocketCache.ReceiveTimeout = _receiveTimeout;
                    break;

                case SocketCachePolicyKey:  _socketCachePolicy = (SocketCachePolicy)(value is SocketCachePolicy ?  value :
                                                                                     Enum.Parse(typeof(SocketCachePolicy),
                                                                                                (String)value, true));
                    ClientSocketCache.CachePolicy = _socketCachePolicy;
                    break;

                case RetryCountKey: _retryCount = Convert.ToInt32(value, CultureInfo.InvariantCulture); break;

                case ConnectionGroupNameKey: _connectionGroupName = (String)value; break;

                case ProtectionLevelKey: _protectionLevel = (ProtectionLevel)(value is ProtectionLevel ? value :
                                                                              Enum.Parse(typeof(ProtectionLevel),
                                                                                         (String)value, true));
                    authSet = true;
                    break;

                case SPNKey: _spn = (String)value; authSet = true; break;
                } // switch (keyStr.ToLower(CultureInfo.InvariantCulturey))
            }
        }         // this[]
        public override object this[object key]
        {
            get
            {
                string str = key as string;
                if (str != null)
                {
                    switch (str.ToLower(CultureInfo.InvariantCulture))
                    {
                        case "username":
                            return this._securityUserName;

                        case "password":
                            return null;

                        case "domain":
                            return this._securityDomain;

                        case "socketcachetimeout":
                            return this._socketCacheTimeout;

                        case "timeout":
                            return this._receiveTimeout;

                        case "socketcachepolicy":
                            return this._socketCachePolicy.ToString();

                        case "retrycount":
                            return this._retryCount;

                        case "connectiongroupname":
                            return this._connectionGroupName;

                        case "tokenimpersonationlevel":
                            if (!this.authSet)
                            {
                                break;
                            }
                            return this._tokenImpersonationLevel.ToString();

                        case "protectionlevel":
                            if (!this.authSet)
                            {
                                break;
                            }
                            return this._protectionLevel.ToString();
                    }
                }
                return null;
            }
            set
            {
                string str = key as string;
                if (str != null)
                {
                    switch (str.ToLower(CultureInfo.InvariantCulture))
                    {
                        case "username":
                            this._securityUserName = (string) value;
                            return;

                        case "password":
                            this._securityPassword = (string) value;
                            return;

                        case "domain":
                            this._securityDomain = (string) value;
                            return;

                        case "socketcachetimeout":
                        {
                            int num = Convert.ToInt32(value, CultureInfo.InvariantCulture);
                            if (num < 0)
                            {
                                throw new RemotingException(CoreChannel.GetResourceString("Remoting_Tcp_SocketTimeoutNegative"));
                            }
                            this._socketCacheTimeout = TimeSpan.FromSeconds((double) num);
                            this.ClientSocketCache.SocketTimeout = this._socketCacheTimeout;
                            return;
                        }
                        case "timeout":
                            this._receiveTimeout = Convert.ToInt32(value, CultureInfo.InvariantCulture);
                            this.ClientSocketCache.ReceiveTimeout = this._receiveTimeout;
                            return;

                        case "socketcachepolicy":
                            this._socketCachePolicy = (value is SocketCachePolicy) ? ((SocketCachePolicy) value) : ((SocketCachePolicy) System.Enum.Parse(typeof(SocketCachePolicy), (string) value, true));
                            this.ClientSocketCache.CachePolicy = this._socketCachePolicy;
                            return;

                        case "retrycount":
                            this._retryCount = Convert.ToInt32(value, CultureInfo.InvariantCulture);
                            return;

                        case "connectiongroupname":
                            this._connectionGroupName = (string) value;
                            return;

                        case "tokenimpersonationlevel":
                            this._tokenImpersonationLevel = (value is TokenImpersonationLevel) ? ((TokenImpersonationLevel) value) : ((TokenImpersonationLevel) System.Enum.Parse(typeof(TokenImpersonationLevel), (string) value, true));
                            this.authSet = true;
                            return;

                        case "protectionlevel":
                            this._protectionLevel = (value is ProtectionLevel) ? ((ProtectionLevel) value) : ((ProtectionLevel) System.Enum.Parse(typeof(ProtectionLevel), (string) value, true));
                            this.authSet = true;
                            return;

                        case "serviceprincipalname":
                            this._spn = (string) value;
                            this.authSet = true;
                            return;
                    }
                }
            }
        }
示例#9
0
 internal SocketCache(SocketHandlerFactory handlerFactory, SocketCachePolicy socketCachePolicy, TimeSpan socketTimeout)
 {
     this._handlerFactory    = handlerFactory;
     this._socketCachePolicy = socketCachePolicy;
     this._socketTimeout     = socketTimeout;
 }