예제 #1
0
        internal void NotifyChange(RevisionInternal rev, RevisionInternal winningRev, Uri source, bool inConflict)
        {
            var change = new DocumentChange(rev, winningRev.GetRevId(), inConflict, source);
            _changesToNotify.Add(change);

            if (!PostChangeNotifications())
            {
                // The notification wasn't posted yet, probably because a transaction is open.
                // But the Document, if any, needs to know right away so it can update its
                // currentRevision.
                var doc = DocumentCache.Get(change.DocumentId);
                if (doc != null) {
                    doc.RevisionAdded(change, false);
                }
            }
        }
예제 #2
0
        public void DatabaseStorageChanged(DocumentChange change)
        {
            Log.D(TAG, "Added: {0}", change.AddedRevision);
            if (_changesToNotify == null) {
                _changesToNotify = new List<DocumentChange>();
            }

            _changesToNotify.Add(change);
            if (!PostChangeNotifications()) {
                // The notification wasn't posted yet, probably because a transaction is open.
                // But the Document, if any, needs to know right away so it can update its
                // currentRevision.
                var doc = DocumentCache.Get(change.DocumentId);
                if (doc != null) {
                    doc.RevisionAdded(change, false);
                }
            }

            // Squish the change objects if too many of them are piling up
            if (_changesToNotify.Count >= NOTIFY_CHANGES_LIMIT) {
                if (_changesToNotify.Count == NOTIFY_CHANGES_LIMIT) {
                    foreach (var c in _changesToNotify) {
                        c.ReduceMemoryUsage();
                    }
                } else {
                    change.ReduceMemoryUsage();
                }
            }
        }
예제 #3
0
		public void NotifyChange(RevisionInternal rev, RevisionInternal winningRev, Uri source
			, bool inConflict)
		{
			DocumentChange change = new DocumentChange(rev, winningRev, inConflict, source);
			NotifyChange(change);
		}
예제 #4
0
        internal void NotifyChange(RevisionInternal rev, RevisionInternal winningRev, Uri source, bool inConflict)
        {
            var change = new DocumentChange(rev, winningRev, inConflict, source);
            _changesToNotify.Add(change);

            PostChangeNotifications();
        }
예제 #5
0
		private void NotifyChange(DocumentChange documentChange)
		{
			if (changesToNotify == null)
			{
				changesToNotify = new AList<DocumentChange>();
			}
			changesToNotify.AddItem(documentChange);
			PostChangeNotifications();
		}
예제 #6
0
		internal void RevisionAdded(DocumentChange documentChange)
		{
			RevisionInternal rev = documentChange.GetWinningRevision();
			if (rev == null)
			{
				return;
			}
			// current revision didn't change
			if (currentRevision != null && !rev.GetRevId().Equals(currentRevision.GetId()))
			{
				currentRevision = new SavedRevision(this, rev);
			}
			foreach (Document.ChangeListener listener in changeListeners)
			{
				listener.Changed(new Document.ChangeEvent(this, documentChange));
			}
		}
예제 #7
0
			public ChangeEvent(Document source, DocumentChange documentChange)
			{
				this.source = source;
				this.change = documentChange;
			}
예제 #8
0
        private void PurgeExpired(object state)
        {
            if (!_purgeActive) {
                _purgeActive = true;
                Log.To.Database.V(TAG, "{0} running purge job NOW...", this);
                if (Storage == null || !Storage.IsOpen) {
                    Log.To.Database.W(TAG, "{0} storage is null or closed, cannot run purge job, returning early...", this);
                    return;
                }

                var results = Storage?.PurgeExpired() ?? new List<string>();
                var changedEvt = _changed;
                if (results.Count > 0) {
                    Log.To.Database.I(TAG, "{0} purged {1} expired documents", this, results.Count);
                    if (changedEvt != null) {
                        var changes = new List<DocumentChange>();
                        var args = new DatabaseChangeEventArgs();
                        args.Source = this;
                        foreach (var result in results) {
                            var change = new DocumentChange(new RevisionInternal(result, null, true), null, false, null);
                            change.IsExpiration = true;
                            changes.Add(change);
                        }

                        args.Changes = changes;
                        changedEvt(this, args);
                    }
                }

                _purgeActive = false;
                SchedulePurgeExpired(TimeSpan.FromSeconds(1));
            } else {
                Log.To.Database.I(TAG, "Purge already running, will try again later...");
            }
        }
예제 #9
0
        internal void RevisionAdded(DocumentChange documentChange)
        {
            var rev = documentChange.WinningRevision;
            if (rev == null)
            {
                return;
            }
            // current revision didn't change
            if (currentRevision != null && !rev.GetRevId().Equals(currentRevision.Id))
            {
                currentRevision = new SavedRevision(this, rev);
            }

            var args = new DocumentChangeEventArgs {
                Change = documentChange,
                Source = this
            } ;

            var changeEvent = Change;
            if (changeEvent != null)
                changeEvent(this, args);
        }