在Windows和Mono中存儲C#服務設置

[英]Storing C# Service Settings in Windows & Mono


I'm writing a C# service that I want to be able to use on Windows and Mono. I've just started experimenting with Mono and am trying to determine the best way to store settings to control the service that works for both Windows and Mono.

我正在編寫一個C#服務,我希望能夠在Windows和Mono上使用它。我剛開始嘗試使用Mono,我正在嘗試確定存儲設置的最佳方法,以控制適用於Windows和Mono的服務。

  1. Settings file where service is installed

    安裝服務的設置文件

    • Pros: Same code for each platform, easy to find for editing
    • 優點:每個平台的代碼相同,易於編輯

    • Cons: Permissions, Windows probably won't like writing to the file
    • 缺點:權限,Windows可能不喜歡寫入文件

  2. Settings file in platform storage (%APPDATA, /etc, ...)

    平台存儲中的設置文件(%APPDATA,/ etc,...)

    • Pros: Will have permissions, easier to find for editing
    • 優點:將擁有權限,更容易找到編輯

    • Cons: More coding required to handle each platform
    • 缺點:處理每個平台需要更多編碼

  3. Small database (SQLite maybe?)

    小數據庫(SQLite可能?)

    • Pros: Easier to write code to store and retrieve settings
    • 優點:更容易編寫代碼來存儲和檢索設置

    • Cons: Not easy to edit manually, same problem of where to store
    • 缺點:手動編輯不容易,存儲位置相同

Which do you think is the best, or do you have a better suggestion?
I will also probably be writing a command line client to allow for easier changing of settings, will this change how settings should be stored?

您認為哪個最好,或者您有更好的建議?我也可能會編寫命令行客戶端以便更改設置,這會改變設置的存儲方式嗎?

1 个解决方案

#1


Take a look at IsolatedStorage. This is an API for providing you with per-application storage, it's built into .NET and is supported in Mono. The API provides you with file IO on files that are stored in a location managed by the framework: in Mono it'll be a ~/.isolatedstorage directory, in Windows it'll be somewhere in the user's Documents and Settings.

看看IsolatedStorage。這是一個為您提供每個應用程序存儲的API,它內置於.NET中,並在Mono中受支持。 API為存儲在框架管理的位置的文件提供文件IO:在Mono中它將是一個〜/ .isolatedstorage目錄,在Windows中它將位於用戶文檔和設置中的某個位置。

With this API, you can maintain your settings file without having to worry about operating system specifics or permissions.

使用此API,您可以維護設置文件,而無需擔心操作系統細節或權限。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2009/04/23/18f95c60f018b1ca65243ef0ce922eec.html



 
  © 2014-2022 ITdaan.com 联系我们: