Пример #1
0
        /// <summary>
        /// Applies a document addition to the document tree. Returns the corresponding DocumentChange event.
        /// </summary>
        private DocumentChange AddDocument(DocumentSnapshot newDocument)
        {
            _documentSet = _documentSet.WithDocumentAdded(newDocument);
            int newIndex = _documentSet.IndexOf(newDocument.Reference);

            return(new DocumentChange(newDocument, DocumentChange.Type.Added, null, newIndex));
        }
Пример #2
0
        /// <summary>
        /// Applies a document delete to the document tree. Returns the corresponding DocumentChange event.
        /// </summary>
        private DocumentChange DeleteDocument(DocumentSnapshot oldDocument)
        {
            int oldIndex = _documentSet.IndexOf(oldDocument.Reference);

            _documentSet = _documentSet.WithDocumentRemoved(oldDocument.Reference);
            return(new DocumentChange(oldDocument, DocumentChange.Type.Removed, oldIndex, null));
        }
Пример #3
0
 internal WatchState(Query query, Func <QuerySnapshot, CancellationToken, Task> callback)
 {
     _query       = query;
     _callback    = callback;
     _comparer    = query.CreateDocumentSnapshotComparer();
     _documentSet = DocumentSet.Empty(_comparer);
     _changeMap   = new Dictionary <DocumentReference, Document>();
 }
Пример #4
0
        internal DocumentSet WithDocumentAdded(DocumentSnapshot document)
        {
            // Remove any prior mapping of the document's key before adding, preventing sortedSet from
            // accumulating values that aren't in the index.
            DocumentSet removed = WithDocumentRemoved(document.Reference);

            var newKeyIndex  = removed._keyIndex.Add(document.Reference, document);
            var newSortedSet = removed._sortedSet.Add(document);

            return(new DocumentSet(newKeyIndex, newSortedSet));
        }
Пример #5
0
        /// <summary>
        /// Applies a document modification to the document tree. Returns the DocumentChange event for
        /// successful modifications, or null if the old and new documents have the same update timestamp.
        /// </summary>
        private DocumentChange ModifyDocument(DocumentSnapshot newDocument)
        {
            var docRef = newDocument.Reference;

            if (!_documentSet.TryGetDocument(docRef, out var oldDocument))
            {
                // TODO: Is this appropriate? Java throws an NPE here...
                throw new InvalidOperationException("Attempt to create a document modification, but document wasn't in set.");
            }
            if (oldDocument.UpdateTime == newDocument.UpdateTime)
            {
                return(null);
            }
            int oldIndex = _documentSet.IndexOf(docRef);

            _documentSet = _documentSet.WithDocumentRemoved(docRef);
            _documentSet = _documentSet.WithDocumentAdded(newDocument);
            int newIndex = _documentSet.IndexOf(docRef);

            return(new DocumentChange(newDocument, DocumentChange.Type.Modified, oldIndex, newIndex));
        }
 internal static QuerySnapshot ForChanges(Query query, DocumentSet documentSet, IReadOnlyList <DocumentChange> changes, Timestamp readTime) =>
 new QuerySnapshot(query, () => documentSet.ToList().AsReadOnly(), () => changes, readTime);