internal static async Task <IndividualEnrollment> CreateOrUpdateAsync( IContractApiHttp contractApiHttp, IndividualEnrollment individualEnrollment, CancellationToken cancellationToken) { if (individualEnrollment == null) { throw new ArgumentNullException(nameof(individualEnrollment)); } ContractApiResponse contractApiResponse = await contractApiHttp .RequestAsync( HttpMethod.Put, GetEnrollmentUri(individualEnrollment.RegistrationId), null, JsonConvert.SerializeObject(individualEnrollment), individualEnrollment.ETag, cancellationToken) .ConfigureAwait(false); if (contractApiResponse.Body == null) { throw new ProvisioningServiceClientHttpException(contractApiResponse, true); } return(JsonConvert.DeserializeObject <IndividualEnrollment>(contractApiResponse.Body)); }
internal static async Task <EnrollmentGroup> CreateOrUpdateAsync( IContractApiHttp contractApiHttp, EnrollmentGroup enrollmentGroup, CancellationToken cancellationToken) { if (enrollmentGroup == null) { throw new ArgumentNullException(nameof(enrollmentGroup)); } ContractApiResponse contractApiResponse = await contractApiHttp .RequestAsync( HttpMethod.Put, GetEnrollmentUri(enrollmentGroup.EnrollmentGroupId), null, JsonConvert.SerializeObject(enrollmentGroup), enrollmentGroup.ETag, cancellationToken) .ConfigureAwait(false); if (contractApiResponse.Body == null) { throw new ProvisioningServiceClientHttpException(contractApiResponse, true); } return(JsonConvert.DeserializeObject <EnrollmentGroup>(contractApiResponse.Body)); }
internal static async Task <BulkEnrollmentOperationResult> BulkOperationAsync( IContractApiHttp contractApiHttp, BulkOperationMode bulkOperationMode, IEnumerable <IndividualEnrollment> individualEnrollments, CancellationToken cancellationToken) { if (individualEnrollments == null) { throw new ArgumentNullException(nameof(individualEnrollments)); } if (!individualEnrollments.Any()) { throw new ArgumentException($"{nameof(individualEnrollments)} cannot be empty."); } ContractApiResponse contractApiResponse = await contractApiHttp .RequestAsync( HttpMethod.Post, GetEnrollmentUri(), null, BulkEnrollmentOperation.ToJson(bulkOperationMode, individualEnrollments), null, cancellationToken) .ConfigureAwait(false); if (contractApiResponse.Body == null) { throw new ProvisioningServiceClientHttpException(contractApiResponse, true); } return(JsonConvert.DeserializeObject <BulkEnrollmentOperationResult>(contractApiResponse.Body)); }
internal static async Task <IndividualEnrollment> GetAsync( IContractApiHttp contractApiHttp, string registrationId, CancellationToken cancellationToken) { /* SRS_INDIVIDUAL_ENROLLMENT_MANAGER_21_007: [The GetAsync shall throw ArgumentException if the provided registrationId is null or empty.] */ ParserUtils.EnsureRegistrationId(registrationId); /* SRS_INDIVIDUAL_ENROLLMENT_MANAGER_21_008: [The GetAsync shall sent the Get HTTP request to get the individualEnrollment information.] */ ContractApiResponse contractApiResponse = await contractApiHttp.RequestAsync( HttpMethod.Get, GetEnrollmentUri(registrationId), null, null, null, cancellationToken).ConfigureAwait(false); if (contractApiResponse.Body == null) { throw new ProvisioningServiceClientHttpException(contractApiResponse, true); } /* SRS_INDIVIDUAL_ENROLLMENT_MANAGER_21_009: [The GetAsync shall return an IndividualEnrollment object created from the body of the HTTP response.] */ return(JsonConvert.DeserializeObject <IndividualEnrollment>(contractApiResponse.Body)); }
internal static async Task <EnrollmentGroup> CreateOrUpdateAsync( IContractApiHttp contractApiHttp, EnrollmentGroup enrollmentGroup, CancellationToken cancellationToken) { /* SRS_ENROLLMENT_GROUP_MANAGER_28_001: [The CreateOrUpdateAsync shall throw ArgumentNullException if the provided enrollmentGroup is null.] */ if (enrollmentGroup == null) { throw new ArgumentNullException(nameof(enrollmentGroup)); } /* SRS_ENROLLMENT_GROUP_MANAGER_28_002: [The CreateOrUpdateAsync shall sent the Put HTTP request to create or update the enrollmentGroup.] */ ContractApiResponse contractApiResponse = await contractApiHttp.RequestAsync( HttpMethod.Put, GetEnrollmentUri(enrollmentGroup.EnrollmentGroupId), null, JsonConvert.SerializeObject(enrollmentGroup), enrollmentGroup.ETag, cancellationToken).ConfigureAwait(false); if (contractApiResponse.Body == null) { throw new ProvisioningServiceClientHttpException(contractApiResponse, true); } /* SRS_ENROLLMENT_GROUP_MANAGER_28_003: [The CreateOrUpdateAsync shall return an enrollmentGroup object created from the body of the HTTP response.] */ return(JsonConvert.DeserializeObject <EnrollmentGroup>(contractApiResponse.Body)); }
internal static async Task <DeviceRegistrationState> GetAsync( IContractApiHttp contractApiHttp, string id, CancellationToken cancellationToken) { /* SRS_REGISTRATION_STATUS_MANAGER_28_001: [The GetAsync shall throw ArgumentException if the provided ID is null or empty.] */ ParserUtils.EnsureRegistrationId(id); /* SRS_REGISTRATION_STATUS_MANAGER_28_002: [The GetAsync shall sent the Get HTTP request to get the deviceRegistrationState information.] */ ContractApiResponse contractApiResponse = await contractApiHttp.RequestAsync( HttpMethod.Get, GetDeviceRegistrationStatusUri(id), null, null, null, cancellationToken).ConfigureAwait(false); if (contractApiResponse.Body == null) { throw new ProvisioningServiceClientHttpException(contractApiResponse, true); } /* SRS_REGISTRATION_STATUS_MANAGER_28_003: [The GetAsync shall return a DeviceRegistrationState object created from the body of the HTTP response.] */ return(JsonConvert.DeserializeObject <DeviceRegistrationState>(contractApiResponse.Body)); }
internal static async Task <IndividualEnrollment> CreateOrUpdateAsync( IContractApiHttp contractApiHttp, IndividualEnrollment individualEnrollment, CancellationToken cancellationToken) { /* SRS_INDIVIDUAL_ENROLLMENT_MANAGER_21_001: [The CreateOrUpdateAsync shall throw ArgumentException if the provided individualEnrollment is null.] */ if (individualEnrollment == null) { throw new ArgumentNullException(nameof(individualEnrollment)); } /* SRS_INDIVIDUAL_ENROLLMENT_MANAGER_21_002: [The CreateOrUpdateAsync shall sent the Put HTTP request to create or update the individualEnrollment.] */ ContractApiResponse contractApiResponse = await contractApiHttp.RequestAsync( HttpMethod.Put, GetEnrollmentUri(individualEnrollment.RegistrationId), null, JsonConvert.SerializeObject(individualEnrollment), individualEnrollment.ETag, cancellationToken).ConfigureAwait(false); if (contractApiResponse.Body == null) { throw new ProvisioningServiceClientHttpException(contractApiResponse, true); } /* SRS_INDIVIDUAL_ENROLLMENT_MANAGER_21_003: [The CreateOrUpdateAsync shall return an IndividualEnrollment object created from the body of the HTTP response.] */ return(JsonConvert.DeserializeObject <IndividualEnrollment>(contractApiResponse.Body)); }
internal static async Task <BulkEnrollmentOperationResult> BulkOperationAsync( IContractApiHttp contractApiHttp, BulkOperationMode bulkOperationMode, IEnumerable <IndividualEnrollment> individualEnrollments, CancellationToken cancellationToken) { /* SRS_INDIVIDUAL_ENROLLMENT_MANAGER_21_004: [The BulkOperationAsync shall throw ArgumentException if the provided * individualEnrollments is null or empty.] */ if (!(individualEnrollments ?? throw new ArgumentNullException(nameof(individualEnrollments))).Any()) { throw new ArgumentException($"{nameof(individualEnrollments)} cannot be empty"); } /* SRS_INDIVIDUAL_ENROLLMENT_MANAGER_21_005: [The BulkOperationAsync shall sent the Put HTTP request to run the bulk operation to the collection of the individualEnrollment.] */ ContractApiResponse contractApiResponse = await contractApiHttp.RequestAsync( HttpMethod.Post, GetEnrollmentUri(), null, BulkEnrollmentOperation.ToJson(bulkOperationMode, individualEnrollments), null, cancellationToken).ConfigureAwait(false); if (contractApiResponse.Body == null) { throw new ProvisioningServiceClientHttpException(contractApiResponse, true); } /* SRS_INDIVIDUAL_ENROLLMENT_MANAGER_21_006: [The BulkOperationAsync shall return an BulkEnrollmentOperationResult object created from the body of the HTTP response.] */ return(JsonConvert.DeserializeObject <BulkEnrollmentOperationResult>(contractApiResponse.Body)); }
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; }
/// <summary> /// Releases the unmanaged resources used by the Component and optionally releases the managed resources. /// </summary> /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param> protected virtual void Dispose(bool disposing) { if (disposing) { if (_contractApiHttp != null) { _contractApiHttp.Dispose(); _contractApiHttp = null; } } }
internal static async Task DeleteAsync( IContractApiHttp contractApiHttp, string enrollmentGroupId, CancellationToken cancellationToken, string eTag = null) { /* SRS_ENROLLMENT_GROUP_MANAGER_28_013: [The DeleteAsync shall sent the Delete HTTP request to remove the EnrollmentGroup.] */ await contractApiHttp.RequestAsync( HttpMethod.Delete, GetEnrollmentUri(enrollmentGroupId), null, null, eTag, cancellationToken).ConfigureAwait(false); }
internal static async Task DeleteAsync( IContractApiHttp contractApiHttp, string registrationId, CancellationToken cancellationToken, string eTag = null) { /* SRS_INDIVIDUAL_ENROLLMENT_MANAGER_21_013: [The DeleteAsync shall sent the Delete HTTP request to remove the individualEnrollment.] */ await contractApiHttp.RequestAsync( HttpMethod.Delete, GetEnrollmentUri(registrationId), null, null, eTag, cancellationToken).ConfigureAwait(false); }
internal static async Task DeleteAsync( IContractApiHttp contractApiHttp, string id, CancellationToken cancellationToken, string eTag = null) { /* SRS_REGISTRATION_STATUS_MANAGER_28_007: [The DeleteAsync shall sent the Delete HTTP request to remove the deviceRegistrationState.] */ await contractApiHttp.RequestAsync( HttpMethod.Delete, GetDeviceRegistrationStatusUri(id), null, null, eTag, cancellationToken).ConfigureAwait(false); }
internal static async Task DeleteAsync( IContractApiHttp contractApiHttp, string id, CancellationToken cancellationToken, string eTag = null) { await contractApiHttp .RequestAsync( HttpMethod.Delete, GetDeviceRegistrationStatusUri(id), null, null, eTag, cancellationToken) .ConfigureAwait(false); }
internal static async Task DeleteAsync( IContractApiHttp contractApiHttp, string registrationId, CancellationToken cancellationToken, string eTag = null) { await contractApiHttp .RequestAsync( HttpMethod.Delete, GetEnrollmentUri(registrationId), null, null, eTag, cancellationToken) .ConfigureAwait(false); }
internal static async Task DeleteAsync( IContractApiHttp contractApiHttp, string registrationId, CancellationToken cancellationToken, string eTag = null) { /* SRS_INDIVIDUAL_ENROLLMENT_MANAGER_21_012: [The DeleteAsync shall throw ArgumentException if the provided registrationId is null or empty.] */ ParserUtils.EnsureRegistrationId(registrationId); /* SRS_INDIVIDUAL_ENROLLMENT_MANAGER_21_013: [The DeleteAsync shall sent the Delete HTTP request to remove the individualEnrollment.] */ await contractApiHttp.RequestAsync( HttpMethod.Delete, GetEnrollmentUri(registrationId), null, null, eTag, cancellationToken).ConfigureAwait(false); }
internal static async Task DeleteAsync( IContractApiHttp contractApiHttp, string enrollmentGroupId, CancellationToken cancellationToken, string eTag = null) { /* SRS_ENROLLMENT_GROUP_MANAGER_28_012: [The DeleteAsync shall throw ArgumentException if the provided enrollmentGroupId is null or empty.] */ ParserUtils.EnsureValidId(enrollmentGroupId); /* SRS_ENROLLMENT_GROUP_MANAGER_28_013: [The DeleteAsync shall sent the Delete HTTP request to remove the EnrollmentGroup.] */ await contractApiHttp.RequestAsync( HttpMethod.Delete, GetEnrollmentUri(enrollmentGroupId), null, null, eTag, cancellationToken).ConfigureAwait(false); }
internal static async Task DeleteAsync( IContractApiHttp contractApiHttp, string id, CancellationToken cancellationToken, string eTag = null) { /* SRS_REGISTRATION_STATUS_MANAGER_28_006: [The DeleteAsync shall throw ArgumentException if the provided id is null or empty.] */ ParserUtils.EnsureRegistrationId(id); /* SRS_REGISTRATION_STATUS_MANAGER_28_007: [The DeleteAsync shall sent the Delete HTTP request to remove the deviceRegistrationState.] */ await contractApiHttp.RequestAsync( HttpMethod.Delete, GetDeviceRegistrationStatusUri(id), null, null, eTag, cancellationToken).ConfigureAwait(false); }
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 async Task DeleteAsync( IContractApiHttp contractApiHttp, DeviceRegistrationState deviceRegistrationState, CancellationToken cancellationToken) { if (deviceRegistrationState == null) { throw new ArgumentNullException(nameof(deviceRegistrationState)); } await contractApiHttp .RequestAsync( HttpMethod.Delete, GetDeviceRegistrationStatusUri(deviceRegistrationState.RegistrationId), null, null, deviceRegistrationState.ETag, cancellationToken) .ConfigureAwait(false); }
internal static async Task <AttestationMechanism> GetEnrollmentAttestationAsync( IContractApiHttp contractApiHttp, string registrationId, CancellationToken cancellationToken) { ContractApiResponse contractApiResponse = await contractApiHttp.RequestAsync( HttpMethod.Post, GetEnrollmentAttestationUri(registrationId), null, null, null, cancellationToken).ConfigureAwait(false); if (contractApiResponse.Body == null) { throw new ProvisioningServiceClientHttpException(contractApiResponse, true); } return(JsonConvert.DeserializeObject <AttestationMechanism>(contractApiResponse.Body)); }
internal static async Task DeleteAsync( IContractApiHttp contractApiHttp, IndividualEnrollment individualEnrollment, CancellationToken cancellationToken) { /* SRS_INDIVIDUAL_ENROLLMENT_MANAGER_21_010: [The DeleteAsync shall throw ArgumentException if the provided individualEnrollment is null.] */ if (individualEnrollment == null) { throw new ArgumentNullException(nameof(individualEnrollment)); } /* SRS_INDIVIDUAL_ENROLLMENT_MANAGER_21_011: [The DeleteAsync shall sent the Delete HTTP request to remove the individualEnrollment.] */ await contractApiHttp.RequestAsync( HttpMethod.Delete, GetEnrollmentUri(individualEnrollment.RegistrationId), null, null, individualEnrollment.ETag, cancellationToken).ConfigureAwait(false); }
internal static async Task DeleteAsync( IContractApiHttp contractApiHttp, DeviceRegistrationState deviceRegistrationState, CancellationToken cancellationToken) { /* SRS_REGISTRATION_STATUS_MANAGER_28_004: [The DeleteAsync shall throw ArgumentException if the provided deviceRegistrationState is null.] */ if (deviceRegistrationState == null) { throw new ArgumentNullException(nameof(deviceRegistrationState)); } /* SRS_REGISTRATION_STATUS_MANAGER_28_005: [The DeleteAsync shall sent the Delete HTTP request to remove the deviceRegistrationState.] */ await contractApiHttp.RequestAsync( HttpMethod.Delete, GetDeviceRegistrationStatusUri(deviceRegistrationState.RegistrationId), null, null, deviceRegistrationState.ETag, cancellationToken).ConfigureAwait(false); }
internal static async Task DeleteAsync( IContractApiHttp contractApiHttp, EnrollmentGroup enrollmentGroup, CancellationToken cancellationToken) { /* SRS_ENROLLMENT_GROUP_MANAGER_28_010: [The DeleteAsync shall throw ArgumentNullException if the provided enrollmentGroup is null.] */ if (enrollmentGroup == null) { throw new ArgumentNullException(nameof(enrollmentGroup)); } /* SRS_ENROLLMENT_GROUP_MANAGER_28_011: [The DeleteAsync shall sent the Delete HTTP request to remove the enrollmentGroup.] */ await contractApiHttp.RequestAsync( HttpMethod.Delete, GetEnrollmentUri(enrollmentGroup.EnrollmentGroupId), null, null, enrollmentGroup.ETag, cancellationToken).ConfigureAwait(false); }
internal static async Task DeleteAsync( IContractApiHttp contractApiHttp, EnrollmentGroup enrollmentGroup, CancellationToken cancellationToken) { if (enrollmentGroup == null) { throw new ArgumentNullException(nameof(enrollmentGroup)); } await contractApiHttp .RequestAsync( HttpMethod.Delete, GetEnrollmentUri(enrollmentGroup.EnrollmentGroupId), null, null, enrollmentGroup.ETag, cancellationToken) .ConfigureAwait(false); }
internal static async Task DeleteAsync( IContractApiHttp contractApiHttp, IndividualEnrollment individualEnrollment, CancellationToken cancellationToken) { if (individualEnrollment == null) { throw new ArgumentNullException(nameof(individualEnrollment)); } await contractApiHttp .RequestAsync( HttpMethod.Delete, GetEnrollmentUri(individualEnrollment.RegistrationId), null, null, individualEnrollment.ETag, cancellationToken) .ConfigureAwait(false); }
internal static async Task <DeviceRegistrationState> GetAsync( IContractApiHttp contractApiHttp, string id, CancellationToken cancellationToken) { ContractApiResponse contractApiResponse = await contractApiHttp .RequestAsync( HttpMethod.Get, GetDeviceRegistrationStatusUri(id), null, null, null, cancellationToken) .ConfigureAwait(false); if (contractApiResponse.Body == null) { throw new ProvisioningServiceClientHttpException(contractApiResponse, true); } return(JsonConvert.DeserializeObject <DeviceRegistrationState>(contractApiResponse.Body)); }
internal static async Task <EnrollmentGroup> GetAsync( IContractApiHttp contractApiHttp, string enrollmentGroupId, CancellationToken cancellationToken) { /* SRS_ENROLLMENT_GROUP_MANAGER_28_008: [The GetAsync shall sent the Get HTTP request to get the enrollmentGroup information.] */ ContractApiResponse contractApiResponse = await contractApiHttp.RequestAsync( HttpMethod.Get, GetEnrollmentUri(enrollmentGroupId), null, null, null, cancellationToken).ConfigureAwait(false); if (contractApiResponse.Body == null) { throw new ProvisioningServiceClientHttpException(contractApiResponse, true); } /* SRS_ENROLLMENT_GROUP_MANAGER_28_009: [The GetAsync shall return an EnrollmentGroup object created from the body of the HTTP response.] */ return(JsonConvert.DeserializeObject <EnrollmentGroup>(contractApiResponse.Body)); }