Exemplo n.º 1
0
        public IActionResult WriteNLBUrls(string urls)
        {
            log.Info($"WriteNLBUrls:{urls}");
            try
            {
                if (string.IsNullOrEmpty(urls))
                {
                    return(Json(new JsonModel()
                    {
                        Success = false, Message = "请输入NLB 其他网址!"
                    }));
                }

                var    urlList  = urls.Split(",");
                string errorMsg = string.Empty;
                foreach (string url in urlList)
                {
                    try
                    {
                        string nlbUrl = url;
                        if (nlbUrl.EndsWith("/"))
                        {
                            nlbUrl = nlbUrl.TrimEnd('/');
                        }

                        HttpClient webRequest = FileLockHelper.GetHttpClient();
                        var        result     = webRequest.GetStringAsync($"{nlbUrl}/NLBLock/GetNLBPoint").GetAwaiter().GetResult();
                    }
                    catch
                    {
                        errorMsg += url + ",";
                    }
                }
                if (!string.IsNullOrEmpty(errorMsg))
                {
                    return(Json(new JsonModel()
                    {
                        Success = false, Message = $"网址: {errorMsg} 无法访问, 请重新输入!"
                    }));
                }

                FileLockHelper.SetNLBUrls(_hostingEnvironment.ContentRootPath, urls);
                log.Info($"WriteNLBUrls Set NLBUrls:{urls}");
                return(Json(new JsonModel()
                {
                    Success = true, Message = "修改成功!"
                }));
            }
            catch (Exception ex)
            {
                return(Json(new JsonModel()
                {
                    Success = false, Message = ex.Message
                }));
            }
        }