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