/// <summary>
        /// Executes the operations associated with the cmdlet.
        /// </summary>
        public override void ExecuteCmdlet()
        {
            ResourceCollection <License> licenses = Partner.Customers[CustomerId]
                                                    .Users[UserId].Licenses.GetAsync(LicenseGroup?.Select(item => item).ToList()).GetAwaiter().GetResult();

            WriteObject(licenses.Items.Select(l => new PSLicense(l)), true);
        }
示例#2
0
        private static LicenseGroup Map(SqlDataReader reader)
        {
            int          i   = 0;
            LicenseGroup obj = new LicenseGroup();

            obj.ID          = reader.GetInt32(i++);
            obj.Group       = reader.GetString(i++);
            obj.Description = reader.GetString(i++);

            return(obj);
        }
示例#3
0
        public async Task ComputeGroups(PerformContext performContext)
        {
            Logger.Info(performContext, "Getting the groups from the Portal...");
            var remoteGroups = PortalService.GetAllGroups().ToArray();

            Logger.Info(performContext, "Getting the groups from Active Directory...");
            var adGroups = _activeDirectoryManager.GetAllGroups().ToArray();

            foreach (var adGroup in adGroups)
            {
                performContext?.Cancel();

                var remoteGroup = remoteGroups.FirstOrDefault(rg => rg.Id == adGroup.Id);
                if (remoteGroup == null)
                {
                    var newGroup = LicenseGroup.Create(
                        adGroup,
                        AuthService.GetAccount());

                    await PortalService.AddGroupAsync(newGroup);

                    performContext?.WriteSuccessLine($"+ {newGroup}");
                    Logger.Info($"Created: {newGroup}");
                    Logger.Debug($"{JsonConvert.SerializeObject(newGroup, Formatting.Indented)}");

                    continue;
                }

                remoteGroup.UpdateValues(adGroup);
                await PortalService.UpdateGroupAsync(remoteGroup);

                performContext?.WriteSuccessLine($"^ {remoteGroup}");
                Logger.Info($"Updated:  {remoteGroup}");
                Logger.Debug($"{JsonConvert.SerializeObject(remoteGroup, Formatting.Indented)}");
            }

            var staleGroups = remoteGroups.Except(adGroups, _licenseGroupEqualityComparer).ToArray();

            foreach (var staleGroup in staleGroups)
            {
                performContext?.Cancel();

                if (staleGroup.IsDeleted)
                {
                    continue;
                }

                await PortalService.DeleteGroupAsync(staleGroup);

                performContext?.WriteWarnLine($"- {staleGroup}");
                Logger.Info($"Delete: {staleGroup}");
                Logger.Debug($"{JsonConvert.SerializeObject(staleGroup, Formatting.Indented)}");
            }
        }
        /// <summary>
        /// Executes the operations associated with the cmdlet.
        /// </summary>
        public override void ExecuteCmdlet()
        {
            ResourceCollection <License> licenses;

            try
            {
                licenses = Partner.Customers[CustomerId].Users[UserId].Licenses.Get(LicenseGroup?.Select(item => item).ToList());
                WriteObject(licenses.Items.Select(l => new PSLicense(l)), true);
            }
            finally
            {
                licenses = null;
            }
        }
        public IEnumerable <LicenseGroup> GetAllGroups()
        {
            using (var principalContext = new PrincipalContext(ContextType.Domain))
            {
                using (var groupPrincipal = new GroupPrincipal(principalContext))
                {
                    using (var principalSearcher = new PrincipalSearcher(groupPrincipal))
                    {
                        using (PrincipalSearchResult <Principal> results = principalSearcher.FindAll())
                        {
                            foreach (Principal principal in results)
                            {
                                if (principal.Guid == null)
                                {
                                    Logger.Debug($"Cannot process {principal.Name} because the Id is null. Please check this manually in Active Directory.");
                                    continue;
                                }

                                bool validId = Guid.TryParse(principal.Guid.ToString(), out Guid principalId);
                                if (!validId)
                                {
                                    Logger.Debug($"Cannot process {principal.Name} because the Id is not valid. Please check this manually in Active Directory.");
                                    continue;
                                }

                                if (!(principal is GroupPrincipal group))
                                {
                                    continue;
                                }

                                Logger.Debug($"Retrieving {group.GetDisplayText()} from Active Directory.");

                                LicenseGroup localGroup = GetGroup(principalId);
                                if (localGroup == null)
                                {
                                    continue;
                                }

                                yield return(localGroup);
                            }
                        }
                    }
                }
            }
        }
示例#6
0
        /// <summary>
        /// Executes the operations associated with the cmdlet.
        /// </summary>
        public override void ExecuteCmdlet()
        {
            Scheduler.RunTask(async() =>
            {
                IPartner partner = await PartnerSession.Instance.ClientFactory.CreatePartnerOperationsAsync();

                ResourceCollection <License> licenses = await partner.Customers[CustomerId]
                                                        .Users[UserId].Licenses.GetAsync(LicenseGroup?.Select(item => item).ToList());

                WriteObject(licenses.Items.Select(l => new PSLicense(l)), true);
            }, true);
        }
示例#7
0
 public async Task UpdateGroupAsync(LicenseGroup group)
 {
     _context.UpdateObject(group);
     await SaveChangesAsync();
 }
示例#8
0
 public async Task AddGroupAsync(LicenseGroup group)
 {
     _context.AddToGroups(group);
     await SaveChangesAsync();
 }