/// <summary>
 /// Adds a <see cref="Bookmark"/> instance to the collection.
 /// </summary>
 public int Add(Bookmark item)
 {
     return base.Add(item);
 }
 /// <summary>
 /// Adds a range of <see cref="Bookmark"/> instances to the collection.
 /// </summary>
 public void AddRange(Bookmark[] items)
 {
     base.AddRange(items);
 }
        private void ReceiveServerItemsForPushChanges(IAsyncResult result)
        {
            try
            {
                if (PushChangesState == null)
                    throw new InvalidOperationException("'PushChangesState' is null.");

                // unwrap the server response...
                var response = new List<AMX.Bookmark>(this.PushChangesState.Query.EndExecute(result));

                // we can only enumerate the server repsonse once - so we'll store it in a separate list 
                // so that we can loop it several times...
                List<AMX.Bookmark> serverItems = new List<AMX.Bookmark>();
                foreach (AMX.Bookmark serverItem in response)
                    serverItems.Add(serverItem);

                // get the local changes...
                List<Bookmark> updates = Bookmark.GetBookmarksForServerUpdate();
                List<Bookmark> deletes = Bookmark.GetBookmarksForServerDelete();

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

                // we do have changes, so get the latest from the server...
                foreach (Bookmark localItem in updates)
                {
                    // find it in our set...
                    Bookmark toUpdateLocal = null;
                    AMX.Bookmark toUpdateServer = null;
                    foreach (AMX.Bookmark serverItem in serverItems)
                    {
                        if (localItem.Ordinal == serverItem.Ordinal)
                        {
                            toUpdateLocal = localItem;
                            toUpdateServer = serverItem;
                            break;
                        }
                    }

                    // did we have one to change?
                    if (toUpdateLocal != null)
                    {
                        if (toUpdateServer == null)
                            throw new InvalidOperationException("'toUpdateServer' is null.");

                        // patch the values...
                        toUpdateServer.Name = toUpdateLocal.Name;
                        toUpdateServer.Url = toUpdateLocal.Url;

                        // update...
                        this.PushChangesState.ServerTarget.UpdateObject(toUpdateServer);
                    }
                    else
                    {
                        // create a new item for the server...
                        AMX.Bookmark newItem = new AMX.Bookmark();
                        newItem.Ordinal = localItem.Ordinal;
                        newItem.Name = localItem.Name;
                        newItem.Url = localItem.Url;

                        // add...
                        this.PushChangesState.ServerTarget.AddObject(et.NativeName, newItem);
                    }
                }

                // what about ones to delete?
                foreach (Bookmark local in deletes)
                {
                    // find a matching ordinal on the server...
                    foreach (AMX.Bookmark serverItem in serverItems)
                    {
                        if (local.Ordinal == serverItem.Ordinal)
                            this.PushChangesState.ServerTarget.DeleteObject(serverItem);
                    }
                }

                // call up and save changes...
                this.PushChangesState.ServerTarget.BeginSaveChanges((AsyncCallback)delegate(IAsyncResult saveResult)
                {
                    try
                    {
                        // unwrap...
                        this.PushChangesState.ServerTarget.EndSaveChanges(saveResult);

                        // great - we've saved changes, now get latest...
                        this.GetLatest();
                    }
                    catch (Exception ex)
                    {
                        this.Failed(ex);
                    }

                }, null);
            }
            catch (Exception ex)
            {
                this.Failed(ex);
            }
        }