/// <summary> /// 查询eSight列表(数据库中的数据,而不是ESSession) /// </summary> /// <returns>eSight列表</returns> public IList <HWESightHost> ListESHost() { IHWESightHostDal hwESightHostDal = HWESightHostDal.Instance; IList <HWESightHost> hostList = hwESightHostDal.GetList("1=1"); return(hostList); }
/// <summary> /// 删除eSight对象,从数据库中。 /// </summary> /// <returns></returns> public bool DeleteESight() { CheckInit();//是否不存在eSight对象。 IHWESightHostDal hwESightHostDal = HWESightHostDal.Instance; if (this.HWESightHost.ID > 0) { hwESightHostDal.DeleteESight(this.HWESightHost.ID); } else { LogUtil.HWLogger.API.WarnFormat("This eSight host has not add to the database,IP:{0}", HWESightHost.HostIP); } return(true); }
/// <summary> /// 保存当前eSight连接对象信息或状态到服务器。 /// </summary public bool SaveToDB() { CheckInit(); try { System.Threading.Monitor.Enter(_lockInstance);//开锁 IHWESightHostDal hwESightHostDal = HWESightHostDal.Instance; LogUtil.HWLogger.API.DebugFormat("db id={0}", this.HWESightHost.ID); if (this.HWESightHost.ID > 0)//是否新的eSight对象 { HWESightHost hwESightHost = hwESightHostDal.GetEntityById(this.HWESightHost.ID); if (hwESightHost != null)//是否新的eSight对象,是否找到 { LogUtil.HWLogger.API.DebugFormat("update old id={0}", _hwESightHost.ID); hwESightHostDal.UpdateEntity(this._hwESightHost); } else //重新保存一个新的。 { LogUtil.HWLogger.API.Debug("add1 old id=" + HWESightHost.ID); int oldid = _hwESightHost.ID; //_hwESightHost.ID = 0; _hwESightHost.CreateTime = System.DateTime.Now; hwESightHostDal.UpdateEntity(_hwESightHost); LogUtil.HWLogger.API.DebugFormat("add old id={0},new id={1}", oldid, _hwESightHost.ID); } } else { //插入新的eSight对象。 _hwESightHost.CreateTime = System.DateTime.Now; _hwESightHost.ID = hwESightHostDal.InsertEntity(_hwESightHost); LogUtil.HWLogger.API.DebugFormat("add1 id=" + _hwESightHost.ID); } } catch (Exception se) { LogUtil.HWLogger.API.Error(se); throw; } finally { System.Threading.Monitor.Exit(_lockInstance);//释放锁。 } return(true); }
/// <summary> /// 初始化所有的eSight连接的配置信息。 /// 注意,并没有open。 /// </summary> /// <param name="timeoutSec">连接超时时间,默认为ConstMgr.HWESightHost.DEFAULT_TIMEOUT_SEC</param> public void InitESSessions(int timeoutSec = ConstMgr.HWESightHost.DEFAULT_TIMEOUT_SEC) { IHWESightHostDal hwESightHostDal = HWESightHostDal.Instance; IList <HWESightHost> hostList = hwESightHostDal.GetList("1=1");//获取eSight foreach (HWESightHost hwESightHost in hostList) { lock (eSightSessions) //开锁 { if (!eSightSessions.ContainsKey(hwESightHost.HostIP.ToUpper())) //判断是否已经在内存中存在,防止反复初始化。 { IESSession iESSession = new ESSession(); iESSession.SetHttpMode(_isHttps); iESSession.InitESight(hwESightHost, timeoutSec); eSightSessions[hwESightHost.HostIP.ToUpper()] = iESSession; } } } }
/// <summary> /// 根据ID删除一个eSight,删除内存和数据库。 /// </summary> /// <param name="id">eSight id</param> /// <returns>成功失败。</returns> public bool RemoveESSession(int id) { bool isNotFind = true; IList <HWESightHost> hostList = ListESHost(); foreach (HWESightHost host in hostList) { if (host.ID == id) { LogUtil.HWLogger.API.InfoFormat("Begining to delete eSight: [{0}, {1}]", host.HostIP, host.ID); RemoveESSession(host.HostIP); isNotFind = false; } } if (isNotFind) {//多删除一次,在数据库中。 没找到时。 IHWESightHostDal hwESightHostDal = HWESightHostDal.Instance; hwESightHostDal.DeleteESight(id); LogUtil.HWLogger.API.InfoFormat("deleted eSight: [{0}]", id); } return(true); }