void CreateGameObjectsView () { var view = _db.GetView ("SphereDocs"); var success = view.SetMap ((doc, emit) => { object key; var hasType = doc.TryGetValue ("type", out key); if (hasType && key.Equals ("CouchbaseSphere")) { emit (doc ["_id"], null); } }, "1.0"); _query = view.CreateQuery ().ToLiveQuery (); _query.Changed += (sender, e) => { ProcessRows(e.Rows); }; _query.Start (); }
public void TestPullerWithLiveQuery() { // Even though this test is passed, there is a runtime exception // thrown regarding the replication's number of changes count versus // number of completed changes count. Investigation is required. Log.D(Database.Tag, "testPullerWithLiveQuery"); string docIdTimestamp = System.Convert.ToString(Runtime.CurrentTimeMillis()); string doc1Id = string.Format("doc1-{0}", docIdTimestamp); string doc2Id = string.Format("doc2-{0}", docIdTimestamp); AddDocWithId(doc1Id, "attachment2.png"); AddDocWithId(doc2Id, "attachment2.png"); int numDocsBeforePull = database.DocumentCount; View view = database.GetView("testPullerWithLiveQueryView"); view.SetMapReduce((document, emitter) => { if (document.Get("_id") != null) { emitter(document.Get("_id"), null); } }, null, "1"); LiveQuery allDocsLiveQuery = view.CreateQuery().ToLiveQuery(); allDocsLiveQuery.Changed += (sender, e) => { int numTimesCalled = 0; if (e.Error != null) { throw new RuntimeException(e.Error); } if (numTimesCalled++ > 0) { NUnit.Framework.Assert.IsTrue(e.Rows.Count > numDocsBeforePull); } Log.D(Database.Tag, "rows " + e.Rows); }; // the first time this is called back, the rows will be empty. // but on subsequent times we should expect to get a non empty // row set. allDocsLiveQuery.Start(); DoPullReplication(); allDocsLiveQuery.Stop(); }
static ContactDatabase() { database = Manager.SharedInstance.GetDatabase ("contacts"); emailLookup = new Dictionary<string, string> (); lookupView = database.GetView ("addresses"); lookupView.SetMap ((document, emit) => { var val = document["contact.address.address"]; emit(document["_id"], val); }, "1"); Query lookupQuery = lookupView.CreateQuery (); BuildLookup(lookupQuery.Run ()); lookupViewLiveQuery = lookupQuery.ToLiveQuery(); lookupViewLiveQuery.Changed += (object sender, QueryChangeEventArgs e) => { BuildLookup(e.Rows); }; lookupViewLiveQuery.Start (); }
void CreateCounterView () { var view = _db.GetView ("SphereCount"); var success = view.SetMapReduce ((doc, emit) => { object key; var hasType = doc.TryGetValue ("type", out key); if (hasType && key.Equals ("CouchbaseSphere")) { emit (doc ["_id"], null); } }, (keys, vals, rereduce) => { return keys.Count (); }, "1.0"); _reduceQuery = view.CreateQuery ().ToLiveQuery (); _reduceQuery.Changed += (sender, e) => { int counter = _counter; Interlocked.CompareExchange(ref _counter, (int)e.Rows.ElementAt(0).Value, counter); }; _reduceQuery.Start (); }
private void InitializeCouchbase() { _db = Manager.SharedInstance.GetDatabase("wpf-lite"); var view = _db.GetView("todos"); if (view.Map == null) { view.SetMap((props, emit) => { Console.WriteLine("Mapper mapping"); emit(DateTime.UtcNow.ToString(), props["text"]); }, "1"); } _query = view.CreateQuery().ToLiveQuery(); _query.Changed += QueryChanged; _query.Completed += QueryCompleted; _query.Start(); }
public TaskManager () { _db = Manager.SharedInstance.GetDatabase("kitchen-sync"); View view = _db.GetView("viewItemsByDate"); view.SetMap((doc, emit) => { if(doc.ContainsKey("created_at") && doc["created_at"] is DateTime) { emit(doc["created_at"], null); } }, "1"); _query = view.CreateQuery().ToLiveQuery(); _query.Descending = true; _query.Changed += (sender, e) => { if(TasksUpdated != null) { var tasks = from row in e.Rows select Task.FromDictionary(row.Document.Properties); TasksUpdated(this, tasks.ToList()); } }; _query.Start(); }
private void CallToView () { var the_view = database.GetView ("testView"); the_view.SetMap (delegate(IDictionary<string, object> document, EmitDelegate emit) { try{ emit (null, document); } catch(Exception ex){ Debug.WriteLine(ex); } }, "0.1.2"); query = the_view.CreateQuery ().ToLiveQuery(); query.Changed += delegate(object sender, QueryChangeEventArgs e) { Debug.WriteLine("changed!"); }; query.Start (); }
/// <summary> /// Starts the live query. /// </summary> public void Start() { liveQuery.Start(); }
private void InitializeCouchbase() { _db = Manager.SharedInstance.GetDatabase("wpf-lite"); _viewModel = new SimpleViewModel(new SimpleModel(Manager.SharedInstance, "wpf-lite")); if (_viewModel.SyncURL != null) { UpdateReplications(_viewModel.SyncURL); } _viewModel.PropertyChanged += (sender, args) => { Console.WriteLine("Replication URL changed to {0}", _viewModel.SyncURL); UpdateReplications(_viewModel.SyncURL); }; var view = _db.GetView("todos"); if (view.Map == null) { view.SetMap((props, emit) => { object date; if (!props.TryGetValue(CREATION_DATE_PROPERTY_NAME, out date)) { return; } object deleted; if (props.TryGetValue("_deleted", out deleted)) { return; } emit(date, props["text"]); }, "1"); } _query = view.CreateQuery().ToLiveQuery(); _query.Changed += QueryChanged; _query.Start(); }
private void RestartLiveQuery() { if (mListsLiveQuery != null) { mListsLiveQuery.Stop(); } mListsLiveQuery = GetLiveQuery(); mListsLiveQuery.Start(); }