schangxiang@126.com
2025-04-02 fdac93d134fa471bf4afb304407f506ba9e3a324
考虑并发的情况
已修改2个文件
29 ■■■■ 文件已修改
Api/Controllers/WareAuthorizeController.cs 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Api/Entity/AuthorizeFunRetEntity.cs 10 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Api/Controllers/WareAuthorizeController.cs
@@ -7,6 +7,10 @@
    [Route("[controller]")]
    public class WareAuthorizeController : ControllerBase
    {
        private static bool isRuning_Fun_MianAgvFun = false;
        private static readonly SemaphoreSlim semaphore_MianAgvFun = new SemaphoreSlim(1, 1);
        private readonly ILogger<WareAuthorizeController> _logger;
        public WareAuthorizeController(ILogger<WareAuthorizeController> logger)
@@ -20,10 +24,18 @@
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet(Name = "ValidateLicense")]
        public AuthorizeFunRetEntity ValidateLicense([FromQuery] ValidateLicenseInput input)
        public async Task<AuthorizeFunRetEntity> ValidateLicense([FromQuery] ValidateLicenseInput input)
        {
            if (isRuning_Fun_MianAgvFun)
            {
                //认为是验证成功,不要并发导致读取授权文件失败
                return AuthorizeFunRetEntity.Success("成功", null);
            }
            try
            {
                await semaphore_MianAgvFun.WaitAsync();
                isRuning_Fun_MianAgvFun = true;
                //if (input == null)
                //{
                //    return AuthorizeFunRetEntity.Fail("参数不能为空");
@@ -39,6 +51,11 @@
            {
                return AuthorizeFunRetEntity.Fail("异常:" + ex.Message);
            }
            finally
            {
                semaphore_MianAgvFun.Release();
                isRuning_Fun_MianAgvFun = false;
            }
        }
    }
}
Api/Entity/AuthorizeFunRetEntity.cs
@@ -71,11 +71,11 @@
                result = true,
                resMsg = _resMsg,
                expiryDate = newFun.expiryDate,
                issueDate = newFun.issueDate,
                macAddress = newFun.macAddress,
                projectId = newFun.projectId,
                type = newFun.type
                expiryDate = newFun?.expiryDate,
                issueDate = newFun?.issueDate,
                macAddress = newFun?.macAddress,
                projectId = newFun?.projectId,
                type = newFun?.type
            };
        }
        /// <summary>