61 lines
2.2 KiB
C#
61 lines
2.2 KiB
C#
// /**
|
|
// * 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.Collections.Generic;
|
|
using ln.http.resources.reflection;
|
|
using ln.types.threads;
|
|
using ln.json.mapping;
|
|
namespace ln.http.resources
|
|
{
|
|
public class ReflectiveResource : Resource
|
|
{
|
|
public override bool HandlesDispatching => true;
|
|
|
|
Reflector reflector;
|
|
Object o;
|
|
|
|
public JSONMapper JSONMapper { get; private set; }
|
|
|
|
public ReflectiveResource(Resource container, string name,object o)
|
|
: base(container, name)
|
|
{
|
|
this.o = o;
|
|
this.reflector = Reflector.GetReflector(o.GetType());
|
|
this.JSONMapper = JSONMapper.DefaultMapper;
|
|
}
|
|
|
|
public override HttpResponse GetResponse(HttpRequest httpRequest,Queue<string> 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", () => {
|
|
response.ContentWriter.Write(
|
|
JSONMapper.ToJson(currentValue).ToString()
|
|
);
|
|
});
|
|
|
|
|
|
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<Resource> GetResources() => throw new NotImplementedException();
|
|
public override HttpResponse GetResponse(HttpRequest httpRequest) => throw new NotImplementedException();
|
|
}
|
|
}
|