static Reply SubmissionTest(Request request) { Document document = new Document("Submission"); string body = ""; foreach (var entry in request.Content) body += Markup.Paragraph(string.Format("{0}: {1}", entry.Key, entry.Value)); Reply reply = new Reply(document.Render(body)); return reply; }
static Reply MarkupTest(Request request) { Document document = new Document("<Test>"); string body = Markup.Paragraph(Markup.Bold("Success!")); body += Markup.Paragraph(string.Format("The path of this handler is: {0}", Markup.Bold(request.RequestHandler.GetPath()))); string form = Markup.Text("input1") + Markup.Text("input2") + Markup.Submit("Submit"); body += Markup.Form(SubmissionHandler.GetPath(), form); Reply reply = new Reply(document.Render(body)); return reply; }
public Reply HandleRequest(Request request) { if (RequestObserver != null) RequestObserver.ObserveRequest(request); if (Debugger.IsAttached) { try { Reply reply = TryHandlers(request); if (reply != null) return reply; } catch (HandlerException exception) { Reply exceptionReply = new Reply(ReplyCode.BadRequest, ContentType.Plain, exception.Message); return exceptionReply; } } else { try { Reply reply = TryHandlers(request); if (reply != null) return reply; } catch (HandlerException exception) { Reply exceptionReply = new Reply(ReplyCode.BadRequest, ContentType.Plain, exception.Message); return exceptionReply; } catch (Exception exception) { //Print the exception to the server console but don't leak any information to the client string message = string.Format("An exception of type {0} occurred at {1}: {2}\n", exception.GetType().ToString(), exception.Source, exception.Message); foreach (var trace in exception.StackTrace) message += string.Format("{0}\n", trace); Output.Write(message); Reply exceptionReply = new Reply(ReplyCode.InternalServerError, ContentType.Plain, "Internal server error"); return exceptionReply; } } if (CatchAll == null) { Reply invalidReply = new Reply(ReplyCode.NotFound, ContentType.Plain, "Invalid path"); return invalidReply; } else return CatchAll.CatchAll(request); }
Reply AutomaticUpdates(Request request) { var arguments = request.Arguments; string regionName = (string)arguments[0]; int accountId = (int)arguments[1]; RegionHandler regionHandler = GetRegionHandler(regionName); using (NpgsqlConnection database = DatabaseProvider.GetConnection()) { SQLCommand command = GetCommand("update summoner set update_automatically = true where region = cast(:region as region_type) and account_id = :account_id", database); command.SetEnum("region", regionHandler.GetRegionEnum()); command.Set("account_id", accountId); int rowsAffected = command.Execute(); bool success = rowsAffected > 0; AutomaticUpdatesResult result = new AutomaticUpdatesResult(success); string body = Serialiser.Serialize(result); Reply reply = new Reply(ReplyCode.Ok, ContentType.JSON, body); return reply; } }
public Reply HandleRequest(Request request) { if (Observer != null) Observer(request); try { List<string> remainingPath = ConvertPath(request.Path); foreach (var handler in Handlers) { Reply reply = handler.RouteRequest(request, remainingPath); if (reply != null) return reply; } } catch (HandlerException exception) { Reply exceptionReply = new Reply(ReplyCode.BadRequest, ContentType.Plain, exception.Message); return exceptionReply; } catch (Exception exception) { if (Debugger.IsAttached) { //While a debugger is attached, it's more convenient to go right to the source of an exception throw; } else { //Print the exception to the server console but don't leak any information to the client string message = string.Format("An exception of type {0} occurred at {1}: {2}\n", exception.GetType().ToString(), exception.Source, exception.Message); foreach (var trace in exception.StackTrace) message += string.Format("{0}\n", trace); Output.Write(message); Reply exceptionReply = new Reply(ReplyCode.InternalServerError, ContentType.Plain, "Internal server error"); return exceptionReply; } } Reply invalidReply = new Reply(ReplyCode.NotFound, ContentType.Plain, "Invalid path"); return invalidReply; }
Reply GetJSONReply(object input) { string body = Serialiser.Serialize(input); Reply reply = new Reply(ReplyCode.Ok, ContentType.JSON, body); return reply; }
Reply LoadAccountData(Request request) { var arguments = request.Arguments; string regionName = (string)arguments[0]; int accountId = (int)arguments[1]; RegionHandler regionHandler = GetRegionHandler(regionName); AccountIdJob job = regionHandler.PerformManualSummonerUpdate(accountId); SummonerUpdateResult result = new SummonerUpdateResult(job); string body = Serialiser.Serialize(result); Reply reply = new Reply(ReplyCode.Ok, ContentType.JSON, body); return reply; }
Reply ViewSummonerGames(Request request) { var arguments = request.Arguments; string regionName = (string)arguments[0]; int accountId = (int)arguments[1]; using (NpgsqlConnection database = DatabaseProvider.GetConnection()) { Summoner summoner = LoadSummoner(regionName, accountId, database); List<GameTeamPlayer> games = LoadSummonerGames(summoner, database); string title = string.Format("Games of {0}", summoner.SummonerName); string table = GetSummonerGamesTable(summoner, games); Document document = GetDocument(title); Reply reply = new Reply(document.Render(table)); return reply; } }
Reply Template(string title, string content, bool useSearchForm = true) { Document document = GetDocument(title); string logo = Markup.Image(GetImage("Logo.jpg"), ProjectTitle, id: "logo"); if (useSearchForm) { string formBody = Markup.Text(SummonerField, null, "text"); formBody += GetServerSelection(); formBody += Markup.Submit("Search", "submit"); string searchForm = Markup.Form(SearchHandler.GetPath(), formBody, id: "searchForm"); content = searchForm + content; } string contentContainer = Markup.Diverse(content, id: "content"); string body = logo + contentContainer; string output = document.Render(body); Reply reply = new Reply(output); return reply; }
public static Reply Referral(string uri) { Reply reply = new Reply(); reply.Initialise(ReplyCode.Found, ContentType.Plain); reply.IsReferral = true; reply.Location = uri; reply.Body = ""; return reply; }