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 ? "添加节点失败,请查看错误日志" : ""
            }));
        }
Esempio n. 2
0
        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 ? "添加节点失败,请查看错误日志" : ""
            }));
        }