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 (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 Stream GetRequestParameters(string id) { try { ResourceManagementWebServicev1.ValidateID(id); ResourceObject request = Global.Client.GetResourceByKey("Request", AttributeNames.ObjectID, id, new[] { "RequestParameter" }); if (request == null) { throw new WebFaultException(HttpStatusCode.NotFound); } if (!request.Attributes.ContainsAttribute("RequestParameter") || request.Attributes["RequestParameter"].IsNull) { return(new MemoryStream()); } IList <string> parameters = request.Attributes["RequestParameter"].StringValues; List <RequestParameter> requestParameters = new List <RequestParameter>(); foreach (string param in parameters) { requestParameters.Add(XmlDeserializeFromString <RequestParameter>(param)); } WebOperationContext.Current.OutgoingResponse.ContentType = "application/json; charset=utf-8"; return(new MemoryStream(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(requestParameters)))); } catch (WebFaultException) { throw; } catch (WebFaultException <ExceptionData> ) { throw; } 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 void UpdateResource(string id, ResourceUpdateRequest request) { try { ResourceManagementWebServicev1.ValidateID(id); CultureInfo locale = GetLocaleFromParameters(); 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 <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 void SetPendingApproval(string id, string decision, ApprovalReason reason) { try { ResourceManagementWebServicev1.ValidateID(id); ResourceObject approval = this.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 (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 ResourceObject GetResourceByID(string id) { try { ResourceManagementWebServicev1.ValidateID(id); CultureInfo locale = GetLocaleFromParameters(); ResourceObject resource = Global.Client.GetResource(id, locale); if (resource == null) { throw new ResourceNotFoundException(); } return(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); } }
public KeyValuePair <string, string[]> GetResourceAttributeByID(string id, string attribute) { try { ResourceManagementSchema.ValidateAttributeName(attribute); ResourceManagementWebServicev1.ValidateID(id); CultureInfo locale = GetLocaleFromParameters(); ResourceObject resource = Global.Client.GetResource(id, 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); } }