Пример #1
0
        public static IEnumerable <MicrosoftGraphUser> FilterUsers(this IMicrosoftGraphClient client, MicrosoftObjectFilterOptions options)
        {
            if (!string.IsNullOrEmpty(options.Id))
            {
                try
                {
                    MicrosoftGraphUser user = client.Users.GetUser(options.Id);
                    if (user != null)
                    {
                        return(new List <MicrosoftGraphUser> {
                            user
                        });
                    }
                }
                catch { /* The group does not exist, ignore the exception */ }
            }
            else if (!string.IsNullOrEmpty(options.UPN) || !string.IsNullOrEmpty(options.Mail))
            {
                IList <MicrosoftGraphUser> result = null;
                try
                {
                    string upnOrMail  = options.UPN ?? options.Mail;
                    var    odataQuery = new ODataQuery <MicrosoftGraphUser>();
                    if (!string.IsNullOrEmpty(options.UPN))
                    {
                        odataQuery.SetFilter(u => u.UserPrincipalName == upnOrMail);
                    }
                    else
                    {
                        odataQuery.SetFilter(u => u.Mail == upnOrMail);
                    }
                    result = client.Users.ListUser(filter: FormatFilterString(odataQuery)).Value;
                }
                catch { /* The user does not exist, ignore the exception. */ }

                if (result != null)
                {
                    return(result.Select(u => u));
                }
            }
            else
            {
                ODataQuery <MicrosoftGraphUser> odataQuery = null;
                if (!string.IsNullOrEmpty(options.SearchString) && options.SearchString.EndsWith("*"))
                {
                    options.SearchString = options.SearchString.TrimEnd('*');
                    odataQuery           = new ODataQuery <MicrosoftGraphUser>(u => u.DisplayName.StartsWith(options.SearchString));
                }
                else
                {
                    odataQuery = new ODataQuery <MicrosoftGraphUser>(u => u.DisplayName == options.SearchString);
                }

                return(client.Users.ListUser(filter: FormatFilterString(odataQuery)).Value);
            }

            return(new List <MicrosoftGraphUser>());
        }
Пример #2
0
        private static async Task <ApplicationInner> GetServiceApplicationInnerAsync(GraphRbacManagementClient client, string identifier)
        {
            var query = new ODataQuery <ApplicationInner>();

            var httpIdentifier  = $"http://{identifier}";
            var httpsIdentifier = $"https://{identifier}";

            if (identifier.IsGuid())
            {
                query.SetFilter(a => a.ObjectId == identifier || a.AppId == identifier);
            }
            else if (!identifier.StartsWithHttp())
            {
                query.SetFilter(a => a.IdentifierUris.Contains(httpIdentifier) || a.IdentifierUris.Contains(httpsIdentifier));
            }
            else
            {
                query.SetFilter(a => a.IdentifierUris.Contains(identifier));
            }

            try
            {
                var page = await client.Applications
                           .ListAsync(query)
                           .ConfigureAwait(false);

                var application = page.FirstOrDefault();

                while (application is null && !string.IsNullOrEmpty(page?.NextPageLink))
                {
                    page = await client.Applications
                           .ListNextAsync(page.NextPageLink)
                           .ConfigureAwait(false);

                    application = page.FirstOrDefault();
                }

                return(application);
            }
            catch (GraphErrorException)
            {
                return(null);
            }
        }
        /// <summary>
        /// Gets job history.
        /// </summary>
        /// <param name="resourceGroupName">The name of the resource.</param>
        /// <param name="jobCollectionName">The job collection name.</param>
        /// <param name="jobName">The name of the job.</param>
        /// <param name="jobStatus">The status of the job.</param>
        /// <returns>List of job history definition.</returns>
        public IList <PSJobHistory> GetJobHistory(string resourceGroupName, string jobCollectionName, string jobName, string jobStatus)
        {
            if (string.IsNullOrWhiteSpace(resourceGroupName))
            {
                throw new PSManagement.PSArgumentNullException(paramName: "ResourceGroupName");
            }

            if (string.IsNullOrWhiteSpace(jobCollectionName))
            {
                throw new PSManagement.PSArgumentNullException(paramName: "JobCollectionName");
            }

            if (string.IsNullOrWhiteSpace(jobName))
            {
                throw new PSManagement.PSArgumentNullException(paramName: "JobName");
            }

            var oDataQuery = new ODataQuery <JobHistoryFilter>();

            JobExecutionStatus?executionStatus = jobStatus.GetValueOrDefaultEnum <JobExecutionStatus?>(defaultValue: null);

            if (executionStatus != null)
            {
                Expression <Func <JobHistoryFilter, bool> > jobHistoryFilterExpression = (jobHistoryFilter) => jobHistoryFilter.Status == executionStatus;
                oDataQuery.SetFilter(jobHistoryFilterExpression);
            }

            var listOfJobHistory = new List <JobHistoryDefinition>();

            IPage <JobHistoryDefinition> jobHistoryPage = this.SchedulerManagementClient.Jobs.ListJobHistory(resourceGroupName, jobCollectionName, jobName, oDataQuery);

            listOfJobHistory.AddRange(jobHistoryPage);

            while (!string.IsNullOrWhiteSpace(jobHistoryPage.NextPageLink))
            {
                jobHistoryPage = this.SchedulerManagementClient.Jobs.ListJobHistoryNext(jobHistoryPage.NextPageLink);
                listOfJobHistory.AddRange(jobHistoryPage);
            }

            return(Converter.ConvertJobHistoryListToPSList(listOfJobHistory));
        }
        /// <summary>
        /// List jobs.
        /// </summary>
        /// <param name="resourceGroupName">Name of the resource group.</param>
        /// <param name="jobCollectionName">job collection name.</param>
        /// <param name="jobName">Name of the job.</param>
        /// <param name="jobState">State of the job.</param>
        /// <returns>List of Job definition.</returns>
        internal IList <JobDefinition> ListJobs(string resourceGroupName, string jobCollectionName, JobState?jobState)
        {
            var listOfJobs = new List <JobDefinition>();

            var oDataQuery = new ODataQuery <JobStateFilter>();

            if (jobState != null)
            {
                Expression <Func <JobStateFilter, bool> > jobFilterExpression = (jobStateFilter) => jobStateFilter.State == jobState;
                oDataQuery.SetFilter(jobFilterExpression);
            }

            IPage <JobDefinition> jobsPage = this.SchedulerManagementClient.Jobs.List(resourceGroupName, jobCollectionName, oDataQuery);

            listOfJobs.AddRange(jobsPage);

            while (!string.IsNullOrWhiteSpace(jobsPage.NextPageLink))
            {
                jobsPage = this.SchedulerManagementClient.Jobs.ListNext(jobsPage.NextPageLink);
                listOfJobs.AddRange(jobsPage);
            }

            return(listOfJobs);
        }
Пример #5
0
        /// <summary>
        /// List jobs.
        /// </summary>
        /// <param name="resourceGroupName">Name of the resource group.</param>
        /// <param name="jobCollectionName">job collection name.</param>
        /// <param name="jobName">Name of the job.</param>
        /// <param name="jobState">State of the job.</param>
        /// <returns>List of Job definition.</returns>
        internal IList<JobDefinition> ListJobs(string resourceGroupName, string jobCollectionName, JobState? jobState)
        {
            var listOfJobs = new List<JobDefinition>();

            var oDataQuery = new ODataQuery<JobStateFilter>();

            if (jobState != null)
            {
                Expression<Func<JobStateFilter, bool>> jobFilterExpression = (jobStateFilter) => jobStateFilter.State == jobState;
                oDataQuery.SetFilter(jobFilterExpression);
            }

            IPage<JobDefinition> jobsPage = this.SchedulerManagementClient.Jobs.List(resourceGroupName, jobCollectionName, oDataQuery);

            listOfJobs.AddRange(jobsPage);

            while (!string.IsNullOrWhiteSpace(jobsPage.NextPageLink))
            {
                jobsPage = this.SchedulerManagementClient.Jobs.ListNext(jobsPage.NextPageLink);
                listOfJobs.AddRange(jobsPage);
            }

            return listOfJobs;
        }
Пример #6
0
        /// <summary>
        /// Gets job history.
        /// </summary>
        /// <param name="resourceGroupName">The name of the resource.</param>
        /// <param name="jobCollectionName">The job collection name.</param>
        /// <param name="jobName">The name of the job.</param>
        /// <param name="jobStatus">The status of the job.</param>
        /// <returns>List of job history definition.</returns>
        public IList<PSJobHistory> GetJobHistory(string resourceGroupName, string jobCollectionName, string jobName, string jobStatus)
        {
            if (string.IsNullOrWhiteSpace(resourceGroupName))
            {
                throw new PSManagement.PSArgumentNullException(paramName: "ResourceGroupName");
            }

            if (string.IsNullOrWhiteSpace(jobCollectionName))
            {
                throw new PSManagement.PSArgumentNullException(paramName: "JobCollectionName");
            }

            if(string.IsNullOrWhiteSpace(jobName))
            {
                throw new PSManagement.PSArgumentNullException(paramName: "JobName");
            }

            var oDataQuery = new ODataQuery<JobHistoryFilter>(); 

            JobExecutionStatus? executionStatus = jobStatus.GetValueOrDefaultEnum<JobExecutionStatus?>(defaultValue: null);

            if (executionStatus != null)
            {
                Expression<Func<JobHistoryFilter, bool>> jobHistoryFilterExpression = (jobHistoryFilter) => jobHistoryFilter.Status == executionStatus;
                oDataQuery.SetFilter(jobHistoryFilterExpression);
            }

            var listOfJobHistory = new List<JobHistoryDefinition>();

            IPage<JobHistoryDefinition> jobHistoryPage = this.SchedulerManagementClient.Jobs.ListJobHistory(resourceGroupName, jobCollectionName, jobName, oDataQuery);

            listOfJobHistory.AddRange(jobHistoryPage);

            while (!string.IsNullOrWhiteSpace(jobHistoryPage.NextPageLink))
            {
                jobHistoryPage = this.SchedulerManagementClient.Jobs.ListJobHistoryNext(jobHistoryPage.NextPageLink);
                listOfJobHistory.AddRange(jobHistoryPage);
            }

            return Converter.ConvertJobHistoryListToPSList(listOfJobHistory);
        }