Handlers refactored; AbstractGetHandler implemented; logic implemented in HandlersFactory; WebContext (+designs) architecture implemented

main
Inga 🏳‍🌈 14 years ago
parent 162043565c
commit c2db737fa3
  1. 4
      IISMainHandler/Extensions.cs
  2. 8
      IISMainHandler/HandlersFactory.cs
  3. 7
      IISMainHandler/IISMainHandler.csproj
  4. 4
      IISMainHandler/ISpecificHandler.cs
  5. 8
      IISMainHandler/MainHandler.cs
  6. 15
      IISMainHandler/TemplateEngine.cs
  7. 40
      IISMainHandler/WebContext.cs
  8. 9
      IISMainHandler/designs/Classic.cs
  9. 9
      IISMainHandler/designs/IDesign.cs
  10. 9
      IISMainHandler/designs/Lite.cs
  11. 20
      IISMainHandler/handlers/AbstractGetHandler.cs
  12. 19
      IISMainHandler/handlers/DebugHandler.cs
  13. 24
      IISMainHandler/handlers/RootHandler.cs
  14. 4
      IISMainHandler/handlers/WrongUrlHandler.cs

@ -13,5 +13,9 @@ namespace FLocal.IISHandler {
response.Write((char)0x0a);
}
public static string[] Split(this string str, string separator, StringSplitOptions options) {
return str.Split(new string[] { separator }, options);
}
}
}

@ -7,9 +7,11 @@ using System.Web;
namespace FLocal.IISHandler {
class HandlersFactory {
public static ISpecificHandler getHandler(HttpContext context) {
//return new handlers.DebugHandler(context);
return new handlers.WrongUrlHandler();
public static ISpecificHandler getHandler(WebContext context) {
string[] requestParts = context.httprequest.Path.Split("/", StringSplitOptions.RemoveEmptyEntries);
if(requestParts.Length < 1) return new handlers.RootHandler();
return new handlers.DebugHandler(requestParts[0]);
//return new handlers.WrongUrlHandler();
}
}

@ -46,13 +46,20 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="designs\Classic.cs" />
<Compile Include="designs\IDesign.cs" />
<Compile Include="designs\Lite.cs" />
<Compile Include="Extensions.cs" />
<Compile Include="HandlersFactory.cs" />
<Compile Include="handlers\AbstractGetHandler.cs" />
<Compile Include="handlers\DebugHandler.cs" />
<Compile Include="handlers\RootHandler.cs" />
<Compile Include="handlers\WrongUrlHandler.cs" />
<Compile Include="ISpecificHandler.cs" />
<Compile Include="MainHandler.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TemplateEngine.cs" />
<Compile Include="WebContext.cs" />
</ItemGroup>
<ItemGroup>
<WCFMetadata Include="Service References\" />

@ -5,9 +5,9 @@ using System.Text;
using System.Web;
namespace FLocal.IISHandler {
interface ISpecificHandler : IDisposable {
interface ISpecificHandler {
void Handle();
void Handle(WebContext context);
}
}

@ -11,10 +11,10 @@ namespace FLocal.IISHandler {
get { return true; }
}
public void ProcessRequest(HttpContext context) {
using(ISpecificHandler handler = HandlersFactory.getHandler(context)) {
handler.Handle();
}
public void ProcessRequest(HttpContext httpcontext) {
WebContext context = new WebContext(httpcontext);
ISpecificHandler handler = HandlersFactory.getHandler(context);
handler.Handle(context);
}
}

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
namespace FLocal.IISHandler {
class TemplateEngine {
public static string Compile(string pathToTemplate, XDocument data) {
throw new NotImplementedException();
}
}
}

@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
namespace FLocal.IISHandler {
class WebContext {
public readonly HttpContext httpcontext;
public HttpRequest httprequest {
get {
return this.httpcontext.Request;
}
}
public HttpResponse httpresponse {
get {
return this.httpcontext.Response;
}
}
public designs.IDesign design {
get {
throw new NotImplementedException();
}
}
public WebContext(HttpContext httpcontext) {
this.httpcontext = httpcontext;
}
public string Transform(string templateName, System.Xml.Linq.XDocument data) {
//TODO: this should work according to design!
return TemplateEngine.Compile(templateName, data);
}
}
}

@ -0,0 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace FLocal.IISHandler.designs {
class Classic : IDesign {
}
}

@ -0,0 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace FLocal.IISHandler.designs {
interface IDesign {
}
}

@ -0,0 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace FLocal.IISHandler.designs {
class Lite : IDesign {
}
}

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace FLocal.IISHandler.handlers {
abstract class AbstractGetHandler : ISpecificHandler {
abstract protected string templateName {
get;
}
abstract protected System.Xml.Linq.XDocument getData(WebContext context);
public void Handle(WebContext context) {
context.httpresponse.Write(context.Transform(this.templateName, this.getData(context)));
}
}
}

@ -7,20 +7,17 @@ using System.Web;
namespace FLocal.IISHandler.handlers {
class DebugHandler : ISpecificHandler {
private HttpContext context;
private string type;
public DebugHandler(HttpContext context) {
this.context = context;
public DebugHandler(string type) {
this.type = type;
}
public void Handle() {
context.Response.ContentType = "text/plain";
context.Response.WriteLine("Path: " + context.Request.Path);
context.Response.WriteLine("PathInfo: " + context.Request.PathInfo);
}
public void Dispose() {
this.context = null;
public void Handle(WebContext context) {
context.httpresponse.ContentType = "text/plain";
context.httpresponse.WriteLine("Page: " + this.type);
context.httpresponse.WriteLine("Path: " + context.httprequest.Path);
context.httpresponse.WriteLine("PathInfo: " + context.httprequest.PathInfo);
}
}

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Xml.Linq;
namespace FLocal.IISHandler.handlers {
class RootHandler : AbstractGetHandler {
override protected string templateName {
get {
throw new NotImplementedException();
}
}
override protected XDocument getData(WebContext context) {
throw new NotImplementedException();
}
}
}

@ -7,11 +7,9 @@ using System.Web;
namespace FLocal.IISHandler.handlers {
class WrongUrlHandler : ISpecificHandler {
public void Handle() {
public void Handle(WebContext context) {
throw new HttpException(404, "page not found");
}
public void Dispose() { }
}
}

Loading…
Cancel
Save