Ejemplo n.º 1
0
        /// <inheritdoc/>
        public async Task DeleteApplicationAsync(string applicationId, bool force)
        {
            Guid appId       = ToGuidAndVerify(applicationId);
            var  application = await _applications.GetAsync(appId);

            if (!force &&
                application.ApplicationState < ApplicationState.Unregistered)
            {
                throw new ResourceInvalidStateException("The record is not in a valid state for this operation.");
            }

            if (_scope != null)
            {
                ICertificateRequest certificateRequestsService = _scope.Resolve <ICertificateRequest>();
                // mark all requests as deleted
                ReadRequestResultModel[] certificateRequests;
                string nextPageLink = null;
                do
                {
                    (nextPageLink, certificateRequests) = await certificateRequestsService.QueryPageAsync(appId.ToString(), null, nextPageLink);

                    foreach (var request in certificateRequests)
                    {
                        await certificateRequestsService.DeleteAsync(request.RequestId);
                    }
                } while (nextPageLink != null);
            }
            await _applications.DeleteAsync(appId);
        }
Ejemplo n.º 2
0
        public async Task <CertificateRequestQueryResponseApiModel> QueryCertificateRequestsAsync(
            string appId,
            CertificateRequestState?requestState,
            [FromQuery] string nextPageLink,
            [FromQuery] int?pageSize)
        {
            if (Request.Headers.ContainsKey(HttpHeader.MaxItemCount))
            {
                pageSize = int.Parse(Request.Headers[HttpHeader.MaxItemCount]
                                     .FirstOrDefault());
            }
            ReadRequestResultModel[] results;
            (nextPageLink, results) = await _certificateRequest.QueryPageAsync(
                appId,
                (Types.CertificateRequestState?) requestState,
                nextPageLink,
                pageSize);

            return(new CertificateRequestQueryResponseApiModel(results, nextPageLink));
        }
Ejemplo n.º 3
0
        /// <inheritdoc/>
        public async Task <Application> UnregisterApplicationAsync(string applicationId)
        {
            Guid        appId = ToGuidAndVerify(applicationId);
            bool        retryUpdate;
            bool        first = true;
            Application record;

            do
            {
                retryUpdate = false;

                List <byte[]> certificates = new List <byte[]>();

                record = await _applications.GetAsync(appId);

                if (record == null)
                {
                    throw new ResourceNotFoundException("A record with the specified application id does not exist.");
                }

                if (record.ApplicationState >= ApplicationState.Unregistered)
                {
                    throw new ResourceInvalidStateException("The record is not in a valid state for this operation.");
                }

                if (first && _scope != null)
                {
                    ICertificateRequest certificateRequestsService = _scope.Resolve <ICertificateRequest>();
                    // mark all requests as deleted
                    ReadRequestResultModel[] certificateRequests;
                    string nextPageLink = null;
                    do
                    {
                        (nextPageLink, certificateRequests) = await certificateRequestsService.QueryPageAsync(appId.ToString(), null, nextPageLink);

                        foreach (var request in certificateRequests)
                        {
                            if (request.State < CertificateRequestState.Deleted)
                            {
                                await certificateRequestsService.DeleteAsync(request.RequestId);
                            }
                        }
                    } while (nextPageLink != null);
                }
                first = false;

                record.ApplicationState = ApplicationState.Unregistered;
                record.DeleteTime       = DateTime.UtcNow;

                try
                {
                    await _applications.UpdateAsync(appId, record, record.ETag);
                }
                catch (DocumentClientException dce)
                {
                    if (dce.StatusCode == HttpStatusCode.PreconditionFailed)
                    {
                        retryUpdate = true;
                    }
                }
            } while (retryUpdate);

            return(record);
        }