Ejemplo n.º 1
0
        public void ChangeTrackerReceivedChange(IDictionary <string, object> change)
        {
            var lastSequence = change.Get("seq").ToString();
            var docID        = (string)change.Get("id");

            if (docID == null)
            {
                return;
            }

            if (!LocalDatabase.IsValidDocumentId(docID))
            {
                if (!docID.StartsWith("_user/", StringComparison.InvariantCultureIgnoreCase))
                {
                    Log.W(TAG, string.Format("{0}: Received invalid doc ID from _changes: {1} ({2})", this, docID, Manager.GetObjectMapper().WriteValueAsString(change)));
                }

                return;
            }

            var deleted = change.GetCast <bool>("deleted");
            var changes = change.Get("changes").AsList <object>();

            SafeAddToChangesCount(changes.Count);

            foreach (var changeObj in changes)
            {
                var changeDict = changeObj.AsDictionary <string, object>();
                var revID      = changeDict.GetCast <string>("rev");
                if (revID == null)
                {
                    continue;
                }

                var rev = new PulledRevision(docID, revID, deleted, LocalDatabase);
                rev.SetRemoteSequenceID(lastSequence);
                if (changes.Count > 1)
                {
                    rev.IsConflicted = true;
                }

                Log.D(TAG, "Adding rev to inbox " + rev);
                AddToInbox(rev);
            }

            PauseOrResume();

            while (_revsToPull != null && _revsToPull.Count > 1000)
            {
                try {
                    // Presumably we are letting 1 or more other threads do something while we wait.
                    Thread.Sleep(500);
                }
                catch (Exception e) {
                    Log.W(TAG, "Swalling exception while sleeping after receiving changetracker changes.", e);
                    // swallow
                }
            }
        }
Ejemplo n.º 2
0
        // Got a _changes feed entry from the ChangeTracker.
        public void ChangeTrackerReceivedChange(IDictionary <string, object> change)
        {
            var lastSequence = change.Get("seq").ToString();
            var docID        = (string)change.Get("id");

            if (docID == null)
            {
                return;
            }

            if (!LocalDatabase.IsValidDocumentId(docID))
            {
                if (!docID.StartsWith("_user/", StringComparison.InvariantCultureIgnoreCase))
                {
                    Log.W(Tag, string.Format("{0}: Received invalid doc ID from _changes: {1} ({2})", this, docID, JsonConvert.SerializeObject(change)));
                }
                return;
            }

            var deleted = (change.ContainsKey("deleted") && ((bool)change.Get("deleted")).Equals(true));

            var changesContainer = change.Get("changes") as JContainer;
            var changes          = changesContainer.ToArray();

            foreach (var changeObj in changes)
            {
                var changeDict = changeObj.ToObject <IDictionary <string, object> >();
                var revID      = (string)changeDict.Get("rev");
                if (revID == null)
                {
                    continue;
                }

                var rev = new PulledRevision(docID, revID, deleted, LocalDatabase);
                rev.SetRemoteSequenceID(lastSequence);

                Log.D(Tag, "adding rev to inbox " + rev);
                Log.V(Tag, "ChangeTrackerReceivedChange() incrementing changesCount by 1");

                SafeAddToChangesCount(changes.Length);

                AddToInbox(rev);
            }

            while (revsToPull != null && revsToPull.Count > 1000)
            {
                try
                {
                    // Presumably we are letting 1 or more other threads do something while we wait.
                    Thread.Sleep(500);
                }
                catch (Exception e)
                {
                    Log.W(Tag, "Swalling exception while sleeping after receiving changetracker changes.", e);
                    // swallow
                }
            }
        }
Ejemplo n.º 3
0
        // Got a _changes feed entry from the ChangeTracker.
        public void ChangeTrackerReceivedChange(IDictionary <string, object> change)
        {
            var lastSequence = change.Get("seq").ToString();
            var docID        = (string)change.Get("id");

            if (docID == null)
            {
                return;
            }

            if (!LocalDatabase.IsValidDocumentId(docID))
            {
                Log.W(Tag, string.Format("{0}: Received invalid doc ID from _changes: {1}", this, change));
                return;
            }

            var deleted = (change.ContainsKey("deleted") && ((bool)change.Get("deleted")).Equals(true));

            var changesContainer = change.Get("changes") as JContainer;
            var changes          = changesContainer.ToArray();

            foreach (var changeObj in changes)
            {
                var changeDict = changeObj.ToObject <IDictionary <string, object> >();
                var revID      = (string)changeDict.Get("rev");
                if (revID == null)
                {
                    continue;
                }
                var rev = new PulledRevision(docID, revID, deleted, LocalDatabase);
                rev.SetRemoteSequenceID(lastSequence);
                Log.D(Tag, this + ": adding rev to inbox " + rev);
                AddToInbox(rev);
            }
            ChangesCount = ChangesCount + changes.Length;
            while (revsToPull != null && revsToPull.Count > 1000)
            {
                try
                {
                    Sharpen.Thread.Sleep(500);
                }
                catch (Exception)
                {
                    // swallow
                }
            }
        }
Ejemplo n.º 4
0
        public void ChangeTrackerReceivedChange(IDictionary <string, object> change)
        {
            string lastSequence = change.Get("seq").ToString();
            string docID        = (string)change.Get("id");

            if (docID == null)
            {
                return;
            }
            if (!Database.IsValidDocumentId(docID))
            {
                Log.W(Log.TagSync, "%s: Received invalid doc ID from _changes: %s", this, change);
                return;
            }
            bool deleted = (change.ContainsKey("deleted") && ((bool)change.Get("deleted")).Equals
                                (true));
            IList <IDictionary <string, object> > changes = (IList <IDictionary <string, object> >)
                                                            change.Get("changes");

            foreach (IDictionary <string, object> changeDict in changes)
            {
                string revID = (string)changeDict.Get("rev");
                if (revID == null)
                {
                    continue;
                }
                PulledRevision rev = new PulledRevision(docID, revID, deleted, db);
                rev.SetRemoteSequenceID(lastSequence);
                Log.D(Log.TagSync, "%s: adding rev to inbox %s", this, rev);
                Log.V(Log.TagSync, "%s: changeTrackerReceivedChange() incrementing changesCount by 1"
                      , this);
                // this is purposefully done slightly different than the ios version
                AddToChangesCount(1);
                AddToInbox(rev);
            }
            while (revsToPull != null && revsToPull.Count > 1000)
            {
                try
                {
                    Sharpen.Thread.Sleep(500);
                }
                catch (Exception)
                {
                }
            }
        }
Ejemplo n.º 5
0
        public void ChangeTrackerReceivedChange(IDictionary <string, object> change)
        {
            string lastSequence = change.Get("seq").ToString();
            string docID        = (string)change.Get("id");

            if (docID == null)
            {
                return;
            }
            if (!Database.IsValidDocumentId(docID))
            {
                Log.W(Database.Tag, string.Format("%s: Received invalid doc ID from _changes: %s"
                                                  , this, change));
                return;
            }
            bool deleted = (change.ContainsKey("deleted") && ((bool)change.Get("deleted")).Equals
                                (true));
            IList <IDictionary <string, object> > changes = (IList <IDictionary <string, object> >)
                                                            change.Get("changes");

            foreach (IDictionary <string, object> changeDict in changes)
            {
                string revID = (string)changeDict.Get("rev");
                if (revID == null)
                {
                    continue;
                }
                PulledRevision rev = new PulledRevision(docID, revID, deleted, db);
                rev.SetRemoteSequenceID(lastSequence);
                Log.D(Database.Tag, this + ": adding rev to inbox " + rev);
                AddToInbox(rev);
            }
            SetChangesCount(GetChangesCount() + changes.Count);
            while (revsToPull != null && revsToPull.Count > 1000)
            {
                try
                {
                    Sharpen.Thread.Sleep(500);
                }
                catch (Exception)
                {
                }
            }
        }
Ejemplo n.º 6
0
        public void ChangeTrackerReceivedChange(IDictionary <string, object> change)
        {
            if (ServerType == null)
            {
                ServerType = _remoteSession.ServerType;
            }

            var lastSequence = change.Get("seq").ToString();
            var docID        = (string)change.Get("id");

            if (docID == null)
            {
                Log.To.Sync.W(TAG, "{0} Change received with no id, ignoring...", this);
                return;
            }

            var removed = change.Get("removed") != null;

            if (removed)
            {
                Log.To.Sync.V(TAG, "Removed entry received, body may not be available");
            }

            if (!Document.IsValidDocumentId(docID))
            {
                if (!docID.StartsWith("_user/", StringComparison.InvariantCultureIgnoreCase))
                {
                    Log.To.Sync.W(TAG, "{0}: Received invalid doc ID from _changes: {1} ({2})",
                                  this, new SecureLogString(docID, LogMessageSensitivity.PotentiallyInsecure), new LogJsonString(change));
                }

                return;
            }

            var deleted = change.GetCast <bool>("deleted");
            var changes = change.Get("changes").AsList <object>();

            SafeAddToChangesCount(changes.Count);

            foreach (var changeObj in changes)
            {
                var changeDict = changeObj.AsDictionary <string, object>();
                var revID      = changeDict.GetCast <string>("rev").AsRevID();
                if (revID == null)
                {
                    Log.To.Sync.W(TAG, "{0} missing revID for entry, skipping...");
                    SafeIncrementCompletedChangesCount();
                    continue;
                }

                var rev = new PulledRevision(docID, revID, deleted, LocalDatabase);
                rev.SetRemoteSequenceID(lastSequence);
                if (changes.Count > 1)
                {
                    rev.IsConflicted = true;
                }

                Log.To.Sync.D(TAG, "Adding rev to inbox " + rev);
                if (!AddToInbox(rev))
                {
                    Log.To.Sync.W(TAG, "{0} Failed to add {1} to inbox, probably already added.  Marking completed", this, rev);
                    SafeIncrementCompletedChangesCount();
                }
            }

            PauseOrResume();

            while (_revsToPull != null && _revsToPull.Count > 1000)
            {
                try {
                    // Presumably we are letting 1 or more other threads do something while we wait.
                    Thread.Sleep(500);
                }
                catch (Exception e) {
                    Log.To.Sync.W(TAG, "Swallowing exception while sleeping after receiving changetracker changes.", e);
                    // swallow
                }
            }
        }