标签: configuration

如何在 WPF 中使用外部配置文件?

我想设置一个外部配置文件,我可以将它存储在我的 WPF 应用程序的目录中,也不一定是我创建程序时的 exe 目录。

我创建了一个 App.Config 文件并将 System.Configuration 添加到我的程序集中。我的 App.Config 有:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings file="sd.config">
   <add key="username" value="joesmith" />
  </appSettings>
</configuration>
Run Code Online (Sandbox Code Playgroud)

我的 sd.config(外部文件)现在在我的项目的根目录中,有

<?xml version="1.0"?>
 <appSettings>
   <add key="username1" value="janedoe" />
</appSettings>
Run Code Online (Sandbox Code Playgroud)

在我使用的 MainWindow cs 类中

string username = ConfigurationManager.AppSettings.Get("username1");
Run Code Online (Sandbox Code Playgroud)

它返回一个空字符串。当我刚刚从 App.Config 检索用户名字段时,它可以工作。我错过了什么?非常感谢!

wpf configuration external

0
推荐指数
1
解决办法
4075
查看次数

jaxb2 maven插件和执行标签内的配置

我尝试使用 JAXB2 maven 插件从一堆 .xsd 文件生成 java 代码。如果我尝试在一次执行中从所有 xsd 生成,我将得到org.xml.sax.SAXParseException: 'root' is already defined. 我无法修改 xsd 文件,因此我需要独立生成每个文件。我找到了以下 pom 配置来实现这一目标:

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.3</version>
<executions>
    <execution>
        <id>jaxb-Execution1</id>
        <phase>generate-sources</phase>
        <goals><goal>xjc</goal></goals>
        <configuration>
            <schemaDirectory>${jaxbSchemaDirectory}</schemaDirectory>
            <outputDirectory>${jaxbGenerateDirectory}</outputDirectory>
            <staleFile>${jaxbGenerateDirectory}/.staleFlagExecution1</staleFile>
            <bindingDirectory>${jaxbSchemaDirectory}</bindingDirectory>
            <bindingFiles>bindings1.xml</bindingFiles>
            <schemaFiles>schema1.xsd</schemaFiles>
            <clearOutputDir>false</clearOutputDir>
        </configuration>
    </execution>
    <execution>
        <id>jaxb-Execution2</id>
        <phase>generate-sources</phase>
        <goals><goal>xjc</goal></goals>
        <configuration>
            <schemaDirectory>${jaxbSchemaDirectory}</schemaDirectory>
            <outputDirectory>${jaxbGenerateDirectory}</outputDirectory>
            <staleFile>${jaxbGenerateDirectory}/.staleFlagExecution2</staleFile>
            <bindingDirectory>${jaxbSchemaDirectory}</bindingDirectory>
            <bindingFiles>bindings2.xml</bindingFiles>
            <schemaFiles>schema2.xsd</schemaFiles>
            <clearOutputDir>false</clearOutputDir>
        </configuration>
    </execution>
</executions>
Run Code Online (Sandbox Code Playgroud)

但这是行不通的。问题是配置不是从执行块内部读取的。这是为什么?我使用的是maven 2.2.1。

configuration jaxb2 maven

0
推荐指数
1
解决办法
3483
查看次数

使用 glib 从配置文本中读取值

我有以下 Config.cfg

[Power]
Power8=8
Temp=5=1001
Hum=7=1002
Link=8=1003
Vol=9=1004

[Power]
Power10=10
Temp=5=1012
Hum=7=1013
Link=8=1014
Vol=9=1015
Run Code Online (Sandbox Code Playgroud)

通过使用 glib,我想读取每个 Power 的值。我想要类似“如果 Power8=8 则返回 temp、hum、Link、Vol”的内容,否则 Power10=10 的情况相同

我写了这个函数

int read_config()
{

 GKeyFile *keyfile;
 GKeyFileFlags flags;
 GError *error = NULL;
 gsize length;
 gchar *temperatura, *humedad, *link, *voltage;


 // Create a new GKeyFile object and a bitwise list of flags.
 keyfile = g_key_file_new ();
 flags = G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS;

 // Load the GKeyFile from keyfile.conf or return.
 if (!g_key_file_load_from_file (keyfile, "/home/pi/Desktop/Config.cfg", flags, &error))
 {
   g_error (error->message); …
Run Code Online (Sandbox Code Playgroud)

c configuration glib

0
推荐指数
1
解决办法
4261
查看次数

Visual Studio 上的 OpenCV 设置问题

我正在尝试在 64 位 Windows 7 系统中使用 Microsoft Visual Studio 2008 设置一个简单的 OpenCV 项目。我没有系统的管理员权限,因此,我不能在这里全新安装 OpenCV。

但是,我确实有在类似平台上编译的 OpenCV 的 bin、include 和 lib 目录。

我启动了一个“Visual C++ -> General -> Empty Project”并创建了一个 .cpp 文件,内容如下:

#include <opencv/cv.h>
#include <opencv/highgui.h>
void main()
{
    cv::Mat frame = cv::imread("D:\\Images\\lena.bmp");
    cv::imwrite("D:\\lena_bw.bmp",frame);
}
Run Code Online (Sandbox Code Playgroud)

在'Property->Configuration Property->C/C++->General->Additional Include Directories'中,我提供了OpenCV的'include'目录的链接。

在“属性->配置属性->链接器->输入->附加依赖项”中,我提供了opencv_core230.lib、opencv_highgui230.lib、opencv_imgproc230.lib等的路径。

代码构建良好,但是当我运行它时,我得到:

Unhandled exception at 0x734761e7 in OpenCVTest.exe: 0xC0000005: Access violation reading location 0xcccccccc.

No symbols are loaded for any call stack frame. The source code cannot be displayed.
Run Code Online (Sandbox Code Playgroud)

我对自己的想法无所适从。我对 Visual Studio 平台有点陌生。 …

configuration opencv visual-studio visual-c++

0
推荐指数
1
解决办法
2172
查看次数

Spring StateMachine 配置:使用 @EnableStateMachineFactory 时命名 StateMachine

我想包含StateMachine使用StateMachineFactory. 但@EnableStateMachineFactory注释允许命名工厂。如何命名每个 Config (即扩展EnumStateMachineConfigurerAdapter)?

setMachineID否则,如果可能的话,提供一个如何在配置定义中使用该方法的示例将会很有用。

configuration factory spring-statemachine

0
推荐指数
1
解决办法
1170
查看次数

Yii2 覆盖嵌套配置参数

我以这种方式合并我的配置:

$config = \yii\helpers\ArrayHelper::merge(
    (require (__DIR__ . '/../config/web.php')),
    (require __DIR__ . '/../config/overrides/web.php')
);
Run Code Online (Sandbox Code Playgroud)

这是config/web.php

$config = [
    'components' => [
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
                [
                    'class' => 'yii\log\EmailTarget',
                    'levels' => ['info'],
                    'categories' => ['parsingFailure'],
                    'logVars' => [],
                    'message' => [
                        'from' => ['system@host.com'],
                        'to' => ['support@host.com'],
                        'subject' => 'Message parsing failure',
                    ],
                ],
            ],
        ],
        //....some more components
    ]
];
Run Code Online (Sandbox Code Playgroud)

这是我尝试应用的覆盖 …

merge configuration yii2

0
推荐指数
1
解决办法
751
查看次数

Angular 2:为 api 端点定义全局常量

我是 Angular2 的新手。我想要一个单一的类或一个配置文件,其中包含我可以在所有服务中注入的所有 API 端点(允许参数等在不同的路由中)。在 Angular2 中这样做的最佳方法是什么?我的意思是,我应该像定义服务时那样定义一个 @Injectable 类(然后将它添加到我的服务的提供者中)。

我发现的问题是,当我将我的 api 部署到客户端部分的服务器上时,我必须更改所有以字符串格式调用的端点,因此如果我有许多端点可以使用,这将是浪费时间。

在此示例中,我使用字符串格式的端点调用服务:

getData() {
    return this._http.get('http://localhost:8000/cartography')
      .map(function(res) {
        const jsonArray = res.json();
        const newJsonArr = [];
        for ( let i = 0; i < jsonArray.length; i++) {
          const object = {
            post_name : jsonArray[i].name,
            employment_name : jsonArray[i].employment.name,
            profession_name : jsonArray[i].employment.profession.name,
            family_name : jsonArray[i].employment.profession.family.name
          };
          newJsonArr.push(object);
        }
          return newJsonArr;
      });
  }
Run Code Online (Sandbox Code Playgroud)

所以我正在寻找一种在类或配置文件中将其定义为全局变量的方法。任何帮助请!谢谢 。

api configuration web-services endpoint angular

0
推荐指数
1
解决办法
6495
查看次数

在Laravel中获取所有ENV变量

Laravel有一个.env文件,其中包含各种变量。有没有一种方法可以在一行PHP代码中获取所有变量?我不想写

echo env('APP_DEBUG')
echo env('APP_URL')
etc...
Run Code Online (Sandbox Code Playgroud)

我试过了

env("*")
env("*")
Run Code Online (Sandbox Code Playgroud)

但没有办法。

php configuration environment-variables laravel

0
推荐指数
2
解决办法
299
查看次数

无法让 Xdebug 与 Lando 和 VSCode 一起工作。立即连接并停止

我已经浏览了我能找到的关于这个主题的所有帖子,但我找不到解决方案。因此,与其将头发拉得更远,我将发布一个问题。

我有一个 Lando 安装(运行 Drupal 8,但我正在测试一个简单的phpinfo()脚本),Xdebug 确认正在运行。每当我添加断点并运行脚本时,它都无法停止。

用于 Xdebug 的自定义 Lando .ini:

[PHP]

Xdebug
xdebug.max_nesting_level = 256
xdebug.show_exception_trace = 0
xdebug.collect_params = 0
; Extra custom Xdebug setting for debug to work in VSCode.
xdebug.remote_enable = 1
xdebug.remote_port = 9000
xdebug.remote_handler = "dbgp"
xdebug.remote_host = ${LANDO_HOST_IP}
xdebug.remote_connect_back = 0
xdebug.remote_mode = req
xdebug.remote_autostart = On
xdebug.remote_log = /tmp/xdebug.log
xdebug.idekey = VSCODE

max_execution_time = 0
Run Code Online (Sandbox Code Playgroud)

xdebug.log 的输出

245] Log opened at 2020-09-09 14:42:21
[245] I: Connecting to configured address/port: …
Run Code Online (Sandbox Code Playgroud)

configuration xdebug visual-studio-code lando

0
推荐指数
1
解决办法
826
查看次数

TYPO3 10 LTS:使 .scss 文件在后端可编辑,就像 .css 文件一样

在 TYPO3 v10 LTS 中,作为后端管理员用户,我可以.css在“文件资源管理器”(在 Filelist 模块中可用。我不知道正确的术语)中编辑文件。请参阅屏幕截图。

Typ3 css 文件 - 存在编辑对话框

当文件具有 .css 扩展名 (1) 时,我可以单击“编辑内容”图标 (2),然后会打开一个编辑器窗口。


但是,当我将文件重命名为.scss(1) 时,我无法再编辑该文件。“编辑”图标不再可用 (2)。见下文:

Typ3 css 文件 - 不存在编辑对话框

有没有办法.scss.css文件一样使文件可编辑?一些设置,或 TypoScript/PageTS 配置参数?如果需要,我还可以修补源代码。

configuration typo3 typo3-10.x

0
推荐指数
1
解决办法
22
查看次数