コード例 #1
0
 public void Setup()
 {
     _connectionInitiator   = Substitute.For <IConnectionInitiator>();
     _previousSessionOpener = new PreviousSessionOpener(_connectionInitiator);
     _connectionTree        = Substitute.For <IConnectionTree>();
     _connectionTree.GetRootConnectionNode().Returns(BuildTree());
 }
コード例 #2
0
        public void reconnectAll(IConnectionInitiator initiator)
        {
            var controlList = new List <InterfaceControl>();

            try
            {
                foreach (var dockContent in connDock.DocumentsToArray())
                {
                    var tab = (ConnectionTab)dockContent;
                    controlList.Add((InterfaceControl)tab.Tag);
                }

                foreach (var iControl in controlList)
                {
                    iControl.Protocol.Close();
                    initiator.OpenConnection(iControl.Info, ConnectionInfo.Force.DoNotJump);
                }
            }
            catch (Exception ex)
            {
                Runtime.MessageCollector.AddExceptionMessage("reconnectAll (UI.Window.ConnectionWindow) failed", ex);
            }

            // ReSharper disable once RedundantAssignment
            controlList = null;
        }
コード例 #3
0
 public DuplexConnectionPoolHelper(ClientFramingDuplexSessionChannel channel,
                                   ConnectionPool connectionPool, IConnectionInitiator connectionInitiator)
     : base(connectionPool, connectionInitiator, channel.Via)
 {
     _channel  = channel;
     _preamble = channel.CreatePreamble();
 }
コード例 #4
0
 public StreamedFramingRequestChannel(ChannelManagerBase factory, IConnectionOrientedTransportChannelFactorySettings settings, EndpointAddress remoteAddresss, Uri via, IConnectionInitiator connectionInitiator, ConnectionPool connectionPool) : base(factory, remoteAddresss, via, settings.ManualAddressing)
 {
     this.settings            = settings;
     this.connectionInitiator = connectionInitiator;
     this.connectionPool      = connectionPool;
     this.messageEncoder      = settings.MessageEncoderFactory.Encoder;
     this.upgrade             = settings.Upgrade;
 }
コード例 #5
0
 public OpenConnectionClickHandler(IConnectionInitiator connectionInitiator)
 {
     if (connectionInitiator == null)
     {
         throw new ArgumentNullException(nameof(connectionInitiator));
     }
     _connectionInitiator = connectionInitiator;
 }
 public StreamedFramingRequestChannel(ChannelManagerBase factory, IConnectionOrientedTransportChannelFactorySettings settings, EndpointAddress remoteAddresss, Uri via, IConnectionInitiator connectionInitiator, ConnectionPool connectionPool) : base(factory, remoteAddresss, via, settings.ManualAddressing)
 {
     this.settings = settings;
     this.connectionInitiator = connectionInitiator;
     this.connectionPool = connectionPool;
     this.messageEncoder = settings.MessageEncoderFactory.Encoder;
     this.upgrade = settings.Upgrade;
 }
コード例 #7
0
 public PreviousSessionOpener(IConnectionInitiator connectionInitiator)
 {
     if (connectionInitiator == null)
     {
         throw new ArgumentNullException(nameof(connectionInitiator));
     }
     _connectionInitiator = connectionInitiator;
 }
コード例 #8
0
        public ConnectionTree()
        {
            InitializeComponent();
            SetupConnectionTreeView();
            UseOverlays = false;

            _connectionInitiator = new ConnectionInitiator();
        }
コード例 #9
0
        /// <summary>
        /// Block the calling thread until the EventDispatcher Queue is empty
        /// and all outstanding tasks have been executed.
        /// </summary>
        public virtual void DrainEvents()
        {
            IConnectionInitiator initiator = Initiator;

            if (initiator is Initiator)
            {
                ((Initiator)initiator).DrainEvents();
            }
        }
コード例 #10
0
        /// <summary>
        /// The <see cref="RemoteService.Configure"/> implementation method.
        /// </summary>
        /// <remarks>
        /// This method must only be called by a thread that has synchronized
        /// on this RemoteService.
        /// </remarks>
        /// <param name="xml">
        /// The <b>IXmlElement</b> containing the new configuration for this
        /// RemoteService.
        /// </param>
        protected override void DoConfigure(IXmlElement xml)
        {
            base.DoConfigure(xml);

            // register all Protocols
            IConnectionInitiator initiator = Initiator;

            initiator.RegisterProtocol(InvocationServiceProtocol.Instance);
        }
コード例 #11
0
        /// <summary>
        /// Return <b>true</b> if the current thread is one of the service
        /// threads.
        /// </summary>
        /// <param name="isStrict">
        /// If <b>true</b> then only the service thread and event dispatcher
        /// thread are considered to be service threads, if <b>false</b>,
        /// then <b>DaemonPool</b> threads are also considered to be service
        /// threads.
        /// </param>
        public virtual bool IsServiceThread(bool isStrict)
        {
            IConnectionInitiator initiator = Initiator;

            if (initiator is Initiator)
            {
                return(((Initiator)initiator).IsServiceThread(isStrict));
            }
            return(false);
        }
コード例 #12
0
 public ConnectionContextMenu(ConnectionTree connectionTree)
 {
     _connectionTree      = connectionTree;
     _connectionInitiator = new ConnectionInitiator();
     InitializeComponent();
     ApplyLanguage();
     EnableShortcutKeys();
     Opening += (sender, args) =>
     {
         AddExternalApps();
         ShowHideMenuItems();
     };
     Closing += (sender, args) => EnableMenuItemsRecursive(Items);
 }
コード例 #13
0
        /// <summary>
        /// The <see cref="RemoteService.Configure"/> implementation method.
        /// </summary>
        /// <remarks>
        /// This method must only be called by a thread that has synchronized
        /// on this RemoteService.
        /// </remarks>
        /// <param name="xml">
        /// The <see cref="IXmlElement"/> containing the new configuration
        /// for this RemoteService.
        /// </param>
        protected override void DoConfigure(IXmlElement xml)
        {
            base.DoConfigure(xml);

            DeferKeyAssociationCheck =
                xml.GetSafeElement("defer-key-association-check")
                .GetBoolean(DeferKeyAssociationCheck);

            // register all Protocols
            IConnectionInitiator initiator = Initiator;

            initiator.RegisterProtocol(CacheServiceProtocol.Instance);
            initiator.RegisterProtocol(NamedCacheProtocol.Instance);
        }
コード例 #14
0
        /// <summary>
        /// The <see cref="RemoteService.Configure"/> implementation method.
        /// </summary>
        /// <remarks>
        /// This method must only be called by a thread that has synchronized
        /// on this RemoteService.
        /// </remarks>
        /// <param name="xml">
        /// The <b>IXmlElement</b> containing the new configuration for this
        /// RemoteService.
        /// </param>
        protected override void DoConfigure(IXmlElement xml)
        {
            base.DoConfigure(xml);

            // register all Protocols
            IConnectionInitiator initiator = Initiator;

            initiator.RegisterProtocol(NameServiceProtocol.Instance);

            if (initiator is Initiator)
            {
                // always use POF for NameService requests
                ((Initiator)initiator).SerializerFactory = this;
            }
        }
コード例 #15
0
 public ConnectionContextMenu(ConnectionTree connectionTree)
 {
     _connectionTree      = connectionTree;
     _connectionInitiator = new ConnectionInitiator();
     InitializeComponent();
     ApplyLanguage();
     EnableShortcutKeys();
     Opening += (sender, args) =>
     {
         AddExternalApps();
         if (_connectionTree.SelectedNode == null)
         {
             args.Cancel = true;
             return;
         }
         ShowHideMenuItems();
     };
 }
コード例 #16
0
        /// <summary>
        /// The <see cref="Configure"/> implementation method.
        /// </summary>
        /// <remarks>
        /// This method must only be called by a thread that has synchronized
        /// on this RemoteService.
        /// </remarks>
        /// <param name="xml">
        /// The <see cref="IXmlElement"/> containing the new configuration
        /// for this RemoteService.
        /// </param>
        protected virtual void DoConfigure(IXmlElement xml)
        {
            if (xml == null)
            {
                throw new ArgumentNullException("xml", "xml configuration must not be null");
            }

            Xml = xml;

            // find the configuration for the Initiator
            IXmlElement xmlInitiator = Tangosol.Util.Daemon.QueueProcessor.
                                       Service.Peer.Initiator.Initiator.FindInitiatorConfig(xml);

            // inject service configuration
            IXmlElement xmlHandler = XmlHelper.EnsureElement(xmlInitiator, "incoming-message-handler");

            IXmlElement xmlSub = XmlHelper.EnsureElement(xmlHandler, "request-timeout");

            if (xmlSub.Value == null)
            {
                xmlSub.SetString(xml.GetSafeElement("request-timeout").GetString());
            }

            // create the Initiator
            IConnectionInitiator initiator = Tangosol.Util.Daemon.QueueProcessor.
                                             Service.Peer.Initiator.Initiator.CreateInitiator(xmlInitiator, OperationalContext);

            if (initiator is Initiator)
            {
                var initiatorImpl = (Initiator)initiator;
                initiatorImpl.ServiceName   = ServiceName + ':' + initiatorImpl.ServiceName;
                initiatorImpl.ParentService = this;
            }
            Initiator = initiator;

            RemoteClusterName = xml.GetSafeElement("cluster-name").GetString();
            RemoteServiceName = xml.GetSafeElement("proxy-service-name").GetString();
            ScopeName         = xml.GetSafeElement("scope-name").GetString();

            if (initiator is TcpInitiator)
            {
                IsNameServiceAddressProvider = ((TcpInitiator)initiator).IsNameService;
            }
        }
コード例 #17
0
        /// <summary>
        /// The <see cref="Start"/> implementation method.
        /// </summary>
        /// <remarks>
        /// This method must only be called by a thread that has synchronized
        /// on this RemoteService.
        /// </remarks>
        protected virtual void DoStart()
        {
            IConnectionInitiator initiator = Initiator;

            Debug.Assert(initiator != null);

            initiator.ConnectionOpened += new ConnectionEventHandler(OnConnectionOpened);
            initiator.ConnectionClosed += new ConnectionEventHandler(OnConnectionClosed);
            initiator.ConnectionError  += new ConnectionEventHandler(OnConnectionError);

            initiator.ServiceStarting += new ServiceEventHandler(OnServiceStarting);
            initiator.ServiceStarted  += new ServiceEventHandler(OnServiceStarted);
            initiator.ServiceStopping += new ServiceEventHandler(OnServiceStopping);
            initiator.ServiceStopped  += new ServiceEventHandler(OnServiceStopped);

            initiator.Start();

            EnsureChannel();
        }
コード例 #18
0
 public ConnectionPoolHelper(ConnectionPool connectionPool, IConnectionInitiator connectionInitiator, Uri via)
 {
     _connectionInitiator = connectionInitiator;
     _connectionPool = connectionPool;
     _via = via;
 }
コード例 #19
0
 public BufferedConnectionInitiator(IConnectionInitiator connectionInitiator, TimeSpan flushTimeout, int writeBufferSize)
 {
     this.connectionInitiator = connectionInitiator;
     this.flushTimeout = flushTimeout;
     this.writeBufferSize = writeBufferSize;
 }
コード例 #20
0
        public IConnection EstablishConnection(TimeSpan timeout)
        {
            TimeoutHelper timeoutHelper        = new TimeoutHelper(timeout);
            IConnection   connection           = null;
            IConnection   upgradedConnection   = null;
            bool          isConnectionFromPool = true;

            while (isConnectionFromPool)
            {
                connection = this.TakeConnection(timeoutHelper.RemainingTime());
                if (connection == null)
                {
                    isConnectionFromPool = false;
                }
                else
                {
                    bool flag2 = false;
                    try
                    {
                        try
                        {
                            upgradedConnection = this.AcceptPooledConnection(connection, ref timeoutHelper);
                            flag2 = true;
                            break;
                        }
                        catch (CommunicationException exception)
                        {
                            if (DiagnosticUtility.ShouldTraceInformation)
                            {
                                DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Information);
                            }
                        }
                        catch (TimeoutException exception2)
                        {
                            if (DiagnosticUtility.ShouldTraceInformation)
                            {
                                DiagnosticUtility.ExceptionUtility.TraceHandledException(exception2, TraceEventType.Information);
                            }
                        }
                        continue;
                    }
                    finally
                    {
                        if (!flag2)
                        {
                            if (DiagnosticUtility.ShouldTraceInformation)
                            {
                                TraceUtility.TraceEvent(TraceEventType.Information, 0x40030, System.ServiceModel.SR.GetString("TraceCodeFailedAcceptFromPool", new object[] { timeoutHelper.RemainingTime() }));
                            }
                            this.connectionPool.ReturnConnection(this.connectionKey, connection, false, TimeSpan.Zero);
                        }
                    }
                }
            }
            if (!isConnectionFromPool)
            {
                bool     flag3 = false;
                TimeSpan span  = timeoutHelper.RemainingTime();
                try
                {
                    try
                    {
                        connection = this.connectionInitiator.Connect(this.via, span);
                    }
                    catch (TimeoutException exception3)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(this.CreateNewConnectionTimeoutException(span, exception3));
                    }
                    this.connectionInitiator = null;
                    upgradedConnection       = this.AcceptPooledConnection(connection, ref timeoutHelper);
                    flag3 = true;
                }
                finally
                {
                    if (!flag3)
                    {
                        this.connectionKey = null;
                        if (connection != null)
                        {
                            connection.Abort();
                        }
                    }
                }
            }
            this.SnapshotConnection(upgradedConnection, connection, isConnectionFromPool);
            return(upgradedConnection);
        }
コード例 #21
0
 public ConnectionPoolHelper(ConnectionPool connectionPool, IConnectionInitiator connectionInitiator, Uri via)
 {
     this.connectionInitiator = connectionInitiator;
     this.connectionPool      = connectionPool;
     this.via = via;
 }
コード例 #22
0
 public DemuxSocketInitiator(IConnectionInitiator innerInitiator, string type)
 {
     this.innerInitiator = innerInitiator;
     this.type           = type;
 }
コード例 #23
0
 public ConnectionPoolHelper(ConnectionPool connectionPool, IConnectionInitiator connectionInitiator, Uri via)
 {
     _connectionInitiator = connectionInitiator;
     _connectionPool      = connectionPool;
     _via = via;
 }
 public ConnectionPoolHelper(ConnectionPool connectionPool, IConnectionInitiator connectionInitiator, Uri via)
 {
     this.connectionInitiator = connectionInitiator;
     this.connectionPool = connectionPool;
     this.via = via;
 }
コード例 #25
0
 internal TracingConnectionInitiator(IConnectionInitiator connectionInitiator, bool isClient)
 {
     this.connectionInitiator = connectionInitiator;
     this.activity            = ServiceModelActivity.CreateActivity(DiagnosticTrace.ActivityId);
     this.isClient            = isClient;
 }
コード例 #26
0
        public IConnection EstablishConnection(TimeSpan timeout)
        {
            TimeoutHelper timeoutHelper             = new TimeoutHelper(timeout);
            IConnection   localRawConnection        = null;
            IConnection   localUpgradedConnection   = null;
            bool          localIsConnectionFromPool = true;

            EventTraceActivity localEventTraceActivity = this.EventTraceActivity;

            if (TD.EstablishConnectionStartIsEnabled())
            {
                TD.EstablishConnectionStart(localEventTraceActivity,
                                            this.via != null ? this.via.AbsoluteUri : string.Empty);
            }

            // first try and use a connection from our pool (and use it if we successfully receive an ACK)
            while (localIsConnectionFromPool)
            {
                localRawConnection = this.TakeConnection(timeoutHelper.RemainingTime());
                if (localRawConnection == null)
                {
                    localIsConnectionFromPool = false;
                }
                else
                {
                    bool preambleSuccess = false;
                    try
                    {
                        localUpgradedConnection = AcceptPooledConnection(localRawConnection, ref timeoutHelper);
                        preambleSuccess         = true;
                        break;
                    }
                    catch (CommunicationException e)
                    {
                        DiagnosticUtility.TraceHandledException(e, TraceEventType.Information);
                        // CommmunicationException is ok since it was a cached connection of unknown state
                    }
                    catch (TimeoutException e)
                    {
                        if (TD.OpenTimeoutIsEnabled())
                        {
                            TD.OpenTimeout(e.Message);
                        }
                        DiagnosticUtility.TraceHandledException(e, TraceEventType.Information);
                        // ditto for TimeoutException
                    }
                    finally
                    {
                        if (!preambleSuccess)
                        {
                            if (TD.ConnectionPoolPreambleFailedIsEnabled())
                            {
                                TD.ConnectionPoolPreambleFailed(localEventTraceActivity);
                            }

                            if (DiagnosticUtility.ShouldTraceInformation)
                            {
                                TraceUtility.TraceEvent(
                                    TraceEventType.Information,
                                    TraceCode.FailedAcceptFromPool,
                                    SR.GetString(
                                        SR.TraceCodeFailedAcceptFromPool,
                                        timeoutHelper.RemainingTime()));
                            }

                            // This cannot throw TimeoutException since isConnectionStillGood is false (doesn't attempt a Close).
                            this.connectionPool.ReturnConnection(connectionKey, localRawConnection, false, TimeSpan.Zero);
                        }
                    }
                }
            }

            // if there isn't anything in the pool, we need to use a new connection
            if (!localIsConnectionFromPool)
            {
                bool     success        = false;
                TimeSpan connectTimeout = timeoutHelper.RemainingTime();
                try
                {
                    try
                    {
                        localRawConnection = this.connectionInitiator.Connect(this.via, connectTimeout);
                    }
                    catch (TimeoutException e)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateNewConnectionTimeoutException(
                                                                                      connectTimeout, e));
                    }

                    this.connectionInitiator = null;
                    localUpgradedConnection  = AcceptPooledConnection(localRawConnection, ref timeoutHelper);
                    success = true;
                }
                finally
                {
                    if (!success)
                    {
                        connectionKey = null;
                        if (localRawConnection != null)
                        {
                            localRawConnection.Abort();
                        }
                    }
                }
            }

            SnapshotConnection(localUpgradedConnection, localRawConnection, localIsConnectionFromPool);

            if (TD.EstablishConnectionStopIsEnabled())
            {
                TD.EstablishConnectionStop(localEventTraceActivity);
            }

            return(localUpgradedConnection);
        }
コード例 #27
0
        /// <summary>
        /// Obtains the connect address of the ProxyService from a remote NameService.
        /// </summary>
        protected void LookupProxyServiceAddress()
        {
            if (IsNameServiceAddressProvider)
            {
                IConnectionInitiator initiator = Initiator;
                if (initiator is TcpInitiator)
                {
                    // attempt to lookup the ProxyService address from a NameService

                    TcpInitiator      tcpInitiator = (TcpInitiator)initiator;
                    RemoteNameService serviceNS    = new RemoteNameService();

                    serviceNS.OperationalContext = OperationalContext;
                    serviceNS.ServiceName        = ServiceName + ':' + ServiceType.RemoteNameService;
                    serviceNS.DoConfigure(Xml);

                    string clusterRemote = RemoteClusterName;
                    string serviceRemote = RemoteServiceName;

                    serviceNS.RemoteClusterName = clusterRemote;
                    serviceNS.RemoteServiceName = "NameService";

                    Exception e = null;
                    try
                    {
                        tcpInitiator.CloseOnExit.Add(serviceNS);
                        serviceNS.Start();

                        Object[] ao = (Object[])serviceNS.Lookup(serviceRemote);
                        if (ao == null)
                        {
                            // we got an answer, which means we found the cluster, but not the service
                            e = new ConnectionException("Unable to locate ProxyService '" + serviceRemote
                                                        + "' within cluster '" + clusterRemote + "'");
                        }
                        else
                        {
                            Port32 port32 = new Port32((Int32)ao[1]);

                            tcpInitiator.RemoteAddressProvider = new SingleAddressProvider(
                                new IPEndPoint(NetworkUtils.GetHostAddress((String)ao[0], tcpInitiator.ConnectTimeout), port32.Baseport));
                            tcpInitiator.Subport       = port32.Subport;
                            tcpInitiator.IsNameService = false;
                        }
                    }
                    catch (Exception ex)
                    {
                        // we failed to connect, thus the cluster was not reachable
                        e = new ConnectionException("Unable to locate cluster '" + clusterRemote + "' while looking for its ProxyService '"
                                                    + serviceRemote + "'", ex);
                    }
                    finally
                    {
                        tcpInitiator.CloseOnExit.Remove(serviceNS);
                        serviceNS.Stop();
                    }
                    if (e != null)
                    {
                        throw e;
                    }
                }
            }
        }
コード例 #28
0
        public IConnection EstablishConnection(TimeSpan timeout)
        {
            TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);
            IConnection   connection    = null;
            IConnection   connection1   = null;
            bool          flag          = true;

            while (flag)
            {
                connection = this.TakeConnection(timeoutHelper.RemainingTime());
                if (connection != null)
                {
                    bool flag1 = false;
                    try
                    {
                        try
                        {
                            connection1 = this.AcceptPooledConnection(connection, ref timeoutHelper);
                            flag1       = true;
                            break;
                        }
                        catch (CommunicationException communicationException1)
                        {
                            CommunicationException communicationException = communicationException1;
                            Fx.Exception.TraceHandled(communicationException, string.Concat(this.GetType(), ".EstablishConnection"), null);
                        }
                        catch (TimeoutException timeoutException1)
                        {
                            TimeoutException timeoutException = timeoutException1;
                            Fx.Exception.TraceHandled(timeoutException, string.Concat(this.GetType(), ".EstablishConnection"), null);
                        }
                    }
                    finally
                    {
                        if (!flag1)
                        {
                            if (Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ShouldTraceInformation)
                            {
                                DiagnosticTrace diagnosticTrace = Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.DiagnosticTrace;
                                string          traceCodeFailedAcceptFromPool = Resources.TraceCodeFailedAcceptFromPool;
                                object[]        objArray = new object[] { timeoutHelper.RemainingTime() };
                                diagnosticTrace.TraceEvent(TraceEventType.Information, TraceCode.FailedAcceptFromPool, Microsoft.ServiceBus.SR.GetString(traceCodeFailedAcceptFromPool, objArray));
                            }
                            this.connectionPool.ReturnConnection(this.connectionKey, connection, false, TimeSpan.Zero);
                        }
                    }
                }
                else
                {
                    flag = false;
                }
            }
            if (!flag)
            {
                bool     flag2    = false;
                TimeSpan timeSpan = timeoutHelper.RemainingTime();
                try
                {
                    try
                    {
                        connection = this.connectionInitiator.Connect(this.via, timeSpan);
                    }
                    catch (TimeoutException timeoutException3)
                    {
                        TimeoutException timeoutException2 = timeoutException3;
                        throw Fx.Exception.AsInformation(this.CreateNewConnectionTimeoutException(timeSpan, timeoutException2), null);
                    }
                    this.connectionInitiator = null;
                    connection1 = this.AcceptPooledConnection(connection, ref timeoutHelper);
                    flag2       = true;
                }
                finally
                {
                    if (!flag2)
                    {
                        this.connectionKey = null;
                        if (connection != null)
                        {
                            connection.Abort();
                        }
                    }
                }
            }
            this.SnapshotConnection(connection1, connection, flag);
            return(connection1);
        }
コード例 #29
0
 public ClientFramingDuplexSessionChannel(ChannelManagerBase factory, IConnectionOrientedTransportChannelFactorySettings settings,
                                          EndpointAddress remoteAddress, Uri via, IConnectionInitiator connectionInitiator, ConnectionPool connectionPool,
                                          bool exposeConnectionProperty, bool flowIdentity)
     : base(factory, settings, remoteAddress, via, exposeConnectionProperty)
 {
     _settings             = settings;
     this.MessageEncoder   = settings.MessageEncoderFactory.CreateSessionEncoder();
     _upgrade              = settings.Upgrade;
     _flowIdentity         = flowIdentity;
     _connectionPoolHelper = new DuplexConnectionPoolHelper(this, connectionPool, connectionInitiator);
 }
コード例 #30
0
        public async Task <IConnection> EstablishConnectionAsync(TimeSpan timeout)
        {
            TimeoutHelper timeoutHelper             = new TimeoutHelper(timeout);
            IConnection   localRawConnection        = null;
            IConnection   localUpgradedConnection   = null;
            bool          localIsConnectionFromPool = true;

            // first try and use a connection from our pool (and use it if we successfully receive an ACK)
            while (localIsConnectionFromPool)
            {
                localRawConnection = this.TakeConnection(timeoutHelper.RemainingTime());
                if (localRawConnection == null)
                {
                    localIsConnectionFromPool = false;
                }
                else
                {
                    bool preambleSuccess = false;
                    try
                    {
                        localUpgradedConnection = await AcceptPooledConnectionAsync(localRawConnection, ref timeoutHelper);

                        preambleSuccess = true;
                        break;
                    }
                    catch (CommunicationException)
                    {
                        // CommunicationException is ok since it was a cached connection of unknown state
                    }
                    catch (TimeoutException)
                    {
                        // ditto for TimeoutException
                    }
                    finally
                    {
                        if (!preambleSuccess)
                        {
                            // This cannot throw TimeoutException since isConnectionStillGood is false (doesn't attempt a Close).
                            _connectionPool.ReturnConnection(_connectionKey, localRawConnection, false, TimeSpan.Zero);
                        }
                    }
                }
            }

            // if there isn't anything in the pool, we need to use a new connection
            if (!localIsConnectionFromPool)
            {
                bool     success        = false;
                TimeSpan connectTimeout = timeoutHelper.RemainingTime();
                try
                {
                    try
                    {
                        localRawConnection = await _connectionInitiator.ConnectAsync(_via, connectTimeout);
                    }
                    catch (TimeoutException e)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateNewConnectionTimeoutException(
                                                                                      connectTimeout, e));
                    }

                    _connectionInitiator    = null;
                    localUpgradedConnection = await AcceptPooledConnectionAsync(localRawConnection, ref timeoutHelper);

                    success = true;
                }
                finally
                {
                    if (!success)
                    {
                        _connectionKey = null;
                        if (localRawConnection != null)
                        {
                            localRawConnection.Abort();
                        }
                    }
                }
            }

            SnapshotConnection(localUpgradedConnection, localRawConnection, localIsConnectionFromPool);

            return(localUpgradedConnection);
        }
コード例 #31
0
        public async Task<IConnection> EstablishConnectionAsync(TimeSpan timeout)
        {
            TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);
            IConnection localRawConnection = null;
            IConnection localUpgradedConnection = null;
            bool localIsConnectionFromPool = true;

            // first try and use a connection from our pool (and use it if we successfully receive an ACK)
            while (localIsConnectionFromPool)
            {
                localRawConnection = this.TakeConnection(timeoutHelper.RemainingTime());
                if (localRawConnection == null)
                {
                    localIsConnectionFromPool = false;
                }
                else
                {
                    bool preambleSuccess = false;
                    try
                    {
                        localUpgradedConnection = await AcceptPooledConnectionAsync(localRawConnection, ref timeoutHelper);
                        preambleSuccess = true;
                        break;
                    }
                    catch (CommunicationException)
                    {
                        // CommunicationException is ok since it was a cached connection of unknown state
                    }
                    catch (TimeoutException)
                    {
                        // ditto for TimeoutException
                    }
                    finally
                    {
                        if (!preambleSuccess)
                        {
                            // This cannot throw TimeoutException since isConnectionStillGood is false (doesn't attempt a Close).
                            _connectionPool.ReturnConnection(_connectionKey, localRawConnection, false, TimeSpan.Zero);
                        }
                    }
                }
            }

            // if there isn't anything in the pool, we need to use a new connection
            if (!localIsConnectionFromPool)
            {
                bool success = false;
                TimeSpan connectTimeout = timeoutHelper.RemainingTime();
                try
                {
                    try
                    {
                        localRawConnection = await _connectionInitiator.ConnectAsync(_via, connectTimeout);
                    }
                    catch (TimeoutException e)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateNewConnectionTimeoutException(
                            connectTimeout, e));
                    }

                    _connectionInitiator = null;
                    localUpgradedConnection = await AcceptPooledConnectionAsync(localRawConnection, ref timeoutHelper);
                    success = true;
                }
                finally
                {
                    if (!success)
                    {
                        _connectionKey = null;
                        if (localRawConnection != null)
                        {
                            localRawConnection.Abort();
                        }
                    }
                }
            }

            SnapshotConnection(localUpgradedConnection, localRawConnection, localIsConnectionFromPool);

            return localUpgradedConnection;
        }
コード例 #32
0
 public BufferedConnectionInitiator(IConnectionInitiator connectionInitiator, TimeSpan flushTimeout, int writeBufferSize)
 {
     this.connectionInitiator = connectionInitiator;
     this.flushTimeout        = flushTimeout;
     this.writeBufferSize     = writeBufferSize;
 }
コード例 #33
0
 public ConnectionDumpInitiator(IConnectionInitiator connectionInitiator)
 {
     this.connectionInitiator = connectionInitiator;
     this.outputDirectory = Environment.GetEnvironmentVariable("ConnectionDump");
 }
 public IConnection EstablishConnection(TimeSpan timeout)
 {
     TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);
     IConnection connection = null;
     IConnection upgradedConnection = null;
     bool isConnectionFromPool = true;
     while (isConnectionFromPool)
     {
         connection = this.TakeConnection(timeoutHelper.RemainingTime());
         if (connection == null)
         {
             isConnectionFromPool = false;
         }
         else
         {
             bool flag2 = false;
             try
             {
                 try
                 {
                     upgradedConnection = this.AcceptPooledConnection(connection, ref timeoutHelper);
                     flag2 = true;
                     break;
                 }
                 catch (CommunicationException exception)
                 {
                     if (DiagnosticUtility.ShouldTraceInformation)
                     {
                         DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Information);
                     }
                 }
                 catch (TimeoutException exception2)
                 {
                     if (DiagnosticUtility.ShouldTraceInformation)
                     {
                         DiagnosticUtility.ExceptionUtility.TraceHandledException(exception2, TraceEventType.Information);
                     }
                 }
                 continue;
             }
             finally
             {
                 if (!flag2)
                 {
                     if (DiagnosticUtility.ShouldTraceInformation)
                     {
                         TraceUtility.TraceEvent(TraceEventType.Information, 0x40030, System.ServiceModel.SR.GetString("TraceCodeFailedAcceptFromPool", new object[] { timeoutHelper.RemainingTime() }));
                     }
                     this.connectionPool.ReturnConnection(this.connectionKey, connection, false, TimeSpan.Zero);
                 }
             }
         }
     }
     if (!isConnectionFromPool)
     {
         bool flag3 = false;
         TimeSpan span = timeoutHelper.RemainingTime();
         try
         {
             try
             {
                 connection = this.connectionInitiator.Connect(this.via, span);
             }
             catch (TimeoutException exception3)
             {
                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(this.CreateNewConnectionTimeoutException(span, exception3));
             }
             this.connectionInitiator = null;
             upgradedConnection = this.AcceptPooledConnection(connection, ref timeoutHelper);
             flag3 = true;
         }
         finally
         {
             if (!flag3)
             {
                 this.connectionKey = null;
                 if (connection != null)
                 {
                     connection.Abort();
                 }
             }
         }
     }
     this.SnapshotConnection(upgradedConnection, connection, isConnectionFromPool);
     return upgradedConnection;
 }
 public void Setup()
 {
     _connectionInitiator = Substitute.For <IConnectionInitiator>();
     _clickHandler        = new OpenConnectionClickHandler(_connectionInitiator);
 }
コード例 #36
0
 public ConnectionDumpInitiator(IConnectionInitiator connectionInitiator)
 {
     this.connectionInitiator = connectionInitiator;
     this.outputDirectory     = Environment.GetEnvironmentVariable("ConnectionDump");
 }
コード例 #37
0
 public BufferedConnectionInitiator(IConnectionInitiator connectionInitiator, TimeSpan flushTimeout, int writeBufferSize)
 {
     _connectionInitiator = connectionInitiator;
     _flushTimeout        = flushTimeout;
     _writeBufferSize     = writeBufferSize;
 }
コード例 #38
0
 internal TracingConnectionInitiator(IConnectionInitiator connectionInitiator, bool isClient)
 {
     this.connectionInitiator = connectionInitiator;
     this.activity = ServiceModelActivity.CreateActivity(DiagnosticTraceBase.ActivityId);
     this.isClient = isClient;
 }
コード例 #39
0
 public BufferedConnectionInitiator(IConnectionInitiator connectionInitiator, TimeSpan flushTimeout, int writeBufferSize)
 {
     _connectionInitiator = connectionInitiator;
     _flushTimeout = flushTimeout;
     _writeBufferSize = writeBufferSize;
 }