using System;
using System.Configuration;
using System.Text;
namespace WX.CRM.DataSynServer.Socket
{
public static class Config
{
///
/// 系统Secrect 非常重要
///
public static string SystemSecrect
{
get
{
var value = ConfigurationManager.AppSettings[$"{nameof(SystemSecrect)}"];
if (string.IsNullOrEmpty(value))
throw new Exception($"请在配置文件中配置{nameof(SystemSecrect)}");
return value;
}
}
///
/// Token过期时间 非常重要
///
public static string TokenExpireMinutes
{
get
{
var value = ConfigurationManager.AppSettings[$"{nameof(TokenExpireMinutes)}"];
if (string.IsNullOrEmpty(value))
throw new Exception($"请在配置文件中配置{nameof(TokenExpireMinutes)}");
return value;
}
}
///
/// 服务IP地址
///
public static string ServerIp
{
get
{
var value = ConfigurationManager.AppSettings[$"{nameof(ServerIp)}"];
if (string.IsNullOrEmpty(value))
throw new Exception($"请在配置文件中配置{nameof(ServerIp)}");
return value;
}
}
///
/// 服务端口
///
public static int ServerPort
{
get
{
var value = ConfigurationManager.AppSettings[$"{nameof(ServerPort)}"];
if (string.IsNullOrEmpty(value))
throw new Exception($"请在配置文件中配置{nameof(ServerPort)}");
if (int.TryParse(value, out int res))
return res;
throw new Exception($"{nameof(ServerPort)}必须为整数");
}
}
///
/// Socket协议起止符
///
public static byte[] BeginMark
{
get
{
var value = ConfigurationManager.AppSettings[$"{nameof(BeginMark)}"];
if (string.IsNullOrEmpty(value))
throw new Exception($"请在配置文件中配置{nameof(BeginMark)}");
return Encoding.UTF8.GetBytes(value);
}
}
///
/// Socket协议结束符
///
public static byte[] EndMark
{
get
{
var value = ConfigurationManager.AppSettings[$"{nameof(EndMark)}"];
if (string.IsNullOrEmpty(value))
throw new Exception($"请在配置文件中配置{nameof(EndMark)}");
return Encoding.UTF8.GetBytes(value);
}
}
public static string BeginMarkStr
{
get
{
return Encoding.UTF8.GetString(BeginMark);
}
}
public static string EndMarkStr
{
get
{
return Encoding.UTF8.GetString(EndMark);
}
}
///
/// 日志Socket服务配置文件名
///
public static string LogServiceConfigFileName
{
get
{
var value = ConfigurationManager.AppSettings[$"{nameof(LogServiceConfigFileName)}"];
if (string.IsNullOrEmpty(value))
throw new Exception($"请在配置文件中配置{nameof(LogServiceConfigFileName)}");
return value;
}
}
///
/// 管理站点服务地址
///
public static string ServiceHost
{
get
{
var value = ConfigurationManager.AppSettings[$"{nameof(ServiceHost)}"];
if (string.IsNullOrEmpty(value))
throw new Exception($"请在配置文件中配置{nameof(ServiceHost)}");
return value;
}
}
///
/// 管理站点服务端口
///
public static int ServicePort
{
get
{
var value = ConfigurationManager.AppSettings[$"{nameof(ServicePort)}"];
if (string.IsNullOrEmpty(value))
throw new Exception($"请在配置文件中配置{nameof(ServicePort)}");
if (!int.TryParse(value, out int res))
throw new Exception("管理站点服务端口只能为整数!");
return res;
}
}
///
/// 管理站点WebSocket端口
///
public static int ServiceWebSocketPort
{
get
{
var value = ConfigurationManager.AppSettings[$"{nameof(ServiceWebSocketPort)}"];
if (string.IsNullOrEmpty(value))
throw new Exception($"请在配置文件中配置{nameof(ServiceWebSocketPort)}");
if (!int.TryParse(value, out int res))
throw new Exception("管理站点WebSocket端口只能为整数!");
return res;
}
}
}
}