ln.http.resources/ResourceApplication.cs

40 lines
1.1 KiB
C#

using System;
using System.Collections.Generic;
namespace ln.http.resources
{
public class ResourceApplication : HttpApplication
{
public Resource RootResource { get; set; }
public ResourceApplication()
{
RootResource = new BaseResource("");
}
public override HttpResponse GetResponse(HttpRequest httpRequest)
{
/* TODO: Implement Session Tracker here... */
/* TODO: Implement Authentication here... */
Resource currentResource = RootResource;
Queue<String> pathStack = new Queue<String>(httpRequest.URI.AbsolutePath.Split(new String[] { "/" }, StringSplitOptions.RemoveEmptyEntries));
while (pathStack.Count > 0)
{
String next = pathStack.Dequeue();
if (!currentResource.Contains(next))
throw new KeyNotFoundException();
currentResource = currentResource.GetResource(next);
/* TODO: Implement Authorization hook here... */
}
return currentResource.GetResponse(httpRequest);
}
}
}