public HttpStatusCode Process(HttpListenerContext context, IResponsePresenter presenter) { Validate(context); if (ConfigurationManager.AppSettings["DataStorageMode"] == "sqlite") { _repository = new GuestBookSqliteRepository(); } else { _repository = new GuestBookXmlRepository(); } string content; HttpStatusCode result; switch (context.Request.HttpMethod) { case "GET": var guestBook = _repository.List(); content = presenter.FormatGuestBook(guestBook.Item1, guestBook.Item2); result = HttpStatusCode.OK; break; case "POST": var query = context.Request.QueryString; var user = query.GetValues("user").First(); var message = query.GetValues("message").First(); _repository.AddEntry(user, message); content = ""; result = HttpStatusCode.NoContent; break; default: content = presenter.FormatError(HttpStatusCode.MethodNotAllowed, "Method not allowed..."); result = HttpStatusCode.MethodNotAllowed; break; } var responseArray = Encoding.UTF8.GetBytes(content); context.Response.StatusCode = (int) result; context.Response.ContentType = "text/html; charset=utf-8"; context.Response.ContentLength64 = responseArray.Length; context.Response.OutputStream.Write(responseArray, 0, responseArray.Length); context.Response.OutputStream.Close(); return result; }