public int Register() { if (_serverManager.MyServer != null) { throw new Exception("已注册过,不能重试注册"); } Ts_Servers Server = new Ts_Servers() { LastHeartTime = DateTime.Now, }; int result = 0; string ServerName = Dns.GetHostName(); try { IPAddress[] ServerIPs = Dns.GetHostAddresses(ServerName); var tempserver = GetServerId(ServerName); if (tempserver != null) { if (!tempserver.IsEnable) { return(-1); } result = _ormServers.Update(Server, w => w.Id == tempserver.Id); Server.Id = tempserver.Id; } else { Server.IsEnable = true; Server.ServerName = ServerName; Server.IsMain = false; Server.ServerIP = ServerIPs.Select <IPAddress, string>(x => x.ToString()).ToJson(); result = (int)_ormServers.Add(Server); Server.Id = result; } if (result <= 0) { log.Fatal(string.Format("Server:{0},服务器注册失败,系统将无法正常运行", ServerName)); throw new Exception(string.Format("Server:{0},服务器注册失败,系统将无法正常运行", ServerName)); } _serverManager.MyServer = new Ts_Servers { Id = Server.Id, ServerName = ServerName }; _serverManager.OnServerCountChange += _serverManager_OnServerCountChange; _serverManager.OnDeadServer += _serverManager_OnDeadServer; _serverManager.StartUp(Heart, QueryUseServerAction); return(Server.Id); } catch (Exception ex) { log.Fatal(string.Format("Server:{0},服务器注册异常,系统将无法正常运行", ServerName), ex); throw new Exception(string.Format("Server:{0},服务器注册异常,系统将无法正常运行", ServerName), ex); } }
private int TaskManager_OnTaskExecBefore(ExecTaskInfo task) { int logId = 0; try { Ts_ExecLog tsLog = new Ts_ExecLog(); tsLog.ExecParams = task.Params; tsLog.ExecStatrtTime = task.LastExecTime; tsLog.ExecUrl = task.ExecUrl; tsLog.TaskGuid = task.Guid; logId = (int)_ormExecLog.Add(tsLog); } catch (Exception ex) { log.ErrorAndEmail(string.Format("保存执行日志结果异常TaskManager_OnTaskExecBefore,参数:{0}", task.ToJson()), ex); } try { Ts_TaskExec taskExec = new Ts_TaskExec(); taskExec.LastExecId = logId; taskExec.LastExecTime = task.LastExecTime; taskExec.TaskGuid = task.Guid; _ormTaskExec.Update(taskExec); } catch (Exception ex) { log.ErrorAndEmail(string.Format("修改最后一次执行时间异常TaskManager_OnTaskExecBefore,参数:{0}", task.ToJson()), ex); } return(logId); }
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); }