Beispiel #1
0
        public object LoadChangeData(LoadChangeContext loadChangeContext)
        {
            object       retVal = null;
            ItemMetadata item   = _metaData.FindItemMetadataById(loadChangeContext.ItemChange.ItemId);

            if (item != null)
            {
                //return a copy of the data.
                retVal = ConvertToTransferData(GetDataItem(item));
            }

            return(retVal);
        }
Beispiel #2
0
        //Update the metadata store with changes that have occured on the data store since the last time it was updated.
        public void UpdateMetadataStoreWithLocalChanges()
        {
            SyncVersion newVersion = new SyncVersion(0, _metadata.GetNextTickCount());

            _metadata.DeleteDetector.MarkAllItemsUnreported();
            foreach (Guid id in _store.Ids)
            {
                ItemData     data = _store.Get(id);
                ItemMetadata item = null;

                //Look up an item's metadata by its ID...
                item = _metadata.FindItemMetadataById(new SyncId(id));
                if (null == item)
                {
                    //New item, must have been created since that last time the metadata was updated.
                    //Create the item metadata required for sync (giving it a SyncID and a version, defined to be a DWORD and a ULONGLONG
                    //For creates, simply provide the relative replica ID (0) and the tick count for the provider (ever increasing)
                    item = _metadata.CreateItemMetadata(new SyncId(id), newVersion);
                    item.ChangeVersion = newVersion;
                    SaveItemMetadata(item, data.TimeStamp);
                    _syncItemCount++;
                }
                else
                {
                    if (data.TimeStamp > item.GetUInt64Field(TIMESTAMP_COLUMNNAME)) // the item has changed since the last sync operation.
                    {
                        //Changed Item, this item has changed since the last time the metadata was updated.
                        //Assign a new version by simply stating "who" modified this item (0 = local/me) and "when" (tick count for the store)
                        item.ChangeVersion = newVersion;
                        SaveItemMetadata(item, data.TimeStamp);
                        _syncItemCount++;
                    }
                    else
                    {
                        //Unchanged item, nothing has changes so just mark it as live so that the metadata knows it has not been deleted.
                        _metadata.DeleteDetector.ReportLiveItemById(new SyncId(id));
                    }
                }
            }

            //Now go back through the items that are no longer in the store and mark them as deleted in the metadata.
            //This sets the item as a tombstone.
            foreach (ItemMetadata item in _metadata.DeleteDetector.FindUnreportedItems())
            {
                item.MarkAsDeleted(newVersion);
                SaveItemMetadata(item, 0); // set timestamp to 0 for tombstones
            }
        }
        public SyncedNodeAttributes FindItemMetadataBySyncId(SyncId syncId)
        {
            var item = _metadata.FindItemMetadataById(syncId);

            return(GetItemInfo(item));
        }
        //Update the metadata store with changes that have occured on the data store since the last time it was updated.
        public void UpdateMetadataStoreWithLocalChanges()
        {
            SyncVersion newVersion = new SyncVersion(0, _metadata.GetNextTickCount());

            _metadata.DeleteDetector.MarkAllItemsUnreported();

            var entities = _syncContext.GetSyncObjects(CompanyId, StoreId);

            foreach (ISyncDataObject entity in entities)
            {
                try
                {
                    ISyncDataObject data = entity;
                    ItemMetadata    item = null;

                    //Look up an item's metadata by its ID...
                    item = _metadata.FindItemMetadataById(new SyncId(entity.SyncItemId));
                    if (null == item)
                    {
                        //New item, must have been created since that last time the metadata was updated.
                        //Create the item metadata required for sync (giving it a SyncID and a version, defined to be a DWORD and a ULONGLONG
                        //For creates, simply provide the relative replica ID (0) and the tick count for the provider (ever increasing)
                        item = _metadata.CreateItemMetadata(new SyncId(entity.SyncItemId), newVersion);
                        item.ChangeVersion = newVersion;
                        SaveItemMetadata(item, BitConverter.ToUInt64(data.SyncItemVersion, 0));
                        //var package = data as SyncDataPackage;
                        //if (package != null)
                        //{
                        //    item.SetCustomField(PACKAGECOUNT, (UInt32)package.Items.Count);
                        //}
                    }
                    else
                    {
                        //var package = data as SyncDataPackage;
                        //var packageCount = item.GetUInt32Field(PACKAGECOUNT);
                        if (BitConverter.ToUInt64(data.SyncItemVersion, 0) != item.GetUInt64Field(TIMESTAMP_COLUMNNAME)) // the item has changed since the last sync operation.
                        {
                            //Changed Item, this item has changed since the last time the metadata was updated.
                            //Assign a new version by simply stating "who" modified this item (0 = local/me) and "when" (tick count for the store)
                            item.ChangeVersion = newVersion;
                            SaveItemMetadata(item, BitConverter.ToUInt64(data.SyncItemVersion, 0));
                        }
                        else
                        {
                            //Unchanged item, nothing has changes so just mark it as live so that the metadata knows it has not been deleted.
                            _metadata.DeleteDetector.ReportLiveItemById(new SyncId(entity.SyncItemId));
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }


            //Now go back through the items that are no longer in the store and mark them as deleted in the metadata.
            //This sets the item as a tombstone.
            foreach (ItemMetadata item in _metadata.DeleteDetector.FindUnreportedItems())
            {
                item.MarkAsDeleted(newVersion);
                SaveItemMetadata(item, 0); // set timestamp to null for tombstones
            }
        }