|
|
|
|
//using Admin.Core.Socket.Model;
|
|
|
|
|
//using System;
|
|
|
|
|
//using System.Collections.Concurrent;
|
|
|
|
|
//using System.Collections.Generic;
|
|
|
|
|
//using System.Linq;
|
|
|
|
|
//using System.Text;
|
|
|
|
|
//using System.Threading.Tasks;
|
|
|
|
|
//using static ICSharpCode.SharpZipLib.Zip.ExtendedUnixData;
|
|
|
|
|
|
|
|
|
|
//namespace Admin.Core.Socket.Helper
|
|
|
|
|
//{
|
|
|
|
|
// public class CacheRegistry
|
|
|
|
|
// {
|
|
|
|
|
// private readonly static ConcurrentDictionary<string, string> _registry = new ConcurrentDictionary<string, ReceiveResult<TcpRfidModel>>();
|
|
|
|
|
|
|
|
|
|
// #region 注册缓存
|
|
|
|
|
// /// <summary>
|
|
|
|
|
// /// 注册
|
|
|
|
|
// /// </summary>
|
|
|
|
|
// /// <param name="definition"></param>
|
|
|
|
|
// /// <exception cref="InvalidOperationException"></exception>
|
|
|
|
|
// public static void RegisterCache(ReceiveResult<TcpRfidModel> definition)
|
|
|
|
|
// {
|
|
|
|
|
// if (_registry.ContainsKey($"{definition.IP}-{definition.Flag}"))
|
|
|
|
|
// {
|
|
|
|
|
// throw new InvalidOperationException($"Cache {definition.IP} {definition.Flag} is already registered");
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// lock (_registry)
|
|
|
|
|
// {
|
|
|
|
|
// _registry[$"{definition.IP}-{definition.Flag}"] = definition;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// #endregion
|
|
|
|
|
|
|
|
|
|
// #region 是否注册
|
|
|
|
|
// /// <summary>
|
|
|
|
|
// /// 是否注册
|
|
|
|
|
// /// </summary>
|
|
|
|
|
// /// <param name="IP"></param>
|
|
|
|
|
// /// <param name="Date"></param>
|
|
|
|
|
// /// <returns></returns>
|
|
|
|
|
// public static bool IsRegistered(string ip, string flag)
|
|
|
|
|
// {
|
|
|
|
|
// return _registry.ContainsKey($"{ip}-{flag}");
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// #endregion
|
|
|
|
|
|
|
|
|
|
// #region 查询
|
|
|
|
|
// /// <summary>
|
|
|
|
|
// /// 是否注册
|
|
|
|
|
// /// </summary>
|
|
|
|
|
// /// <param name="IP"></param>
|
|
|
|
|
// /// <param name="Date"></param>
|
|
|
|
|
// /// <returns></returns>
|
|
|
|
|
// public static ReceiveResult<TcpRfidModel> GetDefinition(string ip, string flag)
|
|
|
|
|
// {
|
|
|
|
|
// if (!_registry.ContainsKey($"{ip}-{flag}"))
|
|
|
|
|
// return default;
|
|
|
|
|
// return _registry[$"{ip}-{flag}"];
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// #endregion
|
|
|
|
|
|
|
|
|
|
// #region 注销
|
|
|
|
|
// /// <summary>
|
|
|
|
|
// /// 注销
|
|
|
|
|
// /// </summary>
|
|
|
|
|
// /// <param name="IP"></param>
|
|
|
|
|
// /// <param name="date"></param>
|
|
|
|
|
// public static void DeregisterCache(string ip, string flag)
|
|
|
|
|
// {
|
|
|
|
|
// try
|
|
|
|
|
// {
|
|
|
|
|
// if (!_registry.ContainsKey($"{ip}-{flag}"))
|
|
|
|
|
// return;
|
|
|
|
|
|
|
|
|
|
// lock (_registry)
|
|
|
|
|
// {
|
|
|
|
|
// _registry.TryRemove($"{ip}-{flag}", out var _);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// catch (Exception)
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
|
|
// throw;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// #endregion
|
|
|
|
|
|
|
|
|
|
// #region 获取所有定义的缓存
|
|
|
|
|
// /// <summary>
|
|
|
|
|
// /// 获取所有定义的缓存
|
|
|
|
|
// /// </summary>
|
|
|
|
|
// /// <returns></returns>
|
|
|
|
|
// public static IEnumerable<ReceiveResult<TcpRfidModel>> GetAllDefinitions()
|
|
|
|
|
// {
|
|
|
|
|
// return _registry.Values;
|
|
|
|
|
// }
|
|
|
|
|
// #endregion
|
|
|
|
|
|
|
|
|
|
// #region 清空所有缓存
|
|
|
|
|
// /// <summary>
|
|
|
|
|
// /// 清空所有缓存
|
|
|
|
|
// /// </summary>
|
|
|
|
|
// /// <returns></returns>
|
|
|
|
|
// public static bool ClearAllDefinitions()
|
|
|
|
|
// {
|
|
|
|
|
// try
|
|
|
|
|
// {
|
|
|
|
|
// _registry.Clear();
|
|
|
|
|
// return true;
|
|
|
|
|
// }
|
|
|
|
|
// catch (Exception)
|
|
|
|
|
// {
|
|
|
|
|
// return false;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// #endregion
|
|
|
|
|
// }
|
|
|
|
|
//}
|