コード例 #1
0
        private ConnectionModeReader SetupModeReader(IConnection connection, bool isCached)
        {
            ConnectionModeReader reader;

            if (isCached)
            {
                if (this.onCachedConnectionModeKnown == null)
                {
                    this.onCachedConnectionModeKnown = new ConnectionModeCallback(this.OnCachedConnectionModeKnown);
                }
                reader = new ConnectionModeReader(connection, this.onCachedConnectionModeKnown, this.onConnectionClosed);
            }
            else
            {
                if (this.onConnectionModeKnown == null)
                {
                    this.onConnectionModeKnown = new ConnectionModeCallback(this.OnConnectionModeKnown);
                }
                reader = new ConnectionModeReader(connection, this.onConnectionModeKnown, this.onConnectionClosed);
            }
            lock (this.ThisLock)
            {
                if (this.isDisposed)
                {
                    reader.Dispose();
                    return(null);
                }
                this.connectionReaders.Add(reader);
                return(reader);
            }
        }
コード例 #2
0
        ConnectionModeReader SetupModeReader(IConnection connection, bool isCached)
        {
            ConnectionModeReader modeReader;

            if (isCached)
            {
                if (onCachedConnectionModeKnown == null)
                {
                    onCachedConnectionModeKnown = new ConnectionModeCallback(OnCachedConnectionModeKnown);
                }

                modeReader = new ConnectionModeReader(connection, onCachedConnectionModeKnown, onConnectionClosed);
            }
            else
            {
                if (onConnectionModeKnown == null)
                {
                    onConnectionModeKnown = new ConnectionModeCallback(OnConnectionModeKnown);
                }

                modeReader = new ConnectionModeReader(connection, onConnectionModeKnown, onConnectionClosed);
            }

            lock (ThisLock)
            {
                if (isDisposed)
                {
                    modeReader.Dispose();
                    return(null);
                }

                connectionReaders.Add(modeReader);
                return(modeReader);
            }
        }
コード例 #3
0
        static void ReadCallback(object state)
        {
            ConnectionModeReader reader   = (ConnectionModeReader)state;
            bool      completeSelf        = false;
            Exception completionException = null;

            try
            {
                if (reader.GetReadResult())
                {
                    completeSelf = reader.ContinueReading();
                }
            }
#pragma warning suppress 56500 // Microsoft, transferring exception to caller
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }

                completeSelf        = true;
                completionException = e;
            }

            if (completeSelf)
            {
                reader.Complete(completionException);
            }
        }
コード例 #4
0
        private static void ReadCallback(object state)
        {
            ConnectionModeReader reader = (ConnectionModeReader)state;
            bool      flag = false;
            Exception e    = null;

            try
            {
                if (reader.GetReadResult())
                {
                    flag = reader.ContinueReading();
                }
            }
            catch (Exception exception2)
            {
                if (Fx.IsFatal(exception2))
                {
                    throw;
                }
                flag = true;
                e    = exception2;
            }
            if (flag)
            {
                reader.Complete(e);
            }
        }
コード例 #5
0
        private void OnConnectionAvailable(IConnection connection, Action connectionDequeuedCallback)
        {
            ConnectionModeReader reader = this.SetupModeReader(connection, false);

            if (reader != null)
            {
                reader.StartReading(this.channelInitializationTimeout, connectionDequeuedCallback);
            }
            else
            {
                connectionDequeuedCallback();
            }
        }
コード例 #6
0
        public void ReuseConnection(IConnection connection, TimeSpan closeTimeout)
        {
            connection.ExceptionEventType = TraceEventType.Information;
            ConnectionModeReader modeReader = this.SetupModeReader(connection, true);

            if (modeReader != null)
            {
                if (this.reuseConnectionCallback == null)
                {
                    this.reuseConnectionCallback = new Action <object>(this.ReuseConnectionCallback);
                }
                ActionItem.Schedule(this.reuseConnectionCallback, new ReuseConnectionState(modeReader, closeTimeout));
            }
        }
コード例 #7
0
        void OnConnectionAvailable(IConnection connection, Action connectionDequeuedCallback)
        {
            ConnectionModeReader modeReader = SetupModeReader(connection, false);

            if (modeReader != null)
            {
                // StartReading() will never throw non-fatal exceptions;
                // it propagates all exceptions into the onConnectionModeKnown callback,
                // which is where we need our robust handling
                modeReader.StartReading(this.channelInitializationTimeout, connectionDequeuedCallback);
            }
            else
            {
                connectionDequeuedCallback();
            }
        }
コード例 #8
0
 void OnConnectionModeKnown(ConnectionModeReader modeReader)
 {
     OnConnectionModeKnownCore(modeReader, false);
 }
コード例 #9
0
 void OnCachedConnectionModeKnown(ConnectionModeReader modeReader)
 {
     OnConnectionModeKnownCore(modeReader, true);
 }
 private void OnConnectionModeKnown(ConnectionModeReader modeReader)
 {
     this.OnConnectionModeKnownCore(modeReader, false);
 }
 public ReuseConnectionState(ConnectionModeReader modeReader, TimeSpan closeTimeout)
 {
     this.modeReader = modeReader;
     this.closeTimeout = closeTimeout;
 }
コード例 #12
0
        private void OnConnectionModeKnownCore(ConnectionModeReader modeReader, bool isCached)
        {
            lock (this.ThisLock)
            {
                if (this.isDisposed)
                {
                    return;
                }
                this.connectionReaders.Remove(modeReader);
            }
            bool flag = true;

            try
            {
                FramingMode connectionMode;
                try
                {
                    connectionMode = modeReader.GetConnectionMode();
                }
                catch (CommunicationException exception)
                {
                    TraceEventType exceptionEventType = modeReader.Connection.ExceptionEventType;
                    if (DiagnosticUtility.ShouldTrace(exceptionEventType))
                    {
                        DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, exceptionEventType);
                    }
                    return;
                }
                catch (TimeoutException exception2)
                {
                    if (!isCached)
                    {
                        exception2 = new TimeoutException(System.ServiceModel.SR.GetString("ChannelInitializationTimeout", new object[] { this.channelInitializationTimeout }), exception2);
                        ErrorBehavior.ThrowAndCatch(exception2);
                    }
                    TraceEventType type = modeReader.Connection.ExceptionEventType;
                    if (DiagnosticUtility.ShouldTrace(type))
                    {
                        DiagnosticUtility.ExceptionUtility.TraceHandledException(exception2, type);
                    }
                    return;
                }
                switch (connectionMode)
                {
                case FramingMode.Singleton:
                    this.OnSingletonConnection(modeReader.Connection, modeReader.ConnectionDequeuedCallback, modeReader.StreamPosition, modeReader.BufferOffset, modeReader.BufferSize, modeReader.GetRemainingTimeout());
                    break;

                case FramingMode.Duplex:
                    this.OnDuplexConnection(modeReader.Connection, modeReader.ConnectionDequeuedCallback, modeReader.StreamPosition, modeReader.BufferOffset, modeReader.BufferSize, modeReader.GetRemainingTimeout());
                    break;

                default:
                {
                    Exception innerException = new InvalidDataException(System.ServiceModel.SR.GetString("FramingModeNotSupported", new object[] { connectionMode }));
                    Exception exception4     = new ProtocolException(innerException.Message, innerException);
                    FramingEncodingString.AddFaultString(exception4, "http://schemas.microsoft.com/ws/2006/05/framing/faults/UnsupportedMode");
                    ErrorBehavior.ThrowAndCatch(exception4);
                    return;
                }
                }
                flag = false;
            }
            catch (Exception exception5)
            {
                if (Fx.IsFatal(exception5))
                {
                    throw;
                }
                if (!System.ServiceModel.Dispatcher.ExceptionHandler.HandleTransportExceptionHelper(exception5))
                {
                    throw;
                }
            }
            finally
            {
                if (flag)
                {
                    modeReader.Dispose();
                }
            }
        }
コード例 #13
0
 private void OnConnectionModeKnown(ConnectionModeReader modeReader)
 {
     this.OnConnectionModeKnownCore(modeReader, false);
 }
コード例 #14
0
 private void OnCachedConnectionModeKnown(ConnectionModeReader modeReader)
 {
     this.OnConnectionModeKnownCore(modeReader, true);
 }
コード例 #15
0
        void OnConnectionModeKnownCore(ConnectionModeReader modeReader, bool isCached)
        {
            lock (ThisLock)
            {
                if (isDisposed)
                    return;

                this.connectionReaders.Remove(modeReader);
            }

            bool closeReader = true;
            try
            {
                FramingMode framingMode;
                try
                {
                    framingMode = modeReader.GetConnectionMode();
                }
                catch (CommunicationException exception)
                {
                    TraceEventType eventType = modeReader.Connection.ExceptionEventType;
                    DiagnosticUtility.TraceHandledException(exception, eventType);
                    return;
                }
                catch (TimeoutException exception)
                {
                    if (!isCached)
                    {
                        exception = new TimeoutException(SR.GetString(SR.ChannelInitializationTimeout, this.channelInitializationTimeout), exception);
                        System.ServiceModel.Dispatcher.ErrorBehavior.ThrowAndCatch(exception);
                    }

                    if (TD.ChannelInitializationTimeoutIsEnabled())
                    {
                        TD.ChannelInitializationTimeout(SR.GetString(SR.ChannelInitializationTimeout, this.channelInitializationTimeout));
                    }

                    TraceEventType eventType = modeReader.Connection.ExceptionEventType;
                    DiagnosticUtility.TraceHandledException(exception, eventType);
                    return;
                }

                switch (framingMode)
                {
                    case FramingMode.Duplex:
                        OnDuplexConnection(modeReader.Connection, modeReader.ConnectionDequeuedCallback,
                            modeReader.StreamPosition, modeReader.BufferOffset, modeReader.BufferSize,
                            modeReader.GetRemainingTimeout());
                        break;

                    case FramingMode.Singleton:
                        OnSingletonConnection(modeReader.Connection, modeReader.ConnectionDequeuedCallback,
                            modeReader.StreamPosition, modeReader.BufferOffset, modeReader.BufferSize,
                            modeReader.GetRemainingTimeout());
                        break;

                    default:
                        {
                            Exception inner = new InvalidDataException(SR.GetString(
                                SR.FramingModeNotSupported, framingMode));
                            Exception exception = new ProtocolException(inner.Message, inner);
                            FramingEncodingString.AddFaultString(exception, FramingEncodingString.UnsupportedModeFault);
                            System.ServiceModel.Dispatcher.ErrorBehavior.ThrowAndCatch(exception);
                            return;
                        }
                }

                closeReader = false;
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }
                if (!ExceptionHandler.HandleTransportExceptionHelper(e))
                {
                    throw;
                }

                // containment -- the reader is aborted, no need for additional containment
            }
            finally
            {
                if (closeReader)
                {
                    modeReader.Dispose();
                }
            }
        }
コード例 #16
0
        ConnectionModeReader SetupModeReader(IConnection connection, bool isCached)
        {
            ConnectionModeReader modeReader;
            if (isCached)
            {
                if (onCachedConnectionModeKnown == null)
                {
                    onCachedConnectionModeKnown = new ConnectionModeCallback(OnCachedConnectionModeKnown);
                }

                modeReader = new ConnectionModeReader(connection, onCachedConnectionModeKnown, onConnectionClosed);
            }
            else
            {
                if (onConnectionModeKnown == null)
                {
                    onConnectionModeKnown = new ConnectionModeCallback(OnConnectionModeKnown);
                }

                modeReader = new ConnectionModeReader(connection, onConnectionModeKnown, onConnectionClosed);
            }

            lock (ThisLock)
            {
                if (isDisposed)
                {
                    modeReader.Dispose();
                    return null;
                }

                connectionReaders.Add(modeReader);
                return modeReader;
            }
        }
コード例 #17
0
 void OnCachedConnectionModeKnown(ConnectionModeReader modeReader)
 {
     OnConnectionModeKnownCore(modeReader, true);
 }
 private ConnectionModeReader SetupModeReader(IConnection connection, bool isCached)
 {
     ConnectionModeReader reader;
     if (isCached)
     {
         if (this.onCachedConnectionModeKnown == null)
         {
             this.onCachedConnectionModeKnown = new ConnectionModeCallback(this.OnCachedConnectionModeKnown);
         }
         reader = new ConnectionModeReader(connection, this.onCachedConnectionModeKnown, this.onConnectionClosed);
     }
     else
     {
         if (this.onConnectionModeKnown == null)
         {
             this.onConnectionModeKnown = new ConnectionModeCallback(this.OnConnectionModeKnown);
         }
         reader = new ConnectionModeReader(connection, this.onConnectionModeKnown, this.onConnectionClosed);
     }
     lock (this.ThisLock)
     {
         if (this.isDisposed)
         {
             reader.Dispose();
             return null;
         }
         this.connectionReaders.Add(reader);
         return reader;
     }
 }
コード例 #19
0
 void OnConnectionModeKnown(ConnectionModeReader modeReader)
 {
     OnConnectionModeKnownCore(modeReader, false);
 }
 private void OnCachedConnectionModeKnown(ConnectionModeReader modeReader)
 {
     this.OnConnectionModeKnownCore(modeReader, true);
 }
コード例 #21
0
        void OnConnectionModeKnownCore(ConnectionModeReader modeReader, bool isCached)
        {
            lock (ThisLock)
            {
                if (isDisposed)
                {
                    return;
                }

                this.connectionReaders.Remove(modeReader);
            }

            bool closeReader = true;

            try
            {
                FramingMode framingMode;
                try
                {
                    framingMode = modeReader.GetConnectionMode();
                }
                catch (CommunicationException exception)
                {
                    TraceEventType eventType = modeReader.Connection.ExceptionEventType;
                    DiagnosticUtility.TraceHandledException(exception, eventType);
                    return;
                }
                catch (TimeoutException exception)
                {
                    if (!isCached)
                    {
                        exception = new TimeoutException(SR.GetString(SR.ChannelInitializationTimeout, this.channelInitializationTimeout), exception);
                        System.ServiceModel.Dispatcher.ErrorBehavior.ThrowAndCatch(exception);
                    }

                    if (TD.ChannelInitializationTimeoutIsEnabled())
                    {
                        TD.ChannelInitializationTimeout(SR.GetString(SR.ChannelInitializationTimeout, this.channelInitializationTimeout));
                    }

                    TraceEventType eventType = modeReader.Connection.ExceptionEventType;
                    DiagnosticUtility.TraceHandledException(exception, eventType);
                    return;
                }

                switch (framingMode)
                {
                case FramingMode.Duplex:
                    OnDuplexConnection(modeReader.Connection, modeReader.ConnectionDequeuedCallback,
                                       modeReader.StreamPosition, modeReader.BufferOffset, modeReader.BufferSize,
                                       modeReader.GetRemainingTimeout());
                    break;

                case FramingMode.Singleton:
                    OnSingletonConnection(modeReader.Connection, modeReader.ConnectionDequeuedCallback,
                                          modeReader.StreamPosition, modeReader.BufferOffset, modeReader.BufferSize,
                                          modeReader.GetRemainingTimeout());
                    break;

                default:
                {
                    Exception inner = new InvalidDataException(SR.GetString(
                                                                   SR.FramingModeNotSupported, framingMode));
                    Exception exception = new ProtocolException(inner.Message, inner);
                    FramingEncodingString.AddFaultString(exception, FramingEncodingString.UnsupportedModeFault);
                    System.ServiceModel.Dispatcher.ErrorBehavior.ThrowAndCatch(exception);
                    return;
                }
                }

                closeReader = false;
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }
                if (!ExceptionHandler.HandleTransportExceptionHelper(e))
                {
                    throw;
                }

                // containment -- the reader is aborted, no need for additional containment
            }
            finally
            {
                if (closeReader)
                {
                    modeReader.Dispose();
                }
            }
        }
        private void OnConnectionModeKnownCore(ConnectionModeReader modeReader, bool isCached)
        {
            lock (this.ThisLock)
            {
                if (this.isDisposed)
                {
                    return;
                }
                this.connectionReaders.Remove(modeReader);
            }
            bool flag = true;
            try
            {
                FramingMode connectionMode;
                try
                {
                    connectionMode = modeReader.GetConnectionMode();
                }
                catch (CommunicationException exception)
                {
                    TraceEventType exceptionEventType = modeReader.Connection.ExceptionEventType;
                    if (DiagnosticUtility.ShouldTrace(exceptionEventType))
                    {
                        DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, exceptionEventType);
                    }
                    return;
                }
                catch (TimeoutException exception2)
                {
                    if (!isCached)
                    {
                        exception2 = new TimeoutException(System.ServiceModel.SR.GetString("ChannelInitializationTimeout", new object[] { this.channelInitializationTimeout }), exception2);
                        ErrorBehavior.ThrowAndCatch(exception2);
                    }
                    TraceEventType type = modeReader.Connection.ExceptionEventType;
                    if (DiagnosticUtility.ShouldTrace(type))
                    {
                        DiagnosticUtility.ExceptionUtility.TraceHandledException(exception2, type);
                    }
                    return;
                }
                switch (connectionMode)
                {
                    case FramingMode.Singleton:
                        this.OnSingletonConnection(modeReader.Connection, modeReader.ConnectionDequeuedCallback, modeReader.StreamPosition, modeReader.BufferOffset, modeReader.BufferSize, modeReader.GetRemainingTimeout());
                        break;

                    case FramingMode.Duplex:
                        this.OnDuplexConnection(modeReader.Connection, modeReader.ConnectionDequeuedCallback, modeReader.StreamPosition, modeReader.BufferOffset, modeReader.BufferSize, modeReader.GetRemainingTimeout());
                        break;

                    default:
                    {
                        Exception innerException = new InvalidDataException(System.ServiceModel.SR.GetString("FramingModeNotSupported", new object[] { connectionMode }));
                        Exception exception4 = new ProtocolException(innerException.Message, innerException);
                        FramingEncodingString.AddFaultString(exception4, "http://schemas.microsoft.com/ws/2006/05/framing/faults/UnsupportedMode");
                        ErrorBehavior.ThrowAndCatch(exception4);
                        return;
                    }
                }
                flag = false;
            }
            catch (Exception exception5)
            {
                if (Fx.IsFatal(exception5))
                {
                    throw;
                }
                if (!System.ServiceModel.Dispatcher.ExceptionHandler.HandleTransportExceptionHelper(exception5))
                {
                    throw;
                }
            }
            finally
            {
                if (flag)
                {
                    modeReader.Dispose();
                }
            }
        }
コード例 #23
0
 public ReuseConnectionState(ConnectionModeReader modeReader, TimeSpan closeTimeout)
 {
     this.modeReader   = modeReader;
     this.closeTimeout = closeTimeout;
 }