public void Write(string collectionName, IStringModel tokenizer, HttpRequest request) { var documents = Deserialize <IEnumerable <IDictionary <string, object> > >(request.Body); var job = new Job(collectionName, documents, tokenizer); _sessionFactory.ExecuteWrite(job); }
public ResponseModel Read(string collectionName, IStringModel model, HttpRequest request) { var timer = Stopwatch.StartNew(); var collectionId = collectionName.ToHash(); using (var session = _sessionFactory.CreateReadSession(collectionName, collectionId)) { var query = _httpQueryParser.Parse(collectionId, model, request); if (query == null) { return(new ResponseModel { MediaType = "application/json", Total = 0 }); } var result = session.Read(query); long total = result.Total; this.Log(string.Format("executed query {0} in {1}", query, timer.Elapsed)); if (request.Query.ContainsKey("create")) { var newCollectionName = request.Query["newCollection"].ToString(); if (string.IsNullOrWhiteSpace(newCollectionName)) { newCollectionName = Guid.NewGuid().ToString(); } _sessionFactory.ExecuteWrite(new Job(newCollectionName, result.Docs, model)); } var mem = new MemoryStream(); Serialize(result.Docs, mem); return(new ResponseModel { MediaType = "application/json", Documents = result.Docs, Total = total, Body = mem.ToArray() }); } }