// /** // * File: JsonCallResource.cs // * Author: haraldwolff // * // * This file and it's content is copyrighted by the Author and / or copyright holder. // * Any use wihtout proper permission is illegal and may lead to legal actions. // * // * // **/ using System; using System.Reflection; using System.Collections.Generic; using Newtonsoft.Json; using ln.http.exceptions; using ln.logging; using Newtonsoft.Json.Linq; using System.Runtime.CompilerServices; 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 { public override bool HandlesDispatching => true; Reflector reflector; Object o; JsonSerializer jsonSerializer = JsonSerializer.CreateDefault(); public ReflectiveResource(Resource container, string name,object o) : base(container, name) { this.o = o; this.reflector = Reflector.GetReflector(o.GetType()); } public override HttpResponse GetResponse(HttpRequest httpRequest,Queue pathStack) { 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); Timing.Meassure("json converter to stream", () => { jsonSerializer.Serialize(response.ContentWriter, currentValue); }); return response; } public override bool Contains(string name) => throw new NotImplementedException(); public override void AddResource(Resource resource) => throw new NotImplementedException(); public override void RemoveResource(Resource resource) => throw new NotImplementedException(); public override IEnumerable GetResources() => throw new NotImplementedException(); public override HttpResponse GetResponse(HttpRequest httpRequest) => throw new NotImplementedException(); } }