示例#1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EndpointConnectionApprover"/> class.
        /// </summary>
        /// <param name="descriptions">The object that stores the protocol subjects for the current endpoint.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="descriptions"/> is <see langword="null" />.
        /// </exception>
        public EndpointConnectionApprover(IStoreProtocolSubjects descriptions)
        {
            {
                Lokad.Enforce.Argument(() => descriptions);
            }

            m_Descriptions = descriptions;
        }
示例#2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ProtocolHandshakeConductor"/> class.
        /// </summary>
        /// <param name="potentialEndpoints">The collection of endpoints that have been discovered.</param>
        /// <param name="discoveryChannel">The object that provides the information about the entry discovery channel for the application.</param>
        /// <param name="discoverySources">The object that handles the discovery of remote endpoints.</param>
        /// <param name="layer">The object responsible for sending messages with remote endpoints.</param>
        /// <param name="descriptions">The object that stores information about the available communication descriptions.</param>
        /// <param name="connectionApprovers">
        /// The collection that contains all the objects that are able to approve connections between the current endpoint and a remote endpoint.
        /// </param>
        /// <param name="allowedChannelTypes">The collection that contains all the channel types for which a channel should be opened.</param>
        /// <param name="configuration">The object that stores the configuration values for the application.</param>
        /// <param name="systemDiagnostics">The object that provides the diagnostics methods for the system.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="potentialEndpoints"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="discoveryChannel"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="discoverySources"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="layer"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="descriptions"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="connectionApprovers"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="allowedChannelTypes"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="configuration"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="systemDiagnostics"/> is <see langword="null" />.
        /// </exception>
        public ProtocolHandshakeConductor(
            IStoreEndpointApprovalState potentialEndpoints,
            IProvideLocalConnectionInformation discoveryChannel,
            IEnumerable <IDiscoverOtherServices> discoverySources,
            IProtocolLayer layer,
            IStoreProtocolSubjects descriptions,
            IEnumerable <IApproveEndpointConnections> connectionApprovers,
            IEnumerable <ChannelTemplate> allowedChannelTypes,
            IConfiguration configuration,
            SystemDiagnostics systemDiagnostics)
        {
            {
                Lokad.Enforce.Argument(() => potentialEndpoints);
                Lokad.Enforce.Argument(() => discoveryChannel);
                Lokad.Enforce.Argument(() => discoverySources);
                Lokad.Enforce.Argument(() => layer);
                Lokad.Enforce.Argument(() => descriptions);
                Lokad.Enforce.Argument(() => connectionApprovers);
                Lokad.Enforce.Argument(() => allowedChannelTypes);
                Lokad.Enforce.Argument(() => configuration);
                Lokad.Enforce.Argument(() => systemDiagnostics);
            }

            m_PotentialEndpoints = potentialEndpoints;

            // Also handle the case where the endpoint signs out while it is trying to
            // connect to us
            m_PotentialEndpoints.OnEndpointDisconnected += HandleEndpointSignedOut;

            m_DiscoveryChannel    = discoveryChannel;
            m_DiscoverySources    = discoverySources;
            m_Layer               = layer;
            m_Descriptions        = descriptions;
            m_AllowedChannelTypes = allowedChannelTypes;
            m_Diagnostics         = systemDiagnostics;

            m_SendTimeout = configuration.HasValueFor(CommunicationConfigurationKeys.WaitForResponseTimeoutInMilliSeconds)
                ? TimeSpan.FromMilliseconds(configuration.Value <int>(CommunicationConfigurationKeys.WaitForResponseTimeoutInMilliSeconds))
                : TimeSpan.FromMilliseconds(CommunicationConstants.DefaultWaitForResponseTimeoutInMilliSeconds);

            foreach (var approver in connectionApprovers)
            {
                m_ConnectionApprovers.Add(approver.ProtocolVersion, approver);
            }

            foreach (var source in m_DiscoverySources)
            {
                source.OnEndpointBecomingAvailable   += HandleEndpointSignIn;
                source.OnEndpointBecomingUnavailable += HandleEndpointSignedOut;
            }
        }