/// <summary> /// Merges the attachments from another revision. /// </summary> /// <param name="revision">The revision.</param> /// <param name="sourceRevision">The revision with the attachments to be merged.</param> /// <param name="keepMine">Controls what happens when the source and target have the same attachment (see remarks).</param> /// <remarks> /// <para> /// The <paramref name="keepMine"/> parameter determines what happens when the source and target /// revisions has an attachment with the same name. When <paramref name="keepMine"/>=<c>true</c> /// (the default), then matching attachments from the source revision will be ignored. /// </para> /// <para> /// When <paramref name="keepMine"/>=<c>false</c>, matching attachments from the source /// revision will be copied to the current revision, overwriting the existion attachment. /// </para> /// </remarks> public static void MergeAttachmentsFrom(this UnsavedRevision revision, Revision sourceRevision, bool keepMine = true) { Covenant.Requires <ArgumentNullException>(revision != null); Covenant.Requires <ArgumentNullException>(sourceRevision != null); // Merge the source attachments. foreach (var sourceAttachment in sourceRevision.Attachments) { var existingAttachment = revision.GetAttachment(sourceAttachment.Name); if (existingAttachment != null && keepMine) { continue; } // $todo(jeff.lill): // // I'm a little nervous about this call. [Attachment.Content] is going to // load the attachment into memory, which could be a significant overhead. // It's possible to pass a stream, but looking at the Couchbase Lite source, // it appears that the new attachment would try to take ownership of the // source attachment's stream (if I passed it), probably ending badly. revision.SetAttachment(sourceAttachment.Name, sourceAttachment.ContentType, sourceAttachment.Content); } }