master
Harald Wolff 2019-04-24 12:53:50 +02:00
parent a100bf3592
commit 92baad434c
4 changed files with 24 additions and 2 deletions

View File

@ -79,6 +79,9 @@ namespace ln.http.resources
switch (httpRequest.Method)
{
case "GET":
responseValue = instance;
break;
case "PUT":
JsonConvert.PopulateObject(httpRequest.ContentReader.ReadToEnd(), instance);
bool updated = collection.Update(instance);

View File

@ -16,6 +16,7 @@ namespace ln.http.resources
public virtual DirectoryInfo DirectoryInfo { get; }
protected Dictionary<string, Resource> cache = new Dictionary<string, Resource>();
protected Dictionary<string, Resource> injectedResources = new Dictionary<string, Resource>();
public DirectoryResource(String path)
: base(System.IO.Path.GetFileName(path))
@ -40,6 +41,9 @@ namespace ln.http.resources
public override bool Contains(string name)
{
if (injectedResources.ContainsKey(name))
return true;
String cPath = GetCombinedPath(name);
bool exists = File.Exists(cPath) || Directory.Exists(cPath);
@ -60,11 +64,19 @@ namespace ln.http.resources
cache.Remove(resource.Name);
}
public void InjectResource(Resource resource)
{
injectedResources.Add(resource.Name, resource);
}
public override Resource GetResource(string name)
{
if (!Contains(name))
return null;
if (injectedResources.ContainsKey(name))
return injectedResources[name];
if (cache.ContainsKey(name))
return cache[name];

View File

@ -19,7 +19,9 @@ namespace ln.http.resources
public Resource(Resource container,String name)
:this(name)
{
container.AddResource(this);
if (container != null)
container.AddResource(this);
Container = container;
}

View File

@ -11,6 +11,8 @@ namespace ln.http.resources
public Template Template { get; }
public object This { get; set; }
public override bool HandlesDispatching => true;
public TemplateResource(Resource container, string filename)
: base(container, System.IO.Path.GetFileName(filename))
{
@ -42,12 +44,15 @@ namespace ln.http.resources
throw new NotImplementedException();
}
public override HttpResponse GetResponse(HttpRequest httpRequest)
public override HttpResponse GetResponse(HttpRequest httpRequest, Queue<string> pathStack) => GetResponse(httpRequest, pathStack.ToArray());
public override HttpResponse GetResponse(HttpRequest httpRequest) => GetResponse(httpRequest,new string[0]);
public HttpResponse GetResponse(HttpRequest httpRequest,string[] suffixPath)
{
HttpResponse httpResponse = new HttpResponse(httpRequest);
Template.Context context = new Template.Context(Template);
context.ExpressionContext.AddMappedValue("__root__", Root);
context.ExpressionContext.AddMappedValue("__path__", suffixPath);
context.ExpressionContext.AddMappedValue("request", httpRequest);
context.ExpressionContext.AddMappedValue("response", httpResponse);
context.ExpressionContext.AddMappedValue("this", This);