private ViewResult ProcessResults(string uri, ViewOptions options) { CouchRequest req = GetRequest(options, uri); CouchResponse resp = req.GetCouchResponse(); return(new ViewResult(resp, req.GetRequest())); }
/// <summary> /// Using the bulk API for the loading of documents. /// </summary> /// <param name="docs"></param> /// <remarks>Here we assume you have either added the correct rev, id, or _deleted attribute to each document. The response will indicate if there were any errors. /// Please note that the max_document_size configuration variable in CouchDB limits the maximum request size to CouchDB.</remarks> /// <returns>JSON of updated documents in the BulkDocumentResponse class. </returns> public BulkDocumentResponses SaveDocuments(Documents docs, bool all_or_nothing) { string uri = databaseBaseUri + "/_bulk_docs"; string data = Newtonsoft.Json.JsonConvert.SerializeObject(docs); if (all_or_nothing == true) { uri = uri + "?all_or_nothing=true"; } CouchResponse resp = GetRequest(uri).Post().Json().Data(data).GetCouchResponse(); if (resp == null) { throw new System.Exception("Response returned null."); } if (resp.StatusCode != HttpStatusCode.Created) { throw new System.Exception("Response returned with a HTTP status code of " + resp.StatusCode + " - " + resp.StatusDescription); } // Get response string x = resp.ResponseString; // Convert to Bulk response BulkDocumentResponses bulk = Newtonsoft.Json.JsonConvert.DeserializeObject <BulkDocumentResponses>(x); return(bulk); }
/// <summary> /// Request multiple documents /// in a single request. /// </summary> /// <param name="keyLst"></param> /// <returns></returns> public ViewResult GetDocuments(Keys keyLst) { // serialize list of keys to json string data = Newtonsoft.Json.JsonConvert.SerializeObject(keyLst); ViewOptions viewOptions = new ViewOptions { IncludeDocs = true, Keys = keyLst.Values.Select(x => new KeyOptions(x)).ToArray() }; CouchResponse resp = GetRequest(viewOptions, databaseBaseUri + "/_all_docs").GetCouchResponse(); if (resp == null) { return(null); } if (resp.StatusCode == HttpStatusCode.NotFound) { return(null); } ViewResult vw = new ViewResult(resp, null); return(vw); }
private ViewResult <T> ProcessGenericResults <T>(string uri, ViewOptions options) { CouchRequest req = GetRequest(options, uri); CouchResponse resp = req.GetCouchResponse(); bool includeDocs = false; if (options != null) { includeDocs = options.IncludeDocs ?? false; } return(new ViewResult <T>(resp, req.GetRequest(), ObjectSerializer, includeDocs)); }
private static JObject CheckAccepted(CouchResponse resp) { if (resp == null) { throw new System.Exception("Response returned null."); } if (resp.StatusCode != HttpStatusCode.Accepted) { throw new System.Exception(string.Format("Response return with a HTTP Code of {0} - {1}", resp.StatusCode, resp.StatusDescription)); } return(resp.GetJObject()); }
public ViewResult(CouchResponse response, HttpWebRequest request, IObjectSerializer objectSerializer, bool includeDocs = false) : base(response, request, includeDocs) { this.objectSerializer = objectSerializer; }
public CouchException(HttpWebRequest request, CouchResponse response, string mesg) : base(BuildExceptionMessage(mesg, request)) { }
public ListResult(HttpWebRequest request, CouchResponse response) { this.request = request; this.response = response; }