protected override IAsyncResult OnBeginClose(TimeSpan timeout, AsyncCallback callback, object state) { IAsyncResult asyncResult; try { asyncResult = this.MessagingFactory.BeginClose(timeout, callback, state); } catch (MessagingException messagingException1) { MessagingException messagingException = messagingException1; throw Microsoft.ServiceBus.Messaging.FxTrace.Exception.AsError(this.ConvertException(messagingException), null); } catch (OperationCanceledException operationCanceledException1) { OperationCanceledException operationCanceledException = operationCanceledException1; ExceptionTrace exception = Microsoft.ServiceBus.Messaging.FxTrace.Exception; string entityClosedOrAborted = SRClient.EntityClosedOrAborted; Exception innerException = operationCanceledException.InnerException; if (innerException == null) { innerException = operationCanceledException; } throw exception.AsError(new CommunicationObjectAbortedException(entityClosedOrAborted, innerException), null); } return(asyncResult); }
public Task RegisterProcessorFactoryAsync(Lease lease, ICheckpointManager checkpointManager, IEventProcessorFactory eventProcessorFactory, EventProcessorOptions processorOptions) { base.ThrowIfDisposed(); if (lease == null) { throw Fx.Exception.ArgumentNull("lease"); } if (checkpointManager == null) { throw Fx.Exception.ArgumentNull("checkpointManager"); } if (eventProcessorFactory == null) { throw Fx.Exception.ArgumentNull("eventProcessorFactory"); } if (processorOptions == null) { throw Fx.Exception.ArgumentNull("processorOptions"); } EventProcessorLifecycleManager eventProcessorLifecycleManager = null; if (this.handlers.TryGetValue(lease, out eventProcessorLifecycleManager)) { ExceptionTrace exception = Fx.Exception; string eventProcessorAlreadyRegistered = Resources.EventProcessorAlreadyRegistered; object[] partitionId = new object[] { lease.PartitionId }; throw exception.AsError(new InvalidOperationException(Microsoft.ServiceBus.SR.GetString(eventProcessorAlreadyRegistered, partitionId)), null); } eventProcessorLifecycleManager = new EventProcessorLifecycleManager(this, lease, checkpointManager, processorOptions); if (!this.handlers.TryAdd(lease, eventProcessorLifecycleManager)) { return(TaskHelpers.GetCompletedTask <object>(null)); } return(eventProcessorLifecycleManager.RegisterProcessorFactoryAsync(eventProcessorFactory)); }
protected override void OnOpen(TimeSpan timeout) { Microsoft.ServiceBus.Channels.IConnection connection; try { connection = this.connectionPoolHelper.EstablishConnection(timeout); } catch (TimeoutException timeoutException1) { TimeoutException timeoutException = timeoutException1; ExceptionTrace exception = Fx.Exception; string timeoutOnOpen = Resources.TimeoutOnOpen; object[] objArray = new object[] { timeout }; throw exception.AsError(new TimeoutException(Microsoft.ServiceBus.SR.GetString(timeoutOnOpen, objArray), timeoutException), base.Activity); } bool flag = false; try { this.AcceptConnection(connection); flag = true; } finally { if (!flag) { this.connectionPoolHelper.Abort(); } } }
internal static void ValidateBufferBounds(int bufferSize, int offset, int size) { if (offset < 0) { throw Fx.Exception.AsError(new ArgumentOutOfRangeException("offset", (object)offset, Microsoft.ServiceBus.SR.GetString(Resources.ValueMustBeNonNegative, new object[0])), null); } if (offset > bufferSize) { ExceptionTrace exception = Fx.Exception; object obj = offset; string offsetExceedsBufferSize = Resources.OffsetExceedsBufferSize; object[] objArray = new object[] { bufferSize }; throw exception.AsError(new ArgumentOutOfRangeException("offset", obj, Microsoft.ServiceBus.SR.GetString(offsetExceedsBufferSize, objArray)), null); } if (size <= 0) { throw Fx.Exception.AsError(new ArgumentOutOfRangeException("size", (object)size, Microsoft.ServiceBus.SR.GetString(Resources.ValueMustBePositive, new object[0])), null); } int num = bufferSize - offset; if (size > num) { ExceptionTrace exceptionTrace = Fx.Exception; object obj1 = size; string sizeExceedsRemainingBufferSpace = Resources.SizeExceedsRemainingBufferSpace; object[] objArray1 = new object[] { num }; throw exceptionTrace.AsError(new ArgumentOutOfRangeException("size", obj1, Microsoft.ServiceBus.SR.GetString(sizeExceedsRemainingBufferSpace, objArray1)), null); } }
public SendAsyncResult(ServiceBusOutputChannel outputChannel, Message message, TimeSpan timeout, AsyncCallback callback, object state) : base(callback, state) { bool flag; bool flag1; this.outputChannel = outputChannel; outputChannel.AddHeadersTo(message); outputChannel.TraceSendingMessage(message); BrokeredMessage brokerMessage = null; try { brokerMessage = outputChannel.ConvertToBrokerMessage(message, out this.bufferToReturn); Microsoft.ServiceBus.Messaging.MessageSender messageSender = outputChannel.MessageSender; BrokeredMessage[] brokeredMessageArray = new BrokeredMessage[] { brokerMessage }; if (base.SyncContinue(messageSender.BeginSend(brokeredMessageArray, timeout, base.PrepareAsyncCompletion(ServiceBusOutputChannel.SendAsyncResult.onSendComplete), this))) { base.Complete(true); } } catch (MessagingException messagingException) { CommunicationException communicationException = MessagingExceptionHelper.ConvertToCommunicationException(messagingException, out flag); if (flag) { this.outputChannel.Fault(); } throw Microsoft.ServiceBus.Messaging.FxTrace.Exception.AsError(communicationException, null); } catch (OperationCanceledException operationCanceledException1) { OperationCanceledException operationCanceledException = operationCanceledException1; MessagingException innerException = operationCanceledException.InnerException as MessagingException; if (innerException != null) { MessagingExceptionHelper.ConvertToCommunicationException(innerException, out flag1); if (flag1) { this.outputChannel.Fault(); } } ExceptionTrace exception = Microsoft.ServiceBus.Messaging.FxTrace.Exception; string entityClosedOrAborted = SRClient.EntityClosedOrAborted; Exception innerException1 = operationCanceledException.InnerException; if (innerException1 == null) { innerException1 = operationCanceledException; } throw exception.AsError(new CommunicationObjectAbortedException(entityClosedOrAborted, innerException1), null); } catch (Exception exception1) { if (this.bufferToReturn != null) { this.outputChannel.ChannelFactory.BufferManager.ReturnBuffer(this.bufferToReturn); } throw; } }
private static bool OnSendComplete(IAsyncResult result) { bool flag; bool flag1; bool flag2; ServiceBusOutputChannel.SendAsyncResult asyncState = (ServiceBusOutputChannel.SendAsyncResult)result.AsyncState; try { try { asyncState.outputChannel.MessageSender.EndSend(result); flag2 = true; } catch (MessagingException messagingException) { CommunicationException communicationException = MessagingExceptionHelper.ConvertToCommunicationException(messagingException, out flag); if (flag) { asyncState.outputChannel.Fault(); } throw Microsoft.ServiceBus.Messaging.FxTrace.Exception.AsError(communicationException, null); } catch (OperationCanceledException operationCanceledException1) { OperationCanceledException operationCanceledException = operationCanceledException1; MessagingException innerException = operationCanceledException.InnerException as MessagingException; if (innerException != null) { MessagingExceptionHelper.ConvertToCommunicationException(innerException, out flag1); if (flag1) { asyncState.outputChannel.Fault(); } } ExceptionTrace exception = Microsoft.ServiceBus.Messaging.FxTrace.Exception; string entityClosedOrAborted = SRClient.EntityClosedOrAborted; Exception innerException1 = operationCanceledException.InnerException; if (innerException1 == null) { innerException1 = operationCanceledException; } throw exception.AsError(new CommunicationObjectAbortedException(entityClosedOrAborted, innerException1), null); } } finally { if (asyncState.bufferToReturn != null) { asyncState.outputChannel.ChannelFactory.BufferManager.ReturnBuffer(asyncState.bufferToReturn); } } return(flag2); }
protected override void OnEndClose(IAsyncResult result) { try { this.MessagingFactory.EndClose(result); } catch (MessagingException messagingException1) { MessagingException messagingException = messagingException1; throw Microsoft.ServiceBus.Messaging.FxTrace.Exception.AsError(this.ConvertException(messagingException), null); } catch (OperationCanceledException operationCanceledException1) { OperationCanceledException operationCanceledException = operationCanceledException1; ExceptionTrace exception = Microsoft.ServiceBus.Messaging.FxTrace.Exception; string entityClosedOrAborted = SRClient.EntityClosedOrAborted; Exception innerException = operationCanceledException.InnerException; if (innerException == null) { innerException = operationCanceledException; } throw exception.AsError(new CommunicationObjectAbortedException(entityClosedOrAborted, innerException), null); } }
public void Send(Message message, TimeSpan timeout) { bool flag; bool flag1; if (message == null) { throw Microsoft.ServiceBus.Messaging.FxTrace.Exception.ArgumentNull("message"); } TimeoutHelper.ThrowIfNegativeArgument(timeout); base.ThrowIfDisposedOrNotOpen(); this.AddHeadersTo(message); this.TraceSendingMessage(message); byte[] numArray = null; BrokeredMessage brokerMessage = null; try { try { brokerMessage = this.ConvertToBrokerMessage(message, out numArray); this.MessageSender.Send(new BrokeredMessage[] { brokerMessage }, timeout); } catch (MessagingException messagingException) { CommunicationException communicationException = MessagingExceptionHelper.ConvertToCommunicationException(messagingException, out flag); if (flag) { base.Fault(); } throw Microsoft.ServiceBus.Messaging.FxTrace.Exception.AsError(communicationException, null); } catch (OperationCanceledException operationCanceledException1) { OperationCanceledException operationCanceledException = operationCanceledException1; MessagingException innerException = operationCanceledException.InnerException as MessagingException; if (innerException != null) { MessagingExceptionHelper.ConvertToCommunicationException(innerException, out flag1); if (flag1) { base.Fault(); } } ExceptionTrace exception = Microsoft.ServiceBus.Messaging.FxTrace.Exception; string entityClosedOrAborted = SRClient.EntityClosedOrAborted; Exception innerException1 = operationCanceledException.InnerException; if (innerException1 == null) { innerException1 = operationCanceledException; } throw exception.AsError(new CommunicationObjectAbortedException(entityClosedOrAborted, innerException1), null); } } finally { if (brokerMessage != null && numArray != null) { this.ChannelFactory.BufferManager.ReturnBuffer(numArray); } } }
private void Initialize(bool useWebStream, bool useHttpsWebStream, IEnumerable <Uri> baseAddresses) { List <Uri> uris = new List <Uri>(); foreach (Uri baseAddress in baseAddresses) { if (base.Address == null) { base.Address = baseAddress; } UriBuilder uriBuilder = new UriBuilder(baseAddress); if (!this.Settings.GatewayMode && string.Compare(uriBuilder.Scheme, "sb", StringComparison.OrdinalIgnoreCase) != 0) { ExceptionTrace exception = Microsoft.ServiceBus.Messaging.FxTrace.Exception; string invalidUriScheme = Resources.InvalidUriScheme; object[] scheme = new object[] { uriBuilder.Scheme, "sb" }; throw exception.AsError(new ArgumentException(Microsoft.ServiceBus.SR.GetString(invalidUriScheme, scheme)), null); } if (!useWebStream) { uriBuilder.Scheme = SbmpProtocolDefaults.TransportUriScheme; } else { uriBuilder.Scheme = "sb"; uriBuilder.Port = (useHttpsWebStream ? RelayEnvironment.RelayHttpsPort : RelayEnvironment.RelayHttpPort); } if (!this.Settings.GatewayMode && uriBuilder.Port == -1) { if (!useWebStream) { uriBuilder.Port = RelayEnvironment.RelayNmfPort; } else { uriBuilder.Port = (useHttpsWebStream ? RelayEnvironment.RelayHttpsPort : RelayEnvironment.RelayHttpPort); } } MessagingUtilities.EnsureTrailingSlash(uriBuilder); uris.Add(uriBuilder.Uri); } this.baseAddresses = null; this.BaseAddress = uris.First <Uri>(); bool useSslStreamSecurity = this.Settings.UseSslStreamSecurity; CustomBinding customBinding = SbmpProtocolDefaults.CreateBinding(false, useWebStream, useHttpsWebStream, 2147483647, useSslStreamSecurity, this.Settings.EndpointIdentity); DuplexRequestBindingElement duplexRequestBindingElement = new DuplexRequestBindingElement() { ClientMode = !this.Settings.GatewayMode, IncludeExceptionDetails = true }; DuplexRequestBindingElement duplexRequestBindingElement1 = duplexRequestBindingElement; int num = 0; if (!this.Settings.GatewayMode) { RedirectBindingElement redirectBindingElement = new RedirectBindingElement() { EnableRedirect = this.Settings.EnableRedirect, UseSslStreamSecurity = useSslStreamSecurity, IncludeExceptionDetails = true, EndpointIdentity = this.Settings.EndpointIdentity }; RedirectBindingElement redirectBindingElement1 = redirectBindingElement; int num1 = num; num = num1 + 1; customBinding.Elements.Insert(num1, new ReconnectBindingElement(uris)); int num2 = num; num = num2 + 1; customBinding.Elements.Insert(num2, redirectBindingElement1); } int num3 = num; num = num3 + 1; customBinding.Elements.Insert(num3, new ReconnectBindingElement(uris)); int num4 = num; num = num4 + 1; customBinding.Elements.Insert(num4, duplexRequestBindingElement1); BindingParameterCollection bindingParameterCollection = new BindingParameterCollection(); if (useSslStreamSecurity) { ClientCredentials clientCredential = new ClientCredentials(); clientCredential.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.Custom; clientCredential.ServiceCertificate.Authentication.CustomCertificateValidator = RetriableCertificateValidator.Instance; bindingParameterCollection.Add(clientCredential); } this.ChannelFactory = customBinding.BuildChannelFactory <IRequestSessionChannel>(bindingParameterCollection); this.MessageVersion = customBinding.MessageVersion; this.ResourceManager = SbmpResourceManager.Instance; this.acceptMessageSessionForNamespaceLinkSettings = new CreateControlLinkSettings(this, string.Empty, "||", MessagingEntityType.Namespace, null); EventHandler eventHandler = new EventHandler(this.OnInnerFactoryFaulted); this.ChannelFactory.SafeAddFaulted(eventHandler); }
private void CreateSession(out Uri endpointLocation1, out Uri endpointLocation2) { WebStream.ProxyAuthMode[] proxyAuthModeArray = new WebStream.ProxyAuthMode[] { WebStream.ProxyAuthMode.None, WebStream.ProxyAuthMode.Kerberos, WebStream.ProxyAuthMode.Ntlm, WebStream.ProxyAuthMode.Other }; this.proxyAuthMode = WebStream.ProxyAuthMode.None; string empty = string.Empty; WebStream.ProxyAuthMode[] proxyAuthModeArray1 = proxyAuthModeArray; int num = 0; Label1: while (num < (int)proxyAuthModeArray1.Length) { WebStream.ProxyAuthMode proxyAuthMode = proxyAuthModeArray1[num]; switch (proxyAuthMode) { case WebStream.ProxyAuthMode.Kerberos: { if (empty.Contains("KERBEROS")) { break; } goto Label0; } case WebStream.ProxyAuthMode.Ntlm: { if (!empty.Contains("NTLM")) { goto Label0; } else { break; } } } try { HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(this.factoryEndpointUri); httpWebRequest.KeepAlive = false; httpWebRequest.Method = "POST"; httpWebRequest.ContentType = "text/plain"; httpWebRequest.Headers.Add("X-WSCREATE", this.webStreamRole); httpWebRequest.Headers.Add("X-PROCESS-AT", "http://schemas.microsoft.com/netservices/2009/05/servicebus/connect/roles/relay"); if (httpWebRequest.Proxy != null) { this.ConfigureProxy(httpWebRequest, proxyAuthMode); } httpWebRequest.ServicePoint.ConnectionLimit = 2048; using (Stream requestStream = httpWebRequest.GetRequestStream()) { using (StreamWriter streamWriter = new StreamWriter(requestStream, Encoding.UTF8)) { streamWriter.Write(string.Empty); streamWriter.Flush(); } } HttpWebResponse response = (HttpWebResponse)httpWebRequest.GetResponse(); if (response.StatusCode != HttpStatusCode.Created || response.Headers["X-WSENDPT1"] == null || response.Headers["X-WSENDPT2"] == null) { throw Fx.Exception.AsWarning(new CommunicationException(SRClient.FaultyEndpointResponse), null); } if (!Uri.TryCreate(response.Headers["X-WSENDPT1"], UriKind.Absolute, out endpointLocation1)) { throw Fx.Exception.AsWarning(new CommunicationException(SRClient.URIEndpoint), null); } if (!Uri.TryCreate(response.Headers["X-WSENDPT2"], UriKind.Absolute, out endpointLocation2)) { throw Fx.Exception.AsWarning(new CommunicationException(SRClient.URIEndpoint), null); } response.Close(); this.proxyAuthMode = proxyAuthMode; } catch (WebException webException1) { WebException webException = webException1; HttpWebResponse httpWebResponse = webException.Response as HttpWebResponse; if (httpWebResponse == null || httpWebResponse.StatusCode != HttpStatusCode.ProxyAuthenticationRequired) { string str = WebStream.CloseResponseInWebException(webException); throw Fx.Exception.AsWarning(new CommunicationException(string.Concat(SRClient.FactoryEndpoint, str), webException), null); } empty = httpWebResponse.Headers["Proxy-Authenticate"].ToUpperInvariant(); goto Label0; } catch (Exception exception1) { Exception exception = exception1; if (!Fx.IsFatal(exception)) { throw Fx.Exception.AsError(new CommunicationException(SRClient.FactoryEndpoint, exception), null); } throw; } return; } ExceptionTrace exceptionTrace = Fx.Exception; CultureInfo invariantCulture = CultureInfo.InvariantCulture; object[] objArray = new object[] { empty }; throw exceptionTrace.AsError(new CommunicationException(string.Format(invariantCulture, "Failed to authenticate with proxy supporting modes '{0}'.", objArray)), null); Label0: num++; goto Label1; }