Esempio n. 1
0
 public Model.Task UpdateTask(Model.Task model)
 {
     if (string.IsNullOrWhiteSpace(model.Title))
     {
         throw new MException("标题不能为空!");
     }
     using (RLib.DB.DbConn dbconn = Pub.GetConn())
     {
         int r = taskdal.Update(dbconn, model);
         return(model);
     }
 }
Esempio n. 2
0
        public int TaskEdit(Task model)
        {
            using (RLib.DB.DbConn dbconn = Pub.GetConn())
            {
                if (string.IsNullOrWhiteSpace(model.Title))
                {
                    throw new MException("标题不能为空!");
                }
                var taskmodel = taskdal.GetDetail(dbconn, model.TaskId);
                if (taskmodel == null || taskmodel.State == -1)
                {
                    throw new MException("任务不存在!");
                }
                SetDefaultNodeBind(model);
                taskmodel.DispatchClass = model.DispatchClass;
                taskmodel.EnterClass    = model.EnterClass;
                taskmodel.EnterDll      = model.EnterDll;
                taskmodel.Remark        = model.Remark;
                taskmodel.RunCron       = model.RunCron;
                taskmodel.State         = model.State;
                taskmodel.TaskConfig    = model.TaskConfig;
                taskmodel.Title         = model.Title;
                taskmodel.TaskType      = model.TaskType;
                taskmodel.UpdateTime    = DateTime.Now;
                taskmodel.TaskBindings  = taskdal.GetTaskBindings(dbconn, model.TaskId);

                var delnodes = new List <int>();
                foreach (var t in taskmodel.TaskBindings)
                {
                    if (!model.TaskBindings.Exists(x => t.NodeId == x.NodeId))
                    {
                        if (t.LocalState == 1)
                        {
                            throw new Exception("节点" + t.Node + "本在状态为运行中,不能删除!");
                        }
                    }
                }
                taskmodel.TaskBindings.Select(x => x.NodeId).Except(model.TaskBindings.Select(x => x.NodeId)).ToList();
                var addnodes = model.TaskBindings.Select(x => x.NodeId).Except(taskmodel.TaskBindings.Select(x => x.NodeId)).ToList();

                dbconn.BeginTransaction();
                try
                {
                    taskdal.Update(dbconn, taskmodel);
                    foreach (var a in delnodes)
                    {
                        taskdal.DeleteBind(dbconn, model.TaskId, a);
                    }
                    foreach (var a in addnodes)
                    {
                        taskdal.AddBinding(dbconn, new Model.TaskBinding()
                        {
                            TaskId = taskmodel.TaskId, NodeId = a
                        });
                    }
                    dbconn.Commit();
                    return(taskmodel.TaskId);
                }
                catch (Exception ex)
                {
                    dbconn.Rollback();
                    throw;
                }
            }
        }