示例#1
0
        public async Task <int> DeleteAsync(IUser registrar, CancellationToken token = default(CancellationToken))
        {
            if (IsDeleted)
            {
                throw new IdentityException("Identity has been deleted");
            }
            if (registrar == null)
            {
                throw new ArgumentException("Registrar should be a valid member");
            }
            string deleteURL = "";

            try
            {
                deleteURL = client.GetURL(HFCA_IDENTITY + "/" + EnrollmentId);
                logger.Debug($"identity  url: {deleteURL}, registrar: {registrar.Name}");
                JObject result = await client.HttpDeleteAsync(deleteURL, registrar, token).ConfigureAwait(false);

                statusCode = result["statusCode"]?.Value <int>() ?? 500;
                if (statusCode < 400)
                {
                    GetHFCAIdentity(result);
                    logger.Debug($"identity  url: {deleteURL}, registrar: {registrar} done.");
                }

                IsDeleted = true;
                return(statusCode);
            }
            catch (HTTPException e)
            {
                string            msg = $"[Code: {e.StatusCode}] - Error while deleting user '{EnrollmentId}' from url '{deleteURL}': {e.Message}";
                IdentityException identityException = new IdentityException(msg, e);
                logger.Error(msg);
                throw identityException;
            }
            catch (Exception e)
            {
                string            msg = $"Error while deleting user '{EnrollmentId}' from url '{deleteURL}':  {e.Message}";
                IdentityException identityException = new IdentityException(msg, e);
                logger.Error(msg);
                throw identityException;
            }
        }