示例#1
0
        /// <summary>
        /// Creates an MQTT Client
        /// </summary>
        /// <param name="configuration">
        /// The configuration used for creating the Client
        /// See <see cref="MqttConfiguration" /> for more details about the supported values
        /// </param>
        /// <returns>A new MQTT Client</returns>
        /// <exception cref="MqttClientException">MqttClientException</exception>
        public async Task <IMqttClient> CreateClientAsync(MqttConfiguration configuration)
        {
            try
            {
                //Adding this to not break backwards compatibility related to the method signature
                //Yielding at this point will cause the method to return immediately after it's called,
                //running the rest of the logic acynchronously
                await Task.Yield();

                MqttTopicEvaluator         topicEvaluator      = new MqttTopicEvaluator(configuration);
                IMqttChannelFactory        innerChannelFactory = _binding.GetChannelFactory(_hostAddress, configuration);
                PacketChannelFactory       channelFactory      = new PacketChannelFactory(innerChannelFactory, topicEvaluator, configuration);
                PacketIdProvider           packetIdProvider    = new PacketIdProvider();
                InMemoryRepositoryProvider repositoryProvider  = new InMemoryRepositoryProvider();
                ClientProtocolFlowProvider flowProvider        = new ClientProtocolFlowProvider(topicEvaluator, repositoryProvider, configuration);

                return(new MqttClientImpl(channelFactory, flowProvider, repositoryProvider, packetIdProvider, configuration));
            }
            catch (Exception ex)
            {
                _tracer.Error(ex, ClientProperties.Client_InitializeError);

                throw new MqttClientException(ClientProperties.Client_InitializeError, ex);
            }
        }
 public PacketChannelFactory(IMqttChannelFactory innerChannelFactory,
                             IMqttTopicEvaluator topicEvaluator,
                             MqttConfiguration configuration)
     : this(topicEvaluator, configuration)
 {
     this.innerChannelFactory = innerChannelFactory;
 }