C# 代码或库来更新虚拟目录内容而不破坏客户端
C# code or library to Update virtual directory contents without breaking clients
我有很多定期更新的静态内容,这些内容通过 IIS 作为虚拟目录通过 HTTP 提供。我有一个更新此静态内容的 C# 应用程序。静态内容表示一个匹配集。
此内容会定期更改,并在提供给客户之前经过验证。我目前正在使用 this code 进行目录复制,但这有点蛮力。
内容有一个包含版本信息的清单文件。我知道我可以最后更新清单文件,但我不想从已经下载旧内容的客户端下撤下地毯,让他们留下一组脏文件。
推荐的文件夹替换方法是什么,这样现有的客户端就不会得到文件集的混合版本?这一定很常见,但我找不到任何图书馆或最佳实践指南来做到这一点。
我看过 Windows 的 rsync 和其他 backup/restore 风格的工具,但它们看起来都太过分了,而且通常没有 API.
我最终使用了Microsoft Sync Framework. It worked out reasonably well. There are still a few bugs. Here's a good intro框架。
这是我实现的重要部分。
public static bool DirectorySynchronisation(string sourceFiles, string targetFiles)
{
Trace.Info("Beginning Directory Sync");
try
{
Trace.Info("... between source location: {0} and targeted location: {1}", sourceFiles, targetFiles);
//Exclude metadata from sync.
var fileSyncScopeFilter = new FileSyncScopeFilter();
fileSyncScopeFilter.FileNameExcludes.Add("metadata.abc");
// Create file system provider
var source = new FileSyncProvider(Guid.NewGuid(), sourceFiles, fileSyncScopeFilter, FileSyncOptions.None);
var target = new FileSyncProvider(Guid.NewGuid(), targetFiles);
// Ask providers to detect changes
source.DetectChanges();
target.DetectChanges();
// Sync changes
SyncOrchestrator agent = new SyncOrchestrator
{
LocalProvider = source,
RemoteProvider = target,
Direction = SyncDirectionOrder.Upload //One way only
};
agent.Synchronize();
Trace.Info("Completed Directory Sync");
return true;
}
catch (Exception exception)
{
Trace.Info("Exception thrown while syncing files");
Trace.Exception(exception);
return false;
}
}
希望这对某人有所帮助。
我有很多定期更新的静态内容,这些内容通过 IIS 作为虚拟目录通过 HTTP 提供。我有一个更新此静态内容的 C# 应用程序。静态内容表示一个匹配集。 此内容会定期更改,并在提供给客户之前经过验证。我目前正在使用 this code 进行目录复制,但这有点蛮力。
内容有一个包含版本信息的清单文件。我知道我可以最后更新清单文件,但我不想从已经下载旧内容的客户端下撤下地毯,让他们留下一组脏文件。
推荐的文件夹替换方法是什么,这样现有的客户端就不会得到文件集的混合版本?这一定很常见,但我找不到任何图书馆或最佳实践指南来做到这一点。 我看过 Windows 的 rsync 和其他 backup/restore 风格的工具,但它们看起来都太过分了,而且通常没有 API.
我最终使用了Microsoft Sync Framework. It worked out reasonably well. There are still a few bugs. Here's a good intro框架。 这是我实现的重要部分。
public static bool DirectorySynchronisation(string sourceFiles, string targetFiles)
{
Trace.Info("Beginning Directory Sync");
try
{
Trace.Info("... between source location: {0} and targeted location: {1}", sourceFiles, targetFiles);
//Exclude metadata from sync.
var fileSyncScopeFilter = new FileSyncScopeFilter();
fileSyncScopeFilter.FileNameExcludes.Add("metadata.abc");
// Create file system provider
var source = new FileSyncProvider(Guid.NewGuid(), sourceFiles, fileSyncScopeFilter, FileSyncOptions.None);
var target = new FileSyncProvider(Guid.NewGuid(), targetFiles);
// Ask providers to detect changes
source.DetectChanges();
target.DetectChanges();
// Sync changes
SyncOrchestrator agent = new SyncOrchestrator
{
LocalProvider = source,
RemoteProvider = target,
Direction = SyncDirectionOrder.Upload //One way only
};
agent.Synchronize();
Trace.Info("Completed Directory Sync");
return true;
}
catch (Exception exception)
{
Trace.Info("Exception thrown while syncing files");
Trace.Exception(exception);
return false;
}
}
希望这对某人有所帮助。