WIP
parent
4d0395dd8f
commit
cead9562d4
|
@ -80,21 +80,11 @@ namespace ln.http.resources
|
|||
switch (httpRequest.Method)
|
||||
{
|
||||
case "PUT":
|
||||
JObject jInstance = JObject.FromObject(instance);
|
||||
JObject jUpdate = JObject.Parse(httpRequest.ContentReader.ReadToEnd());
|
||||
|
||||
foreach (JProperty jProperty in jUpdate.Properties())
|
||||
{
|
||||
if (jInstance.ContainsKey(jProperty.Name))
|
||||
jInstance.Remove(jProperty.Name);
|
||||
|
||||
jInstance.Add(jProperty.Name, jProperty.Value);
|
||||
}
|
||||
|
||||
instance = (T)jInstance.ToObject(instance.GetType());
|
||||
JsonConvert.PopulateObject(httpRequest.ContentReader.ReadToEnd(), instance);
|
||||
bool updated = collection.Update(instance);
|
||||
|
||||
responseValue = instance;
|
||||
|
||||
break;
|
||||
default:
|
||||
throw new NotSupportedException();
|
||||
|
|
|
@ -19,6 +19,7 @@ using System.Linq;
|
|||
using System.Runtime.InteropServices;
|
||||
using System.Diagnostics;
|
||||
using ln.http.resources.reflection;
|
||||
using ln.types.threads;
|
||||
namespace ln.http.resources
|
||||
{
|
||||
public class ReflectiveResource : Resource
|
||||
|
@ -28,6 +29,8 @@ namespace ln.http.resources
|
|||
Reflector reflector;
|
||||
Object o;
|
||||
|
||||
JsonSerializer jsonSerializer = JsonSerializer.CreateDefault();
|
||||
|
||||
public ReflectiveResource(Resource container, string name,object o)
|
||||
: base(container, name)
|
||||
{
|
||||
|
@ -37,13 +40,18 @@ namespace ln.http.resources
|
|||
|
||||
public override HttpResponse GetResponse(HttpRequest httpRequest,Queue<string> pathStack)
|
||||
{
|
||||
object currentValue = reflector.InvokeRequest(httpRequest, pathStack, this.o);
|
||||
String jsonValue = JsonConvert.SerializeObject(currentValue);
|
||||
object currentValue = Timing.Meassure("reflector walk", () => reflector.InvokeRequest(httpRequest, pathStack, this.o));
|
||||
//String jsonValue = Timing.Meassure("json converter", () => JsonConvert.SerializeObject(currentValue));
|
||||
|
||||
HttpResponse response = new HttpResponse(httpRequest);
|
||||
|
||||
response.SetHeader("content-type", "application/json");
|
||||
response.ContentWriter.Write(jsonValue);
|
||||
//response.ContentWriter.Write(jsonValue);
|
||||
|
||||
Timing.Meassure("json converter to stream", () => {
|
||||
jsonSerializer.Serialize(response.ContentWriter, currentValue);
|
||||
});
|
||||
|
||||
|
||||
return response;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue