void Cleanup(bool aborting, TimeSpan timeout)
        {
            lock (ThisLock)
            {
                if (listener != null)
                {
                    if (!aborting)
                    {
                        listener.Stop(timeout);
                    }
                    else
                    {
                        listener.Abort();
                    }

                    // The listener will be closed by the demuxer.
                    listener = null;
                }

                if (connectionDemuxer != null)
                {
                    connectionDemuxer.Dispose();
                }

                demuxerCreated = false;
                settingsApplied = false;
            }
        }
        protected void CleanUp(bool aborting, TimeSpan timeout)
        {
            lock (ThisLock)
            {
                if (listener != null)
                {
                    if (!aborting)
                    {
                        listener.Stop(timeout);
                    }
                    else
                    {
                        listener.Abort();
                    }

                    // The listener will be closed by the demuxer.
                    listener = null;
                }

                if (connectionDemuxer != null)
                {
                    connectionDemuxer.Dispose();
                }

                demuxerCreated = false;
            }
        }
        protected void CleanUp(bool aborting, TimeSpan timeout)
        {
            // We need to be able to call Stop/Abort without acquiring ThisLock.  Otherwise there's a deadlock with OnDuplicatedVia()

            SharedConnectionListener currentListener = Interlocked.Exchange <SharedConnectionListener>(ref this.listener, null);

            if (currentListener != null)
            {
                if (!aborting)
                {
                    currentListener.Stop(timeout);
                }
                else
                {
                    currentListener.Abort();
                }
            }

            lock (ThisLock)
            {
                if (connectionDemuxer != null && demuxerCreated)
                {
                    connectionDemuxer.Dispose();
                }

                demuxerCreated = false;
            }
        }
 private void CreateConnectionDemuxer()
 {
     IConnectionListener listener = new BufferedConnectionListener(this.listener, base.MaxOutputDelay, base.ConnectionBufferSize);
     if (DiagnosticUtility.ShouldUseActivity)
     {
         listener = new TracingConnectionListener(listener, base.ListenUri);
     }
     this.connectionDemuxer = new ConnectionDemuxer(listener, base.MaxPendingAccepts, base.MaxPendingConnections, base.ChannelInitializationTimeout, base.IdleTimeout, base.MaxPooledConnections, new TransportSettingsCallback(this.OnGetTransportFactorySettings), new SingletonPreambleDemuxCallback(this.OnGetSingletonMessageHandler), new ServerSessionPreambleDemuxCallback(this.OnHandleServerSessionPreamble), new System.ServiceModel.Channels.ErrorCallback(this.OnDemuxerError));
     this.connectionDemuxer.StartDemuxing(this.onViaCallback);
 }
        private void CreateConnectionDemuxer()
        {
            IConnectionListener listener = new BufferedConnectionListener(this.listener, base.MaxOutputDelay, base.ConnectionBufferSize);

            if (DiagnosticUtility.ShouldUseActivity)
            {
                listener = new TracingConnectionListener(listener, this.ListenUri);
            }
            this.connectionDemuxer = new ConnectionDemuxer(listener, base.MaxPendingAccepts, base.MaxPendingConnections, base.ChannelInitializationTimeout, base.IdleTimeout, base.MaxPooledConnections, new TransportSettingsCallback(this.OnGetTransportFactorySettings), new SingletonPreambleDemuxCallback(this.OnGetSingletonMessageHandler), new ServerSessionPreambleDemuxCallback(this.OnHandleServerSessionPreamble), new System.ServiceModel.Channels.ErrorCallback(this.OnDemuxerError));
            this.connectionDemuxer.StartDemuxing(this.GetOnViaCallback());
        }
 public SharedListenerProxy(SharedConnectionListener parent)
 {
     this.parent                  = parent;
     this.baseAddress             = parent.baseAddress;
     this.queueId                 = parent.queueId;
     this.token                   = parent.token;
     this.onDuplicatedViaCallback = parent.onDuplicatedViaCallback;
     this.isTcp                   = parent.baseAddress.BaseAddress.Scheme.Equals(Uri.UriSchemeNetTcp);
     this.securityEventName       = Guid.NewGuid().ToString();
     this.serviceName             = SharedConnectionListener.GetServiceName(this.isTcp);
 }
 internal void OnOpenInternal(int queueId, Guid token)
 {
     lock (base.ThisLock)
     {
         this.queueId = queueId;
         this.token   = token;
         BaseUriWithWildcard baseAddress = new BaseUriWithWildcard(this.ListenUri, this.HostNameComparisonMode);
         if (this.onDuplicatedViaCallback == null)
         {
             this.onDuplicatedViaCallback = new Func <Uri, int>(this.OnDuplicatedVia);
         }
         this.listener = new SharedConnectionListener(baseAddress, queueId, token, this.onDuplicatedViaCallback);
     }
 }
        internal void OnOpenInternal(int queueId, Guid token)
        {
            lock (ThisLock)
            {
                this.queueId = queueId;
                this.token   = token;

                BaseUriWithWildcard path = new BaseUriWithWildcard(this.ListenUri, this.HostNameComparisonMode);

                if (this.onDuplicatedViaCallback == null)
                {
                    this.onDuplicatedViaCallback = new Func <Uri, int>(OnDuplicatedVia);
                }

                listener = new SharedConnectionListener(path, queueId, token, this.onDuplicatedViaCallback);

                // Delay the creation of the demuxer on the first request.
            }
        }
        void CreateConnectionDemuxer(SharedConnectionListener sharedListener)
        {
            IConnectionListener connectionListener = new BufferedConnectionListener(sharedListener, MaxOutputDelay, ConnectionBufferSize);

            if (DiagnosticUtility.ShouldUseActivity)
            {
                connectionListener = new TracingConnectionListener(connectionListener, this.ListenUri);
            }

            connectionDemuxer = new ConnectionDemuxer(connectionListener,
                                                      MaxPendingAccepts, MaxPendingConnections, ChannelInitializationTimeout,
                                                      IdleTimeout, MaxPooledConnections,
                                                      OnGetTransportFactorySettings,
                                                      OnGetSingletonMessageHandler,
                                                      OnHandleServerSessionPreamble,
                                                      OnDemuxerError);

            connectionDemuxer.StartDemuxing(this.GetOnViaCallback());
        }
 protected void CleanUp(bool aborting, TimeSpan timeout)
 {
     lock (base.ThisLock)
     {
         if (this.listener != null)
         {
             if (!aborting)
             {
                 this.listener.Stop(timeout);
             }
             else
             {
                 this.listener.Abort();
             }
             this.listener = null;
         }
         if (this.connectionDemuxer != null)
         {
             this.connectionDemuxer.Dispose();
         }
         this.demuxerCreated = false;
     }
 }
 protected void CleanUp(bool aborting, TimeSpan timeout)
 {
     lock (base.ThisLock)
     {
         if (this.listener != null)
         {
             if (!aborting)
             {
                 this.listener.Stop(timeout);
             }
             else
             {
                 this.listener.Abort();
             }
             this.listener = null;
         }
         if (this.connectionDemuxer != null)
         {
             this.connectionDemuxer.Dispose();
         }
         this.demuxerCreated = false;
     }
 }
 public TcpValidatingConnection(IConnection connection, SharedConnectionListener.SharedListenerProxy listenerProxy) : base(connection)
 {
     this.listenerProxy = listenerProxy;
     Socket coreTransport = (Socket) connection.GetCoreTransport();
     this.ipAddress = ((IPEndPoint) coreTransport.LocalEndPoint).Address;
     this.port = ((IPEndPoint) coreTransport.LocalEndPoint).Port;
     this.initialValidation = true;
 }
            private string HandleServiceStart(bool isReconnecting)
            {
                string listenerEndpoint = null;
                string str4;
                string sharedMemoryName = this.isTcp ? "NetTcpPortSharing/endpoint" : "NetPipeActivator/endpoint";

                this.serviceName = SharedConnectionListener.GetServiceName(this.isTcp);
                if (!isReconnecting && this.ReadEndpoint(sharedMemoryName, out listenerEndpoint))
                {
                    return(listenerEndpoint);
                }
                ServiceController service = new ServiceController(this.serviceName);

                try
                {
                    ServiceControllerStatus status = service.Status;
                    if (isReconnecting && (status == ServiceControllerStatus.Running))
                    {
                        try
                        {
                            string str3 = SharedMemory.Read(sharedMemoryName);
                            if (this.listenerEndPoint != str3)
                            {
                                return(str3);
                            }
                        }
                        catch (Win32Exception exception)
                        {
                            if (DiagnosticUtility.ShouldTraceWarning)
                            {
                                DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Warning);
                            }
                        }
                        status = this.ExitServiceStatus(service, 50, 50, ServiceControllerStatus.Running);
                    }
                    if (status == ServiceControllerStatus.Running)
                    {
                        goto Label_021B;
                    }
                    if (!isReconnecting)
                    {
                        try
                        {
                            service.Start();
                            goto Label_01FD;
                        }
                        catch (InvalidOperationException exception2)
                        {
                            Win32Exception innerException = exception2.InnerException as Win32Exception;
                            if (innerException == null)
                            {
                                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(System.ServiceModel.SR.GetString("SharedManagerBase", new object[] { this.serviceName, System.ServiceModel.SR.GetString("SharedManagerServiceStartFailureNoError") }), exception2));
                            }
                            if (innerException.NativeErrorCode == 0x422)
                            {
                                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(System.ServiceModel.SR.GetString("SharedManagerBase", new object[] { this.serviceName, System.ServiceModel.SR.GetString("SharedManagerServiceStartFailureDisabled", new object[] { this.serviceName }) }), exception2));
                            }
                            if (innerException.NativeErrorCode != 0x420)
                            {
                                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(System.ServiceModel.SR.GetString("SharedManagerBase", new object[] { this.serviceName, System.ServiceModel.SR.GetString("SharedManagerServiceStartFailure", new object[] { innerException.NativeErrorCode }) }), exception2));
                            }
                            goto Label_01FD;
                        }
                    }
                    switch (status)
                    {
                    case ServiceControllerStatus.StopPending:
                        status = this.ExitServiceStatus(service, 50, 0x3e8, status);
                        break;

                    case ServiceControllerStatus.Stopped:
                        status = this.ExitServiceStatus(service, 50, 0x3e8, status);
                        break;
                    }
Label_01FD:
                    service.Refresh();
                    status = service.Status;
                    if (status == ServiceControllerStatus.StartPending)
                    {
                        status = this.ExitServiceStatus(service, 50, 50, ServiceControllerStatus.StartPending);
                    }
Label_021B:
                    if (status != ServiceControllerStatus.Running)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(System.ServiceModel.SR.GetString("SharedManagerBase", new object[] { this.serviceName, System.ServiceModel.SR.GetString("SharedManagerServiceStartFailureNoError") })));
                    }
                }
                finally
                {
                    service.Close();
                }
                try
                {
                    str4 = SharedMemory.Read(sharedMemoryName);
                }
                catch (Win32Exception exception4)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(this.WrapEndpointReadingException(exception4));
                }
                return(str4);
            }
 public SharedListenerProxy(SharedConnectionListener parent)
 {
     this.parent = parent;
     this.baseAddress = parent.baseAddress;
     this.queueId = parent.queueId;
     this.token = parent.token;
     this.onDuplicatedViaCallback = parent.onDuplicatedViaCallback;
     this.isTcp = parent.baseAddress.BaseAddress.Scheme.Equals(Uri.UriSchemeNetTcp);
     this.securityEventName = Guid.NewGuid().ToString();
     this.serviceName = SharedConnectionListener.GetServiceName(this.isTcp);
 }
 private void OnOpenInternal(int queueId, Guid token)
 {
     lock (base.ThisLock)
     {
         this.queueId = queueId;
         this.token = token;
         BaseUriWithWildcard baseAddress = new BaseUriWithWildcard(base.ListenUri, base.HostNameComparisonMode);
         this.listener = new SharedConnectionListener(baseAddress, queueId, token, this.onDuplicatedViaCallback);
     }
 }
        internal void OnOpenInternal(int queueId, Guid token)
        {
            lock (ThisLock)
            {
                this.queueId = queueId;
                this.token = token;

                BaseUriWithWildcard path = new BaseUriWithWildcard(this.ListenUri, this.HostNameComparisonMode);

                if (this.onDuplicatedViaCallback == null)
                {
                    this.onDuplicatedViaCallback = new Func<Uri, int>(OnDuplicatedVia);
                }

                listener = new SharedConnectionListener(path, queueId, token, this.onDuplicatedViaCallback);

                // Delay the creation of the demuxer on the first request.
            }
        }
 public NamedPipeValidatingConnection(IConnection connection, SharedConnectionListener.SharedListenerProxy listenerProxy) : base(connection)
 {
     this.listenerProxy = listenerProxy;
     this.initialValidation = true;
 }
 public SharedListenerProxyBehavior(SharedConnectionListener.SharedListenerProxy proxy)
 {
     this.proxy = proxy;
 }
        void OnOpenInternal(int queueId, Guid token)
        {
            lock (ThisLock)
            {
                this.queueId = queueId;
                this.token = token;

                BaseUriWithWildcard path = new BaseUriWithWildcard(this.ListenUri, this.HostNameComparisonMode);

                listener = new SharedConnectionListener(path, queueId, token, this.onDuplicatedViaCallback);
            }
        }
 internal void OnOpenInternal(int queueId, Guid token)
 {
     lock (base.ThisLock)
     {
         this.queueId = queueId;
         this.token = token;
         BaseUriWithWildcard baseAddress = new BaseUriWithWildcard(this.ListenUri, this.HostNameComparisonMode);
         if (this.onDuplicatedViaCallback == null)
         {
             this.onDuplicatedViaCallback = new Func<Uri, int>(this.OnDuplicatedVia);
         }
         this.listener = new SharedConnectionListener(baseAddress, queueId, token, this.onDuplicatedViaCallback);
     }
 }