Пример #1
0
        public void SetPendingApproval(string id, string decision, ApprovalReason reason)
        {
            try
            {
                ResourceManagementWebServicev1.ValidateID(id);

                ResourceObject approval = Global.Client.GetResourceByKey(ObjectTypeNames.Approval, AttributeNames.ObjectID, id);

                if (string.Equals(decision, "approve", StringComparison.OrdinalIgnoreCase))
                {
                    Global.Client.Approve(approval, true, reason?.Reason);
                }
                else if (string.Equals(decision, "reject", StringComparison.OrdinalIgnoreCase))
                {
                    Global.Client.Approve(approval, false, reason?.Reason);
                }
                else
                {
                    throw new ArgumentException($"The value '{decision}' is not supported. Allowed values are 'Approve' or 'Reject'");
                }
            }
            catch (WebFaultException)
            {
                throw;
            }
            catch (WebFaultException <ExceptionData> )
            {
                throw;
            }
            catch (AuthorizationRequiredException ex)
            {
                throw WebExceptionHelper.CreateWebException(ex);
            }
            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);
            }
        }
Пример #2
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));
        }
Пример #3
0
        public Stream GetResourceByID(string id)
        {
            try
            {
                ResourceManagementWebServicev1.ValidateID(id);
                CultureInfo locale = GetLocaleFromParameters();

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

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

                return(ResourceManagementWebServicev1.GetResponse(resource));
            }
            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);
            }
        }
Пример #4
0
        public void DeleteResourceByID(string id)
        {
            try
            {
                ResourceManagementWebServicev1.ValidateID(id);

                Global.Client.DeleteResource(id);
            }
            catch (WebFaultException)
            {
                throw;
            }
            catch (WebFaultException <ExceptionData> )
            {
                throw;
            }
            catch (ResourceNotFoundException)
            {
                throw WebExceptionHelper.CreateWebException(HttpStatusCode.NotFound);
            }
            catch (AuthorizationRequiredException ex)
            {
                throw WebExceptionHelper.CreateWebException(ex);
            }
            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);
            }
        }
Пример #5
0
        public string CreateResource(ResourceUpdateRequest request)
        {
            try
            {
                AttributeValueUpdate objectTypeUpdate = request.Attributes.FirstOrDefault(t => t.Name == AttributeNames.ObjectType);

                if (objectTypeUpdate == null)
                {
                    throw new ArgumentException("An object type must be specified");
                }

                string objectType = objectTypeUpdate.Value?[0] as string;

                if (objectType == null)
                {
                    throw new ArgumentException("An object type must be specified");
                }

                ResourceObject resource = Global.Client.CreateResource(objectType);

                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);
                return(resource.ObjectID.ToString(false));
            }
            catch (WebFaultException)
            {
                throw;
            }
            catch (WebFaultException <ExceptionData> )
            {
                throw;
            }
            catch (AuthorizationRequiredException ex)
            {
                throw WebExceptionHelper.CreateWebException(ex);
            }
            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);
            }
        }
Пример #6
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);
            }
        }
 public static Exception CreateWebException(HttpStatusCode code)
 {
     return(WebExceptionHelper.CreateWebException(code, null, null));
 }