예제 #1
0
        void UpdateMetadataStoreWithLocalChanges(IEnumerable <MegaNodeHelper> nodes)
        {
            SyncVersion newVersion = new SyncVersion(0, _metadata.GetNextTickCount());

            _metadata.DeleteDetector.MarkAllItemsUnreported();
            foreach (var node in nodes)
            {
                var item = FindItemMetadataByNodeId(node.Node.Id);
                if (item == null)
                {
                    item = CreateItemMetadata(new SyncId(new SyncGlobalId(0, Guid.NewGuid())), newVersion);
                    item.ChangeVersion = newVersion;
                    SaveItemMetadata(item, node.Node.Id, node.Path);
                }
                else
                {
                    if (node.Path != item.GetStringField(PATH_COLUMNNAME))
                    {
                        if (node.Node.Type == MegaNodeType.Folder)
                        {
                            item.MarkAsDeleted(newVersion);
                            item.ChangeVersion = newVersion;
                            SaveItemMetadata(item);
                            var newItem = CreateItemMetadata(new SyncId(new SyncGlobalId(0, Guid.NewGuid())), newVersion);
                            newItem.ChangeVersion = newVersion;
                            SaveItemMetadata(newItem, node.Node.Id, node.Path);
                        }
                        else
                        {
                            //Changed Item, this item has changed since the last time the metadata was updated.
                            item.ChangeVersion = newVersion;
                            SaveItemMetadata(item, node.Node.Id, node.Path);
                        }
                    }
                    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(item.GlobalId);
                    }
                }
            }

            foreach (ItemMetadata item in _metadata.DeleteDetector.FindUnreportedItems())
            {
                item.MarkAsDeleted(newVersion);
                SaveItemMetadata(item);
            }
        }
예제 #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
            }
        }
예제 #3
0
 public ulong GetNextTickCount()
 {
     return(_metaData.GetNextTickCount());
 }
예제 #4
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();

            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
            }
        }