Exemple #1
0
 public ServerSingletonConnectionReader(Microsoft.ServiceBus.Channels.ServerSingletonPreambleConnectionReader preambleReader, Microsoft.ServiceBus.Channels.IConnection upgradedConnection, Microsoft.ServiceBus.Channels.ConnectionDemuxer connectionDemuxer) : base(upgradedConnection, preambleReader.BufferOffset, preambleReader.BufferSize, preambleReader.Security, preambleReader.TransportSettings, preambleReader.Via)
 {
     this.decoder           = preambleReader.Decoder;
     this.contentType       = this.decoder.ContentType;
     this.connectionDemuxer = connectionDemuxer;
     this.rawConnection     = preambleReader.RawConnection;
 }
 private void OnSingletonConnection(Microsoft.ServiceBus.Channels.IConnection connection, Action connectionDequeuedCallback, long streamPosition, int offset, int size, TimeSpan timeout)
 {
     if (this.onSingletonPreambleKnown == null)
     {
         this.onSingletonPreambleKnown = new Microsoft.ServiceBus.Channels.ServerSingletonPreambleCallback(this.OnSingletonPreambleKnown);
     }
     Microsoft.ServiceBus.Channels.ServerSingletonPreambleConnectionReader serverSingletonPreambleConnectionReader = new Microsoft.ServiceBus.Channels.ServerSingletonPreambleConnectionReader(connection, connectionDequeuedCallback, streamPosition, offset, size, this.transportSettingsCallback, this.onConnectionClosed, this.onSingletonPreambleKnown);
     lock (this.ThisLock)
     {
         if (!this.isClosed)
         {
             this.connectionReaders.Add(serverSingletonPreambleConnectionReader);
         }
         else
         {
             serverSingletonPreambleConnectionReader.Dispose();
             return;
         }
     }
     serverSingletonPreambleConnectionReader.StartReading(this.viaDelegate, timeout);
 }
        private void OnSingletonPreambleKnown(Microsoft.ServiceBus.Channels.ServerSingletonPreambleConnectionReader serverSingletonPreambleReader)
        {
            lock (this.ThisLock)
            {
                if (!this.isClosed)
                {
                    this.connectionReaders.Remove(serverSingletonPreambleReader);
                }
                else
                {
                    return;
                }
            }
            Microsoft.ServiceBus.Channels.ISingletonChannelListener singletonChannelListener = this.singletonPreambleCallback(serverSingletonPreambleReader);
            Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.DebugAssert(singletonChannelListener != null, "singletonPreambleCallback must return a listener or send a Fault/throw");
            TimeoutHelper timeoutHelper = new TimeoutHelper(singletonChannelListener.ReceiveTimeout);

            Microsoft.ServiceBus.Channels.IConnection connection = serverSingletonPreambleReader.CompletePreamble(timeoutHelper.RemainingTime());
            Microsoft.ServiceBus.Channels.ServerSingletonConnectionReader serverSingletonConnectionReader = new Microsoft.ServiceBus.Channels.ServerSingletonConnectionReader(serverSingletonPreambleReader, connection, this);
            RequestContext requestContext = serverSingletonConnectionReader.ReceiveRequest(timeoutHelper.RemainingTime());

            singletonChannelListener.ReceiveRequest(requestContext, serverSingletonPreambleReader.ConnectionDequeuedCallback, true);
        }
        private void ReadAndDispatch()
        {
            bool flag = false;

            try
            {
                try
                {
                    while ((this.size > 0 || !this.isReadPending) && !base.IsClosed)
                    {
                        if (this.size == 0)
                        {
                            this.isReadPending = true;
                            if (this.onAsyncReadComplete == null)
                            {
                                this.onAsyncReadComplete = new WaitCallback(this.OnAsyncReadComplete);
                            }
                            if (base.Connection.BeginRead(0, (int)this.connectionBuffer.Length, this.GetRemainingTimeout(), this.onAsyncReadComplete, null) == AsyncReadResult.Queued)
                            {
                                break;
                            }
                            this.HandleReadComplete();
                        }
                        int num = this.decoder.Decode(this.connectionBuffer, this.offset, this.size);
                        if (num > 0)
                        {
                            Microsoft.ServiceBus.Channels.ServerSingletonPreambleConnectionReader serverSingletonPreambleConnectionReader = this;
                            serverSingletonPreambleConnectionReader.offset = serverSingletonPreambleConnectionReader.offset + num;
                            Microsoft.ServiceBus.Channels.ServerSingletonPreambleConnectionReader serverSingletonPreambleConnectionReader1 = this;
                            serverSingletonPreambleConnectionReader1.size = serverSingletonPreambleConnectionReader1.size - num;
                        }
                        if (this.decoder.CurrentState != Microsoft.ServiceBus.Channels.ServerSingletonDecoder.State.PreUpgradeStart)
                        {
                            continue;
                        }
                        this.via = this.decoder.Via;
                        if (this.viaDelegate != null)
                        {
                            this.viaDelegate(this.via);
                        }
                        this.transportSettings = this.transportSettingsCallback(this.via);
                        if (this.transportSettings != null)
                        {
                            this.callback(this);
                            break;
                        }
                        else
                        {
                            string   endpointNotFound = Resources.EndpointNotFound;
                            object[] via = new object[] { this.decoder.Via };
                            EndpointNotFoundException endpointNotFoundException = new EndpointNotFoundException(Microsoft.ServiceBus.SR.GetString(endpointNotFound, via));
                            if (Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ShouldTraceInformation)
                            {
                                Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.TraceHandledException(endpointNotFoundException, TraceEventType.Information);
                            }
                            this.SendFault("http://schemas.microsoft.com/ws/2006/05/framing/faults/EndpointNotFound");
                            return;
                        }
                    }
                    flag = true;
                }
                catch (CommunicationException communicationException1)
                {
                    CommunicationException communicationException = communicationException1;
                    if (Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ShouldTraceInformation)
                    {
                        Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.TraceHandledException(communicationException, TraceEventType.Information);
                    }
                }
                catch (TimeoutException timeoutException1)
                {
                    TimeoutException timeoutException = timeoutException1;
                    if (Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ShouldTraceInformation)
                    {
                        Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.TraceHandledException(timeoutException, TraceEventType.Information);
                    }
                }
                catch (Exception exception1)
                {
                    Exception exception = exception1;
                    if (Fx.IsFatal(exception))
                    {
                        throw;
                    }
                    if (!ExceptionHandler.HandleTransportExceptionHelper(exception))
                    {
                        throw;
                    }
                }
            }
            finally
            {
                if (!flag)
                {
                    base.Abort();
                }
            }
        }
        public Microsoft.ServiceBus.Channels.IConnection CompletePreamble(TimeSpan timeout)
        {
            Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper = new Microsoft.ServiceBus.Common.TimeoutHelper(timeout);
            if (!this.transportSettings.MessageEncoderFactory.Encoder.IsContentTypeSupported(this.decoder.ContentType))
            {
                this.SendFault("http://schemas.microsoft.com/ws/2006/05/framing/faults/ContentTypeInvalid", ref timeoutHelper);
                ExceptionUtility exceptionUtility    = Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility;
                string           contentTypeMismatch = Resources.ContentTypeMismatch;
                object[]         contentType         = new object[] { this.decoder.ContentType, this.transportSettings.MessageEncoderFactory.Encoder.ContentType };
                throw exceptionUtility.ThrowHelperError(new ProtocolException(Microsoft.ServiceBus.SR.GetString(contentTypeMismatch, contentType)));
            }
            StreamUpgradeAcceptor streamUpgradeAcceptor = null;
            StreamUpgradeProvider upgrade = this.transportSettings.Upgrade;

            if (upgrade != null)
            {
                streamUpgradeAcceptor = upgrade.CreateUpgradeAcceptor();
            }
            Microsoft.ServiceBus.Channels.IConnection connection = base.Connection;
            while (true)
            {
                if (this.size == 0)
                {
                    this.offset = 0;
                    this.size   = connection.Read(this.connectionBuffer, 0, (int)this.connectionBuffer.Length, timeoutHelper.RemainingTime());
                    if (this.size == 0)
                    {
                        break;
                    }
                }
                do
                {
                    int num = this.decoder.Decode(this.connectionBuffer, this.offset, this.size);
                    if (num > 0)
                    {
                        Microsoft.ServiceBus.Channels.ServerSingletonPreambleConnectionReader serverSingletonPreambleConnectionReader = this;
                        serverSingletonPreambleConnectionReader.offset = serverSingletonPreambleConnectionReader.offset + num;
                        Microsoft.ServiceBus.Channels.ServerSingletonPreambleConnectionReader serverSingletonPreambleConnectionReader1 = this;
                        serverSingletonPreambleConnectionReader1.size = serverSingletonPreambleConnectionReader1.size - num;
                    }
                    switch (this.decoder.CurrentState)
                    {
                    case Microsoft.ServiceBus.Channels.ServerSingletonDecoder.State.UpgradeRequest:
                    {
                        if (streamUpgradeAcceptor == null)
                        {
                            this.SendFault("http://schemas.microsoft.com/ws/2006/05/framing/faults/UpgradeInvalid", ref timeoutHelper);
                            ExceptionUtility exceptionUtility1 = Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility;
                            string           upgradeRequestToNonupgradableService = Resources.UpgradeRequestToNonupgradableService;
                            object[]         objArray = new object[] { this.decoder.Upgrade };
                            throw exceptionUtility1.ThrowHelperError(new ProtocolException(Microsoft.ServiceBus.SR.GetString(upgradeRequestToNonupgradableService, objArray)));
                        }
                        if (!streamUpgradeAcceptor.CanUpgrade(this.decoder.Upgrade))
                        {
                            this.SendFault("http://schemas.microsoft.com/ws/2006/05/framing/faults/UpgradeInvalid", ref timeoutHelper);
                            ExceptionUtility exceptionUtility2           = Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility;
                            string           upgradeProtocolNotSupported = Resources.UpgradeProtocolNotSupported;
                            object[]         upgrade1 = new object[] { this.decoder.Upgrade };
                            throw exceptionUtility2.ThrowHelperError(new ProtocolException(Microsoft.ServiceBus.SR.GetString(upgradeProtocolNotSupported, upgrade1)));
                        }
                        connection.Write(Microsoft.ServiceBus.Channels.ServerSingletonEncoder.UpgradeResponseBytes, 0, (int)Microsoft.ServiceBus.Channels.ServerSingletonEncoder.UpgradeResponseBytes.Length, true, timeoutHelper.RemainingTime());
                        Microsoft.ServiceBus.Channels.IConnection preReadConnection = connection;
                        if (this.size > 0)
                        {
                            preReadConnection = new Microsoft.ServiceBus.Channels.PreReadConnection(preReadConnection, this.connectionBuffer, this.offset, this.size);
                        }
                        try
                        {
                            connection            = Microsoft.ServiceBus.Channels.InitialServerConnectionReader.UpgradeConnection(preReadConnection, streamUpgradeAcceptor, this.transportSettings);
                            this.connectionBuffer = connection.AsyncReadBuffer;
                            continue;
                        }
                        catch (Exception exception1)
                        {
                            Exception exception = exception1;
                            if (Fx.IsFatal(exception))
                            {
                                throw;
                            }
                            this.WriteAuditFailure(streamUpgradeAcceptor as StreamSecurityUpgradeAcceptor, exception);
                            throw;
                        }
                        break;
                    }

                    case Microsoft.ServiceBus.Channels.ServerSingletonDecoder.State.Start:
                    {
                        this.SetupSecurityIfNecessary(streamUpgradeAcceptor);
                        connection.Write(Microsoft.ServiceBus.Channels.ServerSessionEncoder.AckResponseBytes, 0, (int)Microsoft.ServiceBus.Channels.ServerSessionEncoder.AckResponseBytes.Length, true, timeoutHelper.RemainingTime());
                        return(connection);
                    }

                    default:
                    {
                        continue;
                    }
                    }
                }while (this.size != 0);
            }
            throw Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.ThrowHelperError(this.decoder.CreatePrematureEOFException());
        }
Exemple #6
0
        internal Microsoft.ServiceBus.Channels.ISingletonChannelListener OnGetSingletonMessageHandler(Microsoft.ServiceBus.Channels.ServerSingletonPreambleConnectionReader serverSingletonPreambleReader)
        {
            Uri via = serverSingletonPreambleReader.Via;
            TChannelListener channelListener = this.GetChannelListener(via);

            if (channelListener == null)
            {
                serverSingletonPreambleReader.SendFault("http://schemas.microsoft.com/ws/2006/05/framing/faults/EndpointNotFound");
                ExceptionUtility exceptionUtility = Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility;
                string           endpointNotFound = Resources.EndpointNotFound;
                object[]         objArray         = new object[] { via };
                throw exceptionUtility.ThrowHelperError(new EndpointNotFoundException(Microsoft.ServiceBus.SR.GetString(endpointNotFound, objArray)));
            }
            if (!((object)channelListener is IChannelListener <IReplyChannel>))
            {
                serverSingletonPreambleReader.SendFault("http://schemas.microsoft.com/ws/2006/05/framing/faults/UnsupportedMode");
                ExceptionUtility exceptionUtility1       = Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility;
                string           framingModeNotSupported = Resources.FramingModeNotSupported;
                object[]         objArray1 = new object[] { Microsoft.ServiceBus.Channels.FramingMode.Singleton };
                throw exceptionUtility1.ThrowHelperError(new ProtocolException(Microsoft.ServiceBus.SR.GetString(framingModeNotSupported, objArray1)));
            }
            channelListener.RaiseMessageReceived();
            return((Microsoft.ServiceBus.Channels.ISingletonChannelListener)(object) channelListener);
        }