仅同步修改过的文件

发布于 2024-12-08 20:13:33 字数 916 浏览 0 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苹果你个爱泡泡 2024-12-15 20:13:33

您需要连接 ApplyingChange 事件。

这在应用更改之前被调用,因此您有机会覆盖默认行为。

要跳过更改,请将 SkipChange 属性设置为 true。跳过的更改将不会应用于目标副本。对于每个跳过的更改,将触发 SkippedChange 事件,并将 SkippedChangeEventArgs.SkipReason 设置为 ApplicationRequest。

因此,如果 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.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文