private static void ValidateReadingFaultString(Microsoft.ServiceBus.Channels.ClientFramingDecoder decoder) { if (decoder.CurrentState != Microsoft.ServiceBus.Channels.ClientFramingDecoderState.ReadingFaultString) { throw Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MessageSecurityException(Microsoft.ServiceBus.SR.GetString(Resources.ServerRejectedUpgradeRequest, new object[0]))); } }
public static void DecodeFramingFault(Microsoft.ServiceBus.Channels.ClientFramingDecoder decoder, Microsoft.ServiceBus.Channels.IConnection connection, Uri via, string contentType, ref Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper) { Microsoft.ServiceBus.Channels.ConnectionUpgradeHelper.ValidateReadingFaultString(decoder); int num = 0; byte[] numArray = Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.Utility.AllocateByteArray(256); int num1 = connection.Read(numArray, num, (int)numArray.Length, timeoutHelper.RemainingTime()); while (num1 > 0) { int num2 = decoder.Decode(numArray, num, num1); num = num + num2; num1 = num1 - num2; if (decoder.CurrentState == Microsoft.ServiceBus.Channels.ClientFramingDecoderState.Fault) { Microsoft.ServiceBus.Channels.ConnectionUtilities.CloseNoThrow(connection, timeoutHelper.RemainingTime()); throw Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.ThrowHelperError(Microsoft.ServiceBus.Channels.FaultStringDecoder.GetFaultException(decoder.Fault, via.ToString(), contentType)); } if (decoder.CurrentState != Microsoft.ServiceBus.Channels.ClientFramingDecoderState.ReadingFaultString) { throw Fx.AssertAndThrow("invalid framing client state machine"); } if (num1 != 0) { continue; } num = 0; num1 = connection.Read(numArray, num, (int)numArray.Length, timeoutHelper.RemainingTime()); } throw Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.ThrowHelperError(decoder.CreatePrematureEOFException()); }
public InitiateUpgradeAsyncResult(IDefaultCommunicationTimeouts timeouts, EndpointAddress remoteAddress, Microsoft.ServiceBus.Channels.IConnection connection, Microsoft.ServiceBus.Channels.ClientFramingDecoder decoder, StreamUpgradeInitiator upgradeInitiator, string contentType, Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper, AsyncCallback callback, object state) : base(callback, state) { this.defaultTimeouts = timeouts; this.decoder = decoder; this.upgradeInitiator = upgradeInitiator; this.contentType = contentType; this.timeoutHelper = timeoutHelper; this.connection = connection; this.remoteAddress = remoteAddress; if (this.Begin()) { base.Complete(true); } }
public DecodeFailedUpgradeAsyncResult(Microsoft.ServiceBus.Channels.ClientFramingDecoder decoder, Microsoft.ServiceBus.Channels.IConnection connection, Uri via, string contentType, ref Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper, AsyncCallback callback, object state) : base(callback, state) { Microsoft.ServiceBus.Channels.ConnectionUpgradeHelper.ValidateReadingFaultString(decoder); this.decoder = decoder; this.connection = connection; this.via = via; this.contentType = contentType; this.timeoutHelper = timeoutHelper; if (connection.BeginRead(0, Math.Min(256, connection.AsyncReadBufferSize), timeoutHelper.RemainingTime(), Microsoft.ServiceBus.Channels.ConnectionUpgradeHelper.DecodeFailedUpgradeAsyncResult.onReadFaultData, this) == AsyncReadResult.Queued) { return; } this.CompleteReadFaultData(); }
private static bool ValidateUpgradeResponse(byte[] buffer, int count, Microsoft.ServiceBus.Channels.ClientFramingDecoder decoder) { if (count == 0) { throw Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MessageSecurityException(Microsoft.ServiceBus.SR.GetString(Resources.ServerRejectedUpgradeRequest, new object[0]), decoder.CreatePrematureEOFException())); } while (decoder.Decode(buffer, 0, count) == 0) { } if (decoder.CurrentState != Microsoft.ServiceBus.Channels.ClientFramingDecoderState.UpgradeResponse) { return(false); } return(true); }
public SendPreambleAsyncResult(Microsoft.ServiceBus.Channels.StreamedFramingRequestChannel channel, Microsoft.ServiceBus.Channels.IConnection connection, ref Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper, Microsoft.ServiceBus.Channels.ClientFramingDecoder decoder, AsyncCallback callback, object state) : base(callback, state) { this.channel = channel; this.connection = connection; this.timeoutHelper = timeoutHelper; this.decoder = decoder; IAsyncResult asyncResult = connection.BeginWrite(channel.Preamble, 0, (int)channel.Preamble.Length, true, timeoutHelper.RemainingTime(), Microsoft.ServiceBus.Channels.StreamedFramingRequestChannel.StreamedConnectionPoolHelper.SendPreambleAsyncResult.onWritePreamble, this); if (!asyncResult.CompletedSynchronously) { return; } if (this.HandleWritePreamble(asyncResult)) { base.Complete(true); } }
public static bool ValidatePreambleResponse(byte[] buffer, int count, Microsoft.ServiceBus.Channels.ClientFramingDecoder decoder, Uri via) { if (count == 0) { ExceptionUtility exceptionUtility = Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility; string serverRejectedSessionPreamble = Resources.ServerRejectedSessionPreamble; object[] objArray = new object[] { via }; throw exceptionUtility.ThrowHelperError(new ProtocolException(Microsoft.ServiceBus.SR.GetString(serverRejectedSessionPreamble, objArray), decoder.CreatePrematureEOFException())); } while (decoder.Decode(buffer, 0, count) == 0) { } if (decoder.CurrentState != Microsoft.ServiceBus.Channels.ClientFramingDecoderState.Start) { return(false); } return(true); }
private Microsoft.ServiceBus.Channels.IConnection SendPreamble(Microsoft.ServiceBus.Channels.IConnection connection, ref Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper, Microsoft.ServiceBus.Channels.ClientFramingDecoder decoder, out SecurityMessageProperty remoteSecurity) { connection.Write(this.Preamble, 0, (int)this.Preamble.Length, true, timeoutHelper.RemainingTime()); if (this.upgrade == null) { remoteSecurity = null; } else { StreamUpgradeInitiator streamUpgradeInitiator = this.upgrade.CreateUpgradeInitiator(base.RemoteAddress, base.Via); if (!Microsoft.ServiceBus.Channels.ConnectionUpgradeHelper.InitiateUpgrade(streamUpgradeInitiator, ref connection, decoder, this, ref timeoutHelper)) { Microsoft.ServiceBus.Channels.ConnectionUpgradeHelper.DecodeFramingFault(decoder, connection, base.Via, this.messageEncoder.ContentType, ref timeoutHelper); } if (!(streamUpgradeInitiator is StreamSecurityUpgradeInitiator)) { remoteSecurity = null; } else { remoteSecurity = ((StreamSecurityUpgradeInitiator)streamUpgradeInitiator).GetRemoteSecurity(); } connection.Write(Microsoft.ServiceBus.Channels.ClientSingletonEncoder.PreambleEndBytes, 0, (int)Microsoft.ServiceBus.Channels.ClientSingletonEncoder.PreambleEndBytes.Length, true, timeoutHelper.RemainingTime()); } byte[] numArray = new byte[1]; if (!Microsoft.ServiceBus.Channels.ConnectionUpgradeHelper.ValidatePreambleResponse(numArray, connection.Read(numArray, 0, (int)numArray.Length, timeoutHelper.RemainingTime()), decoder, base.Via)) { Microsoft.ServiceBus.Channels.ConnectionUpgradeHelper.DecodeFramingFault(decoder, connection, base.Via, this.messageEncoder.ContentType, ref timeoutHelper); } return(connection); }
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 static IAsyncResult BeginInitiateUpgrade(IDefaultCommunicationTimeouts timeouts, EndpointAddress remoteAddress, Microsoft.ServiceBus.Channels.IConnection connection, Microsoft.ServiceBus.Channels.ClientFramingDecoder decoder, StreamUpgradeInitiator upgradeInitiator, string contentType, Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper, AsyncCallback callback, object state) { return(new Microsoft.ServiceBus.Channels.ConnectionUpgradeHelper.InitiateUpgradeAsyncResult(timeouts, remoteAddress, connection, decoder, upgradeInitiator, contentType, timeoutHelper, callback, state)); }
public static IAsyncResult BeginDecodeFramingFault(Microsoft.ServiceBus.Channels.ClientFramingDecoder decoder, Microsoft.ServiceBus.Channels.IConnection connection, Uri via, string contentType, ref Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper, AsyncCallback callback, object state) { return(new Microsoft.ServiceBus.Channels.ConnectionUpgradeHelper.DecodeFailedUpgradeAsyncResult(decoder, connection, via, contentType, ref timeoutHelper, callback, state)); }