예제 #1
0
        public static ConnectionState FromInternal(InternalConnectionState internalState,
                                                   ConnectionState currentState)
        {
            switch (internalState)
            {
            case InternalConnectionState.New:
                return(ConnectionState.New);

            case InternalConnectionState.Success:
                return(ConnectionState.Success);

            case InternalConnectionState.FailedTry:
                return(ConnectionState.FailedTry);

            case InternalConnectionState.VersionMatch:
                return(currentState);

            case InternalConnectionState.VersionMissmatch:
                return(ConnectionState.VersionMissmatch);

            case InternalConnectionState.ConnectionLost:
                return(ConnectionState.ConnectionLost);

            case InternalConnectionState.Closing:
                return(ConnectionState.Closing);

            case InternalConnectionState.Closed:
                return(ConnectionState.Closed);

            default:
                throw new ArgumentException(string.Format("Can't convert unknown state '{0}'", internalState),
                                            "internalState");
            }
        }
예제 #2
0
 private void SetState(InternalConnectionState newState)
 {
     lock (_stateMutex)
     {
         if (_state == InternalConnectionState.Broken)
         {
             throw new ArgumentException("Cannot change internal connection state as it is Broken");
         }
         _state = newState;
     }
 }
예제 #3
0
        private bool TrySetState(InternalConnectionState newState, Func <InternalConnectionState, bool> predicate)
        {
            lock (_stateMutex)
            {
                if (_state == InternalConnectionState.Broken || !predicate(_state))
                {
                    return(false);
                }

                _state = newState;
                return(true);
            }
        }
        /// <summary>
        /// Sets the state of the <see cref="WcfClientInfo"/> and increases the tries
        /// </summary>
        private void SetClientInfoState(WcfClientInfo clientInfo, InternalConnectionState internalState)
        {
            var newState = StateTransformer.FromInternal(internalState, clientInfo.State);

            if (clientInfo.State == newState)
            {
                clientInfo.Tries++;
            }
            else
            {
                clientInfo.State = newState;
                clientInfo.Tries = 1;
            }

            RaiseClientInfoChanged(clientInfo);
        }
예제 #5
0
        private void SetState(InternalConnectionState newState)
        {
            lock (_stateMutex)
            {
                //if the connection's state is broken, it can't get any more broken!
                if (_state == newState)
                {
                    return;
                }

                if (_state == InternalConnectionState.Broken)
                {
                    throw new ArgumentException("Cannot change internal connection state as it is Broken");
                }
                _state = newState;
            }
        }
        /// <summary>
        /// Handles the state of the connection.
        /// </summary>
        private void HandleConnectionState(MonitoredClient client, InternalConnectionState newState)
        {
            var oldState = client.State;

            client.State = newState;
            SetClientInfoState(client.ClientInfo, newState);

            // Only report state changes if the state has changed
            if (newState == oldState)
            {
                return;
            }

            if ((oldState == InternalConnectionState.New && newState == InternalConnectionState.FailedTry) ||
                (newState == InternalConnectionState.ConnectionLost) || (newState == InternalConnectionState.Closed))
            {
                RaiseClientDisconnected(client.ServiceName);
            }

            if (!client.Destroy)
            {
                _threadContext.Invoke(() => InvokeCreateClient(client));
            }
        }