Exemple #1
0
        public PageModel <Model.TaskWorkLog> PageWorkLog(DateTime date, int?taskid, int?nodeid, int?logtype, string runguid, string keywords, DateTime?begintime, DateTime?endtime, int pno)
        {
            int pagesize = 20;

            using (RLib.DB.DbConn dbconn = Pub.GetConn())
            {
                int totalcount = 0;
                if (!Pub.ExistTableInDB(dbconn, Pub.BuildWTbName(date)))
                {
                    return(new PageModel <Model.TaskWorkLog>()
                    {
                        List = new List <Model.TaskWorkLog>(),
                        PageNo = pno,
                        PageSize = pagesize,
                        TotalCount = 0
                    });
                }
                var model = tasklogdal.GetWorkLogPage(dbconn, date, taskid, nodeid, logtype, false, null,
                                                      runguid, keywords, begintime, endtime, pno, pagesize, out totalcount);
                return(new PageModel <Model.TaskWorkLog>()
                {
                    List = model,
                    PageNo = pno,
                    PageSize = pagesize,
                    TotalCount = totalcount
                });
            }
        }
Exemple #2
0
        public PageModel <Model.TaskWorkLog> PageWorkLogErrorMode(DateTime date, List <string> notContainText, DateTime?begintime, DateTime?endtime, int pno)
        {
            int pagesize = 20;

            using (RLib.DB.DbConn dbconn = Pub.GetConn())
            {
                int totalcount = 0;
                if (!Pub.ExistTableInDB(dbconn, Pub.BuildWTbName(date)))
                {
                    return(new PageModel <Model.TaskWorkLog>()
                    {
                        List = new List <Model.TaskWorkLog>(),
                        PageNo = pno,
                        PageSize = pagesize,
                        TotalCount = 0
                    });
                }
                var model = tasklogdal.GetWorkLogPage(dbconn, date, null, null, 1, false, notContainText,
                                                      null, null, begintime, endtime, pno, pagesize, out totalcount);
                return(new PageModel <Model.TaskWorkLog>()
                {
                    List = model,
                    PageNo = pno,
                    PageSize = pagesize,
                    TotalCount = totalcount
                });
            }
        }
Exemple #3
0
        public bool ChangePwd(int p, string oldpwd, string newpwd)
        {
            if (string.IsNullOrWhiteSpace(oldpwd))
            {
                throw new MException(MExceptionCode.BusinessError, "原密码不能为空!");
            }
            if (string.IsNullOrWhiteSpace(newpwd))
            {
                throw new MException(MExceptionCode.BusinessError, "新密码不能为空!");
            }
            string md5newpwd = RLib.Utils.Security.MakeMD5(newpwd.Trim());
            string md5oldpwd = RLib.Utils.Security.MakeMD5(oldpwd.Trim());

            using (var dbconn = Pub.GetConn())
            {
                var model = managerdal.GetManagerDetail(dbconn, p);
                if (model.LoginPwd != md5oldpwd)
                {
                    throw new MException(MExceptionCode.BusinessError, "原密码不正确!");
                }
                if (managerdal.UpdateManagerPwd(dbconn, p, md5newpwd) > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Exemple #4
0
 public bool DeleteManager(int managerid)
 {
     using (var dbconn = Pub.GetConn())
     {
         dbconn.BeginTransaction();
         try
         {
             var model = managerdal.DeleteManager(dbconn, managerid);
             //添加操作日志
             new OperationLogBll().AddLog(new Model.OperationLog
             {
                 Module           = "员工管理",
                 OperationName    = Utils.CurrUserName(),
                 OperationContent = "删除" + managerid + "号的员工",
                 OperationTitle   = "删除信息",
                 Createtime       = DateTime.Now
             });
             dbconn.Commit();
             return(model > 0);
         }
         catch (Exception ex)
         {
             dbconn.Rollback();
             throw ex;
         }
     }
 }
Exemple #5
0
 public static void InitDefault()
 {
     try
     {
         DAL.ManagerDal managerdal = new DAL.ManagerDal();
         using (var dbconn = Pub.GetConn())
         {
             var items = managerdal.GetManagerMiniTop(dbconn, 2);
             if (items.Count == 0)
             {
                 managerdal.AddManager(dbconn, new Model.Manager()
                 {
                     AllowLogin    = 1,
                     CreateTime    = DateTime.Now,
                     LastLoginTime = null,
                     LoginName     = "run",
                     LoginPwd      = "",
                     ManagerId     = 0,
                     Name          = "张三",
                     Remark        = "",
                     State         = 0,
                     SubName       = "zhangthree",
                     UpdateTime    = null
                 });
             }
         }
     }
     catch (Exception ex) { }
 }
Exemple #6
0
 public Model.Manager LoginIn(string loginname, string loginpwd)
 {
     if (string.IsNullOrEmpty(loginname))
     {
         throw new MException(MExceptionCode.BusinessError, "用户名不能为空!");
     }
     using (var dbconn = Pub.GetConn())
     {
         var models = managerdal.GetByLoginName(dbconn, loginname);
         if (models.Count == 0)
         {
             throw new MException(MExceptionCode.BusinessError, "用户名不存在!");
         }
         if (models.Count > 1)
         {
             throw new MException(MExceptionCode.BusinessError, "用户名有重名,请联系管理员!");
         }
         var model = models[0];
         if (model.State == 1)
         {
             throw new MException(MExceptionCode.BusinessError, "用户已冻结!");
         }
         if (model.AllowLogin == 0)
         {
             throw new MException(MExceptionCode.BusinessError, "不允许登录!");
         }
         loginpwd = (loginpwd ?? "");
         if (model.LoginPwd != (string.IsNullOrEmpty(loginpwd) ? "" : RLib.Utils.Security.MakeMD5(loginpwd)))
         {
             throw new MException(MExceptionCode.BusinessError, "密码不正确!");
         }
         return(model);
     }
 }
Exemple #7
0
        private string RunKeyLongWaitChecker()
        {
            var    longRunMins = Config.GetInt("jobmoni:LongWaitMins", 40);
            string sql         = @"SELECT  dp.[runKey],ta.[Title] FROM [dbo].[dispatch](nolock) dp
        join [Task](nolock) ta on dp.[taskId]=ta.[taskId] 
          where dp.dispatchState<2 and dp.dispatchState>=0  and   dp.createTime<@btime;";

            using (RLib.DB.DbConn dbconn = Pub.GetConn())
            {
                var tb = dbconn.SqlToDataTable(sql, new { btime = DateTime.Now.AddMinutes(-longRunMins) });
                if (tb.Rows.Count == 0)
                {
                    return(null);
                }
                List <string> taskkey = new List <string>();
                foreach (DataRow dr in tb.Rows)
                {
                    taskkey.Add(dr["Title"].ToString() + ":" + dr["runKey"].ToString());
                }
                StringBuilder sb = new StringBuilder();
                sb.Append("调度任务")
                .Append(string.Join("、", taskkey.Take(2)))
                .Append("等 等待" + longRunMins + "分钟未运行");
                return(sb.ToString());
            }
        }
 public override void RunOnce()
 {
     using (var dbconn = Pub.GetConn())
     {
         dispatchDal.AutoExpire(dbconn);
     }
 }
Exemple #9
0
 public bool SetDispatchState(int taskId, int nodeId, int dispatchState)
 {
     using (RLib.DB.DbConn dbconn = Pub.GetConn())
     {
         List <int> nodeids = new List <int>();
         if (nodeId == 0)
         {
             nodeids.AddRange(taskdal.GetTaskBindings(dbconn, taskId).Select(x => x.NodeId));
         }
         else
         {
             nodeids.Add(nodeId);
         }
         dbconn.BeginTransaction();
         try
         {
             foreach (var a in nodeids)
             {
                 taskdal.SetDispatchState(dbconn, taskId, a, dispatchState);
             }
             dbconn.Commit();
             return(true);
         }
         catch (Exception ex)
         {
             dbconn.Rollback();
             throw ex;
         }
     }
 }
Exemple #10
0
 private string TcpConnectChecker()
 {
     using (RLib.DB.DbConn dbconn = Pub.GetConn())
     {
         var nodes = this.nodedal.GetAllNode(dbconn, false);
         List <Model.Node> unoknodes = new List <Model.Node>();
         nodes.AddRange(nodes);
         for (var k = 0; k < 2; k++)
         {
             if (unoknodes.Count == 0)
             {
                 break;
             }
             for (var j = unoknodes.Count - 1; j >= 0; j--)
             {
                 string msg    = Ruanal.Core.ConfigConst.TalkNodeTaskStatus + string.Format("{0}", unoknodes[j].ClientId);
                 var    result = Ruanal.Core.Notify.NotifyHelper.TalkToAll(msg, 5000, 1);
                 if (result != null && result.Count > 0)
                 {
                     unoknodes.RemoveAt(j);
                 }
             }
         }
         if (unoknodes.Count == 0)
         {
             return(null);
         }
         StringBuilder sb = new StringBuilder();
         sb.Append("节点")
         .Append(string.Join("、", unoknodes.Select(x => x.Title).Take(2)))
         .Append("等通知Tcp无法连接");
         return(sb.ToString());
     }
 }
Exemple #11
0
        public JsonEntity AutoEndDispatchExecute(string ClientId, int dispatchId)
        {
            using (RLib.DB.DbConn dbconn = Pub.GetConn())
            {
                dbconn.BeginTransaction();
                try
                {
                    var dispatchmodel = dispatchdal.GetDetail(dbconn, dispatchId);
                    if (dispatchmodel == null || dispatchmodel.DispatchState == -1)
                    {
                        throw new MException("调度不存在!");
                    }
                    if (dispatchmodel.DispatchState != 2)
                    {
                        throw new MException("调度不是执行中状态!");
                    }
                    dispatchdal.EndExec(dbconn, dispatchmodel.DispatchId, false, "自动结束执行" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));

                    //System.Diagnostics.Trace.WriteLine(string.Format("{0} 自动结束执行 {1}", dispatchmodel.DispatchId, DateTime.Now.ToString("HH:mm:ss.fff")));
                    dbconn.Commit();
                    return(new JsonEntity()
                    {
                        code = 1
                    });
                }
                catch (Exception ex)
                {
                    dbconn.Rollback();
                    throw ex;
                }
            }
        }
Exemple #12
0
        public JsonEntity GetNewCmds(string ClientId)
        {
            using (RLib.DB.DbConn dbconn = Pub.GetConn())
            {
                var nodemodel  = nodedal.Detail(dbconn, ClientId);
                int totalcount = 0;
                var cmds       = cmddal.GetNodeNewCmd(dbconn,
                                                      nodemodel.NodeId,
                                                      Ruanal.Core.ConfigConst.CMD_Page_Size,
                                                      out totalcount);

                List <Ruanal.Core.ApiSdk.CmdDetail> cmddetails = new List <Core.ApiSdk.CmdDetail>();
                foreach (var a in cmds)
                {
                    cmddetails.Add(new Core.ApiSdk.CmdDetail()
                    {
                        CmdId   = a.CmdId,
                        NodeId  = a.NodeId,
                        CmdType = a.CmdType,
                        CmdArgs = a.CmdArgs
                    });
                }
                return(new JsonEntity()
                {
                    code = 1, data = cmddetails
                });
            }
        }
Exemple #13
0
        public JsonEntity AddWorkLog(string ClientId, int taskId, string dispatchId, int logType, string logText, DateTime createTime)
        {
            if (Pub.PauseWorkLog)
            {
                return new JsonEntity()
                       {
                           code = 1
                       }
            }
            ;
            var sw = System.Diagnostics.Stopwatch.StartNew();

            using (RLib.DB.DbConn dbconn = Pub.GetConn())
            {
                var nodemodel = nodedal.Detail(dbconn, ClientId);

                Model.TaskWorkLog worklogmodel = new Model.TaskWorkLog()
                {
                    NodeId     = nodemodel.NodeId,
                    TaskId     = taskId,
                    DispatchId = dispatchId ?? "",
                    LogType    = logType,
                    LogText    = logText,
                    ServerTime = createTime
                };
                tasklogdal.AddWorkLog(dbconn, createTime, worklogmodel);
            }
            sw.Stop();
            System.Diagnostics.Trace.WriteLine("服务器写日志用时:" + sw.Elapsed.TotalMilliseconds.ToString("0.0"));
            return(new JsonEntity()
            {
                code = 1
            });
        }
Exemple #14
0
 public void SaveAll(Dictionary <int, string> dic)
 {
     using (RLib.DB.DbConn dbconn = Pub.GetConn())
     {
         dal.SaveAll(dbconn, dic);
     }
 }
Exemple #15
0
 public void SaveConfig(string config)
 {
     using (RLib.DB.DbConn dbconn = Pub.GetConn())
     {
         commDal.SetConfig(dbconn, config);
     }
 }
Exemple #16
0
 public JsonEntity CmdEndExecute(string ClientId, int cmdid, bool success, string msg)
 {
     using (RLib.DB.DbConn dbconn = Pub.GetConn())
     {
         var nodemodel = nodedal.Detail(dbconn, ClientId);
         dbconn.BeginTransaction();
         try
         {
             var cmddetail = cmddal.Detail(dbconn, cmdid);
             if (cmddetail == null || cmddetail.CmdState == -1)
             {
                 throw new MException("命令不存在!");
             }
             if (cmddetail.CmdState != 1)
             {
                 throw new MException("命令不是执行中状态!");
             }
             if (cmddetail.NodeId != nodemodel.NodeId)
             {
                 throw new MException("无权限操作该命令!");
             }
             cmddal.EndCmd(dbconn, cmdid, success, msg);
             dbconn.Commit();
             return(new JsonEntity()
             {
                 code = 1
             });
         }
         catch (Exception ex)
         {
             dbconn.Rollback();
             throw ex;
         }
     }
 }
Exemple #17
0
 public JsonEntity SkipDispatchExecute(string ClientId, int dispatchId)
 {
     using (RLib.DB.DbConn dbconn = Pub.GetConn())
     {
         var nodemodel = nodedal.Detail(dbconn, ClientId);
         dbconn.BeginTransaction();
         try
         {
             var dispatchmodel = dispatchdal.GetDetail(dbconn, dispatchId);
             if (dispatchmodel == null || dispatchmodel.DispatchState == -1)
             {
                 throw new MException("调度不存在!");
             }
             if (dispatchmodel.DispatchState != 2)
             {
                 throw new MException("调度不是执行中状态!");
             }
             dispatchdal.SkipExec(dbconn, dispatchmodel.DispatchId);
             dbconn.Commit();
             return(new JsonEntity()
             {
                 code = 1
             });
         }
         catch (Exception ex)
         {
             dbconn.Rollback();
             throw ex;
         }
     }
 }
Exemple #18
0
 public List <MApiEntity.Task> TaskList()
 {
     using (RLib.DB.DbConn dbconn = Pub.GetConn())
     {
         return(taskdal.GetAllTask(dbconn, -1)
                .Select(x => new MApiEntity.Task()
         {
             DispatchClass = x.DispatchClass,
             EnterClass = x.EnterClass,
             EnterDll = x.EnterDll,
             RunCron = x.RunCron,
             TaskBindings = taskdal.GetTaskBindings(dbconn, x.TaskId)
                            .Select(y => new MApiEntity.TaskBinding()
             {
                 BindId = y.BindId,
                 TaskId = y.TaskId,
                 LastRunTime = y.LastRunTime,
                 LocalState = y.LocalState,
                 NodeId = y.NodeId,
                 ServerState = y.ServerState
             }).ToList(),
             Remark = x.Remark,
             State = x.State,
             Title = x.Title,
             TaskId = x.TaskId,
             TaskConfig = x.TaskConfig,
             TaskType = x.TaskType
         }).ToList());
     }
 }
Exemple #19
0
 /// <summary>
 /// 批量上传版本变指定为当前版本
 /// </summary>
 /// <param name="model"></param>
 /// <param name="tag"></param>
 public void BatchTaskVersion(TaskVersion model, int tag)
 {
     using (RLib.DB.DbConn dbconn = Pub.GetConn())
     {
         var tasks = taskdal.GetAllTask(dbconn, tag);
         if (tasks.Count == 0)
         {
             throw new MException("没有任务!");
         }
         dbconn.BeginTransaction();
         try
         {
             foreach (var a in tasks)
             {
                 model.TaskId = a.TaskId;
                 var versions = taskdal.AddVersion(dbconn, model);
                 taskdal.SetVersion(dbconn, a.TaskId, versions.VersionId);
             }
             dbconn.Commit();
         }
         catch (Exception ex)
         {
             dbconn.Rollback();
             throw;
         }
     }
 }
Exemple #20
0
 public int TaskSetVersion(TaskVersion model)
 {
     using (RLib.DB.DbConn dbconn = Pub.GetConn())
     {
         var task = taskdal.GetDetail(dbconn, model.TaskId);
         if (task == null)
         {
             throw new MException("没有任务!");
         }
         dbconn.BeginTransaction();
         try
         {
             model.TaskId = task.TaskId;
             var versions = taskdal.AddVersion(dbconn, new Model.TaskVersion()
             {
                 CreateTime = DateTime.Now,
                 FilePath   = model.FilePath ?? "",
                 FileSize   = model.FileSize,
                 Remark     = model.Remark ?? "",
                 TaskId     = model.TaskId,
                 VersionId  = 0,
                 VersionNO  = DateTime.Now.ToString("yyyyMMddHHmmssfff" + "-" + model.TaskId),
                 Vstate     = 0
             });
             taskdal.SetVersion(dbconn, task.TaskId, versions.VersionId);
             dbconn.Commit();
             return(model.TaskId);
         }
         catch (Exception ex)
         {
             dbconn.Rollback();
             throw;
         }
     }
 }
Exemple #21
0
        public int AutoEndEnd()
        {
            TimeSpan runtime = TimeSpan.FromHours(1.5);

            using (RLib.DB.DbConn dbconn = Pub.GetConn())
            {
                var disdpatchdal = new DAL.DispatchDal();
                var dis          = disdpatchdal.GetRunDispatchs(dbconn, DateTime.Now.Subtract(runtime));
                int s            = 0;
                foreach (var a in dis)
                {
                    var disitem = disdpatchdal.GetLastDispatchKeyItem(dbconn, a.TaskId, a.RunKey);
                    if (disitem == null)
                    {
                        continue;
                    }
                    if (disitem.DispatchState >= 2 && disitem.DispatchState <= 4)
                    {
                        disdpatchdal.EndExec(dbconn, a.DispatchId, true, "检测自动结束!");
                        try
                        {
                            CmdHelper.Instance.StopDispatch(disitem.DispatchId);
                        }
                        catch { }
                        s++;
                    }
                }
                return(s);
            }
        }
Exemple #22
0
        private string JobRunChecker()
        {
            using (RLib.DB.DbConn dbconn = Pub.GetConn())
            {
                var tasks = taskDal.GetAllTask(dbconn, 0);
                List <Model.Task> unoktasks = new List <Model.Task>();
                foreach (var a in tasks)
                {
                    foreach (var b in taskDal.GetTaskBindings(dbconn, a.TaskId))
                    {
                        if (b.LocalState == 0)
                        {
                            continue;
                        }
                        if (b.LocalState == 1 && b.ServerState != 1)
                        {
                            unoktasks.Add(a);
                            break;
                        }
                    }
                }

                if (unoktasks.Count == 0)
                {
                    return(null);
                }

                StringBuilder sb = new StringBuilder();
                sb.Append("任务")
                .Append(string.Join("、", unoktasks.Select(x => x.Title).Take(2)))
                .Append("等运行异常");
                return(sb.ToString());
            }
        }
Exemple #23
0
        public bool AddTaskBinding(int taskId, string nodeIds)
        {
            var nodes = RLib.Utils.StringHelper.SplitToIntList(nodeIds ?? "", new char[] { ',', ' ' });

            if (nodes.Count == 0)
            {
                throw new MException("请选择节点!");
            }
            using (RLib.DB.DbConn dbconn = Pub.GetConn())
            {
                dbconn.BeginTransaction();
                try
                {
                    foreach (var n in nodes)
                    {
                        taskdal.AddBinding(dbconn, new TaskBinding()
                        {
                            NodeId      = n,
                            ServerState = 0,
                            TaskId      = taskId
                        });
                    }
                    dbconn.Commit();
                    return(true);
                }
                catch (Exception ex)
                {
                    dbconn.Rollback();
                    throw ex;
                }
            }
        }
Exemple #24
0
 public Dictionary <int, string> GetAll()
 {
     using (RLib.DB.DbConn dbconn = Pub.GetConn())
     {
         var dic = dal.GetAll(dbconn);
         return(dic);
     }
 }
Exemple #25
0
 public string GetConfig()
 {
     using (RLib.DB.DbConn dbconn = Pub.GetConn())
     {
         var v = commDal.GetConfig(dbconn);
         return(v);
     }
 }
Exemple #26
0
 public Model.Node GetDetail(int nodeId)
 {
     using (RLib.DB.DbConn dbconn = Pub.GetConn())
     {
         var model = nodedal.Detail(dbconn, nodeId);
         return(model);
     }
 }
Exemple #27
0
 public List <Model.Task> GetAllTask()
 {
     using (RLib.DB.DbConn dbconn = Pub.GetConn())
     {
         var tasks = taskdal.GetAllTask(dbconn, -1);
         return(tasks);
     }
 }
Exemple #28
0
 public int DeleteTaskVersion(int versionid)
 {
     using (RLib.DB.DbConn dbconn = Pub.GetConn())
     {
         var versions = taskdal.DeleteVersion(dbconn, versionid);
         return(versions);
     }
 }
Exemple #29
0
 public List <Model.Node> GetAllNode()
 {
     using (RLib.DB.DbConn dbconn = Pub.GetConn())
     {
         var models = nodedal.GetAllNode(dbconn, false);
         return(models);
     }
 }
Exemple #30
0
 public Model.Task GetDetail(int taskId)
 {
     using (RLib.DB.DbConn dbconn = Pub.GetConn())
     {
         var r = taskdal.GetDetail(dbconn, taskId);
         return(r);
     }
 }