public bool Heart(int ServerId) { Ts_Servers Server = new Ts_Servers() { LastHeartTime = DateTime.Now, }; try { return(_ormServers.Update(Server, w => w.Id == ServerId) > 0); } catch (Exception ex) { log.Fatal(string.Format("Server:{0},服务器心跳异常", _serverManager.MyServer.ServerName), ex); return(false); } }
private void TaskManager_OnTaskExecAfter(TaskExecLog taskExecLog, TaskExecResult result) { try { Ts_ExecLog tsLog = new Ts_ExecLog(); tsLog.ExecEndTime = taskExecLog.ExecEndTime; result.Data = result.Data ?? string.Empty; tsLog.ExecResult = result.ToJson(); if (tsLog.ExecResult.Length > 2000) { tsLog.ExecResult = tsLog.ExecResult.Substring(0, 2000); } tsLog.ExecResultCode = result.Code; tsLog.ExecStatrtTime = taskExecLog.ExecStatrtTime; if (_ormExecLog.Update(tsLog, w => w.Id == taskExecLog.ExecLogId) != 1) { log.Error(string.Format("执行后更新记录异常,logId={0},结果:{1}", taskExecLog.ExecLogId, tsLog.ExecResult)); } } catch (Exception ex) { log.ErrorAndEmail(string.Format("保存执行日志结果异常TaskManager_OnTaskExecAfter,参数:{0}", taskExecLog.ToJson()), ex); } try { Ts_TaskExec taskExec = new Ts_TaskExec(); taskExec.LastExecResultCode = result.Code; _ormTaskExec.Update(taskExec, w => w.TaskGuid == taskExecLog.ExecGuid); } catch (Exception ex) { log.ErrorAndEmail(string.Format("修改执行Code异常TaskManager_OnTaskExecAfter,参数:{0}", taskExecLog.ToJson()), ex); } if (result.Code != 0 && taskExecLog.IsErrorAlert) { _mailService.SendEmail(string.Format("任务【{0}】执行异常", taskExecLog.Title), string.Format("您的任务:{0}\r\n执行异常:\r\n{1}", taskExecLog.Title, result.Data), taskExecLog.ReceiveEmail); } }
public bool SaveUser(Tu_Users user) { if (_ormUsers.Exists(w => w.UserId != user.UserId && w.UserName == user.UserName)) { throw new BOException("账号重复"); } if (user.UserId == 0) { user.InsertTime = DateTime.Now; return(_ormUsers.Add(user) > 0); } return(_ormUsers.Update(user) > 0); }
public bool SaveTask(Ts_Tasks Tasks) { try { new CronExpression(Tasks.Interval); } catch (Exception ex) { throw new BOException("设置的cron表达式格式不正确"); } if (Tasks.TimeOut <= 0) { throw new BOException("超时时间必需大于0"); } if (!string.IsNullOrEmpty(Tasks.Encoding)) { try { Encoding.GetEncoding(Tasks.Encoding); } catch { throw new BOException("编码输入错误"); } } Tasks.RunServerId = GetNewRunServerId(); if (Tasks.ExecType == (int)ExecTypeEnum.EXE) { Tasks.IsResponseNorm = false; } if (string.IsNullOrEmpty(Tasks.Guid)) { Tasks.CreateUser = MyContext.CurrentUser.UserId; Tasks.Guid = Guid.NewGuid().ToString(); Tasks.InsertTime = DateTime.Now; _ormTasks.Add(Tasks); _ormTaskExec.Add(new Ts_TaskExec() { TaskGuid = Tasks.Guid }); return(true); } int result = _ormTasks.Update(Tasks); log.Info(string.Format("保存任务记录:{0},执行结果:{1},操作用户:{2}", Tasks.ToJson(), result, MyContext.CurrentUser.UserName)); return(result > 0); }