In this post I will show a powerful technique for ASP.NET Debugging/Programming, where the Web C# REPL that I recently added to TeamMentor is triggered from a WCF REST API, in such a way that the HttpContext can be programmed in real-time, with the added bonus that the HttpContext.Response OutputStream stays open (and can be written to multiple times).
It all starts with a new TeamMentor REST API method called ‘/admin/scripts/{name}’ :
which is powered by:
and is basically a reflection engine to compile and invoke the strings returned by this class:
This means that in practice:
The /admin/scripts/ping REST call will return the execution result of the string provided by O2_Script_Library.ping() method:
The /admin/scripts/list REST call will return the execution result of the string provided by O2_Script_Library.list() method:
The /admin/scripts/openLogVewer REST call will return the execution result of the string provided by O2_Script_Library.openLogViewer() method:
Note that in screenshot above, the LogViewer is a .NET WinForms created by the Cassini Process (the one hosting the WCF REST API).
The really interesting script/method, is the O2_Script_Library.script_Me() :
This script, when invoked via the /admin/scripts/script_Me REST call, will provide a C# REPL environment, with a live HttpContext object available as a programmable variable :)
Even better, because of the use of .waitForClose() in the httpContext.Current.script_Me().waitForClose() command, we can write in real-time to the browser (ie. the HttpContext.Response OutputStream is still alive)
This means that we have a nice REPL environment, from C# into a web browser:
And in the C# REPL we have full access to all the C# programming techniques, like for example a for-loop
What I really like about this technique, is that it is going to allow me to write custom monitoring and debugging scripts in C# that interact with the target webpage :)
Interestingly the browser will keep the connection open for quite a while, which give us plenty of time to write and debug scripts.
Finally, to release the browser connection, use Response.End() :
Similar Techniques: