public Stream GetApprovalRequestsByStatus(string status) { try { Client.ApprovalStatus approvalStatus; if (Enum.TryParse(status, true, out approvalStatus)) { return(ResourceManagementWebServicev1.GetResponse(Global.Client.GetApprovals(approvalStatus).ToList())); } throw new ArgumentException("Invalid value for status parameter"); } 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 Stream GetResources() { try { string attributes = WebOperationContext.Current?.IncomingRequest.UriTemplateMatch.QueryParameters["attributes"]; string objectType = WebOperationContext.Current?.IncomingRequest.UriTemplateMatch.QueryParameters["objectType"]; string filter = WebOperationContext.Current?.IncomingRequest.UriTemplateMatch.QueryParameters["filter"]; CultureInfo locale = GetLocaleFromParameters(); if (filter == null) { if (objectType == null) { filter = "/*"; } else { filter = $"/{objectType}"; } } if (attributes != null) { return(ResourceManagementWebServicev1.GetResponse(Global.Client.GetResources(filter, attributes.Split(','), locale).ToList())); } if (objectType != null) { return(ResourceManagementWebServicev1.GetResponse(Global.Client.GetResources(filter, ResourceManagementSchema.GetObjectType(objectType).Attributes.Select(t => t.SystemName), locale).ToList())); } else { return(ResourceManagementWebServicev1.GetResponse(Global.Client.GetResources(filter, locale).ToList())); } } 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 (AuthorizationRequiredException ex) { throw WebExceptionHelper.CreateWebException(ex); } 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)); } return(ResourceManagementWebServicev1.GetResponse(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 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); } }
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)); }
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); } }
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); } }
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); } }
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)); }