public MBeanAttributeResource Put(MBeanAttributeResource valueResource) { try { var objectName = (string)ControllerContext.RouteData.Values["objectName"]; var attribute = (string)ControllerContext.RouteData.Values["attribute"]; var attributeInfo = GetAttributeInfo(objectName, attribute); var openType = attributeInfo.Descriptor.GetFieldValue(OpenTypeDescriptor.Field); var value = OpenValueFormatter.ExtractValue(openType, valueResource.Value); _serverConnection.SetAttribute(objectName, attribute, value); var resource = BuildResourceRepresentation(objectName, attribute, openType); return(resource); } catch (FormatException ex) { throw new HttpResponseException(HttpStatusCode.BadRequest); } catch (InstanceNotFoundException) { throw new HttpResponseException(HttpStatusCode.NotFound); } }
public override Task <object> ReadFromStreamAsync(Type type, Stream readStream, System.Net.Http.HttpContent content, IFormatterLogger formatterLogger) { return(Task.Factory.StartNew( () => { using (var streamReader = new StreamReader(readStream, Encoding.UTF8)) { var root = XElement.Load(streamReader); object result = null; if (content.Headers.ContentType.MediaType == "application/vnd.netmx.attr+xml") { result = new MBeanAttributeResource { Value = DeserializeValue(root.Element("Value")) }; } return result; } })); }