private IotHubServiceClient(IotHubSasCredential credential, IotHubServiceClientOptions options)
        {
            options ??= new IotHubServiceClientOptions();
            _clientDiagnostics = new ClientDiagnostics(options);

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

            _devicesRestClient       = new DevicesRestClient(_clientDiagnostics, _httpPipeline, credential.Endpoint, options.GetVersionString());
            _modulesRestClient       = new ModulesRestClient(_clientDiagnostics, _httpPipeline, credential.Endpoint, options.GetVersionString());
            _queryRestClient         = new QueryRestClient(_clientDiagnostics, _httpPipeline, credential.Endpoint, options.GetVersionString());
            _statisticsRestClient    = new StatisticsRestClient(_clientDiagnostics, _httpPipeline, credential.Endpoint, options.GetVersionString());
            _configurationRestClient = new ConfigurationRestClient(_clientDiagnostics, _httpPipeline, credential.Endpoint, options.GetVersionString());

            // Note that the devices and modules subclient take a reference to the Query convenience layer client. This
            // is because they each expose a helper function that uses the query client for listing twins. By passing in
            // the convenience layer query client rather than the protocol layer query client, we minimize rewriting the
            // same pagination logic that now exists only in the query convenience layer client.
            Query          = new QueryClient(_queryRestClient);
            Devices        = new DevicesClient(_devicesRestClient, Query);
            Modules        = new ModulesClient(_devicesRestClient, _modulesRestClient, Query);
            Statistics     = new StatisticsClient(_statisticsRestClient);
            Configurations = new ConfigurationsClient(_configurationRestClient);

            Messages = new CloudToDeviceMessagesClient();
            Files    = new FilesClient();
            Jobs     = new JobsClient();
        }
Exemple #2
0
        private IotHubServiceClient(IotHubSasCredential credential, IotHubServiceClientOptions options)
        {
            options ??= new IotHubServiceClientOptions();
            _clientDiagnostics = new ClientDiagnostics(options);

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

            _devicesRestClient    = new DevicesRestClient(_clientDiagnostics, _httpPipeline, credential.Endpoint, options.GetVersionString());
            _modulesRestClient    = new ModulesRestClient(_clientDiagnostics, _httpPipeline, credential.Endpoint, options.GetVersionString());
            _queryRestClient      = new QueryRestClient(_clientDiagnostics, _httpPipeline, credential.Endpoint, options.GetVersionString());
            _statisticsRestClient = new StatisticsRestClient(_clientDiagnostics, _httpPipeline, credential.Endpoint, options.GetVersionString());

            Devices    = new DevicesClient(_devicesRestClient, _queryRestClient);
            Modules    = new ModulesClient(_devicesRestClient, _modulesRestClient, _queryRestClient);
            Statistics = new StatisticsClient(_statisticsRestClient);

            Messages = new CloudToDeviceMessagesClient();
            Files    = new FilesClient();
            Jobs     = new JobsClient();
        }
        /// <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);

            _devicesRestClient = new DevicesRestClient(_clientDiagnostics, _httpPipeline, _endpoint, options.GetVersionString());
            _modulesRestClient = new ModulesRestClient(_clientDiagnostics, _httpPipeline, _endpoint, options.GetVersionString());
            _queryRestClient   = new QueryRestClient(_clientDiagnostics, _httpPipeline, _endpoint, options.GetVersionString());

            Devices = new DevicesClient(_devicesRestClient, _queryRestClient);
            Modules = new ModulesClient(_devicesRestClient, _modulesRestClient, _queryRestClient);

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