Ejemplo n.º 1
0
        private async Task AnnounceServiceStopPublishingAsync()
        {
            Message message = GetPublishMessage(PublishMessageType.Stop);

            if (_publishing || !MulticastDNSChannel.IsJoined)
            {
                return;
            }

            await MulticastDNSChannel.SendMessageAsync(message).ConfigureAwait(false);

            await TaskUtility.Delay(FirstRebroadcastInterval).ConfigureAwait(false);

            if (_publishing || !MulticastDNSChannel.IsJoined)
            {
                return;
            }

            await MulticastDNSChannel.SendMessageAsync(message).ConfigureAwait(false);

            await TaskUtility.Delay(SecondRebroadcastInterval).ConfigureAwait(false);

            if (_publishing || !MulticastDNSChannel.IsJoined)
            {
                return;
            }

            await MulticastDNSChannel.SendMessageAsync(message).ConfigureAwait(false);
        }
Ejemplo n.º 2
0
        private async Task AnnounceServicePublishAsync()
        {
            if (!_publishing || !MulticastDNSChannel.IsJoined)
            {
                return;
            }

            var initialMessage = GetPublishMessage(PublishMessageType.Initial);

            _currentServicePublishMessage = GetPublishMessage(PublishMessageType.Normal);

            // Send initial message immediately followed by the "normal" message
            await MulticastDNSChannel.SendMessageAsync(initialMessage).ConfigureAwait(false);

            await SendServicePublishMessageAsync().ConfigureAwait(false);

            await TaskUtility.Delay(FirstRebroadcastInterval).ConfigureAwait(false);

            if (!_publishing || !MulticastDNSChannel.IsJoined)
            {
                return;
            }

            await SendServicePublishMessageAsync().ConfigureAwait(false);

            await TaskUtility.Delay(SecondRebroadcastInterval).ConfigureAwait(false);

            if (!_publishing || !MulticastDNSChannel.IsJoined)
            {
                return;
            }

            await SendServicePublishMessageAsync().ConfigureAwait(false);
        }
Ejemplo n.º 3
0
        public async Task <bool> ResolveAsync()
        {
            if (_browser == null)
            {
                throw new InvalidOperationException("This operation is only valid on services that were generated by a NetServiceBrowser.");
            }

            // Making sure that the associated NetServiceBrowser is still active ensures that the MulticastDNSChannel has not been shut down.
            if (!_browser.IsRunning)
            {
                throw new InvalidOperationException("The associated NetServiceBrowser has been stopped.");
            }

            // Resolve the service
            _log.Info("Resolving service '{0}'...", FullServiceInstanceName);
            Message message = GetResolveMessage();

            var tcs = new TaskCompletionSource <object>();

            _resolveTaskCompletionSource = tcs;

            // First resolution attempt
            await MulticastDNSChannel.SendMessageAsync(message).ConfigureAwait(false);

            Task delayTask = TaskUtility.Delay(FirstRebroadcastInterval);
            await TaskUtility.WhenAny(delayTask, tcs.Task).ConfigureAwait(false);

            if (tcs.Task.IsCompleted)
            {
                return(true);
            }

            // Second resolution attempt
            await MulticastDNSChannel.SendMessageAsync(message).ConfigureAwait(false);

            delayTask = TaskUtility.Delay(SecondRebroadcastInterval);
            await TaskUtility.WhenAny(delayTask, tcs.Task).ConfigureAwait(false);

            if (tcs.Task.IsCompleted)
            {
                return(true);
            }

            // Third resolution attempt
            await MulticastDNSChannel.SendMessageAsync(message).ConfigureAwait(false);

            delayTask = TaskUtility.Delay(ServiceResolveTimeout);
            await TaskUtility.WhenAny(delayTask, tcs.Task).ConfigureAwait(false);

            if (tcs.Task.IsCompleted)
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 4
0
        private async Task SendServicePublishMessageAsync()
        {
            if (!_publishing || _currentServicePublishMessage == null)
            {
                return;
            }

            _log.Debug("Sending publish message for service \"{0}\"...", FullServiceInstanceName);
            await MulticastDNSChannel.SendMessageAsync(_currentServicePublishMessage).ConfigureAwait(false);

            _lastServicePublishBroadcast = DateTime.Now;
        }
Ejemplo n.º 5
0
        private async Task SendServiceSearchMessageAsync()
        {
            if (!MulticastDNSChannel.IsJoined || _currentServiceSearchMessage == null)
            {
                return;
            }

            _log.Debug("Sending search message for '{0}'...", _currentServiceType);
            await MulticastDNSChannel.SendMessageAsync(_currentServiceSearchMessage).ConfigureAwait(false);

            _lastServiceBroadcast = DateTime.Now;
        }