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