Ejemplo n.º 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));
        }
Ejemplo n.º 2
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));
        }