ZhiYeJianKang_PeiXun/cyqdata-master/DistributedCache/CacheImplement/MemRedis/HostConfigWatch.cs

127 lines
4.3 KiB
C#
Raw Normal View History

2025-02-20 15:41:53 +08:00
using System.IO;
using CYQ.Data.Tool;
namespace CYQ.Data.Cache
{
/// <summary>
/// <20><><EFBFBD>ڼ<EFBFBD><DABC>طֲ<D8B7>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD><D0B1><EFBFBD>ʵ<EFBFBD>ʸ߿<CAB8><DFBF>ã<EFBFBD><C3A3><EFBFBD>̬<EFBFBD><CCAC><EFBFBD>أ<EFBFBD><D8A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA>ͣ<EFBFBD><CDA3><EFBFBD>еķ<D0B5><C4B7><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
internal class HostConfigWatch
{
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤Ȩ<D6A4>޵<EFBFBD>ί<EFBFBD><CEAF><EFBFBD>¼<EFBFBD><C2BC><EFBFBD>
internal delegate void OnConfigChangedDelegate(string configValue);
public event OnConfigChangedDelegate OnConfigChangedEvent;
public HostConfigWatch(string configValue)
{
StartWatch(configValue);
CompareHostListByConfig(configValue);
}
private void StartWatch(string configValue)
{
if (string.IsNullOrEmpty(configValue)) { return; }
if (configValue.EndsWith(".txt") || configValue.EndsWith(".ini"))
{
string path = AppConfig.RunPath + configValue;
if (File.Exists(path))
{
IOWatch.On(path, delegate (FileSystemEventArgs e)
{
if (OnConfigChangedEvent != null)
{
OnConfigChangedEvent(IOHelper.ReadAllText(path));
}
});
}
}
}
/// <summary>
/// <20><EFBFBD><E6B5B5><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>Ӧ<EFBFBD><D3A6>ԭʼ<D4AD><CABC><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD><D0B1><EFBFBD>
/// </summary>
public MList<string> HostList = new MList<string>();
/// <summary>
/// <20><EFBFBD><E4BBAF>Ҫ׷<D2AA>ӵ<EFBFBD><D3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
public MList<string> HostAddList = new MList<string>();
/// <summary>
/// <20><EFBFBD><E4BBAF>Ҫ<EFBFBD>Ƴ<EFBFBD><C6B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
public MList<string> HostRemoveList = new MList<string>();
/// <summary>
/// <20>;<EFBFBD><CDBE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƚϣ<C8BD><CFA3>ҳ<EFBFBD><D2B3><EFBFBD><E4BBAF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
/// </summary>
/// <param name="configValue"><3E>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD>ֵ</param>
public void CompareHostListByConfig(string configValue)
{
lock (this)
{
if (string.IsNullOrEmpty(configValue)) { return; }
string[] hostItems = configValue.Trim().Split(',');
if (hostItems == null || hostItems.Length == 0) { return; }
HostAddList.Clear();
HostRemoveList.Clear();
//<2F><>ʼ<EFBFBD>Ƚ<EFBFBD><C8BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ð汾<C3B0><E6B1BE><EFBFBD><EFBFBD>
if (HostList.Count == 0)
{
foreach (string host in hostItems)
{
string item = host.Trim();
if (string.IsNullOrEmpty(item) || item.StartsWith("#"))
{
continue;
}
if (!HostAddList.Contains(item))
{
HostAddList.Add(item);
HostList.Add(item);
}
}
}
else
{
foreach (string host in hostItems)
{
string item = host.Trim();
if (string.IsNullOrEmpty(item) || item.StartsWith("#"))
{
continue;
}
if (HostList.Contains(item))
{
HostList.Remove(item);
}
else if (!HostAddList.Contains(item))
{
HostAddList.Add(item);
}
}
//ʣ<>µľ<C2B5><C4BE><EFBFBD>Ҫ<EFBFBD>Ƴ<EFBFBD><C6B3>ġ<EFBFBD>
foreach (string host in HostList.List)
{
HostRemoveList.Add(host);
}
HostList.Clear();
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD>HostList<73>
foreach (string host in hostItems)
{
string item = host.Trim();
if (string.IsNullOrEmpty(item) || item.StartsWith("#"))
{
continue;
}
if (!HostList.Contains(item))
{
HostList.Add(item);
}
}
}
}
}
}
}