public void Process(Router router, HttpListenerContext context) { var request = context.Request; var response = context.Response; if (request.HttpMethod.Equals("GET")) { var rsp = router.ServerStorage.GetAll(); if (rsp.Equals("")) { ErrorRoute.Process(context, 404); return; } var buffer = request.ContentEncoding.GetBytes(rsp); response.OutputStream.Write(buffer, 0, buffer.Length); response.OutputStream.Close(); response.StatusCode = 200; } else { ErrorRoute.Process(context, 404); return; } response.Close(); }
public void Process(Router router, HttpListenerContext context) { var request = context.Request; var response = context.Response; var segments = context.Request.RawUrl.Split('/').Skip(1).ToArray(); var name = HttpUtility.UrlDecode(segments[1], context.Request.ContentEncoding); if (name == null) { ErrorRoute.Process(context, 404); return; } if (request.HttpMethod.Equals("GET")) { var rsp = router.PlayerManager.Get(name); if (rsp.Equals("")) { ErrorRoute.Process(context, 404); return; } var buffer = request.ContentEncoding.GetBytes(rsp); response.OutputStream.Write(buffer, 0, buffer.Length); response.OutputStream.Close(); response.StatusCode = 200; } else { ErrorRoute.Process(context, 404); return; } response.Close(); }
public void Process(Router router, HttpListenerContext context) { var request = context.Request; var response = context.Response; var segments = context.Request.RawUrl.Split('/').Skip(1).ToArray(); if (request.HttpMethod.Equals("GET")) { var rsp = segments.Length == 2 ? router.ReportsManger.Get(segments[1], null) : router.ReportsManger.Get(segments[1], int.Parse(segments[2])); if (rsp.Equals("")) { ErrorRoute.Process(context, 404); return; } var buffer = request.ContentEncoding.GetBytes(rsp); response.OutputStream.Write(buffer, 0, buffer.Length); response.OutputStream.Close(); response.StatusCode = 200; } else { ErrorRoute.Process(context, 404); return; } response.Close(); }
public void Route(HttpListenerContext context) { foreach (var key in _routes.Keys) { if (!Regex.IsMatch(context.Request.RawUrl, key)) { continue; } _routes[key].Process(this, context); return; } ErrorRoute.Process(context, 404); }
public void Process(Router router, HttpListenerContext context) { var request = context.Request; var response = context.Response; var segments = context.Request.RawUrl.Split('/').Skip(1).ToArray(); var endpoint = HttpUtility.UrlDecode(segments[1], context.Request.ContentEncoding); if (endpoint == null) { ErrorRoute.Process(context, 404); return; } if (request.HttpMethod.Equals("PUT")) { string text; using (var reader = new StreamReader(request.InputStream, request.ContentEncoding)) { text = reader.ReadToEnd(); } router.ServerStorage.Add(new ServerData(endpoint, JsonConvert.DeserializeObject <ServerInfo>(text))); response.StatusCode = 200; } else if (request.HttpMethod.Equals("GET")) { var rsp = router.ServerStorage.GetOne(endpoint); if (rsp.Equals("")) { ErrorRoute.Process(context, 404); return; } var buffer = request.ContentEncoding.GetBytes(rsp); response.OutputStream.Write(buffer, 0, buffer.Length); response.OutputStream.Close(); response.StatusCode = 200; } else { ErrorRoute.Process(context, 404); return; } response.Close(); }
public void Process(Router router, HttpListenerContext context) { var request = context.Request; var response = context.Response; var segments = context.Request.RawUrl.Split('/').Skip(1).ToArray(); var endpoint = HttpUtility.UrlDecode(segments[1], context.Request.ContentEncoding); var dateTimestring = HttpUtility.UrlDecode(segments[3], context.Request.ContentEncoding); if (endpoint == null || dateTimestring == null) { ErrorRoute.Process(context, 404); return; } DateTime dateTime; if (DateTime.TryParseExact(segments[3], "yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out dateTime) == false) { ErrorRoute.Process(context, 404); return; } dateTime = dateTime.ToUniversalTime(); if (request.HttpMethod.Equals("PUT")) { var rsp = router.ServerStorage.GetOne(endpoint); if (rsp.Equals("")) { ErrorRoute.Process(context, 400); return; } string text; using (var reader = new StreamReader(request.InputStream, request.ContentEncoding)) { text = reader.ReadToEnd(); } var matchData = new MatchData(endpoint, dateTime, JsonConvert.DeserializeObject <MatchInfo>(text)); router.MatchStorage.Add(matchData); router.ServerManager.Add(matchData); router.PlayerManager.Add(matchData); response.StatusCode = 200; } else if (request.HttpMethod.Equals("GET")) { var rsp = router.MatchStorage.GetOne(endpoint, dateTime); if (rsp.Equals("")) { ErrorRoute.Process(context, 404); return; } var buffer = request.ContentEncoding.GetBytes(rsp); response.OutputStream.Write(buffer, 0, buffer.Length); response.OutputStream.Close(); response.StatusCode = 200; } else { ErrorRoute.Process(context, 404); return; } response.Close(); }