我正在设计一个应用程序,可以让您找到由某些程序制作的图片(屏幕截图)。我将在应用程序本身中提供一些程序的位置,以帮助用户入门。
我想知道随着时间的推移我应该如何添加新位置,我的第一个想法是简单地将其硬编码到应用程序中,但这将意味着用户必须重新安装它才能使更改生效。
我的第二个想法是使用一个 XML 文件来包含所有位置以及其他数据,例如应用程序的名称。这也意味着用户可以根据需要添加自己的位置,也可以通过互联网共享它们。
第二个选项似乎是最好的方法,但我不得不考虑如何在用户计算机上对其进行管理。理想情况下,我只想要一个不依赖任何外部文件(例如 XML)的 .exe,但这会让我回到第一点。
最好只使用 ClickOnce 部署在开始菜单中创建一个条目并创建一个包含 .exe 和文件名的文件夹吗?
感谢您的反馈,在设计确定之前,我不想开始实现应用程序。
最佳答案
通常我不会将任何内容硬编码到应用程序中。正如您正确指出的那样,这会导致设计不灵活。
我通常将此类配置信息存储在 Local Application Data 下的 XML 文件中文件夹。
如果您的用户始终(或经常)连接到互联网,您可以考虑使用替代(或附加)功能在网络服务上存储此类“书签”信息。
编辑:
这是我多年来用于此类事情的代码片段
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Xml.Serialization;
namespace JTools.IO.Configuration
{
public static class ConfigManager<T> where T : new()
{
private const string FILENAME = "Config.xml";
public static T Load()
{
return Load(ConfigFile);
}
public static T Load(string fileName)
{
T ret = default(T);
try
{
// Open file to read the data from
using (FileStream fs = new FileStream(fileName, FileMode.Open))
{
// Create an XmlSerializer object to perform the deserialization
XmlSerializer xs = new XmlSerializer(typeof(T));
// Use the XmlSerializer object to deserialize the data from the file
ret = (T)xs.Deserialize(fs);
}
}
catch (System.IO.DirectoryNotFoundException)
{
throw new Exception("Could not find the data directory '" + fileName + "'");
}
catch (System.IO.FileNotFoundException)
{
ret = new T();
}
return ret;
}
public static void Save(T config)
{
Save(config, ConfigFile);
}
public static void Save(T config, string fileName)
{
// Create file to save the data to
using (FileStream fs = new FileStream(fileName, FileMode.Create))
{
// Create an XmlSerializer object to perform the serialization
XmlSerializer xs = new XmlSerializer(typeof(T));
// Use the XmlSerializer object to serialize the data to the file
xs.Serialize(fs, config);
}
}
static private string configFile = null;
static public string ConfigFile
{
get
{
if (configFile == null)
{
string appName = typeof(T).FullName;
string baseFolder = System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
string jFolder = Path.Combine(baseFolder, "JToolsConfig");
string dataPath = Path.Combine(jFolder, appName);
if (!Directory.Exists(dataPath))
{
Directory.CreateDirectory(dataPath);
}
configFile = Path.Combine(dataPath, FILENAME);
}
return configFile;
}
}
}
}
关于xml - Windows应用程序的设计问题,最佳方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2841339/
我正在学习如何使用Nokogiri,根据这段代码我遇到了一些问题:require'rubygems'require'mechanize'post_agent=WWW::Mechanize.newpost_page=post_agent.get('http://www.vbulletin.org/forum/showthread.php?t=230708')puts"\nabsolutepathwithtbodygivesnil"putspost_page.parser.xpath('/html/body/div/div/div/div/div/table/tbody/tr/td/div
总的来说,我对ruby还比较陌生,我正在为我正在创建的对象编写一些rspec测试用例。许多测试用例都非常基础,我只是想确保正确填充和返回值。我想知道是否有办法使用循环结构来执行此操作。不必为我要测试的每个方法都设置一个assertEquals。例如:describeitem,"TestingtheItem"doit"willhaveanullvaluetostart"doitem=Item.new#HereIcoulddotheitem.name.shouldbe_nil#thenIcoulddoitem.category.shouldbe_nilendend但我想要一些方法来使用
类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc
很好奇,就使用rubyonrails自动化单元测试而言,你们正在做什么?您是否创建了一个脚本来在cron中运行rake作业并将结果邮寄给您?git中的预提交Hook?只是手动调用?我完全理解测试,但想知道在错误发生之前捕获错误的最佳实践是什么。让我们理所当然地认为测试本身是完美无缺的,并且可以正常工作。下一步是什么以确保他们在正确的时间将可能有害的结果传达给您? 最佳答案 不确定您到底想听什么,但是有几个级别的自动代码库控制:在处理某项功能时,您可以使用类似autotest的内容获得关于哪些有效,哪些无效的即时反馈。要确保您的提
我正在尝试设置一个puppet节点,但rubygems似乎不正常。如果我通过它自己的二进制文件(/usr/lib/ruby/gems/1.8/gems/facter-1.5.8/bin/facter)在cli上运行facter,它工作正常,但如果我通过由rubygems(/usr/bin/facter)安装的二进制文件,它抛出:/usr/lib/ruby/1.8/facter/uptime.rb:11:undefinedmethod`get_uptime'forFacter::Util::Uptime:Module(NoMethodError)from/usr/lib/ruby
我需要在客户计算机上运行Ruby应用程序。通常需要几天才能完成(复制大备份文件)。问题是如果启用sleep,它会中断应用程序。否则,计算机将持续运行数周,直到我下次访问为止。有什么方法可以防止执行期间休眠并让Windows在执行后休眠吗?欢迎任何疯狂的想法;-) 最佳答案 Here建议使用SetThreadExecutionStateWinAPI函数,使应用程序能够通知系统它正在使用中,从而防止系统在应用程序运行时进入休眠状态或关闭显示。像这样的东西:require'Win32API'ES_AWAYMODE_REQUIRED=0x0
我有一个模型:classItem项目有一个属性“商店”基于存储的值,我希望Item对象对特定方法具有不同的行为。Rails中是否有针对此的通用设计模式?如果方法中没有大的if-else语句,这是如何干净利落地完成的? 最佳答案 通常通过Single-TableInheritance. 关于ruby-on-rails-Rails-子类化模型的设计模式是什么?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.co
对于具有离线功能的智能手机应用程序,我正在为Xml文件创建单向文本同步。我希望我的服务器将增量/差异(例如GNU差异补丁)发送到目标设备。这是计划:Time=0Server:hasversion_1ofXmlfile(~800kiB)Client:hasversion_1ofXmlfile(~800kiB)Time=1Server:hasversion_1andversion_2ofXmlfile(each~800kiB)computesdeltaoftheseversions(=patch)(~10kiB)sendspatchtoClient(~10kiBtransferred)Cl
我想为Heroku构建一个Rails3应用程序。他们使用Postgres作为他们的数据库,所以我通过MacPorts安装了postgres9.0。现在我需要一个postgresgem并且共识是出于性能原因你想要pggem。但是我对我得到的错误感到非常困惑当我尝试在rvm下通过geminstall安装pg时。我已经非常明确地指定了所有postgres目录的位置可以找到但仍然无法完成安装:$envARCHFLAGS='-archx86_64'geminstallpg--\--with-pg-config=/opt/local/var/db/postgresql90/defaultdb/po
我想了解Ruby方法methods()是如何工作的。我尝试使用“ruby方法”在Google上搜索,但这不是我需要的。我也看过ruby-doc.org,但我没有找到这种方法。你能详细解释一下它是如何工作的或者给我一个链接吗?更新我用methods()方法做了实验,得到了这样的结果:'labrat'代码classFirstdeffirst_instance_mymethodenddefself.first_class_mymethodendendclassSecond使用类#returnsavailablemethodslistforclassandancestorsputsSeco