private void GetLatest()
        {
            Debug.WriteLine("Getting latest...");

            BookmarksService service = new BookmarksService();

            service.GetAll((Action <List <Bookmark> >) delegate(List <Bookmark> bookmarks)
            {
                // delete first...
                Bookmark.DeleteAll();

                // go through and save them...
                foreach (Bookmark fromServer in bookmarks)
                {
                    // we need to clone it as the ones that come from the server will have an id set.  we
                    // need to junk this id...
                    Bookmark newBookmark = new Bookmark();
                    newBookmark.Ordinal  = fromServer.Ordinal;
                    newBookmark.Name     = fromServer.Name;
                    newBookmark.Url      = fromServer.Url;

                    // set the local only stuff...
                    newBookmark.IsLocalModified = false;
                    newBookmark.IsLocalDeleted  = false;

                    // save...
                    newBookmark.SaveChanges();
                }

                // signal that we've finished...
                this.Callback();
            }, this.Failed);
        }
        private void PushChanges()
        {
            // need to get all from the server - we need to calculate a delta...
            BookmarksService service = new BookmarksService();

            service.GetAll <Bookmark>((Action <List <Bookmark> >) delegate(List <Bookmark> fromServer)
            {
                // get the local set...
                List <Bookmark> updates = Bookmark.GetBookmarksForServerUpdate();
                List <Bookmark> deletes = Bookmark.GetBookmarksForServerDelete();

                // et...
                EntityType et = EntityType.GetEntityType(typeof(Bookmark));
                if (et == null)
                {
                    throw new InvalidOperationException("'et' is null.");
                }

                // reset the work items...
                this.WorkItems = new List <SyncWorkItem>();

                // we do have changes, so get the latest from the server...
                foreach (Bookmark local in updates)
                {
                    // find it in our set...
                    Bookmark toUpdate = null;
                    foreach (Bookmark server in fromServer)
                    {
                        if (local.Ordinal == server.Ordinal)
                        {
                            toUpdate = server;
                            break;
                        }
                    }

                    // did we have one to change?
                    if (toUpdate != null)
                    {
                        // walk the fields...
                        int serverId = 0;
                        foreach (EntityField field in et.Fields)
                        {
                            if (!(field.IsKey))
                            {
                                toUpdate.SetValue(field, local.GetValue(field), SetReason.UserSet);
                            }
                            else
                            {
                                serverId = toUpdate.BookmarkId;
                            }
                        }

                        // send that up...
                        this.WorkItems.Add(new SyncWorkItem(ODataOperation.Update, toUpdate, serverId));
                    }
                    else
                    {
                        // we need to insert it...
                        this.WorkItems.Add(new SyncWorkItem(ODataOperation.Insert, local, 0));
                    }
                }

                // what about ones to delete?
                foreach (Bookmark local in deletes)
                {
                    // find a matching ordinal on the server...
                    foreach (Bookmark server in fromServer)
                    {
                        if (local.Ordinal == server.Ordinal)
                        {
                            this.WorkItems.Add(new SyncWorkItem(ODataOperation.Delete, server, server.BookmarkId));
                        }
                    }
                }

                // reset the queue and run it...
                this.WorkItemIndex = 0;
                this.PushNextWorkItem();
            }, this.Failed);
        }
        private void PushChanges()
        {
            // need to get all from the server - we need to calculate a delta...
            BookmarksService service = new BookmarksService();
            service.GetAll<Bookmark>((Action<List<Bookmark>>)delegate(List<Bookmark> fromServer)
            {
                // get the local set...
                List<Bookmark> updates = Bookmark.GetBookmarksForServerUpdate();
                List<Bookmark> deletes = Bookmark.GetBookmarksForServerDelete();

                // et...
                EntityType et = EntityType.GetEntityType(typeof(Bookmark));
                if (et == null)
                    throw new InvalidOperationException("'et' is null.");

                // reset the work items...
                this.WorkItems = new List<SyncWorkItem>();

                // we do have changes, so get the latest from the server...
                foreach (Bookmark local in updates)
                {
                    // find it in our set...
                    Bookmark toUpdate = null;
                    foreach (Bookmark server in fromServer)
                    {
                        if (local.Ordinal == server.Ordinal)
                        {
                            toUpdate = server;
                            break;
                        }
                    }

                    // did we have one to change?
                    if (toUpdate != null)
                    {
                        // walk the fields...
                        int serverId = 0;
                        foreach (EntityField field in et.Fields)
                        {
                            if (!(field.IsKey))
                                toUpdate.SetValue(field, local.GetValue(field), SetReason.UserSet);
                            else
                                serverId = toUpdate.BookmarkId;
                        }

                        // send that up...
                        this.WorkItems.Add(new SyncWorkItem(ODataOperation.Update, toUpdate, serverId));
                    }
                    else
                    {
                        // we need to insert it...
                        this.WorkItems.Add(new SyncWorkItem(ODataOperation.Insert, local, 0));
                    }
                }

                // what about ones to delete?
                foreach (Bookmark local in deletes)
                {
                    // find a matching ordinal on the server...
                    foreach (Bookmark server in fromServer)
                    {
                        if (local.Ordinal == server.Ordinal)
                            this.WorkItems.Add(new SyncWorkItem(ODataOperation.Delete, server, server.BookmarkId));
                    }
                }

                // reset the queue and run it...
                this.WorkItemIndex = 0;
                this.PushNextWorkItem();

            }, this.Failed);
        }
        //private void Doo()
        //{
        //    // need to get all from the server - we need to calculate a delta...
        //    BookmarksService service = new BookmarksService();
        //    service.GetAll((Action<List<Bookmark>>)delegate(List<Bookmark> fromServer)
        //    {
        //        // get the local set...
        //        List<Bookmark> updates = Bookmark.GetBookmarksForServerUpdate();
        //        List<Bookmark> deletes = Bookmark.GetBookmarksForServerDelete();

        //        // et...
        //        EntityType et = EntityType.GetEntityType(typeof(Bookmark));
        //        if (et == null)
        //            throw new InvalidOperationException("'et' is null.");

        //        // reset the work items...
        //        this.WorkItems = new List<SyncWorkItem>();

        //        // we do have changes, so get the latest from the server...
        //        foreach (Bookmark local in updates)
        //        {
        //            // find it in our set...
        //            Bookmark toUpdate = null;
        //            foreach (Bookmark server in fromServer)
        //            {
        //                if (local.Ordinal == server.Ordinal)
        //                {
        //                    toUpdate = server;
        //                    break;
        //                }
        //            }

        //            // did we have one to change?
        //            if (toUpdate != null)
        //            {
        //                // walk the fields...
        //                int serverId = 0;
        //                foreach (EntityField field in et.Fields)
        //                {
        //                    if (!(field.IsKey))
        //                        toUpdate.SetValue(field, local.GetValue(field), SetReason.UserSet);
        //                    else
        //                        serverId = toUpdate.BookmarkId;
        //                }

        //                // send that up...
        //                this.WorkItems.Add(new SyncWorkItem(ODataOperation.Update, toUpdate, serverId));
        //            }
        //            else
        //            {
        //                // we need to insert it...
        //                this.WorkItems.Add(new SyncWorkItem(ODataOperation.Insert, local, 0));
        //            }
        //        }

        //        // what about ones to delete?
        //        foreach (Bookmark local in deletes)
        //        {
        //            // find a matching ordinal on the server...
        //            foreach (Bookmark server in fromServer)
        //            {
        //                if (local.Ordinal == server.Ordinal)
        //                    this.WorkItems.Add(new SyncWorkItem(ODataOperation.Delete, server, server.BookmarkId));
        //            }
        //        }

        //        // reset the queue and run it...
        //        this.WorkItemIndex = 0;
        //        this.PushNextWorkItem();

        //    }, this.Failed);
        //}

        private void GetLatest()
        {
            BookmarksService service = new BookmarksService();
            service.GetAll((Action<List<Bookmark>>)delegate(List<Bookmark> bookmarks)
            {
                // delete first...
                Bookmark.DeleteAll();

                // go through and save them...
                foreach (Bookmark bookmark in bookmarks)
                    bookmark.SaveChanges();

                // signal that we've finished...
                this.Callback();

            }, this.Failed);
        }
        private void GetLatest()
        {
            Debug.WriteLine("Getting latest...");

            BookmarksService service = new BookmarksService();
            service.GetAll((Action<List<Bookmark>>)delegate(List<Bookmark> bookmarks)
            {
                // delete first...
                Bookmark.DeleteAll();

                // go through and save them...
                foreach (Bookmark fromServer in bookmarks)
                {
                    // we need to clone it as the ones that come from the server will have an id set.  we
                    // need to junk this id...
                    Bookmark newBookmark = new Bookmark();
                    newBookmark.Ordinal = fromServer.Ordinal;
                    newBookmark.Name = fromServer.Name;
                    newBookmark.Url = fromServer.Url;

                    // set the local only stuff...
                    newBookmark.IsLocalModified = false;
                    newBookmark.IsLocalDeleted = false;

                    // save...
                    newBookmark.SaveChanges();
                }

                // signal that we've finished...
                this.Callback();

            }, this.Failed);
        }