具有用户提供的正则表达式的插件模型
我有一个 C# WPF 程序,可以分析某些日志文件。每个日志都包含数据行,其格式包含地址和数据偏移量。
例如,某些日志文件可以具有以下格式:
mmio address : data
或者某些日志文件可以具有以下格式:
write address : data
可以有很多这样的格式,但请放心,使用适当的 RegEx 解析时,每一行都应始终返回一个地址和一个数据。
我想让这个正则表达式可以从应用程序中控制。我不想在源代码中硬编码每种格式的正则表达式。用户应该能够修改现有的正则表达式或为新类型的日志文件添加新的正则表达式。我应该为他提供类似表格的内容,他可以从中选择特定行或为新日志文件添加新行 表
:
日志名称 - RegEx
MMIO Log - MMIO ([0-9]{8}) : ([ 0-9]{8}) -->单选按钮
写入日志 - 写入 ([0-9]{8}) : ([0-9]{8}) -->单选按钮
我怎样才能做到这一点?我可以将其存储在某种配置文件中还是使用我不太了解如何实现的插件模型。
I have a program in C# WPF which analyzes certain log files. Each log contains lines of data in a format which contains an address and a data offset.
For example, some log files can have the format:
mmio address : data
or some can have the format:
write address : data
There can be many such formats, but rest assured that each line when parsed with an appropriate RegEx should always return an address and a data.
I want to make this RegEx controllable from the application. I don't want to hardcode the RegEx of each format in the source code. The user should be able to modify an existing RegEx or add a new RegEx for a new kind of log file. I should provide him something like a table from which he can select a particular row or add a new row for a new log file
Table:
Name of Log - RegEx
MMIO Log - MMIO ([0-9]{8}) : ([0-9]{8}) --> Radio Button
Write Log - Write ([0-9]{8}) : ([0-9]{8}) --> Radio Button
How can I do this? Can I store this in some kind of config file or use a plugin model which I don't have much idea how to implement.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
插件系统绝对是大材小用。只需使用
App.config
来存储表达式并将它们显示在组合框或类似的内容中。看看精彩文章系列如何访问配置。System.Configuration
命名空间的其他参考< /a> 来自 MSDN。A plug-in system is absolute overkill. Just use the
App.config
to store the expressions and show them in a combo box or something similar. Have a look at this great article series how to access the configuration. Additional reference for theSystem.Configuration
namespace comes from the MSDN.