我有一个类库,它使用应用程序设置来确定特定方法的行为.
我意识到可以说这是一个坏事,但我们知道网站的行为将在发布一周后发生变化(没有真正的确定时间),并且最简单的方法是更改设置在配置文件中更改站点的行为.
无论如何,关于我的问题......我希望能够根据applicationSetting的true/false值测试一个行为发生变化的方法.如何创建单元测试来测试单元测试的app.config中未定义的值?该设置是应用程序设置,因此它在Settings.Default实例中是只读的.
我正在考虑向应用程序添加可配置设置,我认为最简单的方法是外部文件或win注册表(它是一个仅赢的应用程序).
哪种方式会更好?
我想知道,权限不足的用户可能无法创建/写入配置文件.在注册表的情况下,今天的杀毒软件允许我添加/编辑/删除密钥吗?或者他们只监视某些键?
此外,如果有人知道在vc ++中管理配置设置(在纯win32中)的类/ lib,请发布它.
我有一个程序,我想将信息存储在字符串中。我一直在使用Properties.Setting.Default.STRINGname
来存储信息,这在我的电脑上运行良好,并且我可以看到保存的字符串(当我进入应用程序中的设置时)。但是当我将应用程序带到新电脑上时,它会丢失字符串。有没有办法能够编辑此信息并将其保存在应用程序中?所以基本上我需要能够将用户设置转换为应用程序设置,但在运行时之后。
var settings = Properties.Settings.Default;
settings.H1 = textbox1.text;
settings.H2 = textbox2.text;
settings.Save();
Run Code Online (Sandbox Code Playgroud) 我有一个非常简单的应用程序,我正在尝试使用 Settings 属性构建 app.config 。app.config 已构建,但运行时,键未检索值。
我最初使用的是从项目中添加应用程序配置文件并手动构建 app.config,并取得了巨大成功手动构建的 app.config 如下:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<appSettings>
<add key="Hosppath" value="C:\events\inbound"/>
<add key="Vendpath" value="C:\events\outbound"/>
<add key="Hospname" value="OBLEN_COB_Active_Inv_Advi_Daily_.csv"/>
<add key="Vendname" value="Advi_OBlen_Active_Inv_Ack_Daily_.csv"/>
<add key="Hospkey" value="invoice_number"/>
<add key="Vendkey" value="invoice"/>
<add key="Outpath" value="C:\events\Reports"/>
<add key="Outname" value="OB_Exception_Report_.xlsx"/>
<add key="Hospexcpt" value="O'Bleness Exceptions"/>
<add key="Vendexcpt" value="AdviCare Exceptions"/>
</appSettings>
</configuration>
Run Code Online (Sandbox Code Playgroud)
调用类在这里:
using System;
using System.Configuration;
namespace LoadSettings
{
public static class ConfigReader
{
public static bool ReadAllSettings()
{
var success = false;
var appSettings …
Run Code Online (Sandbox Code Playgroud) c# configurationmanager app-config appsettings application-settings
我们如何从一个表单 (settings.form) 更改所有其他表单的背景颜色?我想开发我的毕业项目。它是一个社交媒体桌面管理项目。我想用一个切换器将所有表单更改为暗模式。我怎样才能做到这一点?这是我的 settings.cs
public void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked)
{
panel1.BackColor= Color.FromArgb(34, 36, 49);
form1.BackColor = Color.FromArgb(34, 36, 49);
form2.BackColor = Color.FromArgb(34, 36, 49);
this.BackColor = Color.FromArgb(34, 36, 49);
this.label1.BackColor = Color.White;
this.label1.ForeColor = Color.FromArgb(34, 36, 49);
}
else
{
this.BackColor = Color.White;
this.label1.BackColor = Color.FromArgb(34, 36, 49);
this.label1.ForeColor = Color.White;
}
form1.Show();
form1.Refresh();
form2.Show();
form2.Refresh();
Run Code Online (Sandbox Code Playgroud)
当我切换时,所有背景颜色都在变化。但所有表格都同时打开。
我的ASP.NET应用程序读取xml文件以确定它当前所处的环境(例如本地,开发,生产).
它每次打开与数据库的连接时都会检查此文件,以便知道从应用程序设置中获取哪个连接字符串.
我正在进入一个发展阶段,效率正在成为一个问题.我不认为在我希望访问数据库的过程中(非常经常)读取物理磁盘上的文件是个好主意.
我正在考虑在Application ["ConnectionString"]中存储连接字符串.所以代码就是
public static string GetConnectionString
{
if (Application["ConnectionString"] == null)
{
XmlDocument doc = new XmlDocument();
doc.Load(HttpContext.Current.Request.PhysicalApplicationPath + "bin/ServerEnvironment.xml");
XmlElement xe = (XmlElement) xnl[0];
switch (xe.InnerText.ToString().ToLower())
{
case "local":
connString = Settings.Default.ConnectionStringLocal;
break;
case "development":
connString = Settings.Default.ConnectionStringDevelopment;
break;
case "production":
connString = Settings.Default.ConnectionStringProduction;
break;
default:
throw new Exception("no connection string defined");
}
Application["ConnectionString"] = connString;
}
return Application["ConnectionString"].ToString();
}
Run Code Online (Sandbox Code Playgroud)
我没有设计应用程序所以我认为每次都必须有一个读取xml文件的原因(在应用程序运行时更改设置?)我对这里的内部工作概念很少.优缺点都有什么?您是否认为通过实施上述功能可以获得较小的性能提升?
谢谢
可能重复:
使用ApplicationSettings存储WinForms RadioButtons的Checked属性
我在组合框中有三个radiobuttons.当它们不受应用程序设置的约束时,它们的行为正常.
将每个已检查的属性绑定到应用程序设置后,会发生以下情况:我必须单击未经检查的radiobutton两次才能检查它.第一次单击后,所有三个都未选中.
我也试过只绑定其中两个,但行为是一样的.
任何人都可以帮忙吗?
谢谢.
我正在尝试调出保存在我的iphone应用程序的设置包中的特定设置.我想根据保存的内容做一个if语句.我在实现文件中的代码如下所示:
branchMatch = [[NSString alloc] initWithString:[defaults objectForKey:@"branch"]];
Run Code Online (Sandbox Code Playgroud)
设置文件中的对象只是特定分支的名称.我一直收到SIGABRT错误,但我不确定原因.
我正在尝试使用下面的代码更新 app.config 文件中的值(该值在“属性”>“设置”中定义为“应用程序范围”)
System.Configuration.Configuration configApp = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
MessageBox.Show(configApp.AppSettings.Settings.Count.ToString()); //this shows 0
configApp.AppSettings.Settings["PontajAdminPwd"].Value = "dsfs";
configApp.Save(ConfigurationSaveMode.Full);
Run Code Online (Sandbox Code Playgroud)
但它说 configApp.AppSettings.Settings 是空的......
这是我的 app.config 文件的一部分
System.Configuration.Configuration configApp = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
MessageBox.Show(configApp.AppSettings.Settings.Count.ToString()); //this shows 0
configApp.AppSettings.Settings["PontajAdminPwd"].Value = "dsfs";
configApp.Save(ConfigurationSaveMode.Full);
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
谢谢
编辑1:我很着急,所以我采用了这里提出的解决方案(手动更改app.config文件后直接文件访问 - 使用appSettings而不是applicationSettings):http:
//www.longhorncorner.com/uploadfile/rahul4_saxena /update-app-config-key-value-at-run-time-in-wpf/
我正在尝试为我的应用创建"设置"表格视图.我试图模仿它与Iphone上的gneral设置相同的风格.我通过继承UITableCell创建了自己的自定义单元类.我给了它适当的IBOulets,我把它们挂在故事板上.我也把开关连接到我的tableViewControler,但由于某种原因,我的代码只返回一个空单元格(只有一个单元格不是问题atm,因为我在我的设置中都有).我三重检查并确保我在我的代码和故事板中使用相同的单元格标识符.任何人都知道为什么我要回一个空白的单元格?
这是我的自定义单元格的.h文件.
@interface NHPSettingsCell : UITableViewCell
@property (nonatomic,weak) IBOutlet UILabel *settingLabel;
@property (nonatomic,strong) IBOutlet UISwitch *settingSwitch;
@end
Run Code Online (Sandbox Code Playgroud)
我的问题代码在这里,我的自定义单元格的.h文件:
#import "NHPSettingsCell.h"
@implementation NHPSettingsCell
@synthesize settingLabel, settingSwitch;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end
Run Code Online (Sandbox Code Playgroud)
我在自定义视图控制器中绘制单元格的方法:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"SettingsCell";
NHPSettingsCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; …
Run Code Online (Sandbox Code Playgroud) 我在 Azure 中有一个 Web 应用程序,我在其应用程序设置中配置了 connectionStrgin,但我不知道如何将此配置设置为应用程序 web.config (.Net) 中的环境变量。
有人有一些文档或知道如何使这成为可能,到目前为止我已经查看了 Microsoft 和其他站点的文档以进行故障排除,但我一直无法找到解决方案
.net connection-string web-config azure application-settings
我想为iOS应用程序构建一个设置界面.
注意 - 这些设置通常会更改,所以我更喜欢设置界面应用程序而不是设置包
我的想法
问题:
在模态视图中,似乎没有出现导航栏.我需要导航栏,以便我可以在其上创建一个"保存"按钮?
为了解决上面提到的问题,我创建了一个UIViewController来管理设置视图,并在UIViewController的视图下添加了一个导航栏和一个表视图(使用UITableViewController使导航栏与单元格一起滚动)
但是创建一个UIViewController不允许我创建一个包含静态内容的表
问题:
.net ×4
c# ×4
ios ×3
app-config ×2
appsettings ×2
settings ×2
uitableview ×2
winforms ×2
asp.net ×1
azure ×1
c++ ×1
iphone ×1
performance ×1
radio-button ×1
segue ×1
static ×1
unit-testing ×1
visual-c++ ×1
web-config ×1
wpf ×1