/// <summary>
        /// Initializes a new instance of the <see cref="IoTHubServiceClient"/> class.
        /// </summary>
        /// <param name="connectionString">
        /// The IoT Hub connection string, with either "iothubowner", "service", "registryRead" or "registryReadWrite" policy, as applicable.
        /// For more information, see <see href="https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-devguide-security#access-control-and-permissions"/>.
        /// </param>
        /// <param name="options">
        /// Options that allow configuration of requests sent to the IoT Hub service.
        /// </param>
        public IoTHubServiceClient(string connectionString, IoTHubServiceClientOptions options)
        {
            Argument.AssertNotNull(options, nameof(options));

            var iotHubConnectionString    = new IotHubConnectionString(connectionString);
            ISasTokenProvider sasProvider = iotHubConnectionString.GetSasTokenProvider();

            _endpoint = BuildEndpointUriFromHostName(iotHubConnectionString.HostName);

            _clientDiagnostics = new ClientDiagnostics(options);

            options.AddPolicy(new SasTokenAuthenticationPolicy(sasProvider), HttpPipelinePosition.PerCall);
            _httpPipeline = HttpPipelineBuilder.Build(options);

            _registryManagerRestClient = new RegistryManagerRestClient(_clientDiagnostics, _httpPipeline, _endpoint, options.GetVersionString());
            _twinRestClient            = new TwinRestClient(_clientDiagnostics, _httpPipeline, _endpoint, options.GetVersionString());
            _deviceMethodRestClient    = new DeviceMethodRestClient(_clientDiagnostics, _httpPipeline, _endpoint, options.GetVersionString());

            Devices = new DevicesClient(_registryManagerRestClient, _twinRestClient, _deviceMethodRestClient);
            Modules = new ModulesClient(_registryManagerRestClient, _twinRestClient, _deviceMethodRestClient);

            Statistics = new StatisticsClient();
            Messages   = new CloudToDeviceMessagesClient();
            Files      = new FilesClient();
            Jobs       = new JobsClient();
        }
Exemple #2
0
        internal ModulesClient(RegistryManagerRestClient registryManagerClient, TwinRestClient twinRestClient, DeviceMethodRestClient deviceMethodRestClient)
        {
            Argument.AssertNotNull(registryManagerClient, nameof(registryManagerClient));
            Argument.AssertNotNull(twinRestClient, nameof(twinRestClient));
            Argument.AssertNotNull(deviceMethodRestClient, nameof(deviceMethodRestClient));

            _registryManagerClient = registryManagerClient;
            _twinClient            = twinRestClient;
            _deviceMethodClient    = deviceMethodRestClient;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="IoTHubServiceClient"/> class.
        /// </summary>
        /// <param name="endpoint">
        /// The IoT Hub service instance URI to connect to.
        /// </param>
        /// <param name="credential">
        /// The <see cref="TokenCredential"/> implementation which will be used to request for the authentication token.
        /// </param>
        /// <param name="options">
        /// Options that allow configuration of requests sent to the IoT Hub service.
        /// </param>
        public IoTHubServiceClient(Uri endpoint, TokenCredential credential, IoTHubServiceClientOptions options)
        {
            Argument.AssertNotNull(options, nameof(options));

            _endpoint          = endpoint;
            _clientDiagnostics = new ClientDiagnostics(options);

            options.AddPolicy(new BearerTokenAuthenticationPolicy(credential, GetAuthorizationScopes(_endpoint)), HttpPipelinePosition.PerCall);
            _httpPipeline = HttpPipelineBuilder.Build(options);

            _registryManagerRestClient = new RegistryManagerRestClient(_clientDiagnostics, _httpPipeline, _endpoint, options.GetVersionString());
            _twinRestClient            = new TwinRestClient(_clientDiagnostics, _httpPipeline, _endpoint, options.GetVersionString());
            _deviceMethodRestClient    = new DeviceMethodRestClient(_clientDiagnostics, _httpPipeline, _endpoint, options.GetVersionString());

            Devices = new DevicesClient(_registryManagerRestClient, _twinRestClient, _deviceMethodRestClient);
            Modules = new ModulesClient(_registryManagerRestClient, _twinRestClient, _deviceMethodRestClient);

            Statistics = new StatisticsClient();
            Messages   = new CloudToDeviceMessagesClient();
            Files      = new FilesClient();
            Jobs       = new JobsClient();
        }