private void Put(HttpListenerContext context, string index) { var data = context.ReadJsonObject<IndexDefinition>(); if (data.Map == null) { context.SetStatusToBadRequest(); context.Write("Expected json document with 'Map' property"); return; } context.SetStatusToCreated("/indexes/" + index); context.WriteJson(new { index = Database.PutIndex(index, data) }); }
private void HandleRequest(HttpListenerContext ctx) { if (AssertSecurityRights(ctx) == false) return; foreach (var requestResponder in requestResponders) { if (requestResponder.WillRespond(ctx)) { requestResponder.Respond(ctx); return; } } ctx.SetStatusToBadRequest(); ctx.Write( @" <html> <body> <h1>Could not figure out what to do</h1> <p>Your request didn't match anything that Raven knows to do, sorry...</p> </body> </html> "); }
private void HandleActualRequest(HttpListenerContext context) { string matchUrl = context.Request.Url.AbsolutePath.Trim().ToLower(); Match match = FilesMatcher.Match(matchUrl); if (match.Success) { string recordNumber = match.Groups["record"].Value; string filePath = null; try { using (var trimService = new TrimAttachmentRetriever(trimServer, trimDatasetId)) { filePath = trimService.GetTrimAttachmentPath(long.Parse(recordNumber)); if (filePath == null) { context.SetStatusToNotFound(); return; } context.WriteEmbeddedFile(filePath, trimService.FileName, trimService.MimeType); } } finally { if (filePath != null) { File.Delete(filePath); } } } else { string lastUpdateString = context.Request.QueryString.Get("from"); DateTime lastUpdated; if (!DateTime.TryParseExact(lastUpdateString, LastUpdateFormat, CultureInfo.CurrentCulture, DateTimeStyles.AssumeLocal, out lastUpdated)) { lastUpdated = DateTime.MinValue; } using (var trimService = new TrimRecordsRetriever(trimServer, trimDatasetId)) { var records = trimService.RetrieveRecords(lastUpdated).ToList(); context.Write(JsonConvert.SerializeObject(new { Records = records, FromDate = trimService.LastRecordUpdatedDate == null ? null : trimService.LastRecordUpdatedDate.Value.ToString(LastUpdateFormat) })); } context.Response.ContentType = "application/json"; } context.Response.StatusCode = 200; context.Response.StatusDescription = "OK"; }