Esempio n. 1
0
 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;
 }
Esempio n. 2
0
 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;
 }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
 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;
     }
 }
Esempio n. 5
0
        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;
        }
Esempio n. 6
0
 Reply GetJSONReply(object input)
 {
     string body = Serialiser.Serialize(input);
     Reply reply = new Reply(ReplyCode.Ok, ContentType.JSON, body);
     return reply;
 }
Esempio n. 7
0
 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;
 }
Esempio n. 8
0
        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;
            }
        }
Esempio n. 9
0
        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;
        }
Esempio n. 10
0
 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;
 }