예제 #1
0
        /// <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);
        }