public async Task <IActionResult> Add([FromBody] ServerNodeVM model) { if (model == null) { throw new ArgumentNullException("model"); } model.Address = model.Address.TrimEnd('/'); var oldNode = await _serverNodeService.GetAsync(model.Address); if (oldNode != null) { return(Json(new { success = false, message = "节点已存在,请重新输入。" })); } var node = new ServerNode(); node.Address = model.Address.TrimEnd('/'); node.Remark = model.Remark; node.Status = NodeStatus.Offline; node.CreateTime = DateTime.Now; var result = await _serverNodeService.AddAsync(node); if (result) { await _sysLogService.AddSysLogAsync(new SysLog { LogTime = DateTime.Now, LogType = SysLogType.Normal, LogText = $"新增节点:{node.Address}" }); await _remoteServerNodeProxy.TestEchoAsync(node.Address); } return(Json(new { data = node, success = result, message = !result ? "添加节点失败,请查看错误日志" : "" })); }
public async Task <IActionResult> Add([FromBody] ServerNodeVM model) { if (model == null) { throw new ArgumentNullException("model"); } model.Address = model.Address.TrimEnd('/'); var oldNode = await _serverNodeService.GetAsync(model.Address); if (oldNode != null) { return(Json(new { success = false, message = "节点已存在,请重新输入。" })); } var node = new ServerNode(); node.Address = model.Address.TrimEnd('/'); node.Remark = model.Remark; node.Status = NodeStatus.Offline; node.CreateTime = DateTime.Now; var result = await _serverNodeService.AddAsync(node); if (result) { dynamic param = new ExpandoObject(); param.node = node; param.userName = this.GetCurrentUserName(); TinyEventBus.Instance.Fire(EventKeys.ADD_NODE_SUCCESS, param); await _remoteServerNodeProxy.TestEchoAsync(node.Address); } return(Json(new { data = node, success = result, message = !result ? "添加节点失败,请查看错误日志" : "" })); }
public async Task TestEchoAsync(string address) { var node = await _serverNodeService.GetAsync(address); try { FunctionUtil.TRY(() => { using (var resp = (node.Address + "/home/echo").AsHttp().Send()) { if (resp.StatusCode == System.Net.HttpStatusCode.OK && resp.GetResponseContent() == "ok") { node.LastEchoTime = DateTime.Now; node.Status = Data.Entity.NodeStatus.Online; var report = GetClientReport(node); if (report != null) { if (_serverNodeClientReports.ContainsKey(node.Address)) { _serverNodeClientReports[node.Address] = report; } else { _serverNodeClientReports.AddOrUpdate(node.Address, report, (k, r) => report); } } } else { node.Status = Data.Entity.NodeStatus.Offline; } _serverNodeService.UpdateAsync(node); } }, 5); } catch (Exception e) { _logger.LogInformation(e, "Try test node {0} echo , but fail .", node.Address); } }