ComplianceServer/oldcode/WX.CRM.DataSynServer/Socket/Config.cs

172 lines
5.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Configuration;
using System.Text;
namespace WX.CRM.DataSynServer.Socket
{
public static class Config
{
/// <summary>
/// 系统Secrect 非常重要
/// </summary>
public static string SystemSecrect
{
get
{
var value = ConfigurationManager.AppSettings[$"{nameof(SystemSecrect)}"];
if (string.IsNullOrEmpty(value))
throw new Exception($"请在配置文件中配置{nameof(SystemSecrect)}");
return value;
}
}
/// <summary>
/// Token过期时间 非常重要
/// </summary>
public static string TokenExpireMinutes
{
get
{
var value = ConfigurationManager.AppSettings[$"{nameof(TokenExpireMinutes)}"];
if (string.IsNullOrEmpty(value))
throw new Exception($"请在配置文件中配置{nameof(TokenExpireMinutes)}");
return value;
}
}
/// <summary>
/// 服务IP地址
/// </summary>
public static string ServerIp
{
get
{
var value = ConfigurationManager.AppSettings[$"{nameof(ServerIp)}"];
if (string.IsNullOrEmpty(value))
throw new Exception($"请在配置文件中配置{nameof(ServerIp)}");
return value;
}
}
/// <summary>
/// 服务端口
/// </summary>
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)}必须为整数");
}
}
/// <summary>
/// Socket协议起止符
/// </summary>
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);
}
}
/// <summary>
/// Socket协议结束符
/// </summary>
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);
}
}
/// <summary>
/// 日志Socket服务配置文件名
/// </summary>
public static string LogServiceConfigFileName
{
get
{
var value = ConfigurationManager.AppSettings[$"{nameof(LogServiceConfigFileName)}"];
if (string.IsNullOrEmpty(value))
throw new Exception($"请在配置文件中配置{nameof(LogServiceConfigFileName)}");
return value;
}
}
/// <summary>
/// 管理站点服务地址
/// </summary>
public static string ServiceHost
{
get
{
var value = ConfigurationManager.AppSettings[$"{nameof(ServiceHost)}"];
if (string.IsNullOrEmpty(value))
throw new Exception($"请在配置文件中配置{nameof(ServiceHost)}");
return value;
}
}
/// <summary>
/// 管理站点服务端口
/// </summary>
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;
}
}
/// <summary>
/// 管理站点WebSocket端口
/// </summary>
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;
}
}
}
}