Exemplo n.º 1
0
        /// <summary>
        /// Executes the operations associated with the cmdlet.
        /// </summary>
        public override void ExecuteCmdlet()
        {
            Scheduler.RunTask(async() =>
            {
                string value = string.IsNullOrEmpty(UserId) ? UserPrincipalName : UserId;

                if (ShouldProcess(string.Format(CultureInfo.CurrentCulture, Resources.RestorePartnerCustomerUserWhatIf, value)))
                {
                    IPartner partner = await PartnerSession.Instance.ClientFactory.CreatePartnerOperationsAsync(CorrelationId, CancellationToken).ConfigureAwait(false);
                    string userId;

                    if (ParameterSetName.Equals("ByUpn", StringComparison.InvariantCultureIgnoreCase))
                    {
                        SimpleFieldFilter filter     = new SimpleFieldFilter("UserState", FieldFilterOperation.Equals, "Inactive");
                        IQuery simpleQueryWithFilter = QueryFactory.BuildSimpleQuery(filter);
                        IResourceCollectionEnumerator <SeekBasedResourceCollection <CustomerUser> > usersEnumerator;
                        List <CustomerUser> users = new List <CustomerUser>();
                        SeekBasedResourceCollection <CustomerUser> seekUsers;

                        seekUsers       = await partner.Customers[CustomerId].Users.QueryAsync(simpleQueryWithFilter, CancellationToken).ConfigureAwait(false);
                        usersEnumerator = partner.Enumerators.CustomerUsers.Create(seekUsers);

                        while (usersEnumerator.HasValue)
                        {
                            users.AddRange(usersEnumerator.Current.Items);
                            await usersEnumerator.NextAsync(RequestContextFactory.Create(CorrelationId), CancellationToken).ConfigureAwait(false);
                        }

                        CustomerUser user = users.SingleOrDefault(u => string.Equals(u.UserPrincipalName, UserPrincipalName, StringComparison.CurrentCultureIgnoreCase));

                        if (user == null)
                        {
                            throw new PSInvalidOperationException($"Unable to locate {UserPrincipalName}");
                        }

                        userId = user.Id;
                    }
                    else
                    {
                        userId = UserId;
                    }

                    CustomerUser updatedCustomerUser = new CustomerUser
                    {
                        State = UserState.Active
                    };

                    await partner.Customers.ById(CustomerId).Users.ById(userId).PatchAsync(updatedCustomerUser, CancellationToken).ConfigureAwait(false);
                }
            }, true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Executes the operations associated with the cmdlet.
        /// </summary>
        public override void ExecuteCmdlet()
        {
            Scheduler.RunTask(async() =>
            {
                IPartner partner = await PartnerSession.Instance.ClientFactory.CreatePartnerOperationsAsync().ConfigureAwait(false);
                IResourceCollectionEnumerator <SeekBasedResourceCollection <Customer> > customersEnumerator;
                List <Customer> customers = new List <Customer>();
                SeekBasedResourceCollection <Customer> seekCustomers;

                if (!string.IsNullOrEmpty(CustomerId))
                {
                    WriteObject(new PSCustomer(await partner.Customers[CustomerId].GetAsync().ConfigureAwait(false)));
                    return;
                }
                if (ParameterSetName.Equals("ByDomain", StringComparison.InvariantCultureIgnoreCase))
                {
                    Graph.GraphServiceClient client = PartnerSession.Instance.ClientFactory.CreateGraphServiceClient() as Graph.GraphServiceClient;
                    client.AuthenticationProvider   = new GraphAuthenticationProvider();

                    Graph.IGraphServiceContractsCollectionPage data = await client.Contracts.Request().Filter($"defaultDomainName eq '{Domain}'").GetAsync().ConfigureAwait(false);

                    if (data.CurrentPage != null && data.CurrentPage.Any())
                    {
                        Customer customer = await partner.Customers.ById(data.CurrentPage[0].CustomerId.ToString()).GetAsync().ConfigureAwait(false);
                        WriteObject(new PSCustomer(customer));
                        return;
                    }

                    seekCustomers = await partner.Customers.QueryAsync(
                        QueryFactory.BuildSimpleQuery(new SimpleFieldFilter(
                                                          CustomerSearchField.Domain.ToString(),
                                                          FieldFilterOperation.StartsWith,
                                                          Domain))).ConfigureAwait(false);
                }
                else
                {
                    seekCustomers = await partner.Customers.GetAsync().ConfigureAwait(false);
                }

                customersEnumerator = partner.Enumerators.Customers.Create(seekCustomers);

                while (customersEnumerator.HasValue)
                {
                    customers.AddRange(customersEnumerator.Current.Items);
                    await customersEnumerator.NextAsync().ConfigureAwait(false);
                }

                WriteObject(customers.Select(c => new PSCustomer(c)), true);
            }, true);
        }
        /// <summary>
        /// Gets a list of deleted users from Partner Center.
        /// </summary>
        /// <param name="customerId">Identifier of the customer.</param>
        /// <exception cref="ArgumentException">
        /// <paramref name="customerId"/> is empty or null.
        /// </exception>
        private List <CustomerUser> GetDeletedUsers(string customerId)
        {
            SimpleFieldFilter filter = new SimpleFieldFilter("UserState", FieldFilterOperation.Equals, "Inactive");
            IQuery            simpleQueryWithFilter = QueryFactory.BuildSimpleQuery(filter);
            IResourceCollectionEnumerator <SeekBasedResourceCollection <CustomerUser> > usersEnumerator;
            List <CustomerUser> users;
            SeekBasedResourceCollection <CustomerUser> seekUsers;

            customerId.AssertNotEmpty(nameof(customerId));

            users = new List <CustomerUser>();

            seekUsers       = Partner.Customers[customerId].Users.QueryAsync(simpleQueryWithFilter).GetAwaiter().GetResult();
            usersEnumerator = Partner.Enumerators.CustomerUsers.Create(seekUsers);
            while (usersEnumerator.HasValue)
            {
                users.AddRange(usersEnumerator.Current.Items);
                usersEnumerator.NextAsync().GetAwaiter().GetResult();
            }

            return(users);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Executes the operations associated with the cmdlet.
        /// </summary>
        public override void ExecuteCmdlet()
        {
            IResourceCollectionEnumerator <SeekBasedResourceCollection <Customer> > customersEnumerator;
            List <Customer> customers;
            SeekBasedResourceCollection <Customer> seekCustomers;

            if (string.IsNullOrEmpty(CustomerId))
            {
                customers = new List <Customer>();

                if (string.IsNullOrEmpty(Domain))
                {
                    seekCustomers = Partner.Customers.GetAsync().GetAwaiter().GetResult();
                }
                else
                {
                    seekCustomers = Partner.Customers.QueryAsync(
                        QueryFactory.BuildSimpleQuery(new SimpleFieldFilter(
                                                          CustomerSearchField.Domain.ToString(),
                                                          FieldFilterOperation.StartsWith,
                                                          Domain))).GetAwaiter().GetResult();
                }

                customersEnumerator = Partner.Enumerators.Customers.Create(seekCustomers);

                while (customersEnumerator.HasValue)
                {
                    customers.AddRange(customersEnumerator.Current.Items);
                    customersEnumerator.NextAsync().GetAwaiter().GetResult();
                }

                WriteObject(customers.Select(c => new PSCustomer(c)), true);
            }
            else
            {
                WriteObject(new PSCustomer(Partner.Customers[CustomerId].GetAsync().GetAwaiter().GetResult()));
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Executes the operations associated with the cmdlet.
        /// </summary>
        public override void ExecuteCmdlet()
        {
            Scheduler.RunTask(async() =>
            {
                IPartner partner = await PartnerSession.Instance.ClientFactory.CreatePartnerOperationsAsync(CorrelationId, CancellationToken).ConfigureAwait(false);

                if (ParameterSetName.Equals("ByUserId", StringComparison.InvariantCultureIgnoreCase))
                {
                    CustomerUser customerUser = await partner.Customers[CustomerId].Users[UserId].GetAsync(CancellationToken).ConfigureAwait(false);
                    WriteObject(new PSCustomerUser(customerUser));
                }
                else if (ParameterSetName.Equals("ByUserState", StringComparison.InvariantCultureIgnoreCase) && ReturnDeletedUsers.ToBool())
                {
                    SimpleFieldFilter filter     = new SimpleFieldFilter("UserState", FieldFilterOperation.Equals, "Inactive");
                    IQuery simpleQueryWithFilter = QueryFactory.BuildSimpleQuery(filter);
                    IResourceCollectionEnumerator <SeekBasedResourceCollection <CustomerUser> > usersEnumerator;
                    List <CustomerUser> users;
                    SeekBasedResourceCollection <CustomerUser> seekUsers;

                    users = new List <CustomerUser>();

                    seekUsers       = await partner.Customers[CustomerId].Users.QueryAsync(simpleQueryWithFilter, CancellationToken).ConfigureAwait(false);
                    usersEnumerator = partner.Enumerators.CustomerUsers.Create(seekUsers);

                    while (usersEnumerator.HasValue)
                    {
                        users.AddRange(usersEnumerator.Current.Items);
                        await usersEnumerator.NextAsync(RequestContextFactory.Create(CorrelationId), CancellationToken).ConfigureAwait(false);
                    }

                    WriteObject(users.Select(u => new PSCustomerUser(u)), true);
                }
                else if (ParameterSetName.Equals("ByUpn", StringComparison.InvariantCultureIgnoreCase))
                {
                    GraphServiceClient client     = PartnerSession.Instance.ClientFactory.CreateGraphServiceClient() as GraphServiceClient;
                    client.AuthenticationProvider = new GraphAuthenticationProvider(CustomerId);

                    Graph.User user           = await client.Users[UserPrincipalName].Request().GetAsync(CancellationToken).ConfigureAwait(false);
                    CustomerUser customerUser = await partner.Customers[CustomerId].Users[user.Id].GetAsync(CancellationToken).ConfigureAwait(false);

                    WriteObject(customerUser);
                }
                else
                {
                    IResourceCollectionEnumerator <SeekBasedResourceCollection <CustomerUser> > usersEnumerator;
                    List <CustomerUser> users;
                    SeekBasedResourceCollection <CustomerUser> seekUsers;

                    users = new List <CustomerUser>();

                    seekUsers       = await partner.Customers[CustomerId].Users.GetAsync(CancellationToken).ConfigureAwait(false);
                    usersEnumerator = partner.Enumerators.CustomerUsers.Create(seekUsers);

                    while (usersEnumerator.HasValue)
                    {
                        users.AddRange(usersEnumerator.Current.Items);
                        await usersEnumerator.NextAsync(RequestContextFactory.Create(CorrelationId), CancellationToken).ConfigureAwait(false);
                    }

                    WriteObject(users.Select(u => new PSCustomerUser(u)), true);
                }
            }, true);
        }