示例#1
0
        public virtual async Task <Status> RemoveChildEnterprise(IApplicationsIoTService appIoTArch,
                                                                 IEnterprisesManagementService entMgr, IIdentityAccessService idMgr,
                                                                 string childEntLookup, string parentEntLookup)
        {
            var childEnt = State.EnterpriseConfig.ChildEnterprises.FirstOrDefault(ent =>
                                                                                  ent.Lookup == childEntLookup
                                                                                  );
            var devices = await appIoTArch.ListEnrolledDevices(childEntLookup);

            //Remove devices

            await devices.Model.Items.Each(async d => {
                await revokeDeviceEnrollment(appIoTArch, childEntLookup, d.DeviceID);
            }, parallel : true);


            //If its the active ent set active to null
            if (State.ActiveEnterpriseConfig.ActiveEnterprise != null && State.ActiveEnterpriseConfig?.ActiveEnterprise.Lookup == childEntLookup)
            {
                State.ActiveEnterpriseConfig.ActiveEnterprise = null;
            }

            var revokePassportRequest = await idMgr.RevokePassport(parentEntLookup, childEnt.Name);

            var revokeAccessCardRequest = await idMgr.RevokeAccessCard(new Host.TempRefit.RevokeAccessCardRequest()
            {
                AccessConfiguration = "LCU",
                Username            = childEnt.Name
            }, childEntLookup);

            if (revokeAccessCardRequest.Status.Code == 1)
            {
                log.LogError($"Unable to revoke access cards: {revokeAccessCardRequest.Status.Message}");
            }

            var revokeLicenceAccess = await idMgr.RevokeLicense(parentEntLookup, childEnt.Name, "iot");

            if (revokeLicenceAccess.Status.Code == 1)
            {
                log.LogError($"Unable to revoke license access: {revokeLicenceAccess.Status.Message}");
            }

            //TODO removing the API Management keys

            var cancelUserSubscription = await entMgr.CancelSubscriptionByUser(childEnt.Name, parentEntLookup, "iot");

            if (cancelUserSubscription.Status.Code == 1)
            {
                log.LogError($"Unable to cancel subscription: {cancelUserSubscription.Status.Message}");
            }

            var deleteRequest = await entMgr.DeleteEnterpriseByLookup(childEntLookup, new Host.TempRefit.DeleteEnterpriseByLookupRequest()
            {
                Password = "******"
            });

            await LoadChildEnterprises(entMgr, parentEntLookup, appIoTArch, idMgr);

            return(Status.Success);
        }