如何持久化/保存程序信息

发布于 2025-01-04 12:13:16 字数 150 浏览 2 评论 0 原文

我编写了一个在启动时自动运行的提醒程序。我想知道除了 SQL-Server 之外是否还有其他方法来存储事件、日期和时间数据。我不想使用 SQL-Server 来完成这项工作,因为我认为 SQL-Server 对于这项简单的任务来说非常大。我认为我可以使用文件来存储数据。您对此有何看法?

I wrote a reminder program that runs automatically on startup. I want to know if there is a way, other than SQL-Server, to store event, date and time data. I do not want to use SQL-Server for this work, because I think SQL-Server is very big for this simple task. I think that I can use a file to store data in it. What do you think about this?

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

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

发布评论

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

评论(4

柒夜笙歌凉 2025-01-11 12:13:16

存储信息的一些常见方式:

  • 作为文件。您可以通过多种方式存储文件。例如,用户目录、程序目录。进一步说明此处此处。我更喜欢使用序列化程序(xml 或 json)。
  • 作为注册表条目。您将信息存储为键值对。
  • 在轻量级数据库中:
    • RavenDB:面向文档,以json格式存储数据
    • SQLite:关系;我推荐这个SQLite Admin用于管理目的

注册表项对于用户操作来说更安全。另一方面,文件可以轻松删除。

您始终可以选择加密您的信息。

附带说明一下,您还可以使用 PostSharp 声明要存储在注册表中的变量。代码变成这样:

[RegistryBacking]
private bool _boolean;

如果您需要的话,我可以稍后提供代码......当我再次回家时。

Some common ways to store information:

  • As a file. You have many options where you can store the file. For instance, user directory, and program directory. Further explanation here and here. I prefer using a serializer (xml or json).
  • As a registry entry. You store your information as key-value pairs.
  • In a light-weight database:
    • RavenDB: its document-oriented, and stores data in json format
    • SQLite: relational; I recommend this SQLite Admin for managing purpose

Registry entries are more safe regarding user actions. On the other hand, files can be easily deleted.

You always have the option, to encrypt your information.

As a side note, you can also use PostSharp to declare variables to be stored in your registry. The code becomes something like this:

[RegistryBacking]
private bool _boolean;

I can provide code later if you need it... when I'm home again.

苍景流年 2025-01-11 12:13:16

对于要保留的部分位置

从此文档(管理用户数据部署指南,下载)

Windows 使用 LocalLocalLow 文件夹来存储应用程序数据
不与用户一起漫游。通常这个数据是机器
具体或太大而无法漫游。

Windows 使用 Roaming 文件夹来存储应用程序特定数据,例如
作为自定义字典,它们是独立于机器的并且应该漫游
与用户个人资料。

因此,我建议使用 AppData\Roaming 并保存到文件,因为我认为“提醒应用程序”是特定于用户的。例如,域用户会认为这是有价值的(同步到服务器)。

LocalLocalLow (后者用于低完整性模式,适用于权限较低的应用程序)更适合某些可以计算的机器/安装特定数据 -苍蝇。

Registry 似乎非常适合一些少量的密钥,但似乎不是此类用途的最佳选择。

还有另一个选项 - IsolatedStorage,当提到的选项不适用时(例如使用 ClickOnce 部署时),应使用该选项。

对于如何将数据保存到文件的部分......好吧,选择您最喜欢的。如果您想要更多的控制和功能,您可以使用 SQLite 数据库,它真的很轻量级;如果您认为使用 SQLite 是一种过度杀伤力,则可以仅使用 XML 序列化到文件。或者任何其他可行的选择。

For the part where to persist

From this document (Managing User Data Deployment Guide, download):

Windows uses the Local and LocalLow folders for application data
that does not roam with the user. Usually this data is either machine
specific or too large to roam.

Windows uses the Roaming folder for application specific data, such
as custom dictionaries, which are machine independent and should roam
with the user profile.

So, I suggest using AppData\Roaming and persisting to a file since I consider a 'reminder app' to be user specific. And domain users for example would consider that valuable (syncing to server).

Local and LocalLow (the latter is used for low integrity mode, for applications with reduced privileges) would be more appropriate for some machine/installation specific data which can be calculated on-the-fly.

Registry seems great for some low amount of keys, but doesn't seem to be the best option for such use.

There is another option - IsolatedStorage, which should be used when mentioned options are not applicable, like when using ClickOnce deployments.

For the part how to persist your data to a file ... well, pick your favorite. You could use SQLite database which comes really lightweigt if you want more control and power or just use XML serialization to a file if you consider using SQLite an overkill. Or any of other viable options.

狂之美人 2025-01-11 12:13:16

XML。 .NET 有一些类,可以进行处理xml 文件很容易。如果您要保存结构化数据,那么 XML 可能是您的最佳选择。

XML. .NET has classes that makes handling xml files easy. If you're saving structured data then XML might be your best bet.

南渊 2025-01-11 12:13:16

出于非常相似的原因,我尝试了一些易于部署的数据库,但仍使用我所拥有的知识。

VistaDB 3.x 和 4 是我的第一选择,因为它们与 SQL Server 非常兼容,并且允许我切换到sql server 任何时候我喜欢。这也支持EF!!!

接下来是 Versant 的 db4o,非常方便。我主要将它用于快速原型设计,但我已经部署了几个小型解决方案,并且非常适合您的应用程序类型。

我希望这有帮助!

I have for very similar reasons tried some easy to deploy databases and yet use the knowledge i have.

VistaDB 3.x and 4 are my first choice because they are very much SQL Server compaible and allows me to switch to sql server anytime i like. This supports EF too!!!

Next is db4o by Versant which is very very handy. I use it mostly for quick prototyping but i have deployed to several small solutions and perfect for your kind of application.

I hope that helps!

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