在我的解决方案中,我有两个项目(Windows 服务和 WPF 来管理服务) 我有一个服务使用的坐席文件 (XML) 我问的是:
我想知道用户何时在不重启服务的情况下对 XML 文件进行任何更改 并知道发生变化的 xml 节点是什么
找了很多,发现解决办法是通过FileSystemWatcher
Listens to the file system change notifications and raises events when a directory, or file in a directory, changes.
但是我怎么知道发生了变化的 xml 节点是什么
谢谢
最佳答案
我会保留原始 XML 的副本,然后在 FileSystemWatcher 触发时运行比较。看看Efficient algorithm for comparing XML nodes有关比较 XML 节点的建议。
文件观察器示例
String folderLocation = System.Configuration.ConfigurationManager.AppSettings["FOLDER_LOCATION"].ToString();
_watcher = new System.IO.FileSystemWatcher();
_watcher.Path = folderLocation;
_watcher.IncludeSubdirectories = false;
_watcher.NotifyFilter = NotifyFilters.Size;
_watcher.Changed += new FileSystemEventHandler(OnFileChanged);
_watcher.EnableRaisingEvents = true;
private void OnFileChanged(object sender, FileSystemEventArgs e)
{
String file = e.FullPath;
...
关于c# - 如何监控(添加 - 编辑 - 删除)节点的 xml 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17828734/