using System; using System.Text; using System.Threading.Tasks; namespace Tesses.WebServer.ConsoleApp { public class DynamicServer : Server { public DynamicServer() { } Random rand = new Random(); int count = 0; public override async Task GetAsync(ServerContext ctx) { //Console.WriteLine("HANDLE"); if(ctx.UrlPath=="/count") { count++; await ctx.SendTextAsync($"This page has been viewed {count} times"); } if(ctx.UrlPath=="/rand") { int min = 0; int max = 65536; int times = 5; bool dont_show_hint = false; if(ctx.QueryParams.ContainsKey("min")) { if(!int.TryParse(ctx.QueryParams.GetFirst("min"),out min)) { min = 0; } else { dont_show_hint = true; } } if (ctx.QueryParams.ContainsKey("max")) { if (!int.TryParse(ctx.QueryParams.GetFirst("max"), out max)) { max = 65536; } else { dont_show_hint = true; } } if (ctx.QueryParams.ContainsKey("times")) { if (!int.TryParse(ctx.QueryParams.GetFirst("times"), out times)) { times = 5; } else { dont_show_hint = true; } } max++; StringBuilder html = new StringBuilder(); html.Append("Random Numbers

Random Numbers

"); if(!dont_show_hint) { string hint = "Hint: ./rand?min=41&max=1992×=42
"; html.Append(hint); } html.Append(rand.Next(min, max)); for(int i = 1;i"); await ctx.SendTextAsync(html.ToString()); } } } }