-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfigInfo.cs
More file actions
159 lines (138 loc) · 4.61 KB
/
ConfigInfo.cs
File metadata and controls
159 lines (138 loc) · 4.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
namespace Bat4WindowsService
{
/// <summary>
/// @author: liusx
/// @repository: https://github.com/l634666/Bat4WindowsService
/// </summary>
internal class ConfigInfo
{
/// <summary>
/// 日志配置项key
/// </summary>
private static readonly string LOG_FILE_PATH_KEY = "LogFilePath";
/// <summary>
/// 环境脚本配置项key
/// </summary>
private static readonly string SETENV_BAT_FILE_PATH_KEY = "SetenvBatFilePath";
/// <summary>
/// 启动脚本配置项key
/// </summary>
private static readonly string STARTUP_BAT_FILE_PATH_KEY = "StartupBatFilePath";
/// <summary>
/// 停止脚本配置项key
/// </summary>
private static readonly string SHUTDOWN_BAT_FILE_PATH_KEY = "ShutdownBatFilePath";
/// <summary>
/// 日志配置项key
/// </summary>
private static string _LogFilePath = "";
/// <summary>
/// 环境脚本配置项
/// </summary>
private static string _SetenvBatFilePath;
/// <summary>
/// 启动脚本配置项
/// </summary>
private static string _StartupBatFilePath;
/// <summary>
/// 停止脚本配置项
/// </summary>
private static string _ShutdownBatFilePath;
/// <summary>
/// 私有构造,不允许创建实例
/// </summary>
private ConfigInfo() { }
/// <summary>
/// 设置信息
/// </summary>
private static Dictionary<string, string> _AppSettings = new Dictionary<string, string>();
/// <summary>
/// 初始化配置信息
/// </summary>
internal static void Init()
{
//从配置文件加载配置项
LoadAppSettings();
}
/// <summary>
/// 加载配置项
/// </summary>
private static void LoadAppSettings()
{
NameValueCollection settings = System.Configuration.ConfigurationManager.AppSettings;
string[] keys = settings.AllKeys;
foreach (string key in keys)
{
_AppSettings.Add(key, settings[key]);
}
// 日志文件配置项
if (_AppSettings.ContainsKey(LOG_FILE_PATH_KEY))
{
_LogFilePath = _AppSettings[LOG_FILE_PATH_KEY];
}
// 环境脚本配置项
if (_AppSettings.ContainsKey(SETENV_BAT_FILE_PATH_KEY))
{
_SetenvBatFilePath = _AppSettings[SETENV_BAT_FILE_PATH_KEY];
}
//启动脚本配置项
if (_AppSettings.ContainsKey(STARTUP_BAT_FILE_PATH_KEY))
{
_StartupBatFilePath = _AppSettings[STARTUP_BAT_FILE_PATH_KEY];
}
//停止脚本配置项
if (_AppSettings.ContainsKey(SHUTDOWN_BAT_FILE_PATH_KEY))
{
_ShutdownBatFilePath = _AppSettings[SHUTDOWN_BAT_FILE_PATH_KEY];
}
}
/// <summary>
/// 获取设置项的值
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
private static string getAppSettingValue(string key)
{
return getAppSettingValue(key, "");
}
/// <summary>
/// 获取设置项的值,传入默认值
/// </summary>
/// <param name="key"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
private static string getAppSettingValue(string key, string defaultValue)
{
string value = "";
if (_AppSettings.ContainsKey(key))
{
value = _AppSettings[key];
}
return String.IsNullOrEmpty(value) ? defaultValue : value;
}
/// <summary>
/// 日志文件配置项
/// </summary>
///
public static string LogFilePath { get => _LogFilePath; }
/// <summary>
/// 环境脚本配置项
/// </summary>
public static string SetenvBatFilePath
{
get => _SetenvBatFilePath;
}
/// <summary>
/// 启动脚本配置项
/// </summary>
public static string StartupBatFilePath { get => _StartupBatFilePath; }
/// <summary>
/// 停止脚本配置项
/// </summary>
///
public static string ShutdownBatFilePath { get => _ShutdownBatFilePath; }
}
}