仅同步修改过的文件
我正在使用 Microsoft Sync Framework 和 C# 开发以下同步文件功能两个目录之间:
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 FileSyncProvider(destId.GetGuidId(), _secondPath);
var agent = new SyncOrchestrator
{
LocalProvider = sourceReplica,
RemoteProvider = destReplica,
Direction = SyncDirectionOrder.UploadAndDownload
};
agent.Synchronize();
}
这段代码工作得很好。问题是,它不仅会同步已更改的文件,还会同步添加到任一目录中的文件以及从任一目录中删除的文件。有没有办法使 agent.Synchronize();
仅同步已更改的文件,而不同步添加或删除的文件?
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 FileSyncProvider(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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要连接 ApplyingChange 事件。
这在应用更改之前被调用,因此您有机会覆盖默认行为。
因此,如果
ApplyingChangeEventArgs.ChangeType
是创建
或删除
,然后将ApplyingChangeEventArgs.SkipChange
设置为true
。然后,只有那些被重命名或更新的文件才会被同步。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.
So if the
ApplyingChangeEventArgs.ChangeType
isCreate
orDelete
then set theApplyingChangeEventArgs.SkipChange
totrue
. Then the only those files that are renamed or updated will be synced.