コード例 #1
0
ファイル: TiandyVideoMonitor.cs プロジェクト: eSDK/esdk_Cgw
        /// <summary>
        /// 获取摄像头列表及分组信息
        /// </summary>
        /// <param name="fromMonitorSys">如果该值为true,则实时从监控平台获取,否则从融合网关缓存获取</param>
        /// <param name="cameraList">摄像头列表</param>
        /// <param name="groupList">组信息</param>
        /// <param name="nodeRelationListT">分组关系</param>
        /// <returns></returns>
        public SmcErr GetAllCameras(out List<Camera> cameraList, out List<CameraGroup> groupList, out List<NodeRelation> nodeRelationListT)
        {
            monitorManageServiceGetCameraList.Stop();
            isGetDevicesFinish = false;

            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: TiandyVideoMonitor.GetAllCameras().");
            SmcErr err = new CgwError();
            cameraList = new List<Camera>();
            groupList = new List<CameraGroup>();
            nodeRelationListT = new List<NodeRelation>();

            if (this.cameraOperateLock.TryEnterReadLock(CgwConst.ENTER_LOCK_WAIT_TIME))
            {
                try
                {
                    #region 深度克隆数据
                    foreach (KeyValuePair<string, TiandyCamera> tiandyCameraKeyValue in this.tiandyCameraDictionary)
                    {
                        TiandyCamera tiandyCamera = tiandyCameraKeyValue.Value;
                        //从缓存获取
                        Camera camera = new Camera(tiandyCamera.No, tiandyCamera.Name);
                        cameraList.Add(camera);
                    }
                    foreach (KeyValuePair<string, CameraGroup> groupDicKeyValue in this.groupDic)
                    {
                        CameraGroup cameraGroupTemp = new CameraGroup(groupDicKeyValue.Value.No, groupDicKeyValue.Value.Name);
                        groupList.Add(cameraGroupTemp);
                    }

                    foreach (NodeRelation nodeRelation in this.nodeRelationList)
                    {
                        NodeRelation nodeRelationTemp = new NodeRelation(nodeRelation.No,
                                                                          nodeRelation.Path,
                                                                          nodeRelation.Type);
                        nodeRelationListT.Add(nodeRelationTemp);
                    }
                    #endregion
                }
                catch (Exception e)
                {
                    err.SetErrorNo(CgwError.GET_ALL_CAMERAS_FAILED);
                    logEx.Error("Get all cameras failed.Execption message:{0}", e.Message);
                    return err;
                }
                finally
                {
                    this.cameraOperateLock.ExitReadLock();
                }
            }
            monitorManageServiceGetCameraList.Start();
            logEx.Info("Get all cameras success.");
            return err;
        }
コード例 #2
0
ファイル: TiandyVideoMonitor.cs プロジェクト: eSDK/esdk_Cgw
        /// <summary>
        /// 获取摄像头列表及分组信息
        /// </summary>
        private void GetAllCamerasMethod()
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: TiandyVideoMonitor.GetAllCamerasTimer().");

            try
            {

                //调用天地伟业http接口获取天地伟业设备管理树列表
                List<Resource> resourceTree = this.httpClient.GetResourceTree();
                if (resourceTree == null)
                {
                    logEx.Error("GetResourceTree failed.");
                    ClearCamera();
                    isRefreshSucess = false;
                    return;
                }

                //调用天地伟业http接口获取自定义设备树列表
                List<Resource> customTree = this.httpClient.GetCustomTree();

                if (customTree == null)
                {
                    logEx.Error("GetCustomTree failed.");
                    ClearCamera();
                    isRefreshSucess = false;
                    return;
                }

                Dictionary<string, TiandyCamera> tiandyCameraDictionaryTemp = new Dictionary<string, TiandyCamera>();
                Dictionary<string, Host> hostDictionaryTemp = new Dictionary<string, Host>();
                Dictionary<string, MediaServer> mediaServerDictionaryTemp = new Dictionary<string, MediaServer>();
                //递归处理,将摄像头、主机、流媒体服务器遍历出来
                RecursionCamera(resourceTree, tiandyCameraDictionaryTemp, hostDictionaryTemp, mediaServerDictionaryTemp);

                Dictionary<string, CameraGroup> groupDicTemp = new Dictionary<string, CameraGroup>();
                Dictionary<string, NodeRelation> nodeRelationDicTemp = new Dictionary<string, NodeRelation>();
                List<NodeRelation> nodeRelationListTemp = new List<NodeRelation>();

                //递归处理,获取组,摄像头、分组关系
                RecursionCameraGroup(customTree, null, groupDicTemp, nodeRelationDicTemp, nodeRelationListTemp);

                //对于未分组的摄像头,父节点设置为空
                foreach (KeyValuePair<string, TiandyCamera> tiandyCameraKeyValue in tiandyCameraDictionaryTemp)
                {
                    if (!nodeRelationDicTemp.ContainsKey(tiandyCameraKeyValue.Key))
                    {
                        NodeRelation nodeRelation = new NodeRelation(tiandyCameraKeyValue.Key,
                                                                     new List<string>(),
                                                                     CgwMonitorManage.Common.NodeType.CAMERA);
                        nodeRelationListTemp.Add(nodeRelation);
                    }
                }

                DateTime dtStart = DateTime.Now;
                DateTime dtNow = new DateTime();
                while (!isGetDevicesFinish)
                {
                    dtNow = DateTime.Now;

                    if ((dtNow - dtStart).TotalSeconds > refreshDeviceListOverTime)
                    {
                        isRefreshSucess = false;
                        return;
                    }
                    Thread.Sleep(1);
                    continue;
                }

                if (this.cameraOperateLock.TryEnterWriteLock(CgwConst.ENTER_LOCK_WAIT_TIME))
                {
                    try
                    {
                        this.tiandyCameraDictionary = tiandyCameraDictionaryTemp;
                        this.hostDictionary = hostDictionaryTemp;
                        this.mediaServerDictionary = mediaServerDictionaryTemp;

                        this.groupDic = groupDicTemp;
                        this.nodeRelationList = nodeRelationListTemp;

                        isRefreshSucess = true;

                    }
                    catch (Exception ex)
                    {
                        isRefreshSucess = false;
                        logEx.Error("Recursion camera failed.Execption message:{0}", ex.Message);
                    }
                    finally
                    {
                        this.cameraOperateLock.ExitWriteLock();
                    }
                }
            }
            catch (System.Exception ex)
            {
                isRefreshSucess = false;
                logEx.Error("GetAllCamerasTimer catch Exception:{0}", ex.Message);
            }
        }
コード例 #3
0
ファイル: IvsVideoMonitor.cs プロジェクト: eSDK/esdk_Cgw
        /// <summary>
        /// 获取摄像头列表及分组信息
        /// </summary>
        private void GetAllCamerasMethod()
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: IvsVideoMonitor.GetAllCamerasMethod().");
            try
            {
                //1、获取系统中所有的域
                List<IvsDomainRoute> ivsDomainRouteList;

                logEx.Trace("Call ivsSdkClient.GetDomainRoute().");
                int result = this.ivsSdkClient.GetDomainRoute(out ivsDomainRouteList);

                if (result == CgwConst.IVS_SDK_SUCCESS_TAG)
                {
                    logEx.Info("GetDomainRoute success.List count:{0}", ivsDomainRouteList.Count);
                }
                else
                {
                    logEx.Error("GetDomainRoute failed.Ivs sdk error code:{0}", result);
                    ClearCamera();
                    isRefreshSucess = false;
                    return;
                }

                List<Camera> cameraListTemp = new List<Camera>();
                List<CameraGroup> groupListTemp = new List<CameraGroup>();
                List<NodeRelation> nodeRelationListTemp = new List<NodeRelation>();
                Dictionary<string, NodeRelation> nodeRelationDicTemp = new Dictionary<string, NodeRelation>();

                foreach (IvsDomainRoute route in ivsDomainRouteList)
                {
                    //加上此判断条件的话,子域将不会作查目录处理,不合理,故注释掉
                    //if (route.ParentDomain != "")
                    //{
                    //    continue;
                    //}
                    Dictionary<string, IvsCameraGroup> ivsCameraGroupDic;

                    logEx.Trace("Call ivsSdkClient.GetDeviceGroupList({0},{1},out groupCount, out ivsCameraGroupDic).",
                                route.DomainCode,
                                CgwConst.IVS_SDK_ROOTGROUP_TAG);

                    result = this.ivsSdkClient.GetDeviceGroupList(route.DomainCode,
                                                             CgwConst.IVS_SDK_ROOTGROUP_TAG,
                                                             out ivsCameraGroupDic);

                    if (result == CgwConst.IVS_SDK_SUCCESS_TAG)
                    {
                        logEx.Info("GetDeviceGroupList success.Current group count:{0}", ivsCameraGroupDic.Count);
                    }
                    else
                    {
                        logEx.Error("GetDeviceGroupList failed.Ivs sdk error code:{0}", result);
                        ClearCamera();
                        isRefreshSucess = false;
                        return;
                    }

                    //域也当做分组使用
                    string encodeDomainNo = CgwConst.IVS_SDK_ROOTGROUP_TAG + CgwConst.IVS_SDK_DOMAINCODE_SEPARATOR_TAG + route.DomainCode;
                    CameraGroup domainGroup = new CameraGroup(encodeDomainNo, route.DomainName);
                    groupListTemp.Add(domainGroup);

                    List<string> pathDomainList = new List<string>();
                    RecursionGroupPath(route.DomainCode, ivsDomainRouteList,ref pathDomainList);
                    NodeRelation nodeDomainRelation = new NodeRelation(encodeDomainNo, pathDomainList, CgwMonitorManage.Common.NodeType.GROUP);
                    nodeRelationDicTemp.Add(encodeDomainNo, nodeDomainRelation);

                    foreach (KeyValuePair<string, IvsCameraGroup> ivsCameraGroupKeyValue in ivsCameraGroupDic)
                    {
                        IvsCameraGroup group = ivsCameraGroupKeyValue.Value;
                        string encodeGroupNo = group.GroupNo + CgwConst.IVS_SDK_DOMAINCODE_SEPARATOR_TAG + group.DomainCode;
                        //添加组信息
                        CameraGroup cameraGroup = new CameraGroup(encodeGroupNo, group.GroupName);
                        groupListTemp.Add(cameraGroup);

                        List<string> pathList = new List<string>();
                        RecursionPath(group.GroupNo, ivsCameraGroupDic, ref pathList);

                        NodeRelation nodeRelation = new NodeRelation(encodeGroupNo, pathList, CgwMonitorManage.Common.NodeType.GROUP);
                        nodeRelationDicTemp.Add(encodeGroupNo, nodeRelation);
                    }
                }
                //添加所有组节点
                nodeRelationListTemp.AddRange(nodeRelationDicTemp.Values);

                List<IvsCamera> ivsCameraPageList = new List<IvsCamera>();
                int cameraCount = 0;
                logEx.Trace("Call ivsSdkClient.GetDeviceList");

                //查询第一页记录,同时获取摄像头个数
                result = this.ivsSdkClient.GetDeviceList(CgwConst.PAGE_FIRST_INDEX, CgwConst.PAGE_LAST_INDEX, out cameraCount, out ivsCameraPageList);

                List<IvsCamera> ivsCameraLeaveList = new List<IvsCamera>();
                //如果总记录大于一页的总记录数
                if (cameraCount > CgwConst.PAGE_LAST_INDEX)
                {
                    //一次将剩下所有记录查询出来
                    result = this.ivsSdkClient.GetDeviceList(CgwConst.PAGE_LAST_INDEX + 1, cameraCount, out cameraCount, out ivsCameraLeaveList);
                }

                if (result == CgwConst.IVS_SDK_SUCCESS_TAG)
                {
                    logEx.Info("GetDeviceList success.Current group count:{0}", cameraCount);
                    ivsCameraPageList.AddRange(ivsCameraLeaveList);
                }
                else
                {
                    logEx.Error("GetDeviceList failed.Ivs sdk error code:{0}", result);
                    ClearCamera();
                    isRefreshSucess = false;
                    return;
                }

                foreach (IvsCamera ivsCamera in ivsCameraPageList)
                {
                    Camera camera = new Camera(ivsCamera.No, ivsCamera.Name);
                    camera.Status = ivsCamera.Status;

                    List<string> cameraPathList = new List<string>();
                    //string encodeGroupNo = ivsCamera.GroupNo + CgwConst.IVS_SDK_DOMAINCODE_SEPARATOR_TAG + ivsCamera.DomainCode;//摄像头所属组号错误(与群组组号混淆了)。
                    string encodeGroupNo = ivsCamera.GroupNo;
                    if (nodeRelationDicTemp.ContainsKey(encodeGroupNo))
                    {
                        //如果自定义分组里面包含该摄像头的父节点,需要设置分组路径
                        cameraPathList.AddRange(nodeRelationDicTemp[encodeGroupNo].Path);
                        cameraPathList.Add(encodeGroupNo);
                    }

                    NodeRelation nodeRelation = new NodeRelation(camera.No, cameraPathList, CgwMonitorManage.Common.NodeType.CAMERA);

                    //解决问题单DTS2013080201001,规避因IVS服务器存在摄像头重复的bug导致融合网关异常的问题
                    if (!nodeRelationDicTemp.ContainsKey(camera.No))
                    {
                        cameraListTemp.Add(camera);
                        nodeRelationDicTemp.Add(camera.No, nodeRelation);
                    }

                    nodeRelationListTemp.Add(nodeRelation);
                }
                //nodeRelationListTemp.AddRange(nodeRelationDicTemp.Values);

                DateTime dtStart = DateTime.Now;
                DateTime dtNow = new DateTime();
                while (!isGetDevicesFinish)
                {
                    dtNow = DateTime.Now;

                    if ((dtNow - dtStart).TotalSeconds > refreshDeviceListOverTime)
                    {
                        isRefreshSucess = false;
                        return;
                    }
                    Thread.Sleep(1);
                    continue;
                }
                //将实时获取的值放到缓存
                if (this.cameraOperateLock.TryEnterWriteLock(CgwConst.ENTER_LOCK_WAIT_TIME))
                {
                    try
                    {
                        this.cameraList = cameraListTemp;
                        this.groupList = groupListTemp;
                        this.nodeRelationList = nodeRelationListTemp;
                        isRefreshSucess = true;
                    }
                    catch (Exception ex)
                    {
                        isRefreshSucess = false;
                        logEx.Error("Set the list to the buffer failed. ", ex.Message);
                    }
                    finally
                    {
                        this.cameraOperateLock.ExitWriteLock();
                    }
                }
                else
                {
                    isRefreshSucess = false;
                }
            }
            catch (System.Exception ex)
            {
                logEx.Error("GetAllCamerasMethod failed.Exception message:{0}", ex.Message);
                isRefreshSucess = false;
            }
        }
コード例 #4
0
ファイル: TiandyVideoMonitor.cs プロジェクト: eSDK/esdk_Cgw
        /// <summary>
        /// 递归天地伟业返回的自定义设备列表,只获取分组节点(TypeId为1000)和通道(摄像头)节点(TypeId为5),舍弃其他节点(如主机,中间件服务器等)
        /// </summary>
        /// <param name="customTree">天地伟业返回的自定义设备列表树</param>
        /// <param name="pathList">节点路径,如果为跟节点,传null即可,主要是用于递归函数处理</param>
        /// <param name="groupDic">组列表</param>
        /// <param name="nodeRelationDic">组、摄像头关系列表Dic,不能重复</param>
        /// <param name="nodeRelationListT">组、摄像头关系列表,可以重复,解决同一摄像头在不同分组下,融合网关报错的问题</param>
        /// 
        private void RecursionCameraGroup(List<Resource> customTree, List<string> pathList, Dictionary<string, CameraGroup> groupDic, Dictionary<string, NodeRelation> nodeRelationDic, List<NodeRelation> nodeRelationListT)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);

            if (customTree == null)
            {
                logEx.Error("RecursionCameraGroup failed.CustomTree is null.");
                return;
            }

            if (pathList == null)
            {
                pathList = new List<string>();
            }

            if (groupDic == null)
            {
                groupDic = new Dictionary<string, CameraGroup>();
            }

            if (nodeRelationDic == null)
            {
                nodeRelationDic = new Dictionary<string, NodeRelation>();
            }

            if (nodeRelationListT == null)
            {
                nodeRelationListT = new List<NodeRelation>();
            }

            foreach (Resource custom in customTree)
            {
                //TypeId为5时,表示该节点为通道,对应一个摄像头
                if (((int)NodeType.CAMERA).ToString().Equals(custom.TypeId))
                {
                    //pathList.Add(custom.Id);
                    NodeRelation nodeRelation = new NodeRelation(custom.Id, new List<string>(pathList), CgwMonitorManage.Common.NodeType.CAMERA);
                    if (!nodeRelationDic.ContainsKey(custom.Id))
                    {
                        nodeRelationDic.Add(custom.Id, nodeRelation);
                    }
                    nodeRelationListT.Add(nodeRelation);

                    //获取完路径后,要返回上一级路径
                    //pathList.Remove(custom.Id);
                }
                //TypeId为1000时,表示该节点为分组
                else if (((int)NodeType.GROUP).ToString().Equals(custom.TypeId))
                {
                    //添加组信息
                    CameraGroup cameraGroup = new CameraGroup(custom.Id, custom.Caption);
                    groupDic.Add(custom.Id, cameraGroup);

                    NodeRelation nodeRelation = new NodeRelation(custom.Id, new List<string>(pathList), CgwMonitorManage.Common.NodeType.GROUP);
                    if (!nodeRelationDic.ContainsKey(custom.Id))
                    {
                        nodeRelationDic.Add(custom.Id, nodeRelation);
                    }
                    nodeRelationListT.Add(nodeRelation);

                    //添加分组关系
                    pathList.Add(custom.Id);

                    //如果是组,还需要递归处理,遍历子节点
                    RecursionCameraGroup(custom.items, pathList, groupDic, nodeRelationDic, nodeRelationListT);

                    //获取完路径后,要返回上一级路径
                    pathList.Remove(custom.Id);

                }
                else
                {
                    //其他类型节点不做处理
                }
            }
        }
コード例 #5
0
ファイル: eLTEVideoMonitor.cs プロジェクト: eSDK/esdk_Cgw
        /// <summary>
        /// 获取摄像头和组之间的关联
        /// </summary>
        /// <param name="cameraListTemp">摄像机列表</param>
        /// <param name="groupListTemp">分组列表</param>
        /// <param name="nodeRelationListTemp">组关系列表</param>
        private void GetCameraAndGroupRelation(List<Camera> cameraListTemp, List<CameraGroup> groupListTemp, List<NodeRelation> nodeRelationListTemp)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: eLTEVideoMonitor.GetCameraAndGroupRelation().");

            try
            {
                //查询摄像机的父节点,保存摄像机父节点关系列表
                foreach (Camera ca in cameraListTemp)
                {
                    //设备没有父节点
                    if (string.IsNullOrEmpty(ca.ParentID))
                    {
                        NodeRelation nodeRelation = new NodeRelation(ca.No, new List<string>(), NodeType.CAMERA);
                        nodeRelationListTemp.Add(nodeRelation);
                    }
                    else
                    {
                        string parentID = ca.ParentID;
                        //获取所有父节点路径
                        List<string> pathList = new List<string>();
                        FindNodeRelationPath(parentID, groupListTemp, ref pathList);

                        if (pathList.Count > 1)
                        {
                            //按照从顶到底排序
                            pathList.Reverse();
                        }
                        if (pathList == null)
                        {
                            pathList = new List<string>();
                        }

                        //设备组之间关系
                        NodeRelation nodeRelation = new NodeRelation(ca.No, pathList, NodeType.CAMERA);
                        nodeRelationListTemp.Add(nodeRelation);

                    }
                }
                logEx.Trace("GetCameraAndGroupRelation.CameraListTemp:{0}", cameraListTemp.Count);

                //比较返回序列中的非重复元素
                List<Camera> noduplicates = new List<Camera>();
                foreach (var camera in cameraListTemp)
                {
                    if (!noduplicates.Exists(x => x.No == camera.No))
                    {
                        noduplicates.Add(camera);
                    }
                }

                cameraListTemp.Clear();
                foreach (var camera in noduplicates)
                {
                    cameraListTemp.Add(camera);
                }

                //查询设备组的父节点,保存设备组父节点关系列表
                foreach (CameraGroup cg in groupListTemp)
                {
                    //设备组没有父节点
                    if (string.IsNullOrEmpty(cg.ParentID))
                    {
                        NodeRelation nodeRelation = new NodeRelation(cg.No, new List<string>(), NodeType.GROUP);
                        nodeRelationListTemp.Add(nodeRelation);
                    }
                    else
                    {
                        string parentID = cg.ParentID;
                        //获取分组所有父节点路径
                        List<string> pathList = new List<string>();
                        FindNodeRelationPath(parentID, groupListTemp, ref pathList);

                        if (pathList.Count > 1)
                        {
                            //按照从顶到底排序
                            pathList.Reverse();
                        }
                        //保存分组的父节点列表
                        NodeRelation nodeRelation = new NodeRelation(cg.No, pathList, NodeType.GROUP);
                        nodeRelationListTemp.Add(nodeRelation);
                    }
                }
            }
            catch (System.Exception ex)
            {
                logEx.Error("GetCameraAndGroupRelation failed. {0} ", ex.Message);
            }
        }
コード例 #6
0
ファイル: eLTEVideoMonitor.cs プロジェクト: eSDK/esdk_Cgw
        /// <summary>
        /// 获取摄像头列表及分组信息
        /// </summary>
        private void GetAllCamerasMethod()
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Info("Enter:GetAllCamerasMethod");
            try
            {
                List<Camera> cameraListTemp = new List<Camera>();
                List<CameraGroup> groupListTemp = new List<CameraGroup>();
                List<NodeRelation> nodeRelationListTemp = new List<NodeRelation>();

                List<eLTEGroupInfo> lsteLTEGroupInfo = new List<eLTEGroupInfo>();
                List<eLTEGrpUserInfo> lsteLTEGrpUserInfo = new List<eLTEGrpUserInfo>();

                List<eLTEUserInfo> dcUsersList = new List<eLTEUserInfo>();
                //获得本DC管理的所有User
                ELTE_RESULT iRet = (ELTE_RESULT)lteSdkClient.GetAllDcUsers(0, out dcUsersList);
                if (ELTE_RESULT.RET_SUCCESS != iRet)
                {
                    isRefreshSuccess = false;
                    logEx.Error("GetAllDcUsers Failed,ELTE_Result:{0}",iRet.ToString());
                    return;
                }

                //获得本DC管理的所有Group,返回值为一份克隆的数据,由调用者负责操纵并最终销毁、dcid:本调度台的用户号,如果 Dcid==0,则返回全网所有的Group
                iRet = (ELTE_RESULT)lteSdkClient.GetAllGroups(0, out lsteLTEGroupInfo);
                if (ELTE_RESULT.RET_SUCCESS != iRet)
                {
                    isRefreshSuccess = false;
                    logEx.Error("GetAllGroups Failed,ELTE_Result:{0}",iRet.ToString());
                    return;
                }

                foreach (eLTEGroupInfo group in lsteLTEGroupInfo)
                {
                    //保存分组信息
                    CameraGroup cameraGroup = new CameraGroup(group.grpid.ToString(), group.grpname);
                    groupListTemp.Add(cameraGroup);

                    List<eLTEGrpUserInfo> groupUserList = new List<eLTEGrpUserInfo>();
                    //获得某个组里的所有User,返回值为一份克隆的数据,由调用者负责操纵并最终销毁、grpid:组号;如果该组不存在,则返回NULL
                    iRet=(ELTE_RESULT)lteSdkClient.GetGroupUsers(group.grpid, out groupUserList);
                    if (ELTE_RESULT.RET_SUCCESS != iRet)
                    {
                        logEx.Error("GetGroupUsers Failed,GroupID:{0},ELTE_Result:{1}", group.grpid,iRet.ToString());
                        break;
                    }

                    foreach (eLTEGrpUserInfo user in groupUserList)
                    {
                        //动态重组中的组成员
                        if (user.memberType == eLTEGroup_Member_t.MEMBER_GROUP)
                        {
                            eLTEUserInfo userInfo = new eLTEUserInfo();
                            iRet=(ELTE_RESULT)lteSdkClient.GetUserInfo(user.userid, out userInfo);
                            if (ELTE_RESULT.RET_SUCCESS != iRet)
                            {
                                logEx.Error("GetUserInfo Failed,UserID:{0},ELTE_Result:{1}", user.userid,iRet.ToString());
                                break;
                            }
                            //保存分组信息
                            if (!groupListTemp.Exists(x => x.No == group.grpid.ToString()))
                            {
                                cameraGroup = new CameraGroup(userInfo.userid.ToString(), userInfo.username);
                                cameraGroup.ParentID = group.grpid.ToString();
                                groupListTemp.Add(cameraGroup);
                            }
                        }
                        //普通用户成员
                        else if (user.memberType == eLTEGroup_Member_t.MEMBER_USER)
                        {
                            eLTEUserInfo userInfo = new eLTEUserInfo();
                            userInfo = dcUsersList.Find(x =>
                            {
                                return x.userid == user.userid;
                            });

                            if (userInfo != null)
                            {
                                if ((userInfo.usercategory == eLTEUser_Category_t.PTTUSER && bPttUser) ||
                                    (userInfo.usercategory == eLTEUser_Category_t.FIXEDCAMERA && bFixedCamera))
                                {
                                    //保存用户信息
                                    Camera camera = new Camera(userInfo.userid.ToString(), userInfo.username);
                                    camera.ParentID = group.grpid.ToString();

                                    try
                                    {
                                        if (this.cameraStatusOperateLock.TryEnterReadLock(CgwConst.ENTER_LOCK_WAIT_TIME))
                                        {
                                            camera.Status = onlineUser.Exists((x) =>
                                            {
                                                if (x == camera.No)
                                                {
                                                    return true;
                                                }
                                                else
                                                {
                                                    return false;
                                                }
                                            }) == true ? CameraStatus.Online : CameraStatus.Offline;
                                        }
                                        cameraListTemp.Add(camera);
                                    }
                                    finally
                                    {
                                        this.cameraStatusOperateLock.ExitReadLock();
                                    }

                                }
                            }
                            else
                            {
                                logEx.Error("UserInfo is null,UserID:{0}", user.userid);
                            }
                        }
                    }
                }

                logEx.Trace("GetElteCameras cameraListTemp:{0}", cameraListTemp.Count);
                logEx.Trace("GetElteCameras groupListTemp:{0}", groupListTemp.Count);

                //获取摄像头和组之间的关联
                GetCameraAndGroupRelation(cameraListTemp, groupListTemp, nodeRelationListTemp);

                ////增加组外的设备信息
                //List<eLTEUserInfo> dcUsersList = new List<eLTEUserInfo>();
                ////获得本DC管理的所有User
                //lteSdkClient.GetAllDcUsers(0, out dcUsersList);

                foreach (eLTEUserInfo userInfo in dcUsersList)
                {
                    if ((userInfo.usercategory == eLTEUser_Category_t.PTTUSER && bPttUser) ||
                                (userInfo.usercategory == eLTEUser_Category_t.FIXEDCAMERA && bFixedCamera))
                    {
                        if (cameraListTemp.Exists(x => x.No == userInfo.userid.ToString()))
                        {
                            continue;
                        }
                        else
                        {
                            Camera camera = new Camera(userInfo.userid.ToString(), userInfo.username);

                            try
                            {
                                if (this.cameraStatusOperateLock.TryEnterReadLock(CgwConst.ENTER_LOCK_WAIT_TIME))
                                {
                                    camera.Status = onlineUser.Exists((x) =>
                                    {
                                        if (x == camera.No)
                                        {
                                            return true;
                                        }
                                        else
                                        {
                                            return false;
                                        }
                                    }) == true ? CameraStatus.Online : CameraStatus.Offline;
                                }
                                cameraListTemp.Add(camera);
                            }
                            finally
                            {
                                this.cameraStatusOperateLock.ExitReadLock();
                            }

                            List<string> pathList = new List<string>();
                            NodeRelation nodeRelation = new NodeRelation(camera.No, pathList, NodeType.CAMERA);
                            nodeRelationListTemp.Add(nodeRelation);
                        }
                    }
                }

                DateTime dtStart = DateTime.Now;
                DateTime dtNow = new DateTime();
                while (!isGetDevicesFinish)
                {
                    dtNow = DateTime.Now;

                    if ((dtNow - dtStart).TotalSeconds > refreshDeviceListOverTime)
                    {
                        isRefreshSuccess = false;
                        return;
                    }
                    Thread.Sleep(1);
                    continue;
                }

                //将实时获取的值放到缓存
                if (this.cameraOperateLock.TryEnterWriteLock(CgwConst.ENTER_LOCK_WAIT_TIME))
                {
                    try
                    {
                        this.cameraList = cameraListTemp;
                        this.groupList = groupListTemp;
                        this.nodeRelationList = nodeRelationListTemp;

                        isRefreshSuccess = true;
                    }
                    catch (Exception ex)
                    {
                        isRefreshSuccess = false;
                        logEx.Error("Set the list to the buffer failed. ", ex.Message);
                    }
                    finally
                    {
                        this.cameraOperateLock.ExitWriteLock();
                    }
                }
            }
            catch (System.Exception ex)
            {
                isRefreshSuccess = false;
                logEx.Error("GetAllCamerasMethod failed.Exception message:{0}", ex.Message);
            }

            logEx.Debug("GetAllCameras eLTE cameraList:{0}", cameraList.Count);
            logEx.Debug("GetAllCameras eLTE groupList:{0}", groupList.Count);
            logEx.Debug("GetAllCameras eLTE nodeRelationList:{0}", nodeRelationList.Count);
        }
コード例 #7
0
ファイル: eLTEVideoMonitor.cs プロジェクト: eSDK/esdk_Cgw
        /// <summary>
        /// 获取摄像头列表及分组信息
        /// </summary>
        /// <param name="isRealTime">是否实时获取,融合网关有个缓存,间隔一段时间获取,默认是从融合网关获取列表,如果该值为true,则实时获取</param>
        /// <param name="cameraList">摄像头列表</param>
        /// <param name="groupList">组信息</param>
        /// <param name="nodeRelationList">分组关系</param>
        /// <returns></returns>
        public SmcError.SmcErr GetAllCameras(out List<Camera> cameraList, out List<CameraGroup> groupList, out List<NodeRelation> nodeRelationList)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: eLTEVideoMonitor.GetAllCameras().");
            SmcErr err = new CgwError();
            cameraList = new List<Camera>();
            groupList = new List<CameraGroup>();
            nodeRelationList = new List<NodeRelation>();

            isGetDevicesFinish = false;
            if (this.cameraOperateLock.TryEnterReadLock(CgwConst.ENTER_LOCK_WAIT_TIME))
            {
                try
                {
                    #region 深度克隆数据
                    foreach (Camera ivsCamera in this.cameraList)
                    {
                        //从缓存获取                        
                        Camera camera = new Camera(ivsCamera.No, ivsCamera.Name);

                        try
                        {
                            if (this.cameraStatusOperateLock.TryEnterReadLock(CgwConst.ENTER_LOCK_WAIT_TIME))
                            {
                                camera.Status = onlineUser.Exists((x) =>
                                {
                                    if (x == camera.No)
                                    {
                                        return true;
                                    }
                                    else
                                    {
                                        return false;
                                    }
                                }) == true ? CameraStatus.Online : CameraStatus.Offline;
                            }
                        }
                        finally
                        {
                            this.cameraStatusOperateLock.ExitReadLock();
                        }
                        cameraList.Add(camera);
                    }
                    foreach (CameraGroup cameraGroup in this.groupList)
                    {
                        CameraGroup cameraGroupTemp = new CameraGroup(cameraGroup.No, cameraGroup.Name);
                        groupList.Add(cameraGroupTemp);
                    }
                    foreach (NodeRelation nodeRelation in this.nodeRelationList)
                    {
                        NodeRelation nodeRelationTemp = new NodeRelation(nodeRelation.No, nodeRelation.Path, nodeRelation.Type);
                        nodeRelationList.Add(nodeRelationTemp);
                    }
                    #endregion
                }
                catch (Exception e)
                {
                    err.SetErrorNo(CgwError.GET_ALL_CAMERAS_FAILED);
                    logEx.Error("Get all cameras failed.Execption message:{0}", e.Message);
                    return err;
                }
                finally
                {
                    this.cameraOperateLock.ExitReadLock();
                }
            }

            logEx.Info("Get all cameras success.");
            return err;
        }
コード例 #8
0
ファイル: T28181VideoMonitor.cs プロジェクト: eSDK/esdk_Cgw
        /// <summary>
        /// 获取摄像头列表及分组信息
        /// </summary>
        /// <param name="isRealTime">是否实时获取,融合网关有个缓存,间隔一段时间获取,默认是从融合网关获取列表,如果该值为true,则实时获取</param>
        /// <param name="cameraList">摄像头列表</param>
        /// <param name="groupList">组信息</param>
        /// <param name="nodeRelationList">分组关系</param>
        /// <returns></returns>
        public SmcErr GetAllCameras(out List<Camera> cameraList, out List<CameraGroup> groupList, out List<NodeRelation> nodeRelationList)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: T28181VideoMonitor.GetAllCameras().");

            SmcErr err = new CgwError();
            cameraList = new List<Camera>();
            groupList = new List<CameraGroup>();
            nodeRelationList = new List<NodeRelation>();

            if (this.cameraOperateLock.TryEnterReadLock(CgwConst.ENTER_LOCK_WAIT_TIME))
            {
                try
                {
                    #region 深度克隆数据
                    foreach (Camera ivsCamera in this.cameraList)
                    {
                        //从缓存获取
                        Camera camera = new Camera(ivsCamera.No, ivsCamera.Name);
                        camera.Status = ivsCamera.Status;
                        cameraList.Add(camera);
                    }
                    foreach (CameraGroup cameraGroup in this.groupList)
                    {
                        CameraGroup cameraGroupTemp = new CameraGroup(cameraGroup.No, cameraGroup.Name);
                        groupList.Add(cameraGroupTemp);
                    }
                    foreach (NodeRelation nodeRelation in this.nodeRelationList)
                    {
                        NodeRelation nodeRelationTemp = new NodeRelation(nodeRelation.No, nodeRelation.Path, nodeRelation.Type);
                        nodeRelationList.Add(nodeRelationTemp);
                    }
                    #endregion
                }
                catch (Exception e)
                {
                    err.SetErrorNo(CgwError.GET_ALL_CAMERAS_FAILED);
                    logEx.Error("Get all cameras failed.Execption message:{0}", e.Message);
                    return err;
                }
                finally
                {
                    this.cameraOperateLock.ExitReadLock();
                }
            }
            logEx.Debug("cameraList.{0}", cameraList.Count);
            logEx.Debug("groupList.{0}", groupList.Count);
            logEx.Debug("nodeRelationList.{0}", nodeRelationList.Count);
            logEx.Debug("Get all cameras success.");
            return err;
        }
コード例 #9
0
ファイル: T28181VideoMonitor.cs プロジェクト: eSDK/esdk_Cgw
        /// <summary>
        /// 获取摄像头和组之间的关联
        /// </summary>
        /// <param name="cameraListTemp">摄像机列表</param>
        /// <param name="groupListTemp">分组列表</param>
        /// <param name="nodeRelationListTemp">组关系列表</param>
        private void GetCameraAndGroupRelation(List<Camera> cameraListTemp, List<CameraGroup> groupListTemp, List<NodeRelation> nodeRelationListTemp)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: T28181VideoMonitor.GetCameraAndGroupRelation().");

            try
            {
                if (platformType == "huawei")
                {
                    //查询摄像机的父节点,保存摄像机父节点关系列表
                    foreach (Camera ca in cameraListTemp)
                    {
                        //IVS 摄像机子设备通过主设备跟父节点关联,子设备没有父节点
                        if (ca.DeviceType == CgwConst.RESOURCE_TYPE_CAMERA)
                        {
                            continue;
                        }
                        //摄像机没有父节点
                        if (string.IsNullOrEmpty(ca.ParentID))
                        {
                            NodeRelation nodeRelation = new NodeRelation(ca.No, new List<String>(), NodeType.CAMERA);
                            nodeRelationListTemp.Add(nodeRelation);
                        }
                        else
                        {
                            string parentID = ca.ParentID;
                            //获取所有父节点路径
                            List<string> pathList = new List<string>();
                            FindNodeRelationPath(parentID, groupListTemp, ref pathList);

                            if (pathList.Count > 1)
                            {
                                //按照从顶到底排序
                                pathList.Reverse();
                            }

                            //查询主设备的子设备
                            Camera camera = cameraListTemp.Find((x)
                              =>
                            {
                                if (x.ParentID == ca.No)
                                {
                                    return true;
                                }
                                else
                                {
                                    return false;
                                }
                            });

                            if (camera != null)
                            {
                                //节点关系列表中将摄像机代替摄像机主设备
                                NodeRelation nodeRelation = new NodeRelation(camera.No, pathList, NodeType.CAMERA);
                                nodeRelationListTemp.Add(nodeRelation);
                            }
                        }
                    }

                    //设备列表过滤掉摄像机主设备
                    cameraListTemp.RemoveAll((x)
                        =>
                    {
                        if (x.DeviceType == CgwConst.RESOURCE_TYPE_MAIN)
                        {
                            return true;
                        }
                        else
                        {
                            return false;
                        }
                    });

                    //查询设备组的父节点,保存设备组父节点关系列表
                    foreach (CameraGroup cg in groupListTemp)
                    {
                        //设备组没有父节点
                        if (string.IsNullOrEmpty(cg.ParentID))
                        {
                            NodeRelation nodeRelation = new NodeRelation(cg.No, new List<String>(), NodeType.GROUP);
                            nodeRelationListTemp.Add(nodeRelation);
                        }
                        else
                        {
                            string parentID = cg.ParentID;
                            //获取分组所有父节点路径
                            List<string> pathList = new List<string>();
                            FindNodeRelationPath(parentID, groupListTemp, ref pathList);

                            if (pathList.Count > 1)
                            {
                                //按照从顶到底排序
                                pathList.Reverse();
                            }
                            //保存分组的父节点列表
                            NodeRelation nodeRelation = new NodeRelation(cg.No, pathList, NodeType.GROUP);
                            nodeRelationListTemp.Add(nodeRelation);
                        }
                    }
                }
                else
                {
                    //查询摄像机的父节点,保存摄像机父节点关系列表
                    foreach (Camera ca in cameraListTemp)
                    {
                        //hikvision 摄像机父节点是设备分组
                        if (string.IsNullOrEmpty(ca.ParentID))
                        {
                            NodeRelation nodeRelation = new NodeRelation(ca.No, new List<String>(), NodeType.CAMERA);
                            nodeRelationListTemp.Add(nodeRelation);
                        }
                        else
                        {
                            //查询 是否存在父节点
                            CameraGroup cameraGroup = groupListTemp.Find((x)
                              =>
                            {
                                if (x.No == ca.ParentID)
                                {
                                    return true;
                                }
                                else
                                {
                                    return false;
                                }
                            });

                            if (cameraGroup == null)
                            {
                                //父节点不存在,把摄像机挂在根节点下
                                NodeRelation nodeRelation = new NodeRelation(ca.No, new List<String>(), NodeType.CAMERA);
                                nodeRelationListTemp.Add(nodeRelation);
                            }
                            else
                            {
                                string parentID = ca.ParentID;
                                //获取所有父节点路径
                                List<string> pathList = new List<string>();
                                FindNodeRelationPath(parentID, groupListTemp, ref pathList);

                                if (pathList.Count > 1)
                                {
                                    //按照从顶到底排序
                                    pathList.Reverse();
                                }

                                //保存分组的父节点列表
                                NodeRelation nodeRelation = new NodeRelation(ca.No, pathList, NodeType.CAMERA);
                                nodeRelationListTemp.Add(nodeRelation);
                            }
                        }
                    }
                    foreach (CameraGroup cg in groupListTemp)
                    {
                        //设备组没有父节点
                        if (string.IsNullOrEmpty(cg.ParentID))
                        {
                            NodeRelation nodeRelation = new NodeRelation(cg.No, new List<String>(), NodeType.GROUP);
                            nodeRelationListTemp.Add(nodeRelation);
                        }
                        else
                        {
                            //查询 是否存在父节点
                            CameraGroup cgTemp = groupListTemp.Find((x)
                              =>
                            {
                                if (x.No == cg.ParentID)
                                {
                                    return true;
                                }
                                else
                                {
                                    return false;
                                }
                            });

                            if (cgTemp == null)
                            {
                                //父节点不存在,把摄像机挂在根节点下
                                NodeRelation nodeRelation = new NodeRelation(cg.No, new List<String>(), NodeType.GROUP);
                                nodeRelationListTemp.Add(nodeRelation);
                            }
                            else
                            {
                                string parentID = cg.ParentID;
                                //获取分组所有父节点路径
                                List<string> pathList = new List<string>();
                                FindNodeRelationPath(parentID, groupListTemp, ref pathList);

                                if (pathList.Count > 1)
                                {
                                    //按照从顶到底排序
                                    pathList.Reverse();
                                }
                                //保存分组的父节点列表
                                NodeRelation nodeRelation = new NodeRelation(cg.No, pathList, NodeType.GROUP);
                                nodeRelationListTemp.Add(nodeRelation);
                            }
                        }
                    }
                }
                DateTime dtStart = DateTime.Now;
                DateTime dtNow = new DateTime();
                while (!isGetDevicesFinish)
                {
                    dtNow = DateTime.Now;

                    if ((dtNow - dtStart).TotalSeconds > refreshDeviceListOverTime)
                    {
                        sipStack.isRefreshSucess = false;
                        return;
                    }
                    Thread.Sleep(1);
                    continue;
                }

                //将实时获取的值放到缓存
                if (this.cameraOperateLock.TryEnterWriteLock(CgwConst.ENTER_LOCK_WAIT_TIME))
                {
                    try
                    {
                        this.cameraList = cameraListTemp;
                        this.groupList = groupListTemp;
                        this.nodeRelationList = nodeRelationListTemp;
                        sipStack.isRefreshSucess = true;
                    }
                    catch (Exception ex)
                    {
                        sipStack.isRefreshSucess = false;
                        logEx.Error("Set the list to the buffer failed. ", ex.Message);
                    }
                    finally
                    {
                        this.cameraOperateLock.ExitWriteLock();
                    }
                }
            }
            catch (System.Exception ex)
            {
                sipStack.isRefreshSucess = false;
                logEx.Error("GetCameraAndGroupRelation failed. {0} ", ex.Message);
            }
        }