Exemplo n.º 1
0
        private static SearchResultPager GetSearchResultPager(IncomingWebRequestContext context, int pageSize, string token)
        {
            SearchResultPager p;

            if (token == null)
            {
                string               filter     = WebResponseHelper.GetFilterText(context);
                CultureInfo          locale     = WebResponseHelper.GetLocale();
                IEnumerable <string> attributes = WebResponseHelper.GetAttributes(context);

                if (attributes != null)
                {
                    p = Global.Client.GetResourcesPaged(filter, pageSize, attributes, locale);
                }
                else
                {
                    p = Global.Client.GetResourcesPaged(filter, pageSize, locale);
                }
            }
            else
            {
                p = (SearchResultPager)ResourceManagementWebServicev2.searchCache.Remove(ResourceManagementWebServicev2.BuildCacheKey(token));

                if (p == null)
                {
                    throw new ArgumentException("Invalid token");
                }
            }
            return(p);
        }
Exemplo n.º 2
0
        public Stream GetResourceByID(string id)
        {
            try
            {
                ResourceManagementWebServicev2.ValidateID(id);
                CultureInfo locale = WebResponseHelper.GetLocale();
                bool        includePermissionHints = WebResponseHelper.IsParameterSet(ParameterNames.IncludePermissionHints);

                ResourceObject resource = Global.Client.GetResource(id, locale, includePermissionHints);

                if (resource == null)
                {
                    throw new ResourceNotFoundException();
                }

                return(WebResponseHelper.GetResponse(resource, true));
            }
            catch (WebFaultException)
            {
                throw;
            }
            catch (WebFaultException <Error> )
            {
                throw;
            }
            catch (Exception ex)
            {
                ResourceManagementWebServicev2.HandleException(ex);
                throw;
            }
        }
Exemplo n.º 3
0
        public Stream GetResourceByKey(string objectType, string key, string keyValue)
        {
            try
            {
                ResourceManagementSchema.ValidateAttributeName(key);
                ResourceManagementSchema.ValidateObjectTypeName(objectType);
                CultureInfo locale = WebResponseHelper.GetLocale();

                ResourceObject resource = Global.Client.GetResourceByKey(objectType, key, keyValue, locale);

                if (resource == null)
                {
                    throw new ResourceNotFoundException();
                }

                return(WebResponseHelper.GetResponse(resource, false));
            }
            catch (WebFaultException)
            {
                throw;
            }
            catch (WebFaultException <Error> )
            {
                throw;
            }
            catch (Exception ex)
            {
                ResourceManagementWebServicev2.HandleException(ex);
                throw;
            }
        }
Exemplo n.º 4
0
        public void RemoveAttributeValue(string id, string attribute, string value)
        {
            try
            {
                ResourceManagementSchema.ValidateAttributeName(attribute);
                ResourceManagementWebServicev2.ValidateID(id);
                CultureInfo locale = WebResponseHelper.GetLocale();

                ResourceObject resource;

                if (ResourceManagementSchema.IsAttributeMultivalued(attribute))
                {
                    resource = Global.Client.GetResource(id, locale);
                }
                else
                {
                    resource = Global.Client.GetResource(id, new[] { attribute }, locale);
                }

                if (resource == null)
                {
                    throw new ResourceNotFoundException();
                }

                if (!resource.Attributes.ContainsAttribute(attribute))
                {
                    WebResponseHelper.ThrowAttributeNotFoundException(attribute);
                }

                resource.Attributes[attribute].RemoveValue(value, true);

                Global.Client.SaveResource(resource, locale);
                WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.NoContent;
            }
            catch (WebFaultException)
            {
                throw;
            }
            catch (WebFaultException <Error> )
            {
                throw;
            }
            catch (Exception ex)
            {
                ResourceManagementWebServicev2.HandleException(ex);
                throw;
            }
        }
Exemplo n.º 5
0
        public void UpdateResource(string id, ResourceUpdateRequest request)
        {
            try
            {
                ResourceManagementWebServicev2.ValidateID(id);
                CultureInfo locale = WebResponseHelper.GetLocale();

                ResourceObject resource = Global.Client.GetResource(id, locale);
                foreach (AttributeValueUpdate kvp in request.Attributes)
                {
                    if (kvp.Value.Length > 1)
                    {
                        resource.Attributes[kvp.Name].SetValue(kvp.Value);
                    }
                    else if (kvp.Value.Length == 1)
                    {
                        resource.Attributes[kvp.Name].SetValue(kvp.Value[0]);
                    }
                    else
                    {
                        resource.Attributes[kvp.Name].RemoveValues();
                    }
                }

                Global.Client.SaveResource(resource, locale);
            }
            catch (WebFaultException)
            {
                throw;
            }
            catch (WebFaultException <Error> )
            {
                throw;
            }
            catch (Exception ex)
            {
                ResourceManagementWebServicev2.HandleException(ex);
                throw;
            }
        }
Exemplo n.º 6
0
        public Stream GetResourceAttributeByID(string id, string attribute)
        {
            try
            {
                ResourceManagementSchema.ValidateAttributeName(attribute);
                ResourceManagementWebServicev2.ValidateID(id);
                CultureInfo locale = WebResponseHelper.GetLocale();

                ResourceObject resource = Global.Client.GetResource(id, new[] { attribute }, locale);

                if (resource == null)
                {
                    throw new ResourceNotFoundException();
                }

                if (!resource.Attributes.ContainsAttribute(attribute))
                {
                    WebResponseHelper.ThrowAttributeNotFoundException(attribute);
                }

                List <string> result = resource.Attributes[attribute].ToStringValues().ToList();

                return(WebResponseHelper.GetResponse(result, true));
            }
            catch (WebFaultException)
            {
                throw;
            }
            catch (WebFaultException <Error> )
            {
                throw;
            }
            catch (Exception ex)
            {
                ResourceManagementWebServicev2.HandleException(ex);
                throw;
            }
        }