Ejemplo n.º 1
0
        // options would go here if there were any

        public static Binding BuildBinding(BindingInformation info, ServerConnectionInformation server)
        {
            var binding = new NetTcpBinding(SecurityMode.Transport, false);

            binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows;

            return(binding);
        }
Ejemplo n.º 2
0
        private void WorkerThread()
        {
            try
            {
                while (true)
                {
                    _resetEvent.Reset();
                    _reconnectEvent.Reset();

                    if (_factory == null)
                    {
                        EndpointAddress endpoint = EndpointInformation.BuildEndpoint(new EndpointInformation(), _serverInfo, typeof(T));
                        Binding         binding  = BindingInformation.BuildBinding(new BindingInformation(), _serverInfo);
                        if (_callback != null)
                        {
                            _factory = new DuplexChannelFactory <T>(_callback, binding, endpoint);
                        }
                        else
                        {
                            _factory = new ChannelFactory <T>(binding, endpoint);
                        }
                    }

                    if (_factory.State != CommunicationState.Opened)
                    {
                        try
                        {
                            _factory.Open();
                            Channel = _factory.CreateChannel();
                            Channel.Ping();
                            ((ICommunicationObject)Channel).Closed  += Channel_Closed;
                            ((ICommunicationObject)Channel).Faulted += Channel_Closed;
                            lock (_stateLock)
                            {
                                State = SubscriptionState.Connected;
                            }
                            if (Connected != null)
                            {
                                Connected(this);
                            }
                        }
                        catch (ThreadAbortException)
                        {
                        }
                        catch (Exception ex)
                        {
                            _lastException = ex;
                            OnDisconnect(ex);
                        }
                    }
                    else
                    {
                        _resetEvent.WaitOne(300000);
                        try
                        {
                            Channel.Ping();
                        }
                        catch (ThreadAbortException) { }
                        catch (Exception ex)
                        {
                            _lastException = ex;
                            OnDisconnect(ex);
                        }
                    }

                    switch (WaitHandle.WaitAny(new WaitHandle[] { _resetEvent, _reconnectEvent }, 15000))
                    {
                    case WaitHandle.WaitTimeout: break;

                    case 0: break;

                    case 1:
                    {
                        Cleanup();
                        lock (_stateLock)
                        {
                            State = SubscriptionState.Connecting;
                        }
                    }
                    break;
                    }
                }
            }
            finally
            {
                Cleanup();
            }
        }