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));
        }
        public override Task <EnrollmentGroup> UpdateEnrollmentGroupAsync(EnrollmentGroup enrollmentGroup, bool forceUpdate, CancellationToken cancellationToken)
        {
            ThrowIfClosed();
            ValidateEnrollmentGroup(enrollmentGroup);

            if (string.IsNullOrWhiteSpace(enrollmentGroup.ETag) && !forceUpdate)
            {
                throw new ArgumentException(ApiResources.ETagNotSetWhileUpdatingEnrollmentGroup);
            }

            var errorMappingOverrides = new Dictionary <HttpStatusCode, Func <HttpResponseMessage, Task <Exception> > >
            {
                {
                    HttpStatusCode.Conflict,
                    responseMessage => Task.FromResult((Exception) new EnrollmentGroupAlreadyExistsException(enrollmentGroup.EnrollmentGroupId))
                },
                {
                    HttpStatusCode.PreconditionFailed,
                    async(responseMessage) => new PreconditionFailedException(await ExceptionHandlingHelper.GetExceptionMessageAsync(responseMessage))
                }
            };

            PutOperationType operationType = forceUpdate ? PutOperationType.ForceUpdateEntity : PutOperationType.UpdateEntity;

            return(this.httpClientHelper.PutAsync(GetEnrollmentGroupUri(enrollmentGroup.EnrollmentGroupId), enrollmentGroup, operationType, errorMappingOverrides, cancellationToken));
        }
Esempio n. 3
0
        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 void ValidateEnrollmentGroup(EnrollmentGroup enrollmentGroup)
        {
            if (enrollmentGroup == null)
            {
                throw new ArgumentNullException(nameof(enrollmentGroup));
            }

            if (string.IsNullOrWhiteSpace(enrollmentGroup.EnrollmentGroupId))
            {
                throw new ArgumentException("enrollmentGroup.EnrollmentGroupId");
            }
        }
        public override Task <EnrollmentGroup> AddEnrollmentGroupAsync(EnrollmentGroup enrollmentGroup, CancellationToken cancellationToken)
        {
            ThrowIfClosed();
            ValidateEnrollmentGroup(enrollmentGroup);

            var errorMappingOverrides = new Dictionary <HttpStatusCode, Func <HttpResponseMessage, Task <Exception> > >
            {
                {
                    HttpStatusCode.Conflict,
                    responseMessage => Task.FromResult((Exception) new EnrollmentGroupAlreadyExistsException(enrollmentGroup.EnrollmentGroupId))
                }
            };

            return(this.httpClientHelper.PutAsync(GetEnrollmentGroupUri(enrollmentGroup.EnrollmentGroupId), enrollmentGroup, PutOperationType.CreateEntity, errorMappingOverrides, cancellationToken));
        }
        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);
        }
Esempio n. 7
0
        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);
        }
Esempio n. 8
0
 /// <summary>
 /// Enrolls a device group.
 /// </summary>
 /// <param name="enrollmentGroup">Device enrollment group object</param>
 /// <returns>echoes back the EnrollmentGroup object</returns>
 public abstract Task <EnrollmentGroup> AddEnrollmentGroupAsync(EnrollmentGroup enrollmentGroup);
Esempio n. 9
0
 /// <summary>
 /// Updates a device enrollment group.
 /// </summary>
 /// <param name="enrollmentGroup">Device enrollment group object</param>
 /// <returns>echoes back the EnrollmentGroup object</returns>
 public abstract Task <EnrollmentGroup> UpdateEnrollmentGroupAsync(EnrollmentGroup enrollmentGroup);
 public override Task <EnrollmentGroup> UpdateEnrollmentGroupAsync(EnrollmentGroup enrollmentGroup, bool forceUpdate)
 {
     return(this.UpdateEnrollmentGroupAsync(enrollmentGroup, forceUpdate, CancellationToken.None));
 }
 public override Task <EnrollmentGroup> UpdateEnrollmentGroupAsync(EnrollmentGroup enrollmentGroup, CancellationToken cancellationToken)
 {
     return(this.UpdateEnrollmentGroupAsync(enrollmentGroup, false, cancellationToken));
 }
 public override Task RemoveEnrollmentGroupAsync(EnrollmentGroup enrollmentGroup, CancellationToken cancellationToken)
 {
     return(this.RemoveEnrollmentGroupAsync(enrollmentGroup.EnrollmentGroupId, enrollmentGroup, CancellationToken.None));
 }
 public override Task <EnrollmentGroup> AddEnrollmentGroupAsync(EnrollmentGroup enrollmentGroup)
 {
     return(this.AddEnrollmentGroupAsync(enrollmentGroup, CancellationToken.None));
 }
Esempio n. 14
0
 /// <summary>
 /// Enrolls a device group.
 /// </summary>
 /// <param name="enrollmentGroup">Device enrollment group object</param>
 /// <param name="cancellationToken">Cancellation Token</param>
 /// <returns>echoes back the EnrollmentGroup object</returns>
 public abstract Task <EnrollmentGroup> AddEnrollmentGroupAsync(EnrollmentGroup enrollmentGroup, CancellationToken cancellationToken);
Esempio n. 15
0
 /// <summary>
 /// Updates a device enrollment group.
 /// </summary>
 /// <param name="enrollmentGroup">Device enrollment group object</param>
 /// <param name="forceUpdate">Forces the <see cref="EnrollmentGroup"/> object to be updated even if it has changed since it was retrieved last time.</param>
 /// <returns>echoes back the EnrollmentGroup object</returns>
 public abstract Task <EnrollmentGroup> UpdateEnrollmentGroupAsync(EnrollmentGroup enrollmentGroup, bool forceUpdate);
Esempio n. 16
0
 /// <summary>
 /// Removes a device enrollment group.
 /// </summary>
 /// <param name="enrollmentGroup">Device enrollment group object</param>
 /// <param name="cancellationToken">Cancellation Token</param>
 public abstract Task RemoveEnrollmentGroupAsync(EnrollmentGroup enrollmentGroup, CancellationToken cancellationToken);
Esempio n. 17
0
 /// <summary>
 /// Removes a device enrollment group.
 /// </summary>
 /// <param name="enrollmentGroup">Device enrollment group object</param>
 public abstract Task RemoveEnrollmentGroupAsync(EnrollmentGroup enrollmentGroup);
Esempio n. 18
0
 /// <summary>
 /// Updates a device enrollment group.
 /// </summary>
 /// <param name="enrollmentGroup">Device enrollment group object</param>
 /// <param name="forceUpdate">Forces the <see cref="EnrollmentGroup"/> object to be updated even if it has changed since it was retrieved last time.</param>
 /// <param name="cancellationToken">Cancellation Token</param>
 /// <returns>echoes back the EnrollmentGroup object</returns>
 public abstract Task <EnrollmentGroup> UpdateEnrollmentGroupAsync(EnrollmentGroup enrollmentGroup, bool forceUpdate, CancellationToken cancellationToken);