多个项目的配置

发布于 2024-09-08 07:18:34 字数 815 浏览 0 评论 0原文

我的项目

我正在使用 VS C# 2.0 编写一个 Winform 应用程序,它由多个库和两个可执行文件组成,每个库和两个可执行文件都位于其自己的项目文件中,并且都是同一解决方案的所有部分。

每个项目都有自己的Settings Class来配置参数。有些参数是特定于项目的,有些参数是多个项目需要的(但不是所有项目都需要),而其他参数则取决于通过 USB 连接到用户计算机的硬件设备的型号(并在运行时选择)。

设置类由枚举、属性以及加载和保存方法组成。

目前,我有一个带有属性网格的表单,它实例化所有类的所有设置并允许用户更改配置。它属于主要的可执行项目。

我的问题

我需要一种让用户配置整个应用程序的方法(让我们称之为配置器),所以我尝试创建另一个项目,该项目的表单如下属性网格,但最终以配置器和我的主可执行文件之间的循环引用问题结束。 配置器需要单独运行或从主可执行文件中调用。

另外,我不知道将公共参数值的更改复制到其对应参数的好方法。例如,如果参数p对于项目AB的设置类是通用的,那么当用户更改Ap时> 值,配置器必须更改Bp值(反之亦然)。我认为解决此问题的唯一解决方案涉及属性网格的 PropertyValueChanged 事件处理程序上的 if 子句的噩梦。

谢谢,海蒂

My Project

I'm writing a Winform application using VS C# 2.0 which consists in several libraries and two executables, each in its own project file and all part of the same solution.

Each project has its own Settings Class which configuration parameters. Some parameters are project specific, some are needed by more than one project (but none for all), and others depend on the model of a hardware device connected via USB to the user machine (and are selected at runtime).

The Setting Class consists on enumerations, properties and Load and Save methods.

Currently I have a form with a property grid which instantiates all the settings from all the classes and lets the user change the configuration. It belongs to the main executable project.

My problem

I need a way for the users to configure the whole application (let's call it a configurator), so I tried to create another project which would have the form with the property grid, but ended with a circular reference problem between the configurator and my main executable. The configurator needs to run on its own or be called from the main executable.

Also, I don't know a good way to replicate changes to the value of a common parameter to its counterparts. For instance, if parameter p is common to the settings classes of projects A and B, when a user changes A.p value, the configurator would have to change B.p value (and the same for the inverse). The only solution I've thought to resolve this involves a nightmare of if clauses on the PropertyValueChanged event handler of the property grid.

Thanks, Heiddy

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

吝吻 2024-09-15 07:18:34

为了减少循环依赖,必须相应地包含抽象类和接口。

基础库:由所有“数据”类组成,实现 IPropertyChangedNoitifier,并且应该始终保持一致。配置的加载/保存应保存在该库本身中。

配置库:引用基础库并进行配置更改并调用有关配置更改的某些事件。然而,这个项目必须只包含要配置的 UI;

配置项目:加载并执行配置库的UI。

实际项目:引用基础库和配置库,您可以从该项目以及其他项目加载配置UI。

谈到设置的运行时复制,您可以通过文件系统观察器监视文件内容更改的事件,并在检测到文件更改后的特定毫秒后重新加载配置。

In order to reduce circular dependency, you must include Abstract classes and Interfaces accordingly.

Base Library: consists of all "Data" classes, implementing IPropertyChangedNoitifier and which should be consistent throughout. Loading/Saving of configuration should be saved in this library itself.

Configuration Library: References Base Library and does configuration changes and invokes certain events about change of configuration. However this project must only contain the UI to configure;

Configuration Project: loads and executes UI of Configuration Library.

Actual Project: References Base Library and Configuration Library, and you can load Configuration UI from this project as well as from other project.

Talking about run time replication of settings, you can watch events of File content changes through File System Watcher and reload your config after certain millseconds once the file changes are detected.

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