Esempio n. 1
0
        public DSResource GetResourceByID(string token, string id,
                                          string[] attributes, string culture = "en-US", bool includePermission = false, bool resolveRef = false)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentException("id must be specified");
            }

            if (attributes == null || attributes.Length == 0)
            {
                attributes = new string[] { "DisplayName" };
            }

            ResourceManagementClient client = Utiles.GetClient(repoCache, token);

            ResourceObject ro = client.GetResource(id, attributes, includePermission);

            ResourceManagementClient rmClient = resolveRef ? client : null;

            if (includePermission)
            {
                return(Utiles.BuildFullResource(ro, attributes.ToList(), schema.GetSchema(token, ro.ObjectTypeName, culture), rmClient));
            }
            else
            {
                return(Utiles.BuildSimpleResource(ro, attributes.ToList(), rmClient));
            }
        }
Esempio n. 2
0
        public DSResource GetCurrentUser(string token, string accountName, string[] attributes)
        {
            if (attributes == null || attributes.Length == 0)
            {
                attributes = new string[] { "DisplayName" };
            }

            ResourceManagementClient client = Utiles.GetClient(repoCache, token);

            ResourceObject ro = client.GetResourceByKey("Person", "AccountName", accountName);

            if (ro == null)
            {
                throw new ArgumentException($"user with account name {accountName} was not found");
            }

            return(Utiles.BuildSimpleResource(ro, attributes.ToList(), null));
        }
Esempio n. 3
0
        public DSResourceSet GetResourceByQuery(string token, string query, string[] attributes,
                                                int pageSize = 0, int index = 0, bool resolveRef = false, Dictionary <string, string> orderBy = null)
        {
            if (string.IsNullOrEmpty(query))
            {
                throw new ArgumentException("xpath query must be specified");
            }

            DSResourceSet result = new DSResourceSet();

            List <SortingAttribute> sortingAttributes = new List <SortingAttribute>();

            if (orderBy != null && orderBy.Count > 0)
            {
                foreach (KeyValuePair <string, string> kvp in orderBy)
                {
                    sortingAttributes.Add(new SortingAttribute
                    {
                        AttributeName = kvp.Key,
                        Ascending     =
                            new string[] { "ascending", "asc" }.Contains(kvp.Value, StringComparer.OrdinalIgnoreCase) ? true : false
                    });
                }
            }

            ResourceManagementClient client = Utiles.GetClient(repoCache, token);

            ResourceManagementClient rmClient = resolveRef ? client : null;

            if (pageSize == 0)
            {
                SearchResultCollection src;

                if (attributes == null || attributes.Length == 0)
                {
                    src = client.GetResources(query) as SearchResultCollection;
                }
                else
                {
                    src = sortingAttributes.Count == 0 ?
                          client.GetResources(query, attributes) as SearchResultCollection :
                          client.GetResources(query, attributes, sortingAttributes) as SearchResultCollection;
                }

                if (src != null)
                {
                    result.TotalCount = src.Count;
                    foreach (ResourceObject resource in src)
                    {
                        result.Results.Add(Utiles.BuildSimpleResource(
                                               resource,
                                               attributes == null || attributes.Length == 0? null : attributes.ToList(),
                                               rmClient));
                    }
                }
            }
            else
            {
                SearchResultPager srp;

                if (attributes == null || attributes.Length == 0)
                {
                    srp = client.GetResourcesPaged(query, pageSize);
                }
                else
                {
                    srp = sortingAttributes.Count == 0 ?
                          client.GetResourcesPaged(query, pageSize, attributes) :
                          client.GetResourcesPaged(query, pageSize, attributes, sortingAttributes);
                }

                if (index >= 0)
                {
                    srp.CurrentIndex = index;
                }

                srp.PageSize = pageSize;

                foreach (ResourceObject resource in srp.GetNextPage())
                {
                    result.Results.Add(Utiles.BuildSimpleResource(
                                           resource,
                                           attributes == null || attributes.Length == 0? null : attributes.ToList(),
                                           rmClient));
                }

                result.TotalCount   = srp.TotalCount;
                result.HasMoreItems = srp.HasMoreItems;
            }

            return(result);
        }