public async Task Close(CancellationToken ct)
 {
     _assemblersCleanTimer.Dispose();
     foreach (var assembler in _assemblers.Values)
     {
         DisposeAssembler(assembler);
     }
     _assemblers = null;
     await _transportChannel.Close(ct);
 }
Пример #2
0
        /// <summary>
        /// Opens a new session.
        /// </summary>
        public Session Connect(ConfiguredEndpoint endpoint, ITransportChannel channel, EndpointDescriptionCollection availableEndpoints)
        {
            if (channel == null)
            {
                throw new ArgumentNullException("channel");
            }

            try
            {
                // create the session.
                Session session = new Session(channel, m_configuration, endpoint, null, availableEndpoints);
                session.ReturnDiagnostics = DiagnosticsMasks.All;

                if (!new SessionOpenDlg().ShowDialog(session, PreferredLocales))
                {
                    return(null);
                }

                // session now owns the channel.
                channel = null;

                // delete the existing session.
                Close();

                // add session to tree.
                AddNode(session);

                // return the new session.
                return(session);
            }
            finally
            {
                // ensure the channel is closed on error.
                if (channel != null)
                {
                    channel.Close();
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Creates a session with the endpoint.
        /// </summary>
        public async Task <Session> Connect(ConfiguredEndpoint endpoint)
        {
            if (endpoint == null)
            {
                throw new ArgumentNullException("endpoint");
            }

            // check if the endpoint needs to be updated.
            if (endpoint.UpdateBeforeConnect)
            {
                ConfiguredServerDlg configurationDialog = new ConfiguredServerDlg();
                endpoint = await configurationDialog.ShowDialog(endpoint, m_configuration);
            }

            if (endpoint == null)
            {
                return(null);
            }

            m_endpoint = endpoint;

            // copy the message context.
            m_messageContext = m_configuration.CreateMessageContext();

            X509Certificate2 clientCertificate = null;

            if (endpoint.Description.SecurityPolicyUri != SecurityPolicies.None)
            {
                if (m_configuration.SecurityConfiguration.ApplicationCertificate == null)
                {
                    throw ServiceResultException.Create(StatusCodes.BadConfigurationError, "ApplicationCertificate must be specified.");
                }

                clientCertificate = await m_configuration.SecurityConfiguration.ApplicationCertificate.Find(true);

                if (clientCertificate == null)
                {
                    throw ServiceResultException.Create(StatusCodes.BadConfigurationError, "ApplicationCertificate cannot be found.");
                }
            }

            // create the channel.
            ITransportChannel channel = SessionChannel.Create(
                m_configuration,
                endpoint.Description,
                endpoint.Configuration,
                clientCertificate,
                m_messageContext);

            try
            {
                // create the session.
                Session session = new Session(channel, m_configuration, endpoint, null);
                session.ReturnDiagnostics = DiagnosticsMasks.All;

                SessionOpenDlg sessiondlg = new SessionOpenDlg();
                session = await sessiondlg.ShowDialog(session, PreferredLocales);

                if (session != null)
                {
                    // session now owns the channel.
                    channel = null;
                    // add session to tree.
                    AddNode(session);

                    return(session);
                }
            }
            finally
            {
                // ensure the channel is closed on error.
                if (channel != null)
                {
                    channel.Close();
                    channel = null;
                }
            }

            return(null);
        }
Пример #4
0
 public async Task Close(CancellationToken ct)
 {
     await _transportChannel.Close(ct);
 }