예제 #1
0
 /// <summary>
 /// 测试eSight是否能够连通。
 /// </summary>
 /// <param name="hostIP">主机IP</param>
 /// <param name="port">端口</param>
 /// <param name="userAccount">用户账户</param>
 /// <param name="passowrd">密码</param>
 /// <param name="timeoutSec">超时时间默认为:ConstMgr.HWESightHost.DEFAULT_TIMEOUT_SEC</param>
 /// <returns>失败返回错误码,成功返回为空字符</returns>
 public string TestESSession(string hostIP, int port, string userAccount, string passowrd, int timeoutSec = ConstMgr.HWESightHost.DEFAULT_TIMEOUT_SEC)
 {
     try
     {
         using (ESSession eSSession = new ESSession())
         {
             eSSession.SetHttpMode(_isHttps);
             eSSession.InitESight(hostIP, port, userAccount, passowrd, timeoutSec);
             eSSession.Open();
         }
     }
     catch (ESSessionExpceion ess)
     {
         LogUtil.HWLogger.API.Error(ess);
         if (ess.Code == "1")
         {
             return(ConstMgr.ErrorCode.SYS_USER_LOGING);
         }
         else
         {
             return(ess.Code);
         }
     }
     catch (Exception se)
     {
         LogUtil.HWLogger.API.Error(se);
         return(ConstMgr.ErrorCode.SYS_UNKNOWN_ERR);
     }
     return("");
 }
예제 #2
0
        /// <summary>
        /// 返回IESSession
        /// </summary>
        /// <param name="hostIP">eSight IP</param>
        /// <param name="aliasName">别名</param>
        /// <param name="port">eSight 端口</param>
        /// <param name="userAccount">对应的账号</param>
        /// <param name="passowrd">对应的密码</param>
        /// <param name="timeoutSec">连接超时时间,默认:ConstMgr.HWESightHost.DEFAULT_TIMEOUT_SEC</param>
        /// <returns></returns>
        public IESSession SaveNewESSession(string hostIP, string aliasName, int port, string userAccount, string passowrd, int timeoutSec = ConstMgr.HWESightHost.DEFAULT_TIMEOUT_SEC)
        {
            //测试连接...
            using (ESSession eSSession = new ESSession())
            {
                eSSession.SetHttpMode(_isHttps);
                eSSession.InitESight(hostIP, port, userAccount, passowrd, timeoutSec);
                eSSession.Open();
            }

            IESSession iESSession = null;

            iESSession = FindESSession(hostIP); //查找已有的eSesssion,防止重复
            if (iESSession == null)             //没有找到已有的eSight.
            {
                iESSession = new ESSession();
                iESSession.SetHttpMode(_isHttps);                                      //设置默认协议为全局。
            }
            iESSession.InitESight(hostIP, port, userAccount, passowrd, timeoutSec);    //初始化eSight.
            iESSession.HWESightHost.AliasName = aliasName;                             //初始化eSight别名.
            iESSession.Open();                                                         //尝试打开连接,可能会抛出异常。

            iESSession.SaveToDB();                                                     //保存到数据库
            lock (eSightSessions)                                                      //锁定向量,防止并发
            {
                eSightSessions[iESSession.HWESightHost.HostIP.ToUpper()] = iESSession; //存储到缓存。
            }
            return(iESSession);
        }
예제 #3
0
 public static void ClassInitialize(TestContext context)
 {
     _hwESightHost              = new HWESightHost();
     _hwESightHost.HostIP       = "127.0.0.1";
     _hwESightHost.HostPort     = 32102;
     _hwESightHost.LoginAccount = "test";
     _hwESightHost.LoginPwd     = "test";
     _esSession = new ESSession();
     _esSession.SetHttpMode(true);
     _esSession.InitESight(_hwESightHost, ConstMgr.HWESightHost.DEFAULT_TIMEOUT_SEC);
 }
예제 #4
0
 public void SaveToDBTest()
 {
     using (ESSession esSession = new ESSession())
     {
         esSession.SetHttpMode(true);
         esSession.InitESight(_hwESightHost, ConstMgr.HWESightHost.DEFAULT_TIMEOUT_SEC);
         bool isSccu = esSession.SaveToDB();
         Assert.IsTrue(isSccu);
         Assert.IsTrue(esSession.HWESightHost.ID > 0);
     }
 }
예제 #5
0
        public void ChkOpenResultTest()
        {
            ESSession    esSession    = new ESSession();
            HWESightHost hwESightHost = new HWESightHost();

            hwESightHost.HostIP       = "127.0.0.1";
            hwESightHost.HostPort     = 32102;
            hwESightHost.LoginAccount = "test";
            hwESightHost.LoginPwd     = "test";
            esSession = new ESSession();
            esSession.SetHttpMode(true);
            esSession.InitESight(hwESightHost, ConstMgr.HWESightHost.DEFAULT_TIMEOUT_SEC);
            JObject result = JsonUtil.DeserializeObject <JObject>("{\"code\":1,\"data\":\"bfec0163 - dd56 - 473e-b11f - 6d5845e1b684\", \"description\":\"Operation success.\"}");

            esSession.ChkOpenResult(result);
        }
예제 #6
0
        /// <summary>
        /// 查询已有的连接列表
        /// </summary>
        /// <returns>返回已有的连接列表</returns>
        public IList <IESSession> ListESSessions()
        {
            lock (eSightSessions)
            {
                IList <IESSession>   retList  = new List <IESSession>();
                IList <HWESightHost> hostList = ListESHost();
                Dictionary <string, HWESightHost> tmpSessions = new Dictionary <string, HWESightHost>();
                foreach (HWESightHost hwESightHost in hostList)
                {
                    tmpSessions[hwESightHost.HostIP.ToUpper()] = hwESightHost;
                    if (eSightSessions.ContainsKey(hwESightHost.HostIP.ToUpper()))//Already exists...
                    {
                        IESSession iESession = eSightSessions[hwESightHost.HostIP.ToUpper()];
                        if (IsSameESightHost(hwESightHost, iESession.HWESightHost))
                        {
                            retList.Add(eSightSessions[hwESightHost.HostIP.ToUpper()]);
                        }
                        else//If not same reinit. 将list增加给retlist
                        {
                            iESession.InitESight(hwESightHost, ConstMgr.HWESightHost.DEFAULT_TIMEOUT_SEC);
                            retList.Add(iESession);
                        }
                    }
                    else
                    {//Create new...
                        IESSession iESSession = new ESSession();
                        iESSession.SetHttpMode(_isHttps);
                        iESSession.InitESight(hwESightHost, ConstMgr.HWESightHost.DEFAULT_TIMEOUT_SEC);
                        eSightSessions[hwESightHost.HostIP.ToUpper()] = iESSession;

                        retList.Add(iESSession);
                    }
                }
                //Clean unused sessions.
                IList <IESSession> existsList = new List <IESSession>(eSightSessions.Values);
                foreach (IESSession ieSSession in existsList)
                {
                    if (!tmpSessions.ContainsKey(ieSSession.HWESightHost.HostIP.ToUpper()))
                    {
                        eSightSessions.Remove(ieSSession.HWESightHost.HostIP.ToUpper());
                    }
                }
                return(retList);
            }
        }
예제 #7
0
        /// <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;
                    }
                }
            }
        }
예제 #8
0
        public void DisposeESightTest()
        {
            ESSession    esSession    = new ESSession();
            HWESightHost hwESightHost = new HWESightHost();

            hwESightHost.HostIP       = "127.0.0.1";
            hwESightHost.HostPort     = 32102;
            hwESightHost.LoginAccount = "test";
            hwESightHost.LoginPwd     = "test";
            esSession = new ESSession();
            esSession.SetHttpMode(true);
            esSession.InitESight(hwESightHost, ConstMgr.HWESightHost.DEFAULT_TIMEOUT_SEC);
            esSession.Open();
            bool isSccu = esSession.SaveToDB();

            Assert.IsTrue(isSccu);

            esSession.HClient = null;
            //esSession.HWESightHost.HostIP = "xxx.xxx.xxx";

            esSession.Dispose();
        }
예제 #9
0
        public void DeleteESightTestZero()
        {
            ESSession    esSession    = new ESSession();
            HWESightHost hwESightHost = new HWESightHost();

            hwESightHost.HostIP       = "127.0.0.1";
            hwESightHost.HostPort     = 32102;
            hwESightHost.LoginAccount = "test";
            hwESightHost.LoginPwd     = "test";
            esSession = new ESSession();
            esSession.SetHttpMode(true);
            esSession.InitESight(hwESightHost, ConstMgr.HWESightHost.DEFAULT_TIMEOUT_SEC);

            bool isSccu = esSession.SaveToDB();

            Assert.IsTrue(isSccu);
            int oldId = esSession.HWESightHost.ID;

            esSession.HWESightHost.ID = 0;
            isSccu = esSession.DeleteESight();
            Assert.IsTrue(isSccu);
            esSession.HWESightHost.ID = oldId;
            esSession.DeleteESight();
        }
예제 #10
0
 public void SetHttpModeTest()
 {
     _esSession.SetHttpMode(true);
 }