Esempio n. 1
0
        /// <summary>
        /// Subscribes to a topic which may or may not be missing.
        /// </summary>
        /// <param name="topicPath">The path of the topic to subscribe to.</param>
        public async void Subscribe(string topicPath)
        {
            var missingTopicHandler = new MissingTopicHandler();

            // Add the 'missing topic handler' to the topic control object
            topicControl.AddMissingTopicHandler(topicPath, missingTopicHandler);

            // Wait for the successful registration of the handler
            var registeredHandler = await missingTopicHandler.OnActiveCalled;

            var topics = clientSession.GetTopicsFeature();

            var topicCompletion = new TaskCompletionSource <bool>();

            // Attempt to subscribe to the topic
            topics.Subscribe(topicPath, new TopicsCompletionCallback(topicCompletion));

            await topicCompletion.Task;

            // Wait and see if a missing topic notification is generated
            var request = await missingTopicHandler.OnMissingTopicCalled;

            // Cancel the client request on the server
            request.Cancel();

            // Close the registered handler
            registeredHandler.Close();

            // All events in Diffusion are asynchronous, so we must wait for the close to happen
            await missingTopicHandler.OnCloseCalled;
        }
        /// <summary>
        /// Subscribes to a topic which may or may not be missing.
        /// </summary>
        /// <param name="topicPath">The path of the topic to subscribe to.</param>
        public async void Subscribe( string topicPath ) {
            var missingTopicHandler = new MissingTopicHandler();

            // Add the 'missing topic handler' to the topic control object
            topicControl.AddMissingTopicHandler( topicPath, missingTopicHandler );

            // Wait for the successful registration of the handler
            var registeredHandler = await missingTopicHandler.OnActiveCalled;

            var topics = clientSession.GetTopicsFeature();

            var topicCompletion = new TaskCompletionSource<bool>();

            // Attempt to subscribe to the topic
            topics.Subscribe( topicPath, new TopicsCompletionCallback( topicCompletion ) );

            await topicCompletion.Task;

            // Wait and see if a missing topic notification is generated
            var request = await missingTopicHandler.OnMissingTopicCalled;

            // Cancel the client request on the server
            request.Cancel();

            // Close the registered handler
            registeredHandler.Close();

            // All events in Diffusion are asynchronous, so we must wait for the close to happen
            await missingTopicHandler.OnCloseCalled;
        }