Пример #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 TwinStateLifecycle(IClock clock, MqttDeviceClient upstreamClient)
 {
     this.clock = clock;
     //requestId = clock.GetCurrentInstant().ToUnixTimeMilliseconds();
     this.upstreamClient = upstreamClient;
     this.isSubscribed   = false;
 }