123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- 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
- {
- /// <summary>
- /// 链接管理
- /// </summary>
- public class UrlManager
- {
- private string servicePath;
- /// <summary>
- /// 后台服务地址
- /// </summary>
- public string ServicePath
- {
- get
- {
- if (servicePath == null)
- {
- servicePath = GetConfigurationValue();
- }
- return servicePath;
- }
- }
- private string dataServicePath;
- /// <summary>
- /// 数据地址
- /// </summary>
- public string DataServicePath
- {
- get
- {
- if (dataServicePath == null)
- {
- dataServicePath = GetConfigurationValue();
- }
- return dataServicePath;
- }
- }
- private string alarmPath;
- /// <summary>
- /// 报警地址
- /// </summary>
- public string AlarmPath
- {
- get
- {
- if (alarmPath == null)
- {
- alarmPath = GetConfigurationValue();
- }
- return alarmPath;
- }
- }
- private string serviceSocketPath;
- /// <summary>
- /// 后台推送地址
- /// </summary>
- public string ServiceSocketPath
- {
- get
- {
- if (serviceSocketPath == null)
- {
- serviceSocketPath = GetConfigurationValue();
- }
- return serviceSocketPath;
- }
- }
- private string adapterSocketPath;
- /// <summary>
- /// 数据推送地址
- /// </summary>
- public string AdapterSocketPath
- {
- get
- {
- if (adapterSocketPath == null)
- {
- adapterSocketPath = GetConfigurationValue();
- }
- return adapterSocketPath;
- }
- }
- private int windturbineDetailsInterval = -777;
- /// <summary>
- /// 风机详情页弹窗时间间隔
- /// </summary>
- 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;
- }
- }
- /// <summary>
- /// 获取配置文件值
- /// </summary>
- 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 "";
- }
- }
- }
- }
|