Пример #1
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;
            }
        }
Пример #2
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;
            }
        }
Пример #3
0
        public Stream GetResourceByKey(string objectType, string key, string keyValue)
        {
            ResourceObject resource;

            try
            {
                ResourceManagementSchema.ValidateAttributeName(key);
                ResourceManagementSchema.ValidateObjectTypeName(objectType);
                CultureInfo locale = GetLocaleFromParameters();

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

                if (resource == null)
                {
                    throw new ResourceNotFoundException();
                }
            }
            catch (WebFaultException)
            {
                throw;
            }
            catch (WebFaultException <ExceptionData> )
            {
                throw;
            }
            catch (ResourceNotFoundException)
            {
                throw WebExceptionHelper.CreateWebException(HttpStatusCode.NotFound);
            }
            catch (ResourceManagementException ex)
            {
                throw WebExceptionHelper.CreateWebException(HttpStatusCode.BadRequest, ex);
            }
            catch (ArgumentException ex)
            {
                throw WebExceptionHelper.CreateWebException(HttpStatusCode.BadRequest, ex);
            }
            catch (Exception ex)
            {
                throw WebExceptionHelper.CreateWebException(HttpStatusCode.InternalServerError, ex);
            }

            return(ResourceManagementWebServicev1.GetResponse(resource));
        }
Пример #4
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;
            }
        }
Пример #5
0
        public KeyValuePair <string, string[]> GetResourceAttributeByKey(string objectType, string key, string keyValue, string attribute)
        {
            try
            {
                ResourceManagementSchema.ValidateAttributeName(attribute);
                ResourceManagementSchema.ValidateObjectTypeName(objectType);
                CultureInfo locale = GetLocaleFromParameters();

                ResourceObject resource = Global.Client.GetResourceByKey(objectType, key, keyValue, new List <string>()
                {
                    attribute
                }, locale);

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

                object        value          = resource.Attributes[attribute].Value;
                List <string> valuesToReturn = new List <string>();

                if (value is string)
                {
                    valuesToReturn.Add(value as string);
                }
                else if (value is byte[])
                {
                    valuesToReturn.Add(Convert.ToBase64String((byte[])value));
                }
                else
                {
                    IEnumerable values = value as IEnumerable;
                    if (values != null)
                    {
                        foreach (object enumvalue in values)
                        {
                            if (enumvalue is DateTime)
                            {
                                valuesToReturn.Add(((DateTime)enumvalue).ToResourceManagementServiceDateFormat());
                            }
                            else if (enumvalue is byte[])
                            {
                                valuesToReturn.Add(Convert.ToBase64String((byte[])enumvalue));
                            }
                            else
                            {
                                valuesToReturn.Add(enumvalue.ToString());
                            }
                        }
                    }
                    else
                    {
                        valuesToReturn.Add(value.ToString());
                    }
                }

                return(new KeyValuePair <string, string[]>(attribute, valuesToReturn.ToArray()));
            }
            catch (WebFaultException)
            {
                throw;
            }
            catch (WebFaultException <ExceptionData> )
            {
                throw;
            }
            catch (ResourceNotFoundException)
            {
                throw WebExceptionHelper.CreateWebException(HttpStatusCode.NotFound);
            }
            catch (ResourceManagementException ex)
            {
                throw WebExceptionHelper.CreateWebException(HttpStatusCode.BadRequest, ex);
            }
            catch (ArgumentException ex)
            {
                throw WebExceptionHelper.CreateWebException(HttpStatusCode.BadRequest, ex);
            }
            catch (Exception ex)
            {
                throw WebExceptionHelper.CreateWebException(HttpStatusCode.InternalServerError, ex);
            }
        }