|
@@ -17,6 +17,7 @@ using WingInterfaceLibrary.DB.Request;
|
|
|
using System.IO;
|
|
|
using WingServerCommon.Config;
|
|
|
using WingServerCommon.Config.Parameters;
|
|
|
+using WingCloudServer.Loader;
|
|
|
|
|
|
namespace WingCloudServer.InteractionCenter
|
|
|
{
|
|
@@ -31,7 +32,9 @@ namespace WingCloudServer.InteractionCenter
|
|
|
|
|
|
private ITokenDBService _tokenDBService;
|
|
|
|
|
|
- private string _folderBase = AppDomain.CurrentDomain.BaseDirectory + "Resource\\IP\\";
|
|
|
+ private IPFilesWatcher _iPFilesWatcher;//监控IP文件热更新重新加载内存中
|
|
|
+
|
|
|
+ private string _folderBase = AppDomain.CurrentDomain.BaseDirectory + "Resource\\IP\\";
|
|
|
|
|
|
private bool _isEnableIPLocation = ConfigurationManager.GetParammeter<BoolParameter>("IPLocation", "Enable").Value;
|
|
|
|
|
@@ -148,6 +151,33 @@ namespace WingCloudServer.InteractionCenter
|
|
|
LoadDBServerInfo();
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 加载IP文件
|
|
|
+ /// </summary>
|
|
|
+ private void LoadDataIPFiles()
|
|
|
+ {
|
|
|
+ if (_isEnableIPLocation)
|
|
|
+ {
|
|
|
+ Task.Run(() =>
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+
|
|
|
+ var ipManager = CacheMaintenance.Instance.Get<IIPManager>();
|
|
|
+ if (ipManager != null)
|
|
|
+ {
|
|
|
+ ipManager.LoadData(_folderBase);
|
|
|
+ Logger.WriteLineInfo($"VinnoServerService LoadDataIPFiles end");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ Logger.WriteLineWarn($"VinnoServerService LoadDataIPFiles err, {ex}");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
/// <summary>
|
|
|
/// 加载ServerInfo到内存
|
|
|
/// </summary>
|
|
@@ -158,44 +188,41 @@ namespace WingCloudServer.InteractionCenter
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
- int tryCount = 1;
|
|
|
- IList<CacheDistributedServerInfosDTO> serverInformationList = null;
|
|
|
- while (true)
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- serverInformationList = await GetServerInformationList(null);
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- Logger.WriteLineError($"ServerInfo Cache Init Error:{ex}");
|
|
|
- }
|
|
|
- if (serverInformationList != null)
|
|
|
- {
|
|
|
- break;
|
|
|
- }
|
|
|
- tryCount++;
|
|
|
- if (tryCount > 10)
|
|
|
- {
|
|
|
- break;
|
|
|
- }
|
|
|
- await Task.Delay(500);
|
|
|
- }
|
|
|
- CacheMaintenance.Instance.Get<IDistributedServerInfosManager>().LoadFromDbOject(serverInformationList);
|
|
|
- if (_isEnableIPLocation)
|
|
|
- {
|
|
|
- var ipManager = CacheMaintenance.Instance.Get<IIPManager>();
|
|
|
- if (ipManager != null)
|
|
|
- {
|
|
|
- ipManager.LoadData(_folderBase);
|
|
|
- }
|
|
|
- }
|
|
|
+ int tryCount = 1;
|
|
|
+ IList<CacheDistributedServerInfosDTO> serverInformationList = null;
|
|
|
+ while (true)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ serverInformationList = await GetServerInformationList(null);
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ Logger.WriteLineError($"ServerInfo Cache Init Error:{ex}");
|
|
|
+ }
|
|
|
+ if (serverInformationList != null)
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ tryCount++;
|
|
|
+ if (tryCount > 10)
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ await Task.Delay(500);
|
|
|
+ }
|
|
|
+ CacheMaintenance.Instance.Get<IDistributedServerInfosManager>().LoadFromDbOject(serverInformationList);
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
Logger.WriteLineWarn($"VinnoServerService LoadDBServerInfo err, {ex}");
|
|
|
}
|
|
|
});
|
|
|
+ LoadDataIPFiles();
|
|
|
+ if (_isEnableIPLocation) //IP 文件变动热更新
|
|
|
+ {
|
|
|
+ _iPFilesWatcher=new IPFilesWatcher(_folderBase, LoadDataIPFiles);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -250,7 +277,8 @@ namespace WingCloudServer.InteractionCenter
|
|
|
/// <returns>是否成功</returns>
|
|
|
public async Task<bool> UpdateServerIPListAsync(UpdateServerIPListRequest request)
|
|
|
{
|
|
|
- if (string.IsNullOrEmpty(request.Name) || request.IpRange == null || request.IpRange.Count <= 0) {
|
|
|
+ if (string.IsNullOrEmpty(request.Name) || request.IpRange == null || request.IpRange.Count <= 0)
|
|
|
+ {
|
|
|
Logger.WriteLineError($"UpdateServerIPListAsync Empty Error");
|
|
|
return false;
|
|
|
}
|
|
@@ -267,7 +295,7 @@ namespace WingCloudServer.InteractionCenter
|
|
|
var endIp = newIpRange[1];
|
|
|
var longStartIp = IpToLong(startIp);
|
|
|
var longEndIp = IpToLong(endIp);
|
|
|
- var ipAddressInfo = new IPAddressInfoDTO()
|
|
|
+ var ipAddressInfo = new IPAddressInfoDTO()
|
|
|
{
|
|
|
StartIp = startIp,
|
|
|
EndIp = endIp,
|
|
@@ -276,7 +304,8 @@ namespace WingCloudServer.InteractionCenter
|
|
|
};
|
|
|
ipRangeList.Add(ipAddressInfo);
|
|
|
}
|
|
|
- var dbRequest = new UpdateServerInfoDBRequest() {
|
|
|
+ var dbRequest = new UpdateServerInfoDBRequest()
|
|
|
+ {
|
|
|
Name = request.Name,
|
|
|
IpRangeList = ipRangeList
|
|
|
};
|