using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace NEIntelligentControl2.Service.WebSocket
{
///
/// 链接管理
///
public class UrlManager
{
private string servicePath;
///
/// 后台服务地址
///
public string ServicePath
{
get
{
if (servicePath == null)
{
servicePath = GetConfigurationValue();
}
return servicePath;
}
}
private string dataServicePath;
///
/// 数据地址
///
public string DataServicePath
{
get
{
if (dataServicePath == null)
{
dataServicePath = GetConfigurationValue();
}
return dataServicePath;
}
}
private string alarmPath;
///
/// 报警地址
///
public string AlarmPath
{
get
{
if (alarmPath == null)
{
alarmPath = GetConfigurationValue();
}
return alarmPath;
}
}
private string serviceSocketPath;
///
/// 后台推送地址
///
public string ServiceSocketPath
{
get
{
if (serviceSocketPath == null)
{
serviceSocketPath = GetConfigurationValue();
}
return serviceSocketPath;
}
}
private string adapterSocketPath;
///
/// 数据推送地址
///
public string AdapterSocketPath
{
get
{
if (adapterSocketPath == null)
{
adapterSocketPath = GetConfigurationValue();
}
return adapterSocketPath;
}
}
private int windturbineDetailsInterval = -777;
///
/// 风机详情页弹窗时间间隔
///
public int WindturbineDetailsInterval
{
get
{
if (windturbineDetailsInterval == -777)
{
windturbineDetailsInterval = GetConfigurationValueInt();
}
return windturbineDetailsInterval;
}
}
private int GetConfigurationValueInt([CallerMemberName] string name = null)
{
if (name == null) return 0;
try
{
var v = ConfigurationManager.AppSettings[name];
int.TryParse(v, out int d);
return d;
}
catch (Exception ex)
{
Console.WriteLine($"读取配置文件[{name}]出错!", ex);
return 0;
}
}
///
/// 获取配置文件值
///
private string GetConfigurationValue([CallerMemberName] string name = null)
{
if (name == null) return "";
try
{
#if (DEBUG)
name += "Debug";
#endif
return ConfigurationManager.AppSettings[name];
}
catch (Exception ex)
{
Console.WriteLine($"读取配置文件[{name}]出错!", ex);
return "";
}
}
}
}