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)); }
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); }
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); }
/// <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);
/// <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)); }
/// <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);
/// <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);
/// <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);
/// <summary> /// Removes a device enrollment group. /// </summary> /// <param name="enrollmentGroup">Device enrollment group object</param> public abstract Task RemoveEnrollmentGroupAsync(EnrollmentGroup enrollmentGroup);
/// <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);