///// <summary> ///// Writes the json object. ///// </summary> ///// <param name="writer">The writer.</param> //public void WriteJsonObject(JsonWriter writer) //{ // writer.WriteStartObject(); // WriteJson(writer); // writer.WriteEndObject(); //} /// <summary> /// Writes the json. /// </summary> /// <param name="doc">The document.</param> /// <returns>System.String.</returns> public static string WriteJson(ICanJson doc, bool isData = true) { if (doc is IDomainObject) { return(JsonConvert.SerializeObject(doc, Formatting.Indented, new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.Objects })); } else { var sb = new StringBuilder(); using (JsonWriter jsonWriter = new JsonTextWriter(new StringWriter(sb, CultureInfo.InvariantCulture))) { if (!(doc is ISelfContained)) { jsonWriter.WriteStartObject(); doc.WriteJson(jsonWriter); jsonWriter.WriteEndObject(); } else { doc.WriteJson(jsonWriter); } string result = sb.ToString(); return(result); } } }
/// <summary> /// Delete documents in bulk fashion. /// </summary> /// <param name="bulk">The bulk.</param> public void DeleteDocuments(ICanJson bulk) { try { var json = BigDDocument.WriteJson(bulk, false); var result = Request("_bulk_docs") .Data(json) .PostJson() .Parse <JArray>(); for (var i = 0; i < result.Count(); i++) { //documents[i]._id= (result[i])["id"].Value<string>(); //documents[i]._rev = (result[i])["rev"].Value<string>(); if ((result[i])["error"] == null) { continue; } throw BigDException.Create(string.Format(CultureInfo.InvariantCulture, "Document with id {0} was not deleted: {1}: {2}", (result[i])["id"].Value <string>(), (result[i])["error"], (result[i])["reason"])); } } catch (WebException e) { throw BigDException.Create("Failed to bulk delete documents", e); } }
public static string WriteJson(ICanJson doc) { var sb = new StringBuilder(); using (JsonWriter jsonWriter = new JsonTextWriter(new StringWriter(sb, CultureInfo.InvariantCulture))) { //jsonWriter.Formatting = Formatting.Indented; if (!(doc is ISelfContained)) { jsonWriter.WriteStartObject(); doc.WriteJson(jsonWriter); jsonWriter.WriteEndObject(); } else { doc.WriteJson(jsonWriter); } string result = sb.ToString(); return(result); } }
public static string WriteJson(ICanJson doc) { var sb = new StringBuilder(); using (JsonWriter jsonWriter = new JsonTextWriter(new StringWriter(sb, CultureInfo.InvariantCulture))) { //jsonWriter.Formatting = Formatting.Indented; if (!(doc is ISelfContained)) { jsonWriter.WriteStartObject(); doc.WriteJson(jsonWriter); jsonWriter.WriteEndObject(); } else doc.WriteJson(jsonWriter); string result = sb.ToString(); return result; } }