/// <summary> /// 得到一个对象实体 /// </summary> public ServerConfigModel GetModel(ServerConfigModel model) { List <OracleParameter> listpara = new List <OracleParameter>(); StringBuilder strSql = new StringBuilder(); strSql.Append("select ID, SERVICENAME, SERVICEIP, LASTTIME,SYSDATE SYSDATETIME,PASSMINUTE,SECOND "); strSql.Append(" from Robots_ServerConfig "); strSql.Append(" where 1=1 "); if (!string.IsNullOrEmpty(model.SERVICENAME)) { strSql.Append(" and SERVICENAME=:SERVICENAME "); listpara.Add(new OracleParameter(":SERVICENAME", OracleType.VarChar, 100) { Value = model.SERVICENAME }); } if (!string.IsNullOrEmpty(model.SERVICEIP)) { strSql.Append(" and SERVICEIP=:SERVICEIP "); listpara.Add(new OracleParameter(":SERVICEIP", OracleType.VarChar, 100) { Value = model.SERVICEIP }); } strSql.Append(" order by id desc "); return(OracleHelper.QueryEntity <ServerConfigModel>(strSql.ToString(), listpara.ToArray())); }
/// <summary> /// 获得数据列表 /// </summary> public List <ServerConfigModel> DataTableToList(DataTable dt) { List <ServerConfigModel> modelList = new List <ServerConfigModel>(); int rowsCount = dt.Rows.Count; if (rowsCount > 0) { ServerConfigModel model; for (int n = 0; n < rowsCount; n++) { model = new ServerConfigModel(); if (dt.Rows[n]["ID"].ToString() != "") { model.ID = decimal.Parse(dt.Rows[n]["ID"].ToString()); } if (dt.Rows[n]["LASTTIME"].ToString() != "") { model.LASTTIME = DateTime.Parse(dt.Rows[n]["LASTTIME"].ToString()); } modelList.Add(model); } } return(modelList); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(ServerConfigModel model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Robots_ServerConfig set "); strSql.Append(" ID = :ID , "); strSql.Append(" SERVICENAME = :SERVICENAME , "); strSql.Append(" SERVICEIP = :SERVICEIP , "); strSql.Append(" LASTTIME = :LASTTIME, "); strSql.Append(" SECOND = :SECOND, "); strSql.Append(" PASSMINUTE = :PASSMINUTE "); strSql.Append(" where ID=:ID "); OracleParameter[] parameters = { new OracleParameter(":ID", OracleType.Number,4){Value = model.ID} , new OracleParameter(":SERVICENAME", OracleType.VarChar,100){Value = model.SERVICENAME} , new OracleParameter(":SERVICEIP", OracleType.VarChar,100){Value = model.SERVICEIP} , new OracleParameter(":LASTTIME", OracleType.DateTime){Value = model.LASTTIME}, new OracleParameter(":PASSMINUTE", OracleType.Number,4){Value = model.PASSMINUTE}, new OracleParameter(":SECOND", OracleType.Number){Value = model.SECOND} }; int rows = OracleHelper.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return true; } else { return false; } }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(ServerConfigModel model) { StringBuilder strSql = new StringBuilder(); List<OracleParameter> listPara = new List<OracleParameter>(); strSql.Append("insert into Robots_ServerConfig("); strSql.Append("ID,SERVICENAME,SERVICEIP,LASTTIME,PASSMINUTE,SECOND"); strSql.Append(") values ("); strSql.Append(":ID,:SERVICENAME,:SERVICEIP,sysdate,:PASSMINUTE,:SECOND"); strSql.Append(") "); listPara.Add(new OracleParameter(":ID", OracleType.Number, 4) { Value = model.ID }); listPara.Add(new OracleParameter(":SERVICENAME", OracleType.VarChar, 100) { Value = model.SERVICENAME }); listPara.Add(new OracleParameter(":SERVICEIP", OracleType.VarChar, 100) { Value = model.SERVICEIP }); listPara.Add(new OracleParameter(":PASSMINUTE", OracleType.Number, 4) { Value = model.PASSMINUTE }); listPara.Add(new OracleParameter(":SECOND", OracleType.Number) { Value = model.SECOND }); int rows = OracleHelper.ExecuteSql(strSql.ToString(), listPara.ToArray()); if (rows > 0) { return true; } else { return false; } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(ServerConfigModel model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Robots_ServerConfig set "); strSql.Append(" ID = :ID , "); strSql.Append(" SERVICENAME = :SERVICENAME , "); strSql.Append(" SERVICEIP = :SERVICEIP , "); strSql.Append(" LASTTIME = :LASTTIME, "); strSql.Append(" SECOND = :SECOND, "); strSql.Append(" PASSMINUTE = :PASSMINUTE "); strSql.Append(" where ID=:ID "); OracleParameter[] parameters = { new OracleParameter(":ID", OracleType.Number, 4) { Value = model.ID }, new OracleParameter(":SERVICENAME", OracleType.VarChar, 100) { Value = model.SERVICENAME }, new OracleParameter(":SERVICEIP", OracleType.VarChar, 100) { Value = model.SERVICEIP }, new OracleParameter(":LASTTIME", OracleType.DateTime) { Value = model.LASTTIME }, new OracleParameter(":PASSMINUTE", OracleType.Number, 4) { Value = model.PASSMINUTE }, new OracleParameter(":SECOND", OracleType.Number) { Value = model.SECOND } }; int rows = OracleHelper.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(ServerConfigModel model) { StringBuilder strSql = new StringBuilder(); List <OracleParameter> listPara = new List <OracleParameter>(); strSql.Append("insert into Robots_ServerConfig("); strSql.Append("ID,SERVICENAME,SERVICEIP,LASTTIME,PASSMINUTE,SECOND"); strSql.Append(") values ("); strSql.Append(":ID,:SERVICENAME,:SERVICEIP,sysdate,:PASSMINUTE,:SECOND"); strSql.Append(") "); listPara.Add(new OracleParameter(":ID", OracleType.Number, 4) { Value = model.ID }); listPara.Add(new OracleParameter(":SERVICENAME", OracleType.VarChar, 100) { Value = model.SERVICENAME }); listPara.Add(new OracleParameter(":SERVICEIP", OracleType.VarChar, 100) { Value = model.SERVICEIP }); listPara.Add(new OracleParameter(":PASSMINUTE", OracleType.Number, 4) { Value = model.PASSMINUTE }); listPara.Add(new OracleParameter(":SECOND", OracleType.Number) { Value = model.SECOND }); int rows = OracleHelper.ExecuteSql(strSql.ToString(), listPara.ToArray()); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public ServerConfigModel GetModel(ServerConfigModel model) { return(dal.GetModel(model)); }
/// <summary> /// 更新一条数据 /// </summary> public bool UpdateLastIp(ServerConfigModel model) { return(dal.UpdateLastIp(model)); }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(ServerConfigModel model) { return(dal.Add(model)); }
/// <summary> /// Checks the server. /// </summary> /// <param name="serviceName">Name of the service.</param> /// <param name="second">The second.</param> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns> public static bool CheckServer(string serviceName, double second) { try { int passMinute = 5; int.TryParse(AppConfigHelper.PassMinute, out passMinute); string serviceIp = NetUtil.GetHostIp(); second = Math.Ceiling(second); var serverConfigBll = new ServerConfigBll(); var severConfigModel = serverConfigBll.GetModel(new ServerConfigModel() { SERVICENAME = serviceName }); //不存在记录,插入记录返回false if (severConfigModel == null) { ServerConfigModel model = new ServerConfigModel(); model.SERVICENAME = serviceName; model.SERVICEIP = serviceIp; model.PASSMINUTE = passMinute; model.SECOND = second; var bak = serverConfigBll.Add(model); TextLog.Append("无服务配制,插入记录,返回F"); return(false); } else { if (severConfigModel.PASSMINUTE > 0) { passMinute = severConfigModel.PASSMINUTE; } else { severConfigModel.PASSMINUTE = passMinute; } //存在记录IP相同 if (severConfigModel.SERVICEIP == serviceIp) { //存在记录IP相同,5分种内更新,返回true; if (severConfigModel.SYSDATETIME < severConfigModel.LASTTIME.AddMinutes(passMinute).AddSeconds(severConfigModel.SECOND)) { severConfigModel.SECOND = second; var bak = serverConfigBll.UpdateLastTime(severConfigModel); if (bolWriteLogFlag) { TextLog.Append(string.Format("IP相同,{0}分内,有权,返回T", passMinute)); bolWriteLogFlag = false; } return(bak); } else { severConfigModel.SECOND = second; var bak = serverConfigBll.UpdateLastTime(severConfigModel); //存在记录IP相同,5分种后主服务器收回权限,返回更新true; TextLog.Append(string.Format("IP相同,{0}分后,获权,返回F", passMinute)); bolWriteLogFlag = true; return(false); } } else { //IP不同,5分种后返回true if (severConfigModel.SYSDATETIME > severConfigModel.LASTTIME.AddMinutes(passMinute).AddSeconds(severConfigModel.SECOND)) { TextLog.Append(string.Format("IP不同,{0}分种后,获权,返回F", passMinute)); bolWriteLogFlag = true; severConfigModel.SERVICEIPPER = severConfigModel.SERVICEIP; severConfigModel.SERVICEIP = serviceIp; severConfigModel.SECOND = second; var bak = serverConfigBll.UpdateLastIp(severConfigModel); return(false); } else { //IP不同,5分种内返回false TextLog.Append(string.Format("IP不同,{0}分种内,无权,返回F", passMinute)); bolWriteLogFlag = true; return(false); } } } } catch (Exception ex) { TextLog.Append(String.Format("检查服务配制失败: " + ex.Message)); return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public ServerConfigModel GetModel(ServerConfigModel model) { List<OracleParameter> listpara = new List<OracleParameter>(); StringBuilder strSql = new StringBuilder(); strSql.Append("select ID, SERVICENAME, SERVICEIP, LASTTIME,SYSDATE SYSDATETIME,PASSMINUTE,SECOND "); strSql.Append(" from Robots_ServerConfig "); strSql.Append(" where 1=1 "); if (!string.IsNullOrEmpty(model.SERVICENAME)) { strSql.Append(" and SERVICENAME=:SERVICENAME "); listpara.Add(new OracleParameter(":SERVICENAME", OracleType.VarChar, 100) { Value = model.SERVICENAME }); } if (!string.IsNullOrEmpty(model.SERVICEIP)) { strSql.Append(" and SERVICEIP=:SERVICEIP "); listpara.Add(new OracleParameter(":SERVICEIP", OracleType.VarChar, 100) { Value = model.SERVICEIP }); } strSql.Append(" order by id desc "); return OracleHelper.QueryEntity<ServerConfigModel>(strSql.ToString(), listpara.ToArray()); }
/// <summary> /// Checks the server. /// </summary> /// <param name="serviceName">Name of the service.</param> /// <param name="second">The second.</param> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns> public static bool CheckServer(string serviceName, double second) { try { int passMinute = 5; int.TryParse(AppConfigHelper.PassMinute, out passMinute); string serviceIp = NetUtil.GetHostIp(); second = Math.Ceiling(second); var serverConfigBll = new ServerConfigBll(); var severConfigModel = serverConfigBll.GetModel(new ServerConfigModel() { SERVICENAME = serviceName }); //不存在记录,插入记录返回false if (severConfigModel == null) { ServerConfigModel model = new ServerConfigModel(); model.SERVICENAME = serviceName; model.SERVICEIP = serviceIp; model.PASSMINUTE = passMinute; model.SECOND = second; var bak = serverConfigBll.Add(model); TextLog.Append("无服务配制,插入记录,返回F"); return false; } else { if (severConfigModel.PASSMINUTE > 0) { passMinute = severConfigModel.PASSMINUTE; } else { severConfigModel.PASSMINUTE = passMinute; } //存在记录IP相同 if (severConfigModel.SERVICEIP == serviceIp) { //存在记录IP相同,5分种内更新,返回true; if (severConfigModel.SYSDATETIME < severConfigModel.LASTTIME.AddMinutes(passMinute).AddSeconds(severConfigModel.SECOND)) { severConfigModel.SECOND = second; var bak = serverConfigBll.UpdateLastTime(severConfigModel); TextLog.Append(string.Format("IP相同,{0}分内,有权,返回T", passMinute)); return bak; } else { severConfigModel.SECOND = second; var bak = serverConfigBll.UpdateLastTime(severConfigModel); //存在记录IP相同,5分种后主服务器收回权限,返回更新true; TextLog.Append(string.Format("IP相同,{0}分后,获权,返回F", passMinute)); return false; } } else { //IP不同,5分种后返回true if (severConfigModel.SYSDATETIME > severConfigModel.LASTTIME.AddMinutes(passMinute).AddSeconds(severConfigModel.SECOND)) { TextLog.Append(string.Format("IP不同,{0}分种后,获权,返回F", passMinute)); severConfigModel.SERVICEIPPER = severConfigModel.SERVICEIP; severConfigModel.SERVICEIP = serviceIp; severConfigModel.SECOND = second; var bak = serverConfigBll.UpdateLastIp(severConfigModel); return false; } else { //IP不同,5分种内返回false TextLog.Append(string.Format("IP不同,{0}分种内,无权,返回F", passMinute)); return false; } } } } catch (Exception ex) { TextLog.Append(String.Format("检查服务配制失败: " + ex.Message)); return false; } }
/// <summary> /// 得到一个对象实体 /// </summary> public ServerConfigModel GetModel(ServerConfigModel model) { return dal.GetModel(model); }
/// <summary> /// 更新一条数据 /// </summary> public bool UpdateLastIp(ServerConfigModel model) { return dal.UpdateLastIp(model); }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(ServerConfigModel model) { return dal.Add(model); }
/// <summary> /// 获得数据列表 /// </summary> public List<ServerConfigModel> DataTableToList(DataTable dt) { List<ServerConfigModel> modelList = new List<ServerConfigModel>(); int rowsCount = dt.Rows.Count; if (rowsCount > 0) { ServerConfigModel model; for (int n = 0; n < rowsCount; n++) { model = new ServerConfigModel(); if (dt.Rows[n]["ID"].ToString() != "") { model.ID = decimal.Parse(dt.Rows[n]["ID"].ToString()); } if (dt.Rows[n]["LASTTIME"].ToString() != "") { model.LASTTIME = DateTime.Parse(dt.Rows[n]["LASTTIME"].ToString()); } modelList.Add(model); } } return modelList; }