简体   繁体   English

存储应用程序设置的位置

[英]Where to store application settings

I am creating an app that reads some info from a scale via RS232 serial port connection. 我正在创建一个应用程序,通过RS232串口连接从秤中读取一些信息。 There are a couple of types of scales that are in use, so I would like to store specific settings for the scale in my program. 有几种类型的秤正在使用中,所以我想在程序中存储秤的特定设置。 What is the best way to do this? 做这个的最好方式是什么? Via app.config? 通过app.config? Or should I put the values in a database? 或者我应该将值放在数据库中?

It really depends on where will these configurations be used? 这真的取决于where will these configurations be used?

If you are working on a distributed huge system, which means these configurations are probably shared/used by other systems. 如果您正在处理分布式庞大系统,这意味着这些配置可能由其他系统共享/使用。 You'd better store it in the database, with a common protocol which other related systems agree with. 您最好将其存储在数据库中,使用其他相关系统同意的通用协议。

On the other hand, if these configurations are used for a small application, storing them in a config file(or an xml file whatever you like) is suggested because, you don't need a gun in order to kill a mosquito. 另一方面,如果这些配置用于小型应用程序,建议将它们存储在配置文件(或任何你喜欢的xml文件)中,因为你不需要用枪来杀死蚊子。

app.config would be the easiest option for you. app.config对您来说是最简单的选择。 I think a database might be a bit overdoing it for just some settings, but if you wish to use something outside of what is offered by VS (namely app.config) then you could always whip up a quick custom XML settings file. 我认为数据库可能只是对某些设置有点过分,但是如果你想使用VS提供的东西之外的东西(即app.config),那么你总是可以创建一个快速的自定义XML设置文件。 All depends on what you wanna do with it and how comfortable you are with the other technology. 一切都取决于你想用它做什么以及你对其他技术的舒适度。

Is the information chaging ? 信息是否在变? that means when you ran ur app , would it be the case that information is updated ? 这意味着当你运行你的应用程序时,是否会更新信息?

if the information is static and do not change frequetly , you can store in the app.config. 如果信息是静态的并且不会频繁更改,则可以存储在app.config中。

or in a xml file and you can read that information lately. 或者在xml文件中,您最近可以阅读该信息。

but if the information is dynamic then you need to create a model and expose scale information through model's peroperty. 但如果信息是动态的,那么您需要创建一个模型并通过模型的peroperty公开比例信息。

Do not forget the registry. 不要忘记注册表。

Use the registry when: 使用注册表时:

  • You need your settings to be accessible for a domain admin 您需要为域管理员访问您的设置
  • you need to secure some settings (using Windows security) 您需要保护一些设置(使用Windows安全性)
    (You can make some settings read-only) (您可以将某些设置设为只读)
  • There are a lot of small settings that change very often 有很多小设置经常变化

If it's simple and straightforward than app.config is the way to go - you don't need to set up a database and you get to use simple built-in interfaces. 如果它比app.config更简单直接 - 你不需要设置数据库就可以使用简单的内置接口。

If you choose to go with a database check out mysql for a simple file based database that has a simple deployment scheme. 如果您选择使用数据库,请查看mysql以获取具有简单部署方案的基于文件的简单数据库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM