From 1b5dd44446ae20c08269e98935c0585370b463a4 Mon Sep 17 00:00:00 2001 From: Jim Borden Date: Thu, 12 Jan 2017 14:16:52 +0900 Subject: [PATCH] Closes #797 --- .../Documents/DocumentChange.cs | 85 +++++++++++-------- 1 file changed, 49 insertions(+), 36 deletions(-) diff --git a/src/Couchbase.Lite.Shared/Documents/DocumentChange.cs b/src/Couchbase.Lite.Shared/Documents/DocumentChange.cs index c97ff1d21..cde1c294a 100644 --- a/src/Couchbase.Lite.Shared/Documents/DocumentChange.cs +++ b/src/Couchbase.Lite.Shared/Documents/DocumentChange.cs @@ -53,57 +53,28 @@ namespace Couchbase.Lite { /// public class DocumentChange { - internal RevisionInternal AddedRevision { get; private set; } - - // Used by plugins - internal DocumentChange(RevisionInternal addedRevision, RevisionID winningRevisionId, bool isConflict, Uri sourceUrl) - { - AddedRevision = addedRevision; - WinningRevisionId = winningRevisionId; - IsConflict = isConflict; - SourceUrl = sourceUrl; - } - #region Instance Members + #region Properties - //Properties /// /// Gets the Id of the that changed. /// - /// The Id of the that changed. - public string DocumentId { get { return AddedRevision.DocID; } } + public string DocumentId { get { return AddedRevision?.DocID; } } /// /// Gets the Id of the new Revision. /// - /// The Id of the new Revision. - public string RevisionId { get { return AddedRevision.RevID.ToString(); } } + public string RevisionId { get { return AddedRevision?.RevID?.ToString(); } } /// /// Gets a value indicating whether this instance is current revision. /// - /// true if this instance is current revision; otherwise, false. - public bool IsCurrentRevision { get { return WinningRevisionId != null && WinningRevisionId.Equals(AddedRevision.RevID.ToString()); } } - - internal RevisionID WinningRevisionId { get; private set; } - - /// - /// Gets the winning revision. - /// - /// The winning revision. - internal RevisionInternal WinningRevisionIfKnown - { - get - { - return IsCurrentRevision ? AddedRevision : null; + public bool IsCurrentRevision { + get { + return WinningRevisionId != null && WinningRevisionId.Equals(AddedRevision?.RevID?.ToString()); } } - internal void ReduceMemoryUsage() - { - AddedRevision = AddedRevision.CopyWithoutBody(); - } - /// /// Gets a value indicating whether this instance is conflict. /// @@ -115,12 +86,55 @@ internal void ReduceMemoryUsage() /// public bool IsExpiration { get; internal set; } + /// + /// Gets whether or not this change is a deletion + /// + public bool IsDeletion { + get { + return AddedRevision?.Deleted == true; + } + } + /// /// Gets the remote URL of the source Database from which this change was replicated. /// /// The remote URL of the source Database from which this change was replicated. public Uri SourceUrl { get; private set; } + internal RevisionInternal AddedRevision { get; private set; } + + internal RevisionID WinningRevisionId { get; } + + internal RevisionInternal WinningRevisionIfKnown { + get { + return IsCurrentRevision ? AddedRevision : null; + } + } + + #endregion + + #region Constructors + + // Used by plugins + internal DocumentChange(RevisionInternal addedRevision, RevisionID winningRevisionId, bool isConflict, Uri sourceUrl) + { + AddedRevision = addedRevision; + WinningRevisionId = winningRevisionId; + IsConflict = isConflict; + SourceUrl = sourceUrl; + } + + #endregion + + #region Internal Methods + + internal void ReduceMemoryUsage() + { + AddedRevision = AddedRevision.CopyWithoutBody(); + } + + + #endregion #region Overrides @@ -152,5 +166,4 @@ public override string ToString() #endregion } - }