private Microsoft.ServiceBus.Channels.IConnection SendPreamble(Microsoft.ServiceBus.Channels.IConnection connection, ArraySegment <byte> preamble, ref Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper) { this.decoder = new Microsoft.ServiceBus.Channels.ClientDuplexDecoder((long)0); byte[] numArray = new byte[1]; connection.Write(preamble.Array, preamble.Offset, preamble.Count, true, timeoutHelper.RemainingTime()); if (this.upgrade != null) { StreamUpgradeInitiator streamUpgradeInitiator = this.upgrade.CreateUpgradeInitiator(this.RemoteAddress, this.Via); Type type = streamUpgradeInitiator.GetType(); object[] objArray = new object[] { timeoutHelper.RemainingTime() }; InvokeHelper.InvokeInstanceMethod(type, streamUpgradeInitiator, "Open", objArray); if (!Microsoft.ServiceBus.Channels.ConnectionUpgradeHelper.InitiateUpgrade(streamUpgradeInitiator, ref connection, this.decoder, this, ref timeoutHelper)) { Microsoft.ServiceBus.Channels.ConnectionUpgradeHelper.DecodeFramingFault(this.decoder, connection, this.Via, base.MessageEncoder.ContentType, ref timeoutHelper); } this.SetRemoteSecurity(streamUpgradeInitiator); Type type1 = streamUpgradeInitiator.GetType(); object[] objArray1 = new object[] { timeoutHelper.RemainingTime() }; InvokeHelper.InvokeInstanceMethod(type1, streamUpgradeInitiator, "Close", objArray1); connection.Write(Microsoft.ServiceBus.Channels.SessionEncoder.PreambleEndBytes, 0, (int)Microsoft.ServiceBus.Channels.SessionEncoder.PreambleEndBytes.Length, true, timeoutHelper.RemainingTime()); } if (!Microsoft.ServiceBus.Channels.ConnectionUpgradeHelper.ValidatePreambleResponse(numArray, connection.Read(numArray, 0, (int)numArray.Length, timeoutHelper.RemainingTime()), this.decoder, this.Via)) { Microsoft.ServiceBus.Channels.ConnectionUpgradeHelper.DecodeFramingFault(this.decoder, connection, this.Via, base.MessageEncoder.ContentType, ref timeoutHelper); } return(connection); }
public Message Request(Message message, TimeSpan timeout) { Message message1; Message message2; if (message == null) { throw Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("message"); } if (timeout < TimeSpan.Zero) { throw Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("timeout", (object)timeout, Microsoft.ServiceBus.SR.GetString(Resources.SFxTimeoutOutOfRange0, new object[0]))); } base.ThrowIfDisposedOrNotOpen(); this.AddHeadersTo(message); Microsoft.ServiceBus.Channels.IRequest request = this.CreateRequest(message); this.TrackRequest(request); try { Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper = new Microsoft.ServiceBus.Common.TimeoutHelper(timeout); TimeSpan timeSpan = timeoutHelper.RemainingTime(); try { request.SendRequest(message, timeSpan); } catch (TimeoutException timeoutException1) { TimeoutException timeoutException = timeoutException1; string requestChannelSendTimedOut = Resources.RequestChannelSendTimedOut; object[] objArray = new object[] { timeSpan }; throw TraceUtility.ThrowHelperError(new TimeoutException(Microsoft.ServiceBus.SR.GetString(requestChannelSendTimedOut, objArray), timeoutException), message); } timeSpan = timeoutHelper.RemainingTime(); try { message1 = request.WaitForReply(timeSpan); } catch (TimeoutException timeoutException3) { TimeoutException timeoutException2 = timeoutException3; string requestChannelWaitForReplyTimedOut = Resources.RequestChannelWaitForReplyTimedOut; object[] objArray1 = new object[] { timeSpan }; throw TraceUtility.ThrowHelperError(new TimeoutException(Microsoft.ServiceBus.SR.GetString(requestChannelWaitForReplyTimedOut, objArray1), timeoutException2), message); } if (Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ShouldTraceInformation) { TraceUtility.TraceEvent(TraceEventType.Information, TraceCode.RequestChannelReplyReceived, message1); } message2 = message1; } finally { this.ReleaseRequest(request); } return(message2); }
protected override IEnumerator <IteratorTask <object> .TaskStep> GetTasks() { Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper = new Microsoft.ServiceBus.Common.TimeoutHelper(this.timeout); if (this.relay.tokenRenewer != null) { yield return(base.CallTask(this.relay.tokenRenewer.GetTokenAsync(timeoutHelper.RemainingTime()), IteratorTask <TResult> .ExceptionPolicy.Transfer)); this.relay.tokenRenewer.TokenRenewed += new EventHandler <AmqpRelay.TokenEventArgs>(this.relay.OnTokenRenewed); } yield return(base.CallTask((new AmqpRelay.ConnectTask(this.relay, timeoutHelper.RemainingTime())).Start(), IteratorTask <TResult> .ExceptionPolicy.Transfer)); this.relay.State = AmqpObjectState.Opened; }
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 void SendRequest(Message message, TimeSpan timeout) { Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper = new Microsoft.ServiceBus.Common.TimeoutHelper(timeout); try { this.connection = this.connectionPoolHelper.EstablishConnection(timeoutHelper.RemainingTime()); MessagingClientEtwProvider.Provider.RelayChannelConnectionTransfer(this.Activity, this.connection.Activity); bool flag = false; try { Microsoft.ServiceBus.Channels.StreamingConnectionHelper.WriteMessage(message, this.connection, true, this.channel.settings, ref timeoutHelper); flag = true; } finally { if (!flag) { this.connectionPoolHelper.Abort(); } } } catch (TimeoutException timeoutException1) { TimeoutException timeoutException = timeoutException1; ExceptionUtility exceptionUtility = Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility; string timeoutOnRequest = Resources.TimeoutOnRequest; object[] objArray = new object[] { timeout }; throw exceptionUtility.ThrowHelperError(new TimeoutException(Microsoft.ServiceBus.SR.GetString(timeoutOnRequest, objArray), timeoutException)); } }
private int ReadCore(byte[] buffer, int offset, int size, TimeSpan timeout, bool closing) { int num; Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper = new Microsoft.ServiceBus.Common.TimeoutHelper(timeout); try { this.SetReadTimeout(timeoutHelper.RemainingTime(), true, closing); num = this.socket.Receive(buffer, offset, size, SocketFlags.None); } catch (SocketException socketException1) { SocketException socketException = socketException1; throw Fx.Exception.TraceException <Exception>(this.ConvertReceiveException(socketException, timeoutHelper.RemainingTime()), this.ExceptionEventType, this.Activity); } catch (ObjectDisposedException objectDisposedException1) { ObjectDisposedException objectDisposedException = objectDisposedException1; Exception exception = this.ConvertObjectDisposedException(objectDisposedException); if (!object.ReferenceEquals(exception, objectDisposedException)) { throw Fx.Exception.TraceException <Exception>(exception, this.ExceptionEventType, this.Activity); } Fx.Exception.TraceException <ObjectDisposedException>(objectDisposedException, this.ExceptionEventType, this.Activity); throw; } return(num); }
public void Write(byte[] buffer, int offset, int size, bool immediate, TimeSpan timeout) { Microsoft.ServiceBus.Channels.ConnectionUtilities.ValidateBufferBounds(buffer, offset, size); Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper = new Microsoft.ServiceBus.Common.TimeoutHelper(timeout); try { this.SetImmediate(immediate); int num = size; while (num > 0) { this.SetWriteTimeout(timeoutHelper.RemainingTime(), true); size = Math.Min(num, 16777216); this.socket.Send(buffer, offset, size, SocketFlags.None); num = num - size; offset = offset + size; } } catch (SocketException socketException1) { SocketException socketException = socketException1; throw Fx.Exception.TraceException <Exception>(this.ConvertSendException(socketException, timeoutHelper.RemainingTime()), this.ExceptionEventType, this.Activity); } catch (ObjectDisposedException objectDisposedException1) { ObjectDisposedException objectDisposedException = objectDisposedException1; Exception exception = this.ConvertObjectDisposedException(objectDisposedException); if (!object.ReferenceEquals(exception, objectDisposedException)) { throw Fx.Exception.TraceException <Exception>(exception, this.ExceptionEventType, this.Activity); } throw; } }
public IAsyncResult BeginWrite(byte[] buffer, int offset, int size, bool immediate, TimeSpan timeout, AsyncCallback callback, object state) { IAsyncResult asyncResult; Microsoft.ServiceBus.Channels.ConnectionUtilities.ValidateBufferBounds(buffer, offset, size); Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper = new Microsoft.ServiceBus.Common.TimeoutHelper(timeout); try { lock (this.ThisLock) { if (this.writeConnectionQueue.Count > 0) { this.writeConnection.Shutdown(timeoutHelper.RemainingTime()); this.writeConnection = this.writeConnectionQueue.Dequeue(); } } IAsyncResult asyncResult1 = this.writeConnection.BeginWrite(buffer, offset, size, immediate, timeoutHelper.RemainingTime(), callback, state); asyncResult = asyncResult1; } catch (ObjectDisposedException objectDisposedException1) { ObjectDisposedException objectDisposedException = objectDisposedException1; Exception exception = this.ConvertObjectDisposedException(objectDisposedException); if (!object.ReferenceEquals(exception, objectDisposedException)) { throw Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.ThrowHelper(exception, this.ExceptionEventType); } throw; } return(asyncResult); }
private int ReadCore(byte[] buffer, int offset, int size, TimeSpan timeout, bool closing) { int num = 0; Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper = new Microsoft.ServiceBus.Common.TimeoutHelper(timeout); try { while (true) { try { num = this.readConnection.Read(buffer, offset, size, timeoutHelper.RemainingTime()); } catch (CommunicationException communicationException) { if (this.readConnectionQueue.Count == 0) { throw; } } if (num != 0 || this.readConnectionQueue.Count <= 0) { break; } if (this.role == HybridConnectionRole.Initiator) { this.readConnection.Close(timeoutHelper.RemainingTime()); } this.readConnection = this.readConnectionQueue.Dequeue(); if (this.role == HybridConnectionRole.Listener) { this.writeConnectionQueue.Enqueue(this.readConnection); } } } catch (ObjectDisposedException objectDisposedException1) { ObjectDisposedException objectDisposedException = objectDisposedException1; Exception exception = this.ConvertObjectDisposedException(objectDisposedException); if (!object.ReferenceEquals(exception, objectDisposedException)) { throw Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.ThrowHelper(exception, this.ExceptionEventType); } throw; } return(num); }
private static void CloseConnections(Microsoft.ServiceBus.Channels.IConnection[] connections, ref Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper) { if (connections != null) { for (int i = 0; i < (int)connections.Length; i++) { connections[i].Close(timeoutHelper.RemainingTime()); } } }
public static void RunSynchronously(TimeSpan timeout, params ICommunicationObject[] collection) { Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper = new Microsoft.ServiceBus.Common.TimeoutHelper(timeout); ICommunicationObject[] communicationObjectArray = collection; for (int i = 0; i < (int)communicationObjectArray.Length; i++) { ICommunicationObject communicationObject = communicationObjectArray[i]; if (communicationObject != null) { communicationObject.Open(timeoutHelper.RemainingTime()); } } }
public bool WaitForMessage(TimeSpan timeout) { bool flag; Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper = new Microsoft.ServiceBus.Common.TimeoutHelper(timeout); if (!this.sourceLock.TryEnter(timeoutHelper.RemainingTime())) { ExceptionUtility exceptionUtility = DiagnosticUtility.ExceptionUtility; string waitForMessageTimedOut = Resources.WaitForMessageTimedOut; object[] objArray = new object[] { timeout }; throw exceptionUtility.ThrowHelperError(new TimeoutException(Microsoft.ServiceBus.SR.GetString(waitForMessageTimedOut, objArray), ThreadNeutralSemaphore.CreateEnterTimedOutException(timeout))); } try { flag = this.source.WaitForMessage(timeoutHelper.RemainingTime()); } finally { this.sourceLock.Exit(); } return(flag); }
public Message Receive(TimeSpan timeout) { Message message; Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper = new Microsoft.ServiceBus.Common.TimeoutHelper(timeout); if (!this.sourceLock.TryEnter(timeoutHelper.RemainingTime())) { ExceptionUtility exceptionUtility = DiagnosticUtility.ExceptionUtility; string receiveTimedOut2 = Resources.ReceiveTimedOut2; object[] objArray = new object[] { timeout }; throw exceptionUtility.ThrowHelperError(new TimeoutException(Microsoft.ServiceBus.SR.GetString(receiveTimedOut2, objArray), ThreadNeutralSemaphore.CreateEnterTimedOutException(timeout))); } try { message = this.source.Receive(timeoutHelper.RemainingTime()); } finally { this.sourceLock.Exit(); } return(message); }
public Message Receive(TimeSpan timeout) { int num; Message pendingMessage = this.GetPendingMessage(); if (pendingMessage != null) { return(pendingMessage); } Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper = new Microsoft.ServiceBus.Common.TimeoutHelper(timeout); while (!this.isAtEOF) { if (this.size > 0) { pendingMessage = this.DecodeMessage(timeoutHelper.RemainingTime()); if (pendingMessage != null) { this.PrepareMessage(pendingMessage); return(pendingMessage); } if (this.isAtEOF) { return(null); } } if (this.size != 0) { throw Fx.AssertAndThrow("Receive: DecodeMessage() should consume the outstanding buffer or return a message."); } if (this.buffer == null) { this.buffer = DiagnosticUtility.Utility.AllocateByteArray(this.connection.AsyncReadBufferSize); } if (this.EnvelopeBuffer == null || this.EnvelopeSize - this.EnvelopeOffset < (int)this.buffer.Length) { num = this.connection.Read(this.buffer, 0, (int)this.buffer.Length, timeoutHelper.RemainingTime()); this.HandleReadComplete(num, false); } else { num = this.connection.Read(this.EnvelopeBuffer, this.EnvelopeOffset, (int)this.buffer.Length, timeoutHelper.RemainingTime()); this.HandleReadComplete(num, true); } } return(null); }
public CloseCollectionAsyncResult(TimeSpan timeout, AsyncCallback otherCallback, object state, IList <ICommunicationObject> collection) : base(otherCallback, state) { IAsyncResult asyncResult; Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper = new Microsoft.ServiceBus.Common.TimeoutHelper(timeout); this.count = collection.Count; if (this.count == 0) { base.Complete(true); return; } foreach (ICommunicationObject communicationObject in collection) { if (communicationObject != null) { Microsoft.ServiceBus.Channels.CloseCollectionAsyncResult.CallbackState callbackState = new Microsoft.ServiceBus.Channels.CloseCollectionAsyncResult.CallbackState(this, communicationObject); try { asyncResult = communicationObject.BeginClose(timeoutHelper.RemainingTime(), Microsoft.ServiceBus.Channels.CloseCollectionAsyncResult.nestedCallback, callbackState); } catch (Exception exception1) { Exception exception = exception1; if (Fx.IsFatal(exception)) { throw; } this.Decrement(true, exception); communicationObject.Abort(); continue; } if (!asyncResult.CompletedSynchronously) { continue; } this.CompleteClose(communicationObject, asyncResult); } else { this.Decrement(true); } } }
protected override RelayedOnewayTcpClient.RelayedOnewayConnection Connect(TimeSpan timeout) { RelayedOnewayTcpClient.RelayedOnewayConnection relayedOnewayConnection; Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper = new Microsoft.ServiceBus.Common.TimeoutHelper(timeout); Message uniqueId = Message.CreateMessage(base.MessageVersion, "http://schemas.microsoft.com/netservices/2009/05/servicebus/connect/Connect", new ConnectMessage(base.Uri)); TrackingIdHeader.TryAddOrUpdate(uniqueId.Headers, base.Activity.ActivityId.ToString()); uniqueId.Headers.MessageId = new UniqueId(); uniqueId.Headers.ReplyTo = EndpointAddress2.AnonymousAddress; if (base.TokenProvider != null) { SecurityToken token = base.TokenProvider.GetToken(base.AppliesTo, "Send", false, timeoutHelper.RemainingTime()); uniqueId.Headers.Add(new RelayTokenHeader(token)); } using (RelayedOnewayTcpClient.ConnectRequestReplyContext connectRequestReplyContext = new RelayedOnewayTcpClient.ConnectRequestReplyContext(this)) { connectRequestReplyContext.Send(uniqueId, timeoutHelper.RemainingTime(), out relayedOnewayConnection); } return(relayedOnewayConnection); }
public void Shutdown(TimeSpan timeout) { Microsoft.ServiceBus.Channels.IConnection[] array; Microsoft.ServiceBus.Channels.IConnection[] connectionArray; Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper = new Microsoft.ServiceBus.Common.TimeoutHelper(timeout); lock (this.ThisLock) { if (!this.isShutdown) { this.isShutdown = true; array = this.readConnectionQueue.ToArray(); this.readConnectionQueue.Clear(); connectionArray = this.writeConnectionQueue.ToArray(); this.writeConnectionQueue.Clear(); } else { return; } } try { this.writeConnection.Shutdown(timeoutHelper.RemainingTime()); HybridConnection.CloseConnections(array, ref timeoutHelper); HybridConnection.CloseConnections(connectionArray, ref timeoutHelper); if (this.directConnect != null) { this.directConnect.Dispose(); } } catch (ObjectDisposedException objectDisposedException1) { ObjectDisposedException objectDisposedException = objectDisposedException1; Exception exception = this.ConvertObjectDisposedException(objectDisposedException); if (!object.ReferenceEquals(exception, objectDisposedException)) { throw Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.ThrowHelper(exception, this.ExceptionEventType); } throw; } }
protected int Read(byte[] buffer, int offset, int size, TimeSpan timeout, bool closing) { int num = 0; Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper = new Microsoft.ServiceBus.Common.TimeoutHelper(timeout); try { this.SetReadTimeout(timeoutHelper.RemainingTime(), true, closing); num = this.Stream.Read(buffer, offset, size); } catch (ObjectDisposedException objectDisposedException1) { ObjectDisposedException objectDisposedException = objectDisposedException1; throw Fx.Exception.AsInformation(this.ConvertObjectDisposedException(objectDisposedException), null); } catch (IOException oException1) { IOException oException = oException1; throw Fx.Exception.AsInformation(BaseStreamConnection.ConvertIOException(oException), null); } catch (CommunicationException communicationException) { throw; } catch (TimeoutException timeoutException) { throw; } catch (Exception exception1) { Exception exception = exception1; if (!Fx.IsFatal(exception)) { throw Fx.Exception.AsError(new CommunicationException(exception.Message, exception), null); } throw; } return(num); }
public IAsyncResult BeginSend(Message message, TimeSpan timeout, AsyncCallback callback, object state) { Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper = new Microsoft.ServiceBus.Common.TimeoutHelper(timeout); this.AddToken(message, timeoutHelper.RemainingTime()); return(this.channel.BeginSend(message, timeoutHelper.RemainingTime(), callback, state)); }
public void Send(Message message, TimeSpan timeout) { Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper = new Microsoft.ServiceBus.Common.TimeoutHelper(timeout); this.AddToken(message, timeoutHelper.RemainingTime()); this.channel.Send(message, timeoutHelper.RemainingTime()); }
private void SendFault(string faultString, ref Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper) { Microsoft.ServiceBus.Channels.InitialServerConnectionReader.SendFault(base.Connection, faultString, this.connectionBuffer, timeoutHelper.RemainingTime(), 65536); }
protected override void OnOpen(TimeSpan timeout) { bool flag = false; try { Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper = new Microsoft.ServiceBus.Common.TimeoutHelper(timeout); this.ValidateContentType(ref timeoutHelper); while (true) { if (this.size == 0) { this.offset = 0; this.size = base.Connection.Read(this.connectionBuffer, 0, (int)this.connectionBuffer.Length, timeoutHelper.RemainingTime()); if (this.size == 0) { break; } } do { this.DecodeBytes(); switch (this.decoder.CurrentState) { case Microsoft.ServiceBus.Channels.ServerSessionDecoder.State.UpgradeRequest: { this.ProcessUpgradeRequest(ref timeoutHelper); base.Connection.Write(Microsoft.ServiceBus.Channels.ServerSessionEncoder.UpgradeResponseBytes, 0, (int)Microsoft.ServiceBus.Channels.ServerSessionEncoder.UpgradeResponseBytes.Length, true, timeoutHelper.RemainingTime()); Microsoft.ServiceBus.Channels.IConnection connection = base.Connection; if (this.size > 0) { connection = new Microsoft.ServiceBus.Channels.PreReadConnection(connection, this.connectionBuffer, this.offset, this.size); } try { base.Connection = Microsoft.ServiceBus.Channels.InitialServerConnectionReader.UpgradeConnection(connection, this.upgradeAcceptor, this); this.connectionBuffer = base.Connection.AsyncReadBuffer; continue; } catch (Exception exception1) { Exception exception = exception1; if (Fx.IsFatal(exception)) { throw; } this.WriteAuditFailure(this.upgradeAcceptor as StreamSecurityUpgradeAcceptor, exception); throw; } break; } case Microsoft.ServiceBus.Channels.ServerSessionDecoder.State.Start: { this.SetupSecurityIfNecessary(); base.Connection.Write(Microsoft.ServiceBus.Channels.ServerSessionEncoder.AckResponseBytes, 0, (int)Microsoft.ServiceBus.Channels.ServerSessionEncoder.AckResponseBytes.Length, true, timeoutHelper.RemainingTime()); this.SetupSessionReader(); flag = true; return; } default: { continue; } } }while (this.size != 0); } throw Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.ThrowHelperError(this.decoder.CreatePrematureEOFException()); } finally { if (!flag) { base.Connection.Abort(); } } }
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(); }
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); } }
protected override IEnumerator <IteratorTask <object> .TaskStep> GetTasks() { ConnectivityMode connectivityMode; object obj = null; bool flag = false; try { object thisLock = this.relay.ThisLock; object obj1 = thisLock; obj = thisLock; Monitor.Enter(obj1, ref flag); if (this.relay.State != AmqpObjectState.OpenReceived && this.relay.State != AmqpObjectState.Opened) { goto Label0; } } finally { if (flag) { Monitor.Exit(obj); } } Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper = new Microsoft.ServiceBus.Common.TimeoutHelper(this.timeout); string host = this.relay.serviceBusUri.Host; AmqpSettings amqpSetting = AmqpRelay.ConnectTask.CreateAmqpSettings(); connectivityMode = (this.relay.connectivitySettings != null ? this.relay.connectivitySettings.Mode : ServiceBusEnvironment.SystemConnectivity.Mode); ConnectivityMode connectivityMode1 = connectivityMode; if (connectivityMode1 == ConnectivityMode.Tcp) { TcpTransportSettings tcpTransportSetting = new TcpTransportSettings() { Host = host, Port = 5671 }; TlsTransportSettings tlsTransportSetting = new TlsTransportSettings(tcpTransportSetting) { TargetHost = host }; AmqpTransportInitiator amqpTransportInitiator = new AmqpTransportInitiator(amqpSetting, tlsTransportSetting); yield return(base.CallTask(amqpTransportInitiator.ConnectTaskAsync(timeoutHelper.RemainingTime()), IteratorTask <TResult> .ExceptionPolicy.Transfer)); } else if (connectivityMode1 == ConnectivityMode.Http || this.relay.httpConnectivitySettings != null) { WebSocketTransportSettings webSocketTransportSetting = new WebSocketTransportSettings(this.relay.serviceBusUri); AmqpTransportInitiator amqpTransportInitiator1 = new AmqpTransportInitiator(amqpSetting, webSocketTransportSetting); yield return(base.CallTask(amqpTransportInitiator1.ConnectTaskAsync(timeoutHelper.RemainingTime()), IteratorTask <TResult> .ExceptionPolicy.Transfer)); } else { TcpTransportSettings tcpTransportSetting1 = new TcpTransportSettings() { Host = host, Port = 5671 }; TlsTransportSettings tlsTransportSetting1 = new TlsTransportSettings(tcpTransportSetting1) { TargetHost = host }; AmqpTransportInitiator amqpTransportInitiator2 = new AmqpTransportInitiator(amqpSetting, tlsTransportSetting1); yield return(base.CallTask(amqpTransportInitiator2.ConnectTaskAsync(Microsoft.ServiceBus.Common.TimeoutHelper.Divide(timeoutHelper.RemainingTime(), 2)), IteratorTask <TResult> .ExceptionPolicy.Continue)); if (base.LastTask.Exception != null) { if (timeoutHelper.RemainingTime() == TimeSpan.Zero) { throw base.LastTask.Exception; } WebSocketTransportSettings webSocketTransportSetting1 = new WebSocketTransportSettings(this.relay.serviceBusUri); AmqpTransportInitiator amqpTransportInitiator3 = new AmqpTransportInitiator(amqpSetting, webSocketTransportSetting1); yield return(base.CallTask(amqpTransportInitiator3.ConnectTaskAsync(timeoutHelper.RemainingTime()), IteratorTask <TResult> .ExceptionPolicy.Transfer)); } } TransportBase transportBase = base.LastTaskResult <TransportBase>(); string[] strArrays = host.Split(new char[] { '.' }); strArrays[0] = string.Concat(strArrays[0], "-relay"); AmqpConnectionSettings amqpConnectionSetting = new AmqpConnectionSettings() { ContainerId = Guid.NewGuid().ToString(), HostName = string.Join(".", strArrays) }; this.relay.connection = new AmqpConnection(transportBase, amqpSetting, amqpConnectionSetting); yield return(base.CallTask(this.relay.connection.OpenAsync(timeoutHelper.RemainingTime()), IteratorTask <TResult> .ExceptionPolicy.Transfer)); AmqpSessionSettings amqpSessionSetting = new AmqpSessionSettings(); AmqpSession amqpSession = this.relay.connection.CreateSession(amqpSessionSetting); yield return(base.CallTask(amqpSession.OpenAsync(timeoutHelper.RemainingTime()), IteratorTask <TResult> .ExceptionPolicy.Transfer)); AmqpLinkSettings amqpLinkSetting = new AmqpLinkSettings() { Role = new bool?(false), InitialDeliveryCount = new uint?(0), LinkName = string.Concat("HttpRelayServer_Link_", Guid.NewGuid()), Target = new Target(this.relay.serviceBusUri), Source = new Source(this.relay.serviceBusUri), TotalLinkCredit = 1000, AutoSendFlow = true }; AmqpLinkSettings amqpLinkSetting1 = amqpLinkSetting; if (this.relay.tokenRenewer != null) { amqpLinkSetting1.AddProperty(AmqpConstants.SimpleWebTokenPropertyName, this.relay.tokenRenewer.CurrentToken.Token); } if (!this.relay.TransportSecurityRequired) { amqpLinkSetting1.AddProperty(ClientConstants.TransportSecurityRequiredName, false); } if (!this.relay.RelayClientAuthorizationRequired) { amqpLinkSetting1.AddProperty(ClientConstants.ClientAuthenticationRequiredName, false); } if (this.relay.PublishToRegistry) { amqpLinkSetting1.AddProperty(ClientConstants.RequiresPublicRegistry, true); } if (!string.IsNullOrEmpty(this.relay.ClientAgent)) { amqpLinkSetting1.AddProperty(ClientConstants.ClientAgent, this.relay.ClientAgent); } if (!string.IsNullOrEmpty(this.relay.DisplayName)) { amqpLinkSetting1.AddProperty(ClientConstants.DisplayName, this.relay.DisplayName); } amqpLinkSetting1.AddProperty(ClientConstants.DynamicRelay, this.relay.IsDynamic); amqpLinkSetting1.AddProperty(ClientConstants.ListenerTypeName, this.relay.ListenerType.ToString()); this.relay.link = new DuplexAmqpLink(amqpSession, amqpLinkSetting1); yield return(base.CallTask(this.relay.link.OpenAsync(timeoutHelper.RemainingTime()), IteratorTask <TResult> .ExceptionPolicy.Transfer)); this.relay.link.SafeAddClosed(this.relay.onAmqpObjectClosed); this.relay.link.RegisterMessageListener((AmqpMessage msg) => this.relay.messageListener(this.relay.link, msg)); this.relay.OnOnline(); Label0: yield break; }
public SendPreambleAsyncResult(Microsoft.ServiceBus.Channels.ClientFramingDuplexSessionChannel channel, Microsoft.ServiceBus.Channels.IConnection connection, ArraySegment <byte> preamble, ref Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper, AsyncCallback callback, object state) : base(callback, state) { this.channel = channel; this.timeoutHelper = timeoutHelper; this.connection = connection; channel.decoder = new Microsoft.ServiceBus.Channels.ClientDuplexDecoder((long)0); IAsyncResult asyncResult = connection.BeginWrite(preamble.Array, preamble.Offset, preamble.Count, true, timeoutHelper.RemainingTime(), Microsoft.ServiceBus.Channels.ClientFramingDuplexSessionChannel.SendPreambleAsyncResult.onWritePreamble, this); if (!asyncResult.CompletedSynchronously) { return; } if (this.HandleWritePreamble(asyncResult)) { base.Complete(true); } }
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 void Close(TimeSpan timeout) { Microsoft.ServiceBus.Channels.IConnection[] array; Microsoft.ServiceBus.Channels.IConnection[] connectionArray; lock (this.ThisLock) { if (this.closeState == HybridConnection.CloseState.Closing || this.closeState == HybridConnection.CloseState.Closed) { return; } else { this.closeState = HybridConnection.CloseState.Closing; array = this.readConnectionQueue.ToArray(); this.readConnectionQueue.Clear(); connectionArray = this.writeConnectionQueue.ToArray(); this.writeConnectionQueue.Clear(); } } Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper = new Microsoft.ServiceBus.Common.TimeoutHelper(timeout); this.Shutdown(timeoutHelper.RemainingTime()); byte[] numArray = new byte[1]; TimeSpan timeSpan = timeoutHelper.RemainingTime(); try { if (this.ReadCore(numArray, 0, 1, timeSpan, true) > 0) { ExceptionUtility exceptionUtility = Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility; string socketCloseReadReceivedData = Resources.SocketCloseReadReceivedData; object[] remoteIPEndPoint = new object[] { this.readConnection.RemoteIPEndPoint }; throw exceptionUtility.ThrowHelper(new CommunicationException(Microsoft.ServiceBus.SR.GetString(socketCloseReadReceivedData, remoteIPEndPoint)), this.ExceptionEventType); } } catch (TimeoutException timeoutException1) { TimeoutException timeoutException = timeoutException1; ExceptionUtility exceptionUtility1 = Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility; string socketCloseReadTimeout = Resources.SocketCloseReadTimeout; object[] objArray = new object[] { this.readConnection.RemoteIPEndPoint, timeSpan }; throw exceptionUtility1.ThrowHelper(new TimeoutException(Microsoft.ServiceBus.SR.GetString(socketCloseReadTimeout, objArray), timeoutException), this.ExceptionEventType); } if (timeoutHelper.RemainingTime() <= TimeSpan.Zero && Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ShouldTraceWarning) { TraceUtility.TraceEvent(TraceEventType.Warning, TraceCode.SocketConnectionAbortClose, this); } this.readConnection.Close(timeoutHelper.RemainingTime()); HybridConnection.CloseConnections(array, ref timeoutHelper); HybridConnection.CloseConnections(connectionArray, ref timeoutHelper); if (this.directConnect != null) { this.directConnect.Dispose(); } lock (this.ThisLock) { this.closeState = HybridConnection.CloseState.Closed; } EventHandler eventHandler = this.Closed; if (eventHandler != null) { eventHandler(this, EventArgs.Empty); } }
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()); }