예제 #1
0
        private CompositeDeviceClient(CompositeDeviceConfiguration.Device device,
                                      IotHubDeviceCredentials upstreamDeviceCredentials,
                                      MqttBrokerCredentials downstreamClientCredentials,
                                      Messaging.MessageHandler upstreamToDownstream,
                                      Messaging.MessageHandler downstreamToUpstream,
                                      IClock clock,
                                      ILoggerFactory loggerFactory)
        {
            this.logger = loggerFactory.CreateLogger <CompositeDeviceClient>();//provider.GetRequiredService<ILogger<CompositeDeviceClient>>();
            this.device = device;
            this.upstreamClientCredentials   = upstreamDeviceCredentials;
            this.downstreamClientCredentials = downstreamClientCredentials;
            this.clock = clock;
            UpstreamConnectionStatus   = CompositeDeviceClientStatus.Disconnected;
            DownstreamConnectionStatus = CompositeDeviceClientStatus.Disconnected;
            upstreamMessageHandler     = upstreamToDownstream;
            downstreamMessageHandler   = downstreamToUpstream;


            this.TwinStateLifecycle = new TwinStateLifecycle(clock, null);

            // create lookups for topics
            AddTopicsToDictionary(device.LocalDeviceMqttPublications.CloudToDevice, cloudToDevicePublishingTopics);
            AddTopicsToDictionary(device.LocalDeviceMqttPublications.DirectMethods, directMethodPublishingTopics);
            AddTopicsToDictionary(device.LocalDeviceMqttPublications.Twin, twinPublishingTopics);
            AddTopicsToDictionary(device.LocalDeviceMqttSubscriptions.DeviceToCloudTopics, deviceToCloudSubscriptions);
            AddTopicsToDictionary(device.LocalDeviceMqttSubscriptions.TwinRequestTopics, twiRequestSubscriptions);

            mqttClient    = new MqttDeviceClient(this, downstreamToUpstream, loggerFactory.CreateLogger <MqttDeviceClient>());
            iotEdgeClient = new IotEdgeDeviceClient(this, upstreamToDownstream, loggerFactory.CreateLogger <IotEdgeDeviceClient>());
        }
예제 #2
0
 public IotEdgeDeviceClient(CompositeDeviceClient client,
                            Messaging.MessageHandler messageHandler,
                            ILogger <IotEdgeDeviceClient> logger)
 {
     this.logger          = logger;
     this.compositeClient = client;
     this.messageHandler  = messageHandler;
 }
예제 #3
0
        public static CompositeDeviceClient CreateInModule(IConfiguration config,
                                                           CompositeDeviceConfiguration.Device device,
                                                           Messaging.MessageHandler upstreamToDownstream,
                                                           Messaging.MessageHandler downstreamToUpstream,
                                                           IClock clock,
                                                           ILoggerFactory loggerFactory)
        {
            var moduleConnectionString      = config.GetValue <string>("EdgeHubConnectionString");
            var upstreamClientCredentials   = EdgeTools.GetDeviceCredentialsFromModule(moduleConnectionString, device.IothubDeviceId, device.SasKey);
            var downstreamClientCredentials = EdgeTools.GetMqttDeviceCredentials(device);

            return(new CompositeDeviceClient(device, upstreamClientCredentials, downstreamClientCredentials, upstreamToDownstream, downstreamToUpstream, clock, loggerFactory));
        }