예제 #1
0
        public int GetResourceCount(string token, string query)
        {
            if (string.IsNullOrEmpty(query))
            {
                throw new ArgumentException("xpath query must be specified");
            }

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

            return(client.GetResourceCount(query));
        }
예제 #2
0
        public void DeleteResource(string token, string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentException("id must be specified");
            }

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

            client.DeleteResource(id);
        }
예제 #3
0
        public void Approve(string token, string id, bool approve, string reason = null)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentException("id must be specified");
            }

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

            ResourceObject ro = client.GetResourceByKey("Approval", "Request", id);

            if (ro == null)
            {
                throw new ArgumentException($"{id} is not a request");
            }

            client.Approve(ro, approve, reason);
        }
예제 #4
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));
        }
예제 #5
0
        public string CreateResource(string token, DSResource resource)
        {
            if (resource == null)
            {
                throw new ArgumentException("resource must be specified");
            }

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

            ResourceObject ro = client.CreateResource(resource.ObjectType);

            Utiles.BuildResourceObject(resource, ref ro);

            try
            {
                ro.Save();
                return(ro.ObjectID.Value);
            }
            catch (AuthorizationRequiredException e)
            {
                throw new AuthZRequiredException(e.Message);
            }
        }
예제 #6
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);
        }
예제 #7
0
        public Dictionary <string, DSAttribute> GetSchema(string token, string typeName, string culture)
        {
            if (string.IsNullOrEmpty(typeName))
            {
                throw new ArgumentException("type name must be specified");
            }

            if (string.IsNullOrEmpty(culture))
            {
                throw new ArgumentException("culture must be specified");
            }

            string schemaToken = $"schema_{typeName.ToLower()}_{culture.ToLower()}";

            if (this.schemaCache.Contains(schemaToken))
            {
                schemaCache.TryGet(schemaToken, out Dictionary <string, DSAttribute> schemaType);
                return(schemaType);
            }
            else
            {
                Dictionary <string, DSAttribute> result = new Dictionary <string, DSAttribute>();

                ResourceManagementClient client = Utiles.GetClient(this.schemaCache, token);

                SearchResultCollection srcBindings = client.GetResources(
                    $"/BindingDescription[BoundObjectType=/ObjectTypeDescription[Name='{typeName}']]",
                    new string[] { "DisplayName", "Description", "BoundAttributeType",
                                   "Required", "StringRegex", "IntegerMinimum", "IntegerMaximum" },
                    new CultureInfo(culture)) as SearchResultCollection;

                SearchResultCollection srcAttributes = client.GetResources(
                    $"/BindingDescription[BoundObjectType=/ObjectTypeDescription[Name='{typeName}']]/BoundAttributeType",
                    new string[] { "DisplayName", "Description", "Name", "DataType",
                                   "Multivalued", "StringRegex", "IntegerMinimum", "IntegerMaximum" },
                    new CultureInfo(culture)) as SearchResultCollection;

                if (srcBindings.Count == 0 || srcAttributes.Count == 0)
                {
                    throw new ArgumentException("invalid type name");
                }

                foreach (ResourceObject binding in srcBindings)
                {
                    string         attributeID = binding.Attributes["BoundAttributeType"].StringValue;
                    ResourceObject attribute   = srcAttributes.First(
                        a => a.ObjectID.Value.Equals(attributeID, StringComparison.OrdinalIgnoreCase));

                    DSAttribute dsAttribute = new DSAttribute
                    {
                        DisplayName = string.IsNullOrEmpty(binding.DisplayName) ? attribute.DisplayName : binding.DisplayName,
                        SystemName  = attribute.Attributes["Name"].StringValue,
                        DataType    = attribute.Attributes["DataType"].StringValue,
                        Multivalued = attribute.Attributes["Multivalued"].BooleanValue,
                        Required    = binding.Attributes["Required"].BooleanValue
                    };

                    dsAttribute.Description = !binding.Attributes["Description"].IsNull ?
                                              binding.Attributes["Description"].StringValue :
                                              !attribute.Attributes["Description"].IsNull ?
                                              attribute.Attributes["Description"].StringValue :
                                              null;

                    dsAttribute.StringRegex = !binding.Attributes["StringRegex"].IsNull ?
                                              binding.Attributes["StringRegex"].StringValue :
                                              !attribute.Attributes["StringRegex"].IsNull ?
                                              attribute.Attributes["StringRegex"].StringValue :
                                              null;

                    if (!binding.Attributes["IntegerMaximum"].IsNull)
                    {
                        dsAttribute.IntegerMaximum = binding.Attributes["IntegerMaximum"].IntegerValue;
                    }
                    else if (!attribute.Attributes["IntegerMaximum"].IsNull)
                    {
                        dsAttribute.IntegerMaximum = attribute.Attributes["IntegerMaximum"].IntegerValue;
                    }
                    else
                    {
                        dsAttribute.IntegerMaximum = null;
                    }

                    if (!binding.Attributes["IntegerMinimum"].IsNull)
                    {
                        dsAttribute.IntegerMinimum = binding.Attributes["IntegerMinimum"].IntegerValue;
                    }
                    else if (!attribute.Attributes["IntegerMinimum"].IsNull)
                    {
                        dsAttribute.IntegerMinimum = attribute.Attributes["IntegerMinimum"].IntegerValue;
                    }
                    else
                    {
                        dsAttribute.IntegerMinimum = null;
                    }

                    result.Add(attribute.Attributes["Name"].StringValue, dsAttribute);
                }

                this.schemaCache.Set(schemaToken, result);

                return(result);
            }
        }