Пример #1
0
 protected override void OnAbort()
 {
     if (_innerFactory != null)
     {
         _innerFactory.Abort();
     }
 }
Пример #2
0
 private static NetworkDetector.ConnectivityStatus CheckTcpConnectivity(Uri baseAddress, out Exception exception)
 {
     NetworkDetector.ConnectivityStatus connectivityStatu = NetworkDetector.ConnectivityStatus.Unavailable;
     exception = null;
     if (!RelayEnvironment.GetEnvironmentVariable("RELAYFORCEHTTP", false) && !RelayEnvironment.GetEnvironmentVariable("RELAYFORCEHTTPS", false))
     {
         try
         {
             BinaryMessageEncodingBindingElement binaryMessageEncodingBindingElement = new BinaryMessageEncodingBindingElement();
             TcpTransportBindingElement          tcpTransportBindingElement          = new TcpTransportBindingElement();
             tcpTransportBindingElement.ConnectionPoolSettings.MaxOutboundConnectionsPerEndpoint = 100;
             tcpTransportBindingElement.MaxReceivedMessageSize = (long)65536;
             CustomBinding customBinding = new CustomBinding();
             customBinding.Elements.Add(binaryMessageEncodingBindingElement);
             customBinding.Elements.Add(tcpTransportBindingElement);
             customBinding.OpenTimeout    = TimeSpan.FromSeconds(10);
             customBinding.SendTimeout    = TimeSpan.FromSeconds(10);
             customBinding.ReceiveTimeout = TimeSpan.MaxValue;
             int num = 9350;
             Uri uri = ServiceBusUriHelper.CreateServiceUri("net.tcp", string.Concat(baseAddress.DnsSafeHost, ":", num.ToString(CultureInfo.InvariantCulture)), "/");
             IChannelFactory <IDuplexSessionChannel> channelFactory = null;
             IDuplexSessionChannel duplexSessionChannel             = null;
             try
             {
                 channelFactory = customBinding.BuildChannelFactory <IDuplexSessionChannel>(new object[0]);
                 channelFactory.Open();
                 duplexSessionChannel = channelFactory.CreateChannel(new EndpointAddress(uri, new AddressHeader[0]));
                 duplexSessionChannel.Open();
                 Message message = Message.CreateMessage(MessageVersion.Default, "http://schemas.microsoft.com/netservices/2009/05/servicebus/connect/OnewayPing", new OnewayPingMessage());
                 duplexSessionChannel.Send(message, customBinding.SendTimeout);
                 duplexSessionChannel.Close();
                 duplexSessionChannel = null;
                 channelFactory.Close();
                 channelFactory = null;
             }
             finally
             {
                 if (duplexSessionChannel != null)
                 {
                     duplexSessionChannel.Abort();
                 }
                 if (channelFactory != null)
                 {
                     channelFactory.Abort();
                 }
             }
             connectivityStatu = NetworkDetector.ConnectivityStatus.Available;
         }
         catch (CommunicationException communicationException)
         {
             exception = communicationException;
         }
         catch (TimeoutException timeoutException)
         {
             exception = timeoutException;
         }
     }
     NetworkDetector.LogResult(baseAddress, "Tcp", connectivityStatu);
     return(connectivityStatu);
 }
Пример #3
0
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        /// <param name="disposing">Disposes of the channel factory if set to true.</param>
        /// <remarks>You should use this method when finished with an instance of <see cref="ServiceClient{TService}"/>.</remarks>
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (_channelFactory != null)
                {
                    try
                    {
                        if (_channelFactory.State != CommunicationState.Faulted)
                        {
                            _channelFactory.Close();
                        }
                        else
                        {
                            _channelFactory.Abort();
                        }
                    }
                    catch (CommunicationException)
                    {
                        if (_channelFactory != null)
                        {
                            _channelFactory.Abort();
                        }
                    }
                    catch (TimeoutException)
                    {
                        if (_channelFactory != null)
                        {
                            _channelFactory.Abort();
                        }
                    }
                    catch (Exception)
                    {
                        if (_channelFactory != null)
                        {
                            _channelFactory.Abort();
                        }

                        throw;
                    }
                    finally
                    {
                        _channelFactory = null;
                    }
                }
            }
        }
Пример #4
0
 protected override void OnAbort()
 {
     channel.Abort();
     if (factory != null)             // ... is it valid?
     {
         factory.Abort();
     }
 }
Пример #5
0
 protected override void OnAbort()
 {
     channel.Abort();
     if (factory != null)
     {
         factory.Abort();
     }
 }
Пример #6
0
        // CommunicationObject

        protected override void OnAbort()
        {
            if (client_factory != null)
            {
                client_factory.Abort();
                client_factory = null;
            }
            OnClose(TimeSpan.Zero);
        }
Пример #7
0
 public override void OnAbort()
 {
     if (_rstChannelFactory != null)
     {
         _rstChannelFactory.Abort();
         _rstChannelFactory = null;
     }
     base.OnAbort();
 }
Пример #8
0
        private void CloseChannelFactory(IChannelFactory channelFactory)
        {
            if (channelFactory == null)
            {
                return;
            }

            channelFactory.Close();
            channelFactory.Abort();
        }
Пример #9
0
        public new void Abort()
        {
            AbortListeners();

            foreach (IDuplexSessionChannel proxy in m_Proxies.Values)
            {
                try
                {
                    proxy.Abort();
                }
                catch
                {}
            }
            m_Factory.Abort();

            base.Abort();
        }
Пример #10
0
 public virtual void Dispose()
 {
     if (client != null)
     {
         try
         {
             ((ICommunicationObject)client).Close();
         }
         catch
         {
             try
             {
                 ((ICommunicationObject)client).Abort();
             }
             catch { }     // Die quietly.
         }
     }
     if (channelFactory != null)
     {
         try
         {
             channelFactory.Close();
         }
         catch
         {
             try
             {
                 channelFactory.Abort();
             }
             catch { }     // Die quietly.
         }
         channelFactory = null;
     }
     _endpointAddress = null;
     httpBinding      = null;
     tcpBinding       = null;
 }
Пример #11
0
        public static ServicoInfo Consultar(Type servicoInterface)
        {
            ServicoInfo info = null;

            try
            {
                LocalizadorCliente.MutexLocalizador.WaitOne();

                info = LocalizadorCliente.ServicoLocalizador.Consultar(servicoInterface.FullName);

                LocalizadorCliente.MutexLocalizador.ReleaseMutex();

                Desconectar();
            }
            catch (Exception ex)
            {
                logger.Error("Erro em LocalizadorCliente.Consultar()", ex);
                _canal.Abort();
                throw ex;
            }

            return(info);
        }
Пример #12
0
        static void Main(string[] args)
        {
            try
            {
                ParseArgs(args);
                Console.Title = "Message Sender";

                // Get credentials as Endpoint behavior
                TransportClientEndpointBehavior securityBehavior = new TransportClientEndpointBehavior();
                securityBehavior.TokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider(serviceBusKeyName, serviceBusKey);

                // Create factory and channel using NetMessagingBinding
                NetMessagingBinding messagingBinding = new NetMessagingBinding("messagingBinding");
                EndpointAddress     address          = SampleManager.GetEndpointAddress(SampleManager.SessionlessQueueName, serviceBusNamespace);

                IChannelFactory <IOutputChannel> messagingChannelFactory = null;
                IOutputChannel messagingOutputChannel = null;
                try
                {
                    messagingChannelFactory = messagingBinding.BuildChannelFactory <IOutputChannel>(securityBehavior);
                    messagingChannelFactory.Open();
                    messagingOutputChannel = messagingChannelFactory.CreateChannel(address);
                    messagingOutputChannel.Open();

                    // Send messages to queue which does not require session
                    Console.WriteLine("Preparing to send messages to {0}...", SampleManager.SessionlessQueueName);
                    Thread.Sleep(3000);

                    SendMessages(messagingOutputChannel, messagingBinding);
                    messagingOutputChannel.Close();
                    messagingChannelFactory.Close();
                }
                catch (Exception)
                {
                    if (messagingOutputChannel != null)
                    {
                        messagingOutputChannel.Abort();
                    }
                    if (messagingChannelFactory != null)
                    {
                        messagingChannelFactory.Abort();
                    }
                    throw;
                }

                // Wait for all receivers to receive message
                Thread.Sleep(TimeSpan.FromSeconds(5.0d));
                Console.Clear();

                // Create factory and channel using custom binding
                CustomBinding customBinding = new CustomBinding("customBinding");
                address = SampleManager.GetEndpointAddress(SampleManager.SessionQueueName, serviceBusNamespace);

                IChannelFactory <IOutputChannel> customChannelFactory = null;
                IOutputChannel customOutputChannel = null;
                try
                {
                    customChannelFactory = customBinding.BuildChannelFactory <IOutputChannel>(securityBehavior);
                    customChannelFactory.Open();
                    customOutputChannel = customChannelFactory.CreateChannel(address);
                    customOutputChannel.Open();

                    // Send messages to queue which requires session
                    Console.Title = "Session MessageSender";
                    Console.WriteLine("Preparing to send messages to {0}...", SampleManager.SessionQueueName);
                    Thread.Sleep(3000);

                    SendMessages(customOutputChannel, customBinding);
                    customOutputChannel.Close();
                    customChannelFactory.Close();
                }
                catch (Exception)
                {
                    if (customOutputChannel != null)
                    {
                        customOutputChannel.Abort();
                    }
                    if (customChannelFactory != null)
                    {
                        customChannelFactory.Abort();
                    }
                    throw;
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine("Exception Occurred: {0}", exception);
                SampleManager.ExceptionOccurred = true;
            }

            // All messages sent
            Console.WriteLine("\nSender complete. Press [Enter] to exit.");
            Console.ReadLine();
        }
Пример #13
0
 protected override void OnAbort()
 {
     base.OnAbort();
     _innerChannelFactory.Abort();
 }
Пример #14
0
 protected override void OnAbort()
 {
     innerFactory.Abort();
 }
Пример #15
0
 public void Abort()
 {
     _innerChannelFactory.Abort();
 }
Пример #16
0
 protected override void OnAbort()
 {
     inner.Abort();
 }
Пример #17
0
        public IDisposable Start()
        {
            ConnectionRateMonitor monitor = new ConnectionRateMonitor();
            var connections = new Task[_connections];

            for (int i = 0; i < _connections; i++)
            {
                var channel  = _factory.CreateChannel(_address);
                var openTask = Task.Factory.FromAsync(channel.BeginOpen, channel.EndOpen, null);
                openTask.ContinueWith(_ => monitor.OnConnect());
                _channels.Enqueue(channel);
                connections[i] = openTask;
            }

            Task.WaitAll(connections);

            double        backlog     = 0;
            double        currentRate = 0;
            AsyncCallback cb          = (iar) =>
            {
                IDuplexSessionChannel channel = (IDuplexSessionChannel)iar.AsyncState;
                backlog = monitor.OnMessageEnd();
                monitor.OnMessage();
                channel.EndSend(iar);
            };

            var load = Observable.Interval(TimeSpan.FromMilliseconds(1000))
                       .TakeWhile(_ => !_isDisposed)
                       .Where(_ => backlog <= _rate)
                       .Subscribe(async _ =>
            {
                int pending = _rate;

                Action action = () =>
                {
                    //Console.WriteLine("Thread ID" + System.Threading.Thread.CurrentThread.ManagedThreadId);
                    while (Interlocked.Decrement(ref pending) >= 0)
                    {
                        var channel = GetNextChannel();
                        monitor.OnMessageStart();
                        var iar = channel.BeginSend(_messageBuffer.CreateMessage(), cb, channel);
                    }
                };

                Parallel.Invoke(
                    new ParallelOptions()
                {
                    MaxDegreeOfParallelism = Environment.ProcessorCount * 4,
                },
                    action, action, action, action,
                    action, action, action, action
                    );
            },
                                  ex => Console.WriteLine(ex.Message + " \n" + ex.StackTrace));

            var ratemonitor = monitor.Start();

            return(Disposable.Create(() =>
            {
                // Terminate the timer as well.
                _isDisposed = true;
                load.Dispose();
                ratemonitor.Dispose();

                lock (ThisLock)
                {
                    while (_channels.Count > 0)
                    {
                        var c = _channels.Dequeue();
                        c.Abort();
                    }

                    _factory.Abort();
                }
            }));
        }