public Task Invoke(IDictionary<string, object> env)
{
var request = new Request(env);
var response = new Response(env)
{
ContentType = "text/html",
};
var wilson = "left - right\r\n123456789012\r\nhello world!\r\n";
var href = "?flip=left";
if (request.Query["flip"] == "left")
{
wilson = wilson.Split(new[] {System.Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)
.Select(line => new string(line.Reverse().ToArray()))
.Aggregate("", (agg, line) => agg + line + System.Environment.NewLine);
href = "?flip=right";
}
return TimerLoop(350,
() => response.Write("<title>Hutchtastic</title>"),
() => response.Write("<pre>"),
() => response.Write(wilson),
() => response.Write("</pre>"),
() =>
{
if (request.Query["flip"] == "crash")
{
throw new ApplicationException("Wilson crashed!");
}
},
() => response.Write("<p><a href='" + href + "'>flip!</a></p>"),
() => response.Write("<p><a href='?flip=crash'>crash!</a></p>"));
}