开发者

Syncing modified files only

I am using the Microsoft Sync Framework and C# to develop the following function for syncing files between two directories:

    private void InitialSync()
    {
        var sourceId = new SyncId(Guid.NewGuid());
        var destId = new SyncId(Guid.NewGuid());
        var sourceReplica = new FileSyncProvider(sourceId.GetGuidId(), _firstPath);
        var destReplica = new File开发者_开发知识库SyncProvider(destId.GetGuidId(), _secondPath);
        var agent = new SyncOrchestrator
                        {
                            LocalProvider = sourceReplica,
                            RemoteProvider = destReplica,
                            Direction = SyncDirectionOrder.UploadAndDownload
                        };

        agent.Synchronize();
    }

This code works just fine. The problem is, it will sync not only files that have changed, but also it will sync files that are added to either directory and files that are deleted from either directory. Is there a way to make the agent.Synchronize(); ONLY sync files that have been changed and NOT sync files added or deleted?


You will need to hook into the ApplyingChange event.

This gets called before the change is applied so gives you a chance to overwrite the default behaviour.

To skip a change, set the SkipChange property to true. A change that is skipped will not be applied to the destination replica. A SkippedChange event will be fired with SkippedChangeEventArgs.SkipReason set to ApplicationRequest for each change that is skipped.

So if the ApplyingChangeEventArgs.ChangeType is Create or Delete then set the ApplyingChangeEventArgs.SkipChange to true. Then the only those files that are renamed or updated will be synced.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜