public static void ToCouchDb(RuntimeStorage intent){ CouchClient client = new CouchClient (); if (!client.HasDatabase (DATABASE)) client.CreateDatabase (DATABASE); CouchDatabase db = client.GetDatabase(DATABASE); CouchDbIntentData dbIntent; try{ Document doc = db.GetDocument(intent.filename); dbIntent = new CouchDbIntentData(); dbIntent.data = intent.data; Document<CouchDbIntentData> tosave = new Document<CouchDbIntentData>(dbIntent); tosave.Id = doc.Id; tosave.Rev = doc.Rev; db.SaveDocument(tosave); }catch{ dbIntent = new CouchDbIntentData (); dbIntent.data = intent.data; Document<CouchDbIntentData> tosave = new Document<CouchDbIntentData>(dbIntent); tosave.Id = intent.filename; db.CreateDocument (tosave); } }
public static void ToCouchDb(RuntimeStorage intent) { CouchClient client = new CouchClient(); if (!client.HasDatabase(DATABASE)) { client.CreateDatabase(DATABASE); } CouchDatabase db = client.GetDatabase(DATABASE); CouchDbIntentData dbIntent; try{ Document doc = db.GetDocument(intent.filename); dbIntent = new CouchDbIntentData(); dbIntent.data = intent.data; Document <CouchDbIntentData> tosave = new Document <CouchDbIntentData>(dbIntent); tosave.Id = doc.Id; tosave.Rev = doc.Rev; db.SaveDocument(tosave); }catch { dbIntent = new CouchDbIntentData(); dbIntent.data = intent.data; Document <CouchDbIntentData> tosave = new Document <CouchDbIntentData>(dbIntent); tosave.Id = intent.filename; db.CreateDocument(tosave); } }
public CouchDbIntent(string name) { _intent = new RuntimeStorage(); _intent.filename = name; _intent.data = new Dictionary <string, JToken>(); CouchClient client = new CouchClient(); if (!client.HasDatabase(DATABASE)) { client.CreateDatabase(DATABASE); } CouchDatabase database = client.GetDatabase(DATABASE); CouchDbIntentData data = null; try{ Document d = database.GetDocument(name); data = JsonConvert.DeserializeObject <CouchDbIntentData>(d.ToString()); }catch { } if (data == null) { data = new CouchDbIntentData(); data.data = new Dictionary <string, JToken>(); Document <CouchDbIntentData> tosave = new Document <CouchDbIntentData>(data); tosave.Id = name; database.CreateDocument(tosave); } if (data.data != null) { foreach (var entry in data.data) { _intent.data.Add(entry.Key, entry.Value); } } }
public CouchDbIntent(string name){ _intent = new RuntimeStorage(); _intent.filename = name; _intent.data = new Dictionary<string, JToken>(); CouchClient client = new CouchClient(); if(!client.HasDatabase(DATABASE)) client.CreateDatabase(DATABASE); CouchDatabase database = client.GetDatabase(DATABASE); CouchDbIntentData data = null; try{ Document d = database.GetDocument(name); data = JsonConvert.DeserializeObject<CouchDbIntentData>(d.ToString()); }catch{ } if(data == null) { data = new CouchDbIntentData(); data.data = new Dictionary<string, JToken>(); Document<CouchDbIntentData> tosave = new Document<CouchDbIntentData>(data); tosave.Id = name; database.CreateDocument( tosave ); } if (data.data != null) { foreach (var entry in data.data) { _intent.data.Add(entry.Key, entry.Value); } } }