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);
}
}