public async Task <IActionResult> Delete(string collectionId, string q) { var mediaType = Request.ContentType ?? string.Empty; var queryParser = _plugins.Get <IQueryParser>(mediaType); var reader = _plugins.Get <IReader>(); var writers = _plugins.All <IWriter>(mediaType).ToList(); var tokenizer = _plugins.Get <ITokenizer>(mediaType); if (queryParser == null || writers == null || writers.Count == 0 || tokenizer == null) { throw new NotSupportedException(); } var parsedQuery = queryParser.Parse(q, tokenizer); parsedQuery.CollectionId = collectionId.ToHash(); var oldData = reader.Read(parsedQuery).ToList(); foreach (var writer in writers) { await Task.Run(() => { writer.Remove(collectionId, oldData); }); } return(StatusCode(202)); // marked for deletion }
public async Task <IActionResult> Page(string url, string collectionId) { if (string.IsNullOrWhiteSpace(url)) { return(View("Index")); } if (!url.StartsWith("http://") && !url.StartsWith("https://")) { return(View("Index")); } var collectionName = collectionId ?? "www"; try { var uri = new Uri(url); var document = new Dictionary <string, object>(); var parsed = GetWebString(uri); document["site"] = uri.Host; document["url"] = uri.ToString(); document["body"] = parsed.body; document["title"] = parsed.title; document["created"] = DateTime.Now.ToBinary(); var writers = _plugins.All <IWriter>(Request.ContentType).ToList(); var reader = _plugins.Get <IReader>(); var mediaType = Request.ContentType ?? string.Empty; var queryParser = _plugins.Get <IQueryParser>(mediaType); var tokenizer = _plugins.Get <ITokenizer>(mediaType); if (writers == null || reader == null || queryParser == null || tokenizer == null) { return(StatusCode(415)); // Media type not supported } var deleteQuery = queryParser.Parse(string.Format("url:{0}", uri.ToString()), tokenizer); deleteQuery.CollectionId = collectionName.ToHash(); var oldData = reader.Read(deleteQuery).ToList(); foreach (var writer in writers) { await Task.Run(() => { writer.Update(collectionName, new[] { document }, oldData); }); } return(Redirect("/add/thankyou")); } catch (Exception ex) { // TODO: add logging framework System.IO.File.WriteAllText(string.Format("_{0}_{1}.log", DateTime.Now.ToBinary(), WebUtility.UrlEncode(url)), ex.ToString()); return(View("Error")); } }
public async Task <IActionResult> Post(string collectionId, [FromBody] IEnumerable <IDictionary> payload) { if (collectionId == null) { throw new ArgumentNullException(nameof(collectionId)); } if (payload == null) { throw new ArgumentNullException(nameof(collectionId)); } var writers = _plugins.All <IWriter>(Request.ContentType).ToList(); if (writers == null || writers.Count == 0) { return(StatusCode(415)); // Media type not supported } foreach (var writer in writers) { try { await Task.Run(() => { writer.Write(collectionId, payload); }); } catch (Exception ew) { throw ew; } } Response.Headers.Add( "Location", new Microsoft.Extensions.Primitives.StringValues(string.Format("/{0}", collectionId))); return(StatusCode(201)); // Created }