/// <summary> /// CONSTRUCTOR /// </summary> /// <param name="baseAddress">the <code>Uri</code> HTTP endpoint in the service.</param> /// <param name="authenticationHeaderProvider">the <see cref="IAuthorizationHeaderProvider"/> that will provide the /// authorization token for the HTTP communication.</param> /// <param name="httpTransportSettings"> Specifies HTTP Transport Settings for the request</param> public ContractApiHttp( Uri baseAddress, IAuthorizationHeaderProvider authenticationHeaderProvider, HttpTransportSettings httpTransportSettings) { _baseAddress = baseAddress; _authenticationHeaderProvider = authenticationHeaderProvider; _httpClientHandler = new HttpClientHandler { // Cannot specify a specific protocol here, as desired due to an error: // ProvisioningDeviceClient_ValidRegistrationId_AmqpWithProxy_SymmetricKey_RegisterOk_GroupEnrollment failing for me with System.PlatformNotSupportedException: Operation is not supported on this platform. // When revisiting TLS12 work for DPS, we should figure out why. Perhaps the service needs to support it. //SslProtocols = TlsVersions.Preferred, CheckCertificateRevocationList = TlsVersions.Instance.CertificateRevocationCheck }; IWebProxy webProxy = httpTransportSettings.Proxy; if (webProxy != DefaultWebProxySettings.Instance) { _httpClientHandler.UseProxy = webProxy != null; _httpClientHandler.Proxy = webProxy; } _httpClientObj = new HttpClient(_httpClientHandler) { BaseAddress = _baseAddress, Timeout = s_defaultOperationTimeout, }; _httpClientObj.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(MediaTypeForDeviceManagementApis)); _httpClientObj.DefaultRequestHeaders.ExpectContinue = false; }
internal static Query CreateEnrollmentGroupQuery( ServiceConnectionString provisioningConnectionString, QuerySpecification querySpecification, HttpTransportSettings httpTransportSettings, CancellationToken cancellationToken, string enrollmentGroupId, int pageSize = 0) { if (querySpecification == null) { throw new ArgumentNullException(nameof(querySpecification)); } if (pageSize < 0) { throw new ArgumentException($"{nameof(pageSize)} cannot be negative"); } return(new Query( provisioningConnectionString, GetGetDeviceRegistrationStatus(enrollmentGroupId), querySpecification, httpTransportSettings, pageSize, cancellationToken)); }
/// <summary> /// CONSTRUCTOR /// </summary> /// <param name="baseAddress">the <code>Uri</code> HTTP endpoint in the service.</param> /// <param name="authenticationHeaderProvider">the <see cref="IAuthorizationHeaderProvider"/> that will provide the /// authorization token for the HTTP communication.</param> /// <param name="httpTransportSettings"> Specifies HTTP Transport Settings for the request</param> public ContractApiHttp( Uri baseAddress, IAuthorizationHeaderProvider authenticationHeaderProvider, HttpTransportSettings httpTransportSettings) { _baseAddress = baseAddress; _authenticationHeaderProvider = authenticationHeaderProvider; IWebProxy webProxy = httpTransportSettings.Proxy; if (webProxy != DefaultWebProxySettings.Instance) { HttpClientHandler httpClientHandler = new HttpClientHandler(); httpClientHandler.UseProxy = (webProxy != null); httpClientHandler.Proxy = webProxy; _httpClientObj = new HttpClient(httpClientHandler); } else { _httpClientObj = new HttpClient(); } _httpClientObj.BaseAddress = _baseAddress; _httpClientObj.Timeout = s_defaultOperationTimeout; _httpClientObj.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue(MediaTypeForDeviceManagementApis)); _httpClientObj.DefaultRequestHeaders.ExpectContinue = false; }
internal static Query CreateEnrollmentGroupQuery( ServiceConnectionString provisioningConnectionString, QuerySpecification querySpecification, HttpTransportSettings httpTransportSettings, CancellationToken cancellationToken, string enrollmentGroupId, int pageSize = 0) { /* SRS_REGISTRATION_STATUS_MANAGER_28_008: [The CreateQuery shall throw ArgumentException if the provided querySpecification is null.] */ if (querySpecification == null) { throw new ArgumentNullException(nameof(querySpecification)); } if (pageSize < 0) { throw new ArgumentException($"{nameof(pageSize)} cannot be negative"); } /* SRS_REGISTRATION_STATUS_MANAGER_28_010: [The CreateQuery shall return a new Query for DeviceRegistrationState.] */ return(new Query( provisioningConnectionString, GetGetDeviceRegistrationStatus(enrollmentGroupId), querySpecification, httpTransportSettings, pageSize, cancellationToken)); }
internal Query( ServiceConnectionString serviceConnectionString, string serviceName, QuerySpecification querySpecification, HttpTransportSettings httpTransportSettings, int pageSize, CancellationToken cancellationToken) { /* SRS_QUERY_21_001: [The constructor shall throw ArgumentNullException if the provided serviceConnectionString is null.] */ if (serviceConnectionString == null) { throw new ArgumentNullException(nameof(serviceConnectionString)); } /* SRS_QUERY_21_002: [The constructor shall throw ArgumentException if the provided serviceName is null or empty.] */ if (string.IsNullOrWhiteSpace(serviceName ?? throw new ArgumentNullException(nameof(serviceName)))) { throw new ArgumentException($"{nameof(serviceName)} cannot be an empty string"); } /* SRS_QUERY_21_003: [The constructor shall throw ArgumentException if the provided querySpecification is null.] */ if (querySpecification == null) { throw new ArgumentNullException(nameof(querySpecification)); } /* SRS_QUERY_21_004: [The constructor shall throw ArgumentException if the provided pageSize is negative.] */ if (pageSize < 0) { throw new ArgumentException($"{nameof(pageSize)} cannot be negative."); } // TODO: Refactor ContractApiHttp being created again /* SRS_QUERY_21_005: [The constructor shall create and store a `contractApiHttp` using the provided Service Connection String.] */ _contractApiHttp = new ContractApiHttp( serviceConnectionString.HttpsEndpoint, serviceConnectionString, httpTransportSettings); /* SRS_QUERY_21_006: [The constructor shall store the provided `pageSize`, and `cancelationToken`.] */ PageSize = pageSize; _cancellationToken = cancellationToken; /* SRS_QUERY_21_007: [The constructor shall create and store a JSON from the provided querySpecification.] */ _querySpecificationJson = JsonConvert.SerializeObject(querySpecification); /* SRS_QUERY_21_008: [The constructor shall create and store a queryPath adding `/query` to the provided `targetPath`.] */ _queryPath = GetQueryUri(serviceName); /* SRS_QUERY_21_009: [The constructor shall set continuationToken and current as null.] */ ContinuationToken = null; /* SRS_QUERY_21_010: [The constructor shall set hasNext as true.] */ _hasNext = true; }
internal Query( ServiceConnectionString serviceConnectionString, string serviceName, QuerySpecification querySpecification, HttpTransportSettings httpTransportSettings, int pageSize, CancellationToken cancellationToken) { if (serviceConnectionString == null) { throw new ArgumentNullException(nameof(serviceConnectionString)); } if (string.IsNullOrWhiteSpace(serviceName ?? throw new ArgumentNullException(nameof(serviceName)))) { throw new ArgumentException($"{nameof(serviceName)} cannot be an empty string"); } if (querySpecification == null) { throw new ArgumentNullException(nameof(querySpecification)); } if (pageSize < 0) { throw new ArgumentException($"{nameof(pageSize)} cannot be negative."); } // TODO: Refactor ContractApiHttp being created again _contractApiHttp = new ContractApiHttp( serviceConnectionString.HttpsEndpoint, serviceConnectionString, httpTransportSettings); PageSize = pageSize; _cancellationToken = cancellationToken; _querySpecificationJson = JsonConvert.SerializeObject(querySpecification); _queryPath = GetQueryUri(serviceName); ContinuationToken = null; _hasNext = true; }
internal static Query CreateQuery( ServiceConnectionString provisioningConnectionString, QuerySpecification querySpecification, HttpTransportSettings httpTransportSettings, CancellationToken cancellationToken, int pageSize = 0) { if (querySpecification == null) { throw new ArgumentNullException(nameof(querySpecification)); } if (pageSize < 0) { throw new ArgumentException($"{nameof(pageSize)} cannot be negative"); } return(new Query(provisioningConnectionString, ServiceName, querySpecification, httpTransportSettings, pageSize, cancellationToken)); }
internal static Query CreateQuery( ServiceConnectionString provisioningConnectionString, QuerySpecification querySpecification, HttpTransportSettings httpTransportSettings, CancellationToken cancellationToken, int pageSize = 0) { /* SRS_INDIVIDUAL_ENROLLMENT_MANAGER_21_014: [The CreateQuery shall throw ArgumentException if the provided querySpecification is null.] */ if (querySpecification == null) { throw new ArgumentNullException(nameof(querySpecification)); } if (pageSize < 0) { throw new ArgumentException($"{nameof(pageSize)} cannot be negative"); } /* SRS_INDIVIDUAL_ENROLLMENT_MANAGER_21_015: [The CreateQuery shall return a new Query for IndividualEnrollments.] */ return(new Query(provisioningConnectionString, ServiceName, querySpecification, httpTransportSettings, pageSize, cancellationToken)); }