Esempio n. 1
0
        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 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));
        }