Exemplo n.º 1
0
        /// <summary>
        /// Detects changes not known to the destination and returns a change batch
        /// </summary>
        /// <param name="destinationKnowledge">Requester Knowledge</param>
        /// <param name="batchSize">Maximum number of changes to return</param>
        /// <returns>List of changes</returns>
        private List <ItemChange> DetectChanges(SyncKnowledge destinationKnowledge, uint batchSize)
        {
            List <ItemChange> changeBatch = new List <ItemChange>();

            if (destinationKnowledge == null)
            {
                throw new ArgumentNullException("destinationKnowledge");
            }
            if (batchSize < 0)
            {
                throw new ArgumentOutOfRangeException("batchSize");
            }

            if (!localChangedDetected)
            {
                FindLocalFileChanges(folderPath);
                localChangedDetected = true;
            }

            // Map the destination knowledge
            // This maps the knowledge from the remote replica key map (where the destination is replicaKey 0)
            // to the local replica key map (where the source is replicaKey)
            //
            // We do this because our metadata is relative to the local store (and local key map)
            // (This is typical of most sync providers)
            SyncKnowledge mappedKnowledge = SyncKnowledge.MapRemoteKnowledgeToLocal(destinationKnowledge);

            foreach (ItemMetadata item in metadataStore)
            {
                // Check if the current version of the item is known to the destination
                // We simply check if the update version is contained in his knowledge

                // If the metadata is for a tombstone, the change is a delete
                if (!mappedKnowledge.Contains(ReplicaId, item.ItemId, item.ChangeVersion))
                {
                    ItemChange itemChange = new ItemChange(IdFormats, ReplicaId, item.ItemId, item.IsTombstone ? ChangeKind.Deleted : ChangeKind.Update, item.CreationVersion, item.ChangeVersion);
                    // Change isn't known to the remote store, so add it to the batch
                    changeBatch.Add(itemChange);
                }

                // If the batch is full, break
                //
                // N.B. Rest of changes will be detected in next batch. Current batch will not be
                // reenumerated (except in case destination doesn't successfully apply them) as
                // when destination applies the changes in this batch, they will add them to their
                // knowledge.
                if (changeBatch.Count == batchSize)
                {
                    break;
                }
            }

            return(changeBatch);
        }