161 lines
5.5 KiB
C#
161 lines
5.5 KiB
C#
|
using System;
|
|||
|
using System.IO;
|
|||
|
using System.Xml;
|
|||
|
|
|||
|
namespace HL_FristAidPlatform_POCTWindowsService
|
|||
|
{
|
|||
|
public class Config : IDisposable
|
|||
|
{
|
|||
|
#region 属性
|
|||
|
/// <summary>
|
|||
|
/// 系统用于标志此服务的名称
|
|||
|
/// </summary>
|
|||
|
public string ServiceName;
|
|||
|
/// <summary>
|
|||
|
/// 向用户标志服务的友好名称
|
|||
|
/// </summary>
|
|||
|
public string DisplayName;
|
|||
|
/// <summary>
|
|||
|
/// 服务的说明
|
|||
|
/// </summary>
|
|||
|
public string ServiceDescription;
|
|||
|
/// <summary>
|
|||
|
/// 监听端口
|
|||
|
/// </summary>
|
|||
|
public int StrPort;
|
|||
|
/// <summary>
|
|||
|
/// 是否开启调试模式 True:开启,记录错误日志;False:不开启,日常运行
|
|||
|
/// </summary>
|
|||
|
public bool IsDebug;
|
|||
|
/// <summary>
|
|||
|
/// 数据库连接字符
|
|||
|
/// </summary>
|
|||
|
public string StrCon;
|
|||
|
/// <summary>
|
|||
|
/// 胸痛中心系统 模块编号
|
|||
|
/// </summary>
|
|||
|
public string ChestPain;
|
|||
|
/// <summary>
|
|||
|
/// 卒中中心系统 模块编号
|
|||
|
/// </summary>
|
|||
|
public string Apoplexy;
|
|||
|
/// <summary>
|
|||
|
/// 创伤救治中心系统 模块编号
|
|||
|
/// </summary>
|
|||
|
public string Trauma;
|
|||
|
/// <summary>
|
|||
|
/// 危重孕产妇救治中心系统 模块编号
|
|||
|
/// </summary>
|
|||
|
public string CriticalPregnant;
|
|||
|
/// <summary>
|
|||
|
/// 危重新生儿救治中心系统 模块编号
|
|||
|
/// </summary>
|
|||
|
public string CriticalNeonatal;
|
|||
|
#endregion
|
|||
|
|
|||
|
#region 构造函数
|
|||
|
/// <summary>
|
|||
|
/// 初始化服务配置帮助类
|
|||
|
/// </summary>
|
|||
|
public Config()
|
|||
|
{
|
|||
|
InitSettings();
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region 私有方法
|
|||
|
#region 初始化服务配置信息
|
|||
|
/// <summary>
|
|||
|
/// 初始化服务配置信息
|
|||
|
/// </summary>
|
|||
|
private void InitSettings()
|
|||
|
{
|
|||
|
string root = System.Reflection.Assembly.GetExecutingAssembly().Location;
|
|||
|
string xmlfile = root.Remove(root.LastIndexOf('\\') + 1) + "HL_FristAidPlatform_POCTWindowsService.exe.config";
|
|||
|
if (File.Exists(xmlfile))
|
|||
|
{
|
|||
|
//系统用于标志此服务名称(唯一性)
|
|||
|
ServiceName = Get_ConfigValue(xmlfile, "ServiceName");
|
|||
|
//向用户标志服务的显示名称(可以重复)
|
|||
|
DisplayName = Get_ConfigValue(xmlfile, "DisplayName");
|
|||
|
//服务的说明(描述)
|
|||
|
ServiceDescription = Get_ConfigValue(xmlfile, "ServiceDescription");
|
|||
|
//监听端口
|
|||
|
StrPort = Convert.ToInt32(Get_ConfigValue(xmlfile, "StrPort"));
|
|||
|
//是否开启调试模式 True:开启,记录错误日志;False:不开启,日常运行
|
|||
|
IsDebug = Convert.ToBoolean(Get_ConfigValue(xmlfile, "IsDebug"));
|
|||
|
//数据库连接字符
|
|||
|
StrCon = Get_ConfigValue(xmlfile, "StrCon");
|
|||
|
//胸痛中心系统 模块编号
|
|||
|
ChestPain = Get_ConfigValue(xmlfile, "ChestPain");
|
|||
|
//卒中中心系统 模块编号
|
|||
|
Apoplexy = Get_ConfigValue(xmlfile, "Apoplexy");
|
|||
|
//创伤救治中心系统 模块编号
|
|||
|
Trauma = Get_ConfigValue(xmlfile, "Trauma");
|
|||
|
//危重孕产妇救治中心系统 模块编号
|
|||
|
CriticalPregnant = Get_ConfigValue(xmlfile, "CriticalPregnant");
|
|||
|
//危重新生儿救治中心系统 模块编号
|
|||
|
CriticalNeonatal = Get_ConfigValue(xmlfile, "CriticalNeonatal");
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
throw new FileNotFoundException("未能找到服务名称配置文件 HL_FristAidPlatform_POCTWindowsService.exe.config!路径:" + xmlfile);
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 读取 XML中指定节点值
|
|||
|
/// </summary>
|
|||
|
/// <param name="configpath">配置文件路径</param>
|
|||
|
/// <param name="strKeyName">键值</param>
|
|||
|
/// <returns></returns>
|
|||
|
protected static string Get_ConfigValue(string configpath, string strKeyName)
|
|||
|
{
|
|||
|
using (XmlTextReader tr = new XmlTextReader(configpath))
|
|||
|
{
|
|||
|
while (tr.Read())
|
|||
|
{
|
|||
|
if (tr.NodeType == XmlNodeType.Element)
|
|||
|
{
|
|||
|
if (tr.Name == "add" && tr.GetAttribute("key") == strKeyName)
|
|||
|
{
|
|||
|
return tr.GetAttribute("value");
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
return "";
|
|||
|
}
|
|||
|
#endregion
|
|||
|
#endregion
|
|||
|
|
|||
|
#region IDisposable 成员
|
|||
|
private bool disposed = false;
|
|||
|
public void Dispose()
|
|||
|
{
|
|||
|
Dispose(true);
|
|||
|
GC.SuppressFinalize(this);
|
|||
|
}
|
|||
|
protected virtual void Dispose(bool disposing)
|
|||
|
{
|
|||
|
if (!this.disposed)
|
|||
|
{
|
|||
|
if (disposing)
|
|||
|
{
|
|||
|
//managed dispose
|
|||
|
ServiceName = null;
|
|||
|
DisplayName = null;
|
|||
|
ServiceDescription = null;
|
|||
|
}
|
|||
|
//unmanaged dispose
|
|||
|
}
|
|||
|
disposed = true;
|
|||
|
}
|
|||
|
~Config()
|
|||
|
{
|
|||
|
Dispose(false);
|
|||
|
}
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|