Exemple #1
0
        /// <summary>
        /// Adds an existing revision copied from another database.  Unlike a normal insertion, this does
        /// not assign a new revision ID; instead the revision's ID must be given.  Ths revision's history
        /// (ancestry) must be given, which can put it anywhere in the revision tree.  It's not an error if
        /// the revision already exists locally; it will just be ignored.
        ///
        /// This is not an operation that clients normall perform; it's used by the replicator.  You might want
        /// to use it if you're pre-loading a database with canned content, or if you're implementing some new
        /// kind of replicator that transfers revisions from another database
        /// </summary>
        /// <param name="properties">The properties of the revision (_id and _rev will be ignored but _deleted
        /// and _attachments are recognized)</param>
        /// <param name="attachments">A dictionary providing attachment bodies.  The keys are the attachment
        /// names (matching the keys in the properties `_attachments` dictionary) and the values are streams
        /// that contain the attachment bodies.</param>
        /// <param name="revisionHistory">The revision history in the form of an array of revision-ID strings, in
        /// reverse chronological order.  The first item must be the new revision's ID.  Following items are its
        /// parent's ID, etc.</param>
        /// <param name="sourceUri">The URL of the database this revision came from, if any.  (This value
        /// shows up in the Database Changed event triggered by this insertion, and can help clients decide
        /// whether the change is local or not)</param>
        /// <returns><c>true</c> on success, false otherwise</returns>
        public bool PutExistingRevision(IDictionary <string, object> properties, IDictionary <string, Stream> attachments, IList <string> revisionHistory, Uri sourceUri)
        {
            if (revisionHistory == null || revisionHistory.Count == 0)
            {
                Log.To.Database.E(Tag, "Invalid revision history in PutExistingRevision (must contain at " +
                                  "least one revision ID), throwing...");
                throw new ArgumentException("revisionHistory");
            }

            var revIDs = revisionHistory.AsRevIDs().ToList();
            var rev    = new RevisionInternal(Id, revIDs[0], properties.CblDeleted());

            rev.SetProperties(PropertiesToInsert(properties));
            if (!Database.RegisterAttachmentBodies(attachments, rev))
            {
                Log.To.Database.W(Tag, "Failed to register attachment bodies, aborting insert...");
                return(false);
            }

            Database.ForceInsert(rev, revIDs, sourceUri);
            return(true);
        }