Beispiel #1
0
        /// <summary>
        /// Checks whether or not a document with the given ID has any pending revisions to push
        /// </summary>
        /// <param name="documentID">The document ID</param>
        /// <returns>A bool which represents whether or not the document with the corresponding ID has one or more pending revisions.
        /// <c>true</c> means that one or more revisions have not been pushed to the remote yet,
        /// and <c>false</c> means that all revisions on the document have been pushed</returns>
        /// <exception cref="CouchbaseLiteException">Thrown if no push replication</exception>
        /// <exception cref="CouchbaseException">Thrown if an error condition is returned from LiteCore</exception>
        public bool IsDocumentPending([NotNull] string documentID)
        {
            CBDebug.MustNotBeNull(WriteLog.To.Sync, Tag, nameof(documentID), documentID);
            bool isDocPending = false;

            if (!IsPushing())
            {
                CBDebug.LogAndThrow(WriteLog.To.Sync,
                                    new CouchbaseLiteException(C4ErrorCode.Unsupported, CouchbaseLiteErrorMessage.PullOnlyPendingDocIDs),
                                    Tag, CouchbaseLiteErrorMessage.PullOnlyPendingDocIDs, true);
            }

            DispatchQueue.DispatchSync(() => {
                var errSetupRepl = SetupC4Replicator();
                if (errSetupRepl.code > 0)
                {
                    CBDebug.LogAndThrow(WriteLog.To.Sync, CouchbaseException.Create(errSetupRepl), Tag, errSetupRepl.ToString(), true);
                }
            });

            LiteCoreBridge.Check(err =>
            {
                isDocPending = Native.c4repl_isDocumentPending(_repl, documentID, err);
                return(isDocPending);
            });

            return(isDocPending);
        }
 protected void ValidateParams <T>(T[] param, [CallerMemberName] string tag = null)
 {
     if (param.Length == 0)
     {
         var message = String.Format(CouchbaseLiteErrorMessage.ExpressionsMustContainOnePlusElement, tag);
         CBDebug.LogAndThrow(WriteLog.To.Query, new InvalidOperationException(message), Tag, message, true);
     }
 }
Beispiel #3
0
        public IImmutableSet <string> GetPendingDocumentIDs()
        {
            var result = new HashSet <string>();

            if (!IsPushing())
            {
                CBDebug.LogAndThrow(WriteLog.To.Sync,
                                    new CouchbaseLiteException(C4ErrorCode.Unsupported, CouchbaseLiteErrorMessage.PullOnlyPendingDocIDs),
                                    Tag, CouchbaseLiteErrorMessage.PullOnlyPendingDocIDs, true);
            }

            DispatchQueue.DispatchSync(() => {
                var errSetupRepl = SetupC4Replicator();
                if (errSetupRepl.code > 0)
                {
                    CBDebug.LogAndThrow(WriteLog.To.Sync, CouchbaseException.Create(errSetupRepl), Tag, errSetupRepl.ToString(), true);
                }
            });

            byte[] pendingDocIds = LiteCoreBridge.Check(err =>
            {
                return(Native.c4repl_getPendingDocIDs(_repl, err));
            });

            if (pendingDocIds != null)
            {
                _databaseThreadSafety.DoLocked(() => {
                    var flval = Native.FLValue_FromData(pendingDocIds, FLTrust.Trusted);
                    var flarr = Native.FLValue_AsArray(flval);
                    var cnt   = (int)Native.FLArray_Count(flarr);
                    for (int i = 0; i < cnt; i++)
                    {
                        var flv = Native.FLArray_Get(flarr, (uint)i);
                        result.Add(Native.FLValue_AsString(flv));
                    }

                    Array.Clear(pendingDocIds, 0, pendingDocIds.Length);
                    pendingDocIds = null;
                });
            }

            _pendingDocIds = result.ToImmutableHashSet <string>();
            return(_pendingDocIds);
        }