2019-04-04 19:34:13 +02:00
|
|
|
|
// /**
|
|
|
|
|
// * 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;
|
2019-04-05 00:59:02 +02:00
|
|
|
|
using ln.http.resources.reflection;
|
2019-04-04 19:34:13 +02:00
|
|
|
|
namespace ln.http.resources
|
|
|
|
|
{
|
2019-04-05 00:59:02 +02:00
|
|
|
|
public class ReflectiveResource : Resource
|
2019-04-04 19:34:13 +02:00
|
|
|
|
{
|
|
|
|
|
public override bool HandlesDispatching => true;
|
|
|
|
|
|
2019-04-05 00:59:02 +02:00
|
|
|
|
Reflector reflector;
|
|
|
|
|
Object o;
|
2019-04-04 19:34:13 +02:00
|
|
|
|
|
|
|
|
|
public ReflectiveResource(Resource container, string name,object o)
|
|
|
|
|
: base(container, name)
|
|
|
|
|
{
|
2019-04-05 00:59:02 +02:00
|
|
|
|
this.o = o;
|
|
|
|
|
this.reflector = Reflector.GetReflector(o.GetType());
|
2019-04-04 19:34:13 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-04-05 00:59:02 +02:00
|
|
|
|
public override HttpResponse GetResponse(HttpRequest httpRequest,Queue<string> pathStack)
|
2019-04-04 19:34:13 +02:00
|
|
|
|
{
|
2019-04-05 00:59:02 +02:00
|
|
|
|
object currentValue = reflector.InvokeRequest(httpRequest, pathStack, this.o);
|
|
|
|
|
String jsonValue = JsonConvert.SerializeObject(currentValue);
|
2019-04-04 19:34:13 +02:00
|
|
|
|
|
2019-04-05 00:59:02 +02:00
|
|
|
|
HttpResponse response = new HttpResponse(httpRequest);
|
2019-04-04 19:34:13 +02:00
|
|
|
|
|
2019-04-05 00:59:02 +02:00
|
|
|
|
response.SetHeader("content-type", "application/json");
|
|
|
|
|
response.ContentWriter.Write(jsonValue);
|
2019-04-04 19:34:13 +02:00
|
|
|
|
|
2019-04-05 00:59:02 +02:00
|
|
|
|
return response;
|
2019-04-04 19:34:13 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-04-05 00:59:02 +02:00
|
|
|
|
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();
|
2019-04-04 19:34:13 +02:00
|
|
|
|
}
|
|
|
|
|
}
|