public IEnumerable <PSADGroup> FilterGroups(ADObjectFilterOptions options, ulong first = ulong.MaxValue, ulong skip = 0)
        {
            if (!string.IsNullOrEmpty(options.Id))
            {
                try
                {
                    // use GetObjectsByObjectId to handle Redirects in the CSP scenario
                    PSADGroup group = this.GetObjectsByObjectId(new List <string> {
                        options.Id
                    }).FirstOrDefault() as PSADGroup;
                    if (group != null)
                    {
                        return(new List <PSADGroup> {
                            group
                        });
                    }
                }
                catch { /* The group does not exist, ignore the exception */ }

                return(new List <PSADGroup>());
            }
            else if (options.Mail != null)
            {
                Rest.Azure.OData.ODataQuery <ADGroup> odataQuery = new Rest.Azure.OData.ODataQuery <ADGroup>(g => g.Mail == options.Mail);
                return(new GenericPageEnumerable <ADGroup>(
                           delegate()
                {
                    return GraphClient.Groups.List(odataQuery);
                }, GraphClient.Groups.ListNext, first, skip).Select(g => g.ToPSADGroup()));
            }
            else
            {
                Rest.Azure.OData.ODataQuery <ADGroup> odataQuery = null;
                if (!string.IsNullOrEmpty(options.SearchString) && options.SearchString.EndsWith("*"))
                {
                    options.SearchString = options.SearchString.TrimEnd('*');
                    odataQuery           = new Rest.Azure.OData.ODataQuery <ADGroup>(g => g.DisplayName.StartsWith(options.SearchString));
                }
                else
                {
                    odataQuery = new Rest.Azure.OData.ODataQuery <ADGroup>(g => g.DisplayName == options.SearchString);
                }

                return(new GenericPageEnumerable <ADGroup>(
                           delegate()
                {
                    return GraphClient.Groups.List(odataQuery);
                }, GraphClient.Groups.ListNext, first, skip).Select(g => g.ToPSADGroup()));
            }
        }
Beispiel #2
0
        public IEnumerable <PSADGroup> FilterGroups(ADObjectFilterOptions options, int first = int.MaxValue, int skip = 0)
        {
            if (!string.IsNullOrEmpty(options.Id))
            {
                try
                {
                    // use GetObjectsByObjectId to handle Redirects in the CSP scenario
                    PSADGroup group = GetObjectByObjectId(options.Id) as PSADGroup;
                    if (group != null)
                    {
                        return(new List <PSADGroup> {
                            group
                        });
                    }
                }
                catch { /* The group does not exist, ignore the exception */ }

                return(new List <PSADGroup>());
            }
            else if (options.Mail != null)
            {
                Rest.Azure.OData.ODataQuery <MicrosoftGraphGroup> odataQuery = new Rest.Azure.OData.ODataQuery <MicrosoftGraphGroup>(g => g.Mail == options.Mail);
                return(GraphClient.Groups.ListGroup(filter: OdataHelper.GetFilterString(odataQuery)).Value.Select(g => g.ToPSADGroup()));
            }
            else
            {
                Rest.Azure.OData.ODataQuery <MicrosoftGraphGroup> odataQuery = null;
                if (!string.IsNullOrEmpty(options.SearchString) && options.SearchString.EndsWith("*"))
                {
                    options.SearchString = options.SearchString.TrimEnd('*');
                    odataQuery           = new Rest.Azure.OData.ODataQuery <MicrosoftGraphGroup>(g => g.DisplayName.StartsWith(options.SearchString));
                }
                else
                {
                    odataQuery = new Rest.Azure.OData.ODataQuery <MicrosoftGraphGroup>(g => g.DisplayName == options.SearchString);
                }

                return(GraphClient.Groups.ListGroup(filter: OdataHelper.GetFilterString(odataQuery)).Value.Select(g => g.ToPSADGroup()));
            }
        }