private bool CompleteReadUpgradeResponse()
            {
                int num = this.connection.EndRead();

                if (Microsoft.ServiceBus.Channels.ConnectionUpgradeHelper.ValidateUpgradeResponse(this.connection.AsyncReadBuffer, num, this.decoder))
                {
                    this.connectionStream = new Microsoft.ServiceBus.Channels.ConnectionStream(this.connection, this.defaultTimeouts);
                    IAsyncResult asyncResult = this.upgradeInitiator.BeginInitiateUpgrade(this.connectionStream, Microsoft.ServiceBus.Channels.ConnectionUpgradeHelper.InitiateUpgradeAsyncResult.onInitiateUpgrade, this);
                    if (!asyncResult.CompletedSynchronously)
                    {
                        return(false);
                    }
                    this.CompleteUpgrade(asyncResult);
                    return(true);
                }
                if (Microsoft.ServiceBus.Channels.ConnectionUpgradeHelper.InitiateUpgradeAsyncResult.onFailedUpgrade == null)
                {
                    Microsoft.ServiceBus.Channels.ConnectionUpgradeHelper.InitiateUpgradeAsyncResult.onFailedUpgrade = Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ThunkAsyncCallback(new AsyncCallback(Microsoft.ServiceBus.Channels.ConnectionUpgradeHelper.InitiateUpgradeAsyncResult.OnFailedUpgrade));
                }
                IAsyncResult asyncResult1 = Microsoft.ServiceBus.Channels.ConnectionUpgradeHelper.BeginDecodeFramingFault(this.decoder, this.connection, this.remoteAddress.Uri, this.contentType, ref this.timeoutHelper, Microsoft.ServiceBus.Channels.ConnectionUpgradeHelper.InitiateUpgradeAsyncResult.onFailedUpgrade, this);

                if (asyncResult1.CompletedSynchronously)
                {
                    Microsoft.ServiceBus.Channels.ConnectionUpgradeHelper.EndDecodeFramingFault(asyncResult1);
                }
                return(asyncResult1.CompletedSynchronously);
            }
        public static Microsoft.ServiceBus.Channels.IConnection UpgradeConnection(Microsoft.ServiceBus.Channels.IConnection connection, StreamUpgradeAcceptor upgradeAcceptor, IDefaultCommunicationTimeouts defaultTimeouts)
        {
            Microsoft.ServiceBus.Channels.ConnectionStream connectionStream = new Microsoft.ServiceBus.Channels.ConnectionStream(connection, defaultTimeouts);
            Stream stream = upgradeAcceptor.AcceptUpgrade(connectionStream);

            if (upgradeAcceptor is StreamSecurityUpgradeAcceptor && Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ShouldTraceInformation)
            {
                TraceUtility.TraceEvent(TraceEventType.Information, TraceCode.StreamSecurityUpgradeAccepted, new StringTraceRecord("Type", upgradeAcceptor.GetType().ToString()), connection, null);
            }
            return(new Microsoft.ServiceBus.Channels.StreamConnection(stream, connectionStream));
        }
 public static bool InitiateUpgrade(StreamUpgradeInitiator upgradeInitiator, ref Microsoft.ServiceBus.Channels.IConnection connection, Microsoft.ServiceBus.Channels.ClientFramingDecoder decoder, IDefaultCommunicationTimeouts defaultTimeouts, ref Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper)
 {
     for (string i = upgradeInitiator.GetNextUpgrade(); i != null; i = upgradeInitiator.GetNextUpgrade())
     {
         Microsoft.ServiceBus.Channels.EncodedUpgrade encodedUpgrade = new Microsoft.ServiceBus.Channels.EncodedUpgrade(i);
         connection.Write(encodedUpgrade.EncodedBytes, 0, (int)encodedUpgrade.EncodedBytes.Length, true, timeoutHelper.RemainingTime());
         byte[] numArray = new byte[1];
         if (!Microsoft.ServiceBus.Channels.ConnectionUpgradeHelper.ValidateUpgradeResponse(numArray, connection.Read(numArray, 0, (int)numArray.Length, timeoutHelper.RemainingTime()), decoder))
         {
             return(false);
         }
         Microsoft.ServiceBus.Channels.ConnectionStream connectionStream = new Microsoft.ServiceBus.Channels.ConnectionStream(connection, defaultTimeouts);
         connection = new Microsoft.ServiceBus.Channels.StreamConnection(upgradeInitiator.InitiateUpgrade(connectionStream), connectionStream);
     }
     return(true);
 }
            public UpgradeConnectionAsyncResult(Microsoft.ServiceBus.Channels.IConnection connection, StreamUpgradeAcceptor upgradeAcceptor, IDefaultCommunicationTimeouts defaultTimeouts, AsyncCallback callback, object state) : base(callback, state)
            {
                this.upgradeAcceptor  = upgradeAcceptor;
                this.connectionStream = new Microsoft.ServiceBus.Channels.ConnectionStream(connection, defaultTimeouts);
                bool         flag        = false;
                IAsyncResult asyncResult = upgradeAcceptor.BeginAcceptUpgrade(this.connectionStream, Microsoft.ServiceBus.Channels.InitialServerConnectionReader.UpgradeConnectionAsyncResult.onAcceptUpgrade, this);

                if (asyncResult.CompletedSynchronously)
                {
                    this.CompleteAcceptUpgrade(asyncResult);
                    flag = true;
                }
                if (flag)
                {
                    base.Complete(true);
                }
            }
示例#5
0
 public StreamConnection(System.IO.Stream stream, Microsoft.ServiceBus.Channels.ConnectionStream innerStream)
 {
     this.stream      = stream;
     this.innerStream = innerStream;
     this.onRead      = Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ThunkAsyncCallback(new AsyncCallback(this.OnRead));
 }