protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Register the device for Push Notifications GcmBroadcastRegister.Register(this); SetContentView(Resource.Layout.Main); // Get our button from the layout resource, // and attach an event to it FloatingActionButton btnNewConversation = FindViewById <FloatingActionButton> (Resource.Id.btnNewConversation); ListView ConversationslistView = FindViewById <ListView>(Resource.Id.listViewConversations); btnNewConversation.Click += (sender, e) => { var intent = new Intent(this, typeof(NewConversationActivity)); StartActivity(intent); }; ConversationslistView.ItemClick += (sender, e) => { // Get conversation document var doc = ConversationslistView.GetItemAtPosition(e.Position).Cast <Document>(); var intent = new Intent(this, typeof(ConversationActivity)); intent.PutExtra("normalizedPhone", (string)doc.GetProperty("conversationId")); StartActivity(intent); }; // Get database instance Database = Manager.SharedInstance.GetDatabase(Tag.ToLower()); // Create a view and register its map function: var view = Database.GetView("conversations"); view.SetMap((doc, emit) => { if (!doc.ContainsKey("type")) { return; } // If document is a conversation, we emit it if (doc["type"].ToString() == Tag) { emit( doc["lastMessageTime"], doc ); } }, "1"); // Set up a query for a view that indexes conversations, to get every unique conversation: var query = Database.GetView("conversations").CreateQuery(); query.Descending = true; query.Completed += (sender, e) => Log.Verbose(Tag, e.ErrorInfo.ToString() ?? e.Rows.ToString()); LiveQuery = query.ToLiveQuery(); // Bind listview adapyer to liveQuery ConversationslistView.Adapter = new ListLiveQueryAdapter(this, LiveQuery); }
/// <exception cref="System.Exception"></exception> public virtual void TestPullerWithLiveQuery() { // This is essentially a regression test for a deadlock // that was happening when the LiveQuery#onDatabaseChanged() // was calling waitForUpdateThread(), but that thread was // waiting on connection to be released by the thread calling // waitForUpdateThread(). When the deadlock bug was present, // this test would trigger the deadlock and never finish. Log.D(Database.Tag, "testPullerWithLiveQuery"); string docIdTimestamp = System.Convert.ToString(Runtime.CurrentTimeMillis()); string doc1Id = string.Format("doc1-%s", docIdTimestamp); string doc2Id = string.Format("doc2-%s", docIdTimestamp); AddDocWithId(doc1Id, "attachment2.png"); AddDocWithId(doc2Id, "attachment2.png"); int numDocsBeforePull = database.GetDocumentCount(); View view = database.GetView("testPullerWithLiveQueryView"); view.SetMapAndReduce(new _Mapper_307(), null, "1"); LiveQuery allDocsLiveQuery = view.CreateQuery().ToLiveQuery(); allDocsLiveQuery.AddChangeListener(new _ChangeListener_317(numDocsBeforePull)); // 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(); }
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 InitializeDatasource() { var view = InitializeCouchbaseView(); _tableQuery = view.CreateQuery().ToLiveQuery(); _tableQuery.Descending = true; _tableQuery.Changed += UpdateTable; _tableQuery.Start(); var doneView = _database.GetView("Done"); _doneQuery = doneView.CreateQuery().ToLiveQuery(); _doneQuery.Changed += (sender, e) => { string val; if (_doneQuery.Rows.Count == 0) { val = String.Empty; } else { var row = _doneQuery.Rows.ElementAt(0); var doc = (IDictionary <string, string>)row.Value; val = String.Format("{0}: {1}", doc["Label"], doc["Count"]); } DoneText = val; }; _doneQuery.Start(); }
private void RestartLiveQuery() { if (mListsLiveQuery != null) { mListsLiveQuery.Stop(); } mListsLiveQuery = GetLiveQuery(); mListsLiveQuery.Start(); }
/// <summary> /// Starts a live query to watch for conflicts /// </summary> public static void StartConflictLiveQuery() { // TRAINING: Detecting when conflicts occur _conflictsLiveQuery = Database.CreateAllDocumentsQuery().ToLiveQuery(); _conflictsLiveQuery.AllDocsMode = AllDocsMode.OnlyConflicts; _conflictsLiveQuery.Changed += ResolveConflicts; _conflictsLiveQuery.Start(); }
public ConversationListViewAdapter(Context context, LiveQuery query) { this.Context = context; this.query = query; query.Changed += (sender, e) => { enumerator = e.Rows; ((Activity)context).RunOnUiThread(new Action(NotifyDataSetChanged)); }; //TODO: Revise query.Start(); }
private void SetupViewAndQuery() { var view = _db.GetView("tasksByCreatedAt"); view.SetMap((doc, emit) => { if (!doc.ContainsKey("type")) { return; } var type = doc["type"] as string; if (type != "task") { return; } var elements = new List <object>(); if (!doc.Extract(elements, "taskList", "createdAt", "task")) { return; } var listInfo = JsonUtility.ConvertToNetObject <IDictionary <string, object> >(elements[0]); if (!listInfo.ContainsKey("id")) { return; } elements[0] = listInfo["id"]; emit(elements.ToArray(), null); }, "1.0"); _tasksLiveQuery = view.CreateQuery().ToLiveQuery(); _tasksLiveQuery.StartKey = new[] { _taskList.Id }; _tasksLiveQuery.EndKey = new[] { _taskList.Id }; _tasksLiveQuery.PrefixMatchLevel = 1; _tasksLiveQuery.Descending = false; _tasksLiveQuery.Changed += (sender, e) => { Console.WriteLine("_tasksLiveQuery changed..."); ListData.Replace(e.Rows.Select(x => { Console.WriteLine($" ...Found #{x.SequenceNumber} ({x.DocumentId})"); return(new TaskCellModel(x.DocumentId)); }), true); }; _tasksLiveQuery.Start(); }
void InitializeDatasource() { var view = Database.ViewNamed(DefaultViewName); LiveQuery query = view.Query.AsLiveQuery; query.Descending = true; Datasource.Query = query; Datasource.LabelProperty = DocumentDisplayPropertyName; // Document property to display in the cell label DoneQuery = Database.ViewNamed("Done").Query.AsLiveQuery; DoneQuery.AddObserver(this, (NSString)"rows", NSKeyValueObservingOptions.New, IntPtr.Zero); }
public virtual void TestPullerWithLiveQuery() { Assert.Fail(); // TODO.ZJG: Needs debugging. // This is essentially a regression test for a deadlock // that was happening when the LiveQuery#onDatabaseChanged() // was calling waitForUpdateThread(), but that thread was // waiting on connection to be released by the thread calling // waitForUpdateThread(). When the deadlock bug was present, // this test would trigger the deadlock and never finish. 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(); }
public LiveQueryAdapter(Context context, LiveQuery query) { this.context = context; this.query = query; query.Changed += async(sender, e) => { enumerator = e.Rows; var evt = DataSetChanged; if (evt == null) { return; } ((Activity)context).RunOnUiThread(new Action(() => evt(e))); }; //TODO: Revise query.Start(); }
private LiveQuery GetLiveQuery() { LiveQuery query = List.GetQuery(GetDatabase()).ToLiveQuery(); query.Changed += async(sender, e) => { var changedEnumerator = e.Rows; mListsAdapter.Update(changedEnumerator); int position = GetCurrentSelectedPosition(changedEnumerator ); if (position != -1 && position != mCurrentSelectedPosition) { SelectListItem(position, false); } }; return(query); }
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(); }
private void setupLiveQuery() { QueryEnumerator mEnumerator; Documents docs = new Documents(); mLiveQuery = docs.getAllContent(mDatabase).ToLiveQuery(); mLiveQuery.Changed += delegate(object sender, QueryChangeEventArgs e) { mEnumerator = e.Rows; foreach (var q in mEnumerator) { var rDoc = mDatabase.GetDocument(q.DocumentId); var props = rDoc.Properties; Log.Info("--NEW DATA--", "Type: " + rDoc.GetProperty("type").ToString() + " message: " + rDoc.GetProperty("message").ToString() + " Channel: " + rDoc.GetProperty("channels").ToString() + " Created: " + rDoc.GetProperty("created").ToString()); } }; mLiveQuery.Start(); }
/// <summary> /// db and query initialization /// </summary> public void init() { db = Manager.SharedInstance.GetDatabase(DB_NAME); var view = db.GetView("tasks"); if (view.Map == null) { view.SetMap((props, emit) => { emit(DateTime.UtcNow.ToString(), props["text"]); }, "1"); } query = view.CreateQuery().ToLiveQuery(); query.Changed += QueryChanged; query.Completed += QueryCompleted; query.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(); }
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(); }
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(); }
public LiveQueryObservableCollection(LiveQuery query, Func <QueryRow, T> transform) : base() { this.query = query; query.Changed += (sender, e) => { Items.Clear(); foreach (var row in e.Rows) { var o = transform(row); if (o != null) { Items.Add(o); } } OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, Items.ToList())); OnPropertyChanged(new PropertyChangedEventArgs("Count")); OnPropertyChanged(new PropertyChangedEventArgs("Item[]")); }; query.Start(); }
private void SetupViewAndQuery() { var view = _db.GetView("usersByUsername"); view.SetMap((doc, emit) => { var elements = new List <object>(); if (!doc.Extract(elements, "type", "username", "taskList")) { return; } if (elements[0] as string != UserType) { return; } var listInfo = JsonUtility.ConvertToNetObject <IDictionary <string, object> >(elements[2]); var listId = listInfo?["id"] as string; emit(new[] { listId, elements[1] }, null); }, "1.0"); _usersLiveQuery = view.CreateQuery().ToLiveQuery(); _usersLiveQuery.StartKey = new[] { _taskList.Id }; _usersLiveQuery.EndKey = new[] { _taskList.Id }; _usersLiveQuery.PrefixMatchLevel = 1; _usersLiveQuery.Changed += (sender, e) => { ListData.Replace(e.Rows.Select(x => { var key = JsonUtility.ConvertToNetList <string>(x.Key); var id = key[0]; var name = key[1]; var docId = $"{id}.{name}"; return(new UserCellModel(docId)); })); }; _usersLiveQuery.Start(); }
public override global::Android.Views.View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ListView listView = (ListView)inflater.Inflate(Resource.Layout.fragment_main, container, false); string listId = Arguments.GetString(ArgListDocId); ViewGroup header = (ViewGroup)inflater.Inflate(Resource.Layout.view_task_create, listView , false); ImageView imageView = (ImageView)header.FindViewById(Resource.Id.image); imageView.SetOnClickListener(new _OnClickListener_560(this)); EditText text = (EditText)header.FindViewById(Resource.Id.text); text.SetOnKeyListener(new _OnKeyListener_568(this, text, listId)); // Reset text and current selected photo if available. listView.AddHeaderView(header); listView.SetOnItemClickListener(new _OnItemClickListener_594()); listView.SetOnItemLongClickListener(new _OnItemLongClickListener_608(this)); LiveQuery query = Task.GetQuery(GetDatabase(), listId).ToLiveQuery(); mAdapter = new MainActivity.TasksFragment.TaskAdapter(this, Activity, query); listView.SetAdapter(mAdapter); return(listView); }
public ListLiveQueryAdapter(Context context, LiveQuery query) : base(context, query) { }
public UserAdapter(ShareActivity _enclosing, Context context, LiveQuery query) : base(context, query) { this._enclosing = _enclosing; }
public abstract void UpdateFromQuery(CouchbaseTableSource source, LiveQuery query, QueryRow [] previousRows);
public override void WillUpdateFromQuery(CouchbaseTableSource source, LiveQuery query) { return; }
private void SetupViewAndQuery() { var view = _db.GetView("list/listsByName"); view.SetMap((doc, emit) => { if (!doc.ContainsKey("type") || doc["type"] as string != "task-list" || !doc.ContainsKey("name")) { return; } emit(doc["name"], null); }, "1.0"); _byNameQuery = view.CreateQuery().ToLiveQuery(); _byNameQuery.Changed += (sender, args) => { TasksList.Replace(args.Rows.Select(x => new TaskListCellModel(x.DocumentId, x.Key as string))); }; _byNameQuery.Start(); var incompleteTasksView = _db.GetView("list/incompleteTasksCount"); incompleteTasksView.SetMapReduce((doc, emit) => { if (!doc.ContainsKey("type") || doc["type"] as string != "task") { return; } if (!doc.ContainsKey("taskList")) { return; } var list = JsonUtility.ConvertToNetObject <IDictionary <string, object> >(doc["taskList"]); if (!list.ContainsKey("id") || (doc.ContainsKey("complete") && (bool)doc["complete"])) { return; } emit(list["id"], null); }, BuiltinReduceFunctions.Count, "1.0"); _incompleteQuery = incompleteTasksView.CreateQuery().ToLiveQuery(); _incompleteQuery.GroupLevel = 1; _incompleteQuery.Changed += (sender, e) => { var newItems = TasksList.ToList(); foreach (var row in e.Rows) { var item = newItems.FirstOrDefault(x => x.DocumentID == row.Key as string); if (item != null) { item.IncompleteCount = (int)row.Value; } } TasksList.Replace(newItems); }; _incompleteQuery.Start(); }
public abstract void WillUpdateFromQuery (CouchbaseTableSource source, LiveQuery query);
public override void UpdateFromQuery(CouchbaseTableSource source, LiveQuery query, QueryRow[] previousRows) { return; }
public abstract void WillUpdateFromQuery(CouchbaseTableSource source, LiveQuery query);
public abstract void UpdateFromQuery (CouchbaseTableSource source, LiveQuery query, QueryRow [] previousRows);
public TaskAdapter(TasksFragment _enclosing, Context context, LiveQuery query) : base(context, query) { this._enclosing = _enclosing; }