Ejemplo n.º 1
0
        /// <summary>
        /// Initialize Connection properties from connection configuration object
        /// </summary>
        private void Initialize()
        {
            PubSubConnectionDataType            pubSubConnectionConfiguration = m_udpConnection.PubSubConnectionConfiguration;
            DatagramConnectionTransportDataType transportSettings             = ExtensionObject.ToEncodeable(pubSubConnectionConfiguration.TransportSettings)
                                                                                as DatagramConnectionTransportDataType;

            if (transportSettings != null && transportSettings.DiscoveryAddress != null)
            {
                NetworkAddressUrlDataType discoveryNetworkAddressUrlState = ExtensionObject.ToEncodeable(transportSettings.DiscoveryAddress)
                                                                            as NetworkAddressUrlDataType;
                if (discoveryNetworkAddressUrlState != null)
                {
                    Utils.Trace(Utils.TraceMasks.Information, "The configuration for connection {0} has custom DiscoveryAddress configuration.",
                                pubSubConnectionConfiguration.Name);

                    DiscoveryNetworkInterfaceName   = discoveryNetworkAddressUrlState.NetworkInterface;
                    DiscoveryNetworkAddressEndPoint = UdpClientCreator.GetEndPoint(discoveryNetworkAddressUrlState.Url);
                }
            }

            if (DiscoveryNetworkAddressEndPoint == null)
            {
                Utils.Trace(Utils.TraceMasks.Information, "The configuration for connection {0} will use the default DiscoveryAddress: {1}.",
                            pubSubConnectionConfiguration.Name, kDefaultDiscoveryUrl);

                DiscoveryNetworkAddressEndPoint = UdpClientCreator.GetEndPoint(kDefaultDiscoveryUrl);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Start the UdpDiscovery process
        /// </summary>
        /// <param name="messageContext">The <see cref="IServiceMessageContext"/> object that should be used in encode/decode messages</param>
        /// <returns></returns>
        public virtual async Task StartAsync(IServiceMessageContext messageContext)
        {
            await Task.Run(() => {
                lock (m_lock)
                {
                    MessageContext = messageContext;

                    // initialize Discovery channels
                    m_discoveryUdpClients = UdpClientCreator.GetUdpClients(UsedInContext.Discovery, DiscoveryNetworkInterfaceName, DiscoveryNetworkAddressEndPoint);
                }
            }).ConfigureAwait(false);
        }
        /// <summary>
        /// Perform specific Start tasks
        /// </summary>
        protected override Task InternalStart()
        {
            lock (m_lock)
            {
                //cleanup all existing UdpClient previously open
                InternalStop();

                NetworkAddressUrlDataType networkAddressUrlState = ExtensionObject.ToEncodeable(PubSubConnectionConfiguration.Address)
                                                                   as NetworkAddressUrlDataType;
                if (networkAddressUrlState == null)
                {
                    Utils.Trace(Utils.TraceMasks.Error, "The configuration for connection {0} has invalid Address configuration.",
                                this.PubSubConnectionConfiguration.Name);
                    return(Task.FromResult <object>(null));
                }
                NetworkInterfaceName   = networkAddressUrlState.NetworkInterface;
                NetworkAddressEndPoint = UdpClientCreator.GetEndPoint(networkAddressUrlState.Url);

                if (NetworkAddressEndPoint == null)
                {
                    Utils.Trace(Utils.TraceMasks.Error, "The configuration for connection {0} with Url:'{1}' resulted in an invalid endpoint.",
                                this.PubSubConnectionConfiguration.Name, networkAddressUrlState.Url);
                    return(Task.FromResult <object>(null));
                }

                //publisher initialization
                if (Publishers.Count > 0)
                {
                    m_publisherUdpClients = UdpClientCreator.GetUdpClients(UsedInContext.Publisher, networkAddressUrlState, NetworkAddressEndPoint);
                }

                //subscriber initialization
                if (GetAllDataSetReaders().Count > 0)
                {
                    m_subscriberUdpClients = UdpClientCreator.GetUdpClients(UsedInContext.Subscriber, networkAddressUrlState, NetworkAddressEndPoint);

                    foreach (UdpClient subscriberUdpClient in m_subscriberUdpClients)
                    {
                        try
                        {
                            subscriberUdpClient.BeginReceive(new AsyncCallback(OnUadpReceive), subscriberUdpClient);
                        }
                        catch (Exception ex)
                        {
                            Utils.Trace(Utils.TraceMasks.Information, "UdpClient '{0}' Cannot receive data. Exception: {1}",
                                        subscriberUdpClient.Client.LocalEndPoint, ex.Message);
                        }
                    }
                }
            }
            return(Task.FromResult <object>(null));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Perform specific Start tasks
        /// </summary>
        protected override async Task InternalStart()
        {
            //cleanup all existing UdpClient previously open
            await InternalStop();

            if (NetworkAddressEndPoint == null)
            {
                return;
            }

            //publisher initialization
            if (Publishers.Count > 0)
            {
                lock (m_lock)
                {
                    m_publisherUdpClients = UdpClientCreator.GetUdpClients(UsedInContext.Publisher, NetworkInterfaceName, NetworkAddressEndPoint);
                }

                m_udpDiscoveryPublisher = new UdpDiscoveryPublisher(this);
                await m_udpDiscoveryPublisher.StartAsync(MessageContext);
            }

            //subscriber initialization
            if (GetAllDataSetReaders().Count > 0)
            {
                lock (m_lock)
                {
                    m_subscriberUdpClients = UdpClientCreator.GetUdpClients(UsedInContext.Subscriber, NetworkInterfaceName, NetworkAddressEndPoint);

                    foreach (UdpClient subscriberUdpClient in m_subscriberUdpClients)
                    {
                        try
                        {
                            subscriberUdpClient.BeginReceive(new AsyncCallback(OnUadpReceive), subscriberUdpClient);
                        }
                        catch (Exception ex)
                        {
                            Utils.Trace(Utils.TraceMasks.Information, "UdpClient '{0}' Cannot receive data. Exception: {1}",
                                        subscriberUdpClient.Client.LocalEndPoint, ex.Message);
                        }
                    }
                }

                // initialize the discovery channel
                m_udpDiscoverySubscriber = new UdpDiscoverySubscriber(this);
                await m_udpDiscoverySubscriber.StartAsync(MessageContext);

                // add handler to metaDataReceived event
                this.Application.MetaDataReceived += Application_MetaDataReceived;
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Initialize Conection properties from connection configuration object
        /// </summary>
        private void Initialize()
        {
            NetworkAddressUrlDataType networkAddressUrlState = ExtensionObject.ToEncodeable(PubSubConnectionConfiguration.Address)
                                                               as NetworkAddressUrlDataType;

            if (networkAddressUrlState == null)
            {
                Utils.Trace(Utils.TraceMasks.Error, "The configuration for connection {0} has invalid Address configuration.",
                            PubSubConnectionConfiguration.Name);
                return;
            }
            // set properties
            NetworkInterfaceName   = networkAddressUrlState.NetworkInterface;
            NetworkAddressEndPoint = UdpClientCreator.GetEndPoint(networkAddressUrlState.Url);

            if (NetworkAddressEndPoint == null)
            {
                Utils.Trace(Utils.TraceMasks.Error, "The configuration for connection {0} with Url:'{1}' resulted in an invalid endpoint.",
                            PubSubConnectionConfiguration.Name, networkAddressUrlState.Url);
            }
        }