private void OnContactChanged(CouchChangeResult aChangeResult)
        {
            //add to the list of changes
            Items.Add(aChangeResult);

            //record the sequence number of the change so when we run the application we
            //tell that we only need changes > this number.
            //(Otherwise you get a change message for every doc in the db at the startup)
            SetSequence(aChangeResult.Sequence);

            //verifiy type of change announced so we know if we need to refresh a contact
            if (aChangeResult.Id.StartsWith("_design"))
            {
                return;
            }

            if (aChangeResult.Deleted)
            {
                OnContactDeleted(aChangeResult.Id);
            }
            else
            {
                Console.WriteLine("Retrieving last version of {0}", aChangeResult.Id);
                //get the latest version of this document
                theDatabase.GetDocument(aChangeResult.Id, new Result <Contact>()).WhenDone(
                    a => BeginInvoke((MethodInvoker)(() => OnContactChanged(a))),
                    ErrorManagement.ProcessException
                    );
            }
        }
        private static void ChangesListBoxFormat(object sender, ListControlConvertEventArgs e)
        {
            CouchChangeResult change = e.ListItem as CouchChangeResult;

            if ((change != null) && (change.Changes.Length >= 1))
            {
                e.Value = String.Format("{0:0000}\t{1}\t{2}", change.Sequence, change.Id, change.Changes[0].ToString());
            }
        }
Exemple #3
0
        /// <summary>
        /// Determine whether the given sequence number
        /// matches the most up-to-date status.
        /// </summary>
        public bool LastSequenceNumberChanged(int since)
        {
            using (JtTimer pt = new JtTimer(
                       "LastSequenceNumberChanged"))
            {
                ChangeOptions opt = new ChangeOptions();

                opt.Since       = since;
                opt.IncludeDocs = false;

                CouchChanges <DbFurniture> changes
                    = _db.GetChanges <DbFurniture>(opt);

                CouchChangeResult <DbFurniture> r
                    = changes.Results.LastOrDefault <
                          CouchChangeResult <DbFurniture> >();

                Debug.Assert(null == r || since < r.Sequence,
                             "expected monotone growing sequence number");

                return(null != r && since < r.Sequence);
            }
        }