コード例 #1
0
        public ResponseBase <AddCommandQueueItemResponse> AddCommandQueueItem(AddCommandQueueItemRequest req)
        {
            try
            {
                int nid  = int.Parse(req.NodeId);
                var node = noderepository.FindSingle(x => x.id == nid);
                if (node == null)
                {
                    return(ResponseToClient <AddCommandQueueItemResponse>(ResponesStatus.Failed, "当前节点" + req.NodeId + "不存在库中!"));
                }
                if (node.nodestatus == (int)NodeStatus.NoRun)
                {
                    return(ResponseToClient <AddCommandQueueItemResponse>(ResponesStatus.Failed, "当前节点未启动,暂不能执行此操作!"));
                }
                string cmdName       = req.CommandName.ToString();
                var    commandDetail = cmdRep.FindSingle(x => x.commandmainclassname == cmdName && x.isdel == 0);
                if (commandDetail == null)
                {
                    return(ResponseToClient <AddCommandQueueItemResponse>(ResponesStatus.Failed, "未知的命令操作!"));
                }
                int r = cmdqueuerespository.Add(new tb_commandqueue()
                {
                    commanddetailid      = commandDetail.id,
                    commandmainclassname = commandDetail.commandmainclassname,
                    commandparams        = string.IsNullOrEmpty(req.CommandParam) ? "":req.CommandParam,
                    commandstate         = (int)ExecuteStatus.NoExecute,
                    createby             = int.Parse(req.AdminId),
                    createtime           = DateTime.Now,
                    failedcount          = 0,
                    nodeid        = int.Parse(req.NodeId),
                    isdel         = 0,
                    taskid        = int.Parse(req.TaskId),
                    taskversionid = int.Parse(req.TaskVersionId)
                });
                if (r <= 0)
                {
                    return(ResponseToClient <AddCommandQueueItemResponse>(ResponesStatus.Failed, "执行失败"));
                }
                if (!string.IsNullOrEmpty(req.TaskId))//如果task不为空,说明是针对任务的命令
                {
                    int tid  = int.Parse(req.TaskId);
                    var task = taskRep.FindSingle(x => x.id == tid);
                    if (req.CommandName == CommandName.StartTaskCommand)
                    {
                        task.taskschedulestatus = (int)TaskScheduleStatus.WaitSchedule;
                        taskRep.Update(task);
                    }
                }

                return(ResponseToClient <AddCommandQueueItemResponse>(ResponesStatus.Success, ""));
            }
            catch (Exception ex)
            {
                return(ResponseToClient <AddCommandQueueItemResponse>(ResponesStatus.Exception, "添加命令队列项异常:" + JsonConvert.SerializeObject(ex)));
            }
        }
コード例 #2
0
        public JsonResult ChangeTaskStatus(string nodeid, string taskid, string taskversionid, string commandname)
        {
            try
            {
                //添加启动命令
                AddCommandQueueItemRequest model = new AddCommandQueueItemRequest()
                {
                    AdminId       = "0",
                    CommandName   = (CommandName)(int.Parse(commandname)),
                    CommandParam  = "",
                    NodeId        = nodeid,
                    TaskId        = taskid,
                    TaskVersionId = taskversionid,
                };
                ResponseBase <AddCommandQueueItemResponse> rep = PostToServer <AddCommandQueueItemResponse, AddCommandQueueItemRequest>(ClientProxy.AddCommandQueue_Url, model);


                // var ret = JsonConvert.SerializeObject(rep, setting);
                // Response.Write(ret);
                //  return Json(rep, JsonRequestBehavior.AllowGet);
                // return Json(rep);
                return(Json(rep));
            }
            catch (Exception ex)
            {
                var rep2 = new ResponseBase <AddCommandQueueItemResponse>()
                {
                    Status = ResponesStatus.Exception, Msg = ex.Message
                };
                return(Json(rep2));
                // var ret2 = JsonConvert.SerializeObject(rep2, setting);
                // var ret2 = JsonConvert.SerializeObject(rep2, setting);
                // return Json(rep2,JsonRequestBehavior.AllowGet);
                //Response.Write(ret2);
                //return Json(rep2, JsonRequestBehavior.AllowGet);
            }
        }