Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
mevdschee committed Aug 26, 2022
1 parent 01aeccc commit 98d38e0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
6 changes: 3 additions & 3 deletions ViewRouter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public ViewRouter(string viewNamespace)

private string Invoke(WebContext<TSession> context, Type routedClass)
{
Type genericClass = routedClass.MakeGenericType(typeof(TSession));
View<TSession> view = Activator.CreateInstance(genericClass) as View<TSession>;
Console.WriteLine(routedClass.FullName);
View<TSession> view = Activator.CreateInstance(routedClass) as View<TSession>;
if (view == null)
{
Console.WriteLine("ViewRouter: object {0} could not be created.", routedClass.FullName);
Expand All @@ -39,7 +39,7 @@ private string Match(WebContext<TSession> context, string prefix, string classNa

Console.WriteLine("ViewRouter: try {0}.Render()", className);

routedClass = assembly.GetType(prefix + '.' + className + "`1");
routedClass = assembly.GetType(prefix + '.' + className);
if (routedClass == null)
{
Console.WriteLine("ViewRouter: class {0} does not exist.", prefix + '.' + className);
Expand Down
12 changes: 12 additions & 0 deletions WebContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,18 @@ public void WriteSession()
}
}

public void FinalizeSession()
{
var bytes = JsonSerializer.SerializeToUtf8Bytes<TSession>(Session);

var newSessionHashCode = ComputeHash(bytes);

if (newSessionHashCode != this.sessionHashCode)
{
throw new Exception("A '" + Method + "' on '" + Controller + "." + Action + "' shouldn't write to the session in the View '" + View + "'");
}
}

FileStream WaitForFile(string fullPath, FileMode mode, FileAccess access, FileShare share)
{
for (int numTries = 0; numTries < 3000; numTries++)
Expand Down
1 change: 1 addition & 0 deletions WebServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public void Run()
webctx.WriteSession();
if (!actionResult) webctx.View = "Error.NotFound";
viewResult = new ViewRouter<TSession>(this.viewNamespace).Route(webctx);
webctx.FinalizeSession();
if (viewResult == null) webctx.SendString("NotFound", 404);
else webctx.SendString(viewResult);
}
Expand Down

0 comments on commit 98d38e0

Please sign in to comment.