// Processes a change in the subscribed database
        private void DatabaseChanged(object sender, DatabaseChangeEventArgs args)
        {
            foreach (var change in args.Changes)
            {
                var rev        = change.AddedRevision;
                var winningRev = change.WinningRevision;

                if (!ChangesIncludeConflicts)
                {
                    if (winningRev == null)
                    {
                        continue; // this change doesn't affect the winning rev ID, no need to send it
                    }

                    if (rev.Equals(winningRev))
                    {
                        // This rev made a _different_ rev current, so substitute that one.
                        // We need to emit the current sequence # in the feed, so put it in the rev.
                        // This isn't correct internally (this is an old rev so it has an older sequence)
                        // but consumers of the _changes feed don't care about the internal state.
                        if (ChangesIncludeDocs)
                        {
                            _db.LoadRevisionBody(rev, DocumentContentOptions.None);
                        }
                    }
                }

                if (!_db.RunFilter(ChangesFilter, null, rev))
                {
                    continue;
                }

                if (ChangesFeedMode == ChangesFeedMode.LongPoll)
                {
                    _changes.Add(rev);
                }
                else
                {
                    Log.D(TAG, "Sending continuous change chunk");
                    var written = Response.SendContinuousLine(DatabaseMethods.ChangesDictForRev(rev, this), ChangesFeedMode);
                    if (!written)
                    {
                        Terminate();
                    }
                }
            }

            if (ChangesFeedMode == ChangesFeedMode.LongPoll && _changes.Count > 0)
            {
                var body = new Body(DatabaseMethods.ResponseBodyForChanges(_changes, 0, this));
                Response.WriteData(body.AsJson(), true);
                CouchbaseLiteRouter.ResponseFinished(this);
            }
        }
示例#2
0
        // This method is called when an observed replication changes
        private void ReplicationChanged(object sender, ReplicationChangeEventArgs e)
        {
            var replication = (Replication)sender;

            if (replication.LocalDatabase.Manager == DbManager)
            {
                if (!Response.SendContinuousLine(replication.ActiveTaskInfo, ChangesFeedMode))
                {
                    replication.Changed -= ReplicationChanged;
                    CouchbaseLiteRouter.ResponseFinished(this);
                }
            }
        }
        // Tear down this object because an error occurred
        private void Terminate()
        {
            var db = Interlocked.Exchange(ref _db, null);

            if (db == null)
            {
                return;
            }

            Log.To.Router.I(TAG, "Shutting down DBMonitorCouchbaseState");
            db.Changed -= DatabaseChanged;
            CouchbaseLiteRouter.ResponseFinished(this);
            _heartbeatTimer?.Dispose();
            _heartbeatTimer = null;
        }
        // Tear down this object because an error occurred
        private void Terminate()
        {
            if (_db == null)
            {
                return;
            }

            _db.Changed -= DatabaseChanged;
            CouchbaseLiteRouter.ResponseFinished(this);
            _db = null;

            if (_heartbeatTimer != null)
            {
                _heartbeatTimer.Dispose();
                _heartbeatTimer = null;
            }
        }
示例#5
0
        // Tear down this object because an error occurred
        private void Terminate()
        {
            if (Db == null)
            {
                return;
            }

            Log.To.Router.I(TAG, "Shutting down DBMonitorCouchbaseState");
            Db.Changed -= DatabaseChanged;
            CouchbaseLiteRouter.ResponseFinished(this);
            Db = null;

            if (_heartbeatTimer != null)
            {
                _heartbeatTimer.Dispose();
                _heartbeatTimer = null;
            }
        }