public long ReplicateWith(string server, string database, bool reset = false) { long docsSync = 0; RemoteDB remoteDB = new RemoteDB(); long lastSync = GetLastSync(server + "/" + database); if (reset) { lastSync = 0; } JsonData docs = remoteDB.GetChanges(server, database, true, lastSync); foreach (JsonData result in docs["results"]) { string id = (string)result["id"]; string rev = (string)result["changes"][0]["rev"]; // //result.Remove("_rev"); // //result.Remove("_id"); string doc = result["doc"].ToJson(); try { PutDoc(id, doc, rev); } catch (Exception ee) { Debug.WriteLine(ee.ToString()); } } docsSync = docs["results"].Count; ///Debug.WriteLine("Document sync: " + docs.results.Count); ////Debug.WriteLine(AllDocs()); SetLastSync(server + "/" + database, (int)docs["last_seq"]); docs = null; remoteDB = null; return(docsSync); }
public void ReplicationTest() { RemoteDB remoteDB = new RemoteDB(); //DocInfo[] info = remoteDB.GetAllDocuments("http://127.0.0.1:5984", "test"); NouchDB nouchDB = new NouchDB(); //nouchDB.Delete(new Options()); //Debug.WriteLine(nouchDB.Changes()); //string res = RevsDiff(nouchDB, remoteDB, info); //res = "{\"keys\":" + res + "}"; long lastSync = nouchDB.GetLastSync("http://127.0.0.1:5984/test"); JsonData docs = remoteDB.GetChanges("http://127.0.0.1:5984", "test", true, lastSync); foreach (JsonData result in docs["results"]) { string id = (string) result["id"]; string rev = (string) result["changes"][0]["rev"]; // //result.Remove("_rev"); // //result.Remove("_id"); string doc = result["doc"].ToJson() ; try { nouchDB.PutDoc(id, doc, rev); } catch (Exception ee) { Debug.WriteLine(ee.ToString()); } } Debug.WriteLine("Document sync: " + docs["results"].Count); Debug.WriteLine(nouchDB.AllDocs()); nouchDB.SetLastSync("http://127.0.0.1:5984/test",(int) docs["last_seq"]); //nouchDB.Close(); }
public string RevsDiff(NDB.NouchDB db, RemoteDB remoteDB, DocInfo[] docInfo) { var result = "["; Dictionary<string,string> docList = new Dictionary<string,string>(); for (int f = 0; f < docInfo.Length; f++ ) { DocInfo remoteDoc = docInfo[f]; long revision = Convert.ToInt64(remoteDoc.Revision.Split('-')[0]); Node localDoc = db.GetDocInfo(remoteDoc.ID); if (localDoc == null) { if (Convert.ToInt64(localDoc.currentVersion) < revision) { if (!docList.ContainsKey(remoteDoc.ID)) { docList.Add(remoteDoc.ID,""); } } } else { if (!docList.ContainsKey(remoteDoc.ID)) { docList.Add(remoteDoc.ID, ""); } } } return JsonMapper.ToJson(docList.Keys); }
public void RemoteTest() { RemoteDB remoteDB = new RemoteDB(); remoteDB.GetAllDocuments("http://127.0.0.1:5984", "test"); }
public long ReplicateWith(string server, string database, bool reset = false) { long docsSync = 0; RemoteDB remoteDB = new RemoteDB(); long lastSync = GetLastSync(server+"/"+database); if (reset) { lastSync = 0; } JsonData docs = remoteDB.GetChanges(server, database, true, lastSync); foreach (JsonData result in docs["results"]) { string id = (string)result["id"]; string rev = (string)result["changes"][0]["rev"]; // //result.Remove("_rev"); // //result.Remove("_id"); string doc = result["doc"].ToJson(); try { PutDoc(id, doc, rev); } catch (Exception ee) { Debug.WriteLine(ee.ToString()); } } docsSync = docs["results"].Count; ///Debug.WriteLine("Document sync: " + docs.results.Count); ////Debug.WriteLine(AllDocs()); SetLastSync(server+"/"+database,(int)docs["last_seq"]); docs = null; remoteDB = null; return docsSync; }