private void RecursionCamera(List<Resource> resourceTree, Dictionary<string, TiandyCamera> tiandyCameraDictionary, Dictionary<string, Host> hostDictionary, Dictionary<string, MediaServer> mediaServerDictionary)
{
NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
if (resourceTree == null)
{
logEx.Error("Recursion camera failed.ResourceTree is null.");
return;
}
if (tiandyCameraDictionary == null)
{
tiandyCameraDictionary = new Dictionary<string, TiandyCamera>();
}
if (hostDictionary == null)
{
hostDictionary = new Dictionary<string, Host>();
}
if (mediaServerDictionary == null)
{
mediaServerDictionary = new Dictionary<string, MediaServer>();
}
foreach (Resource resource in resourceTree)
{
//TypeId为5时,表示该节点为通道,对应一个摄像头
if (((int)NodeType.CAMERA).ToString().Equals(resource.TypeId))
{
TiandyCamera camera = new TiandyCamera(resource.Id, resource.Caption);
camera.Channel = resource.Ch;
//摄像头的父节点为主机
camera.HostNo = resource.ParentId;
tiandyCameraDictionary.Add(camera.No, camera);
//如果是摄像头节点,不需要递归
continue;
}
else if (((int)NodeType.HOST).ToString().Equals(resource.TypeId))
{
//将主机加入缓存,主机的父节点为流媒体(中间件)服务器
Host host = new Host(
resource.Id,
resource.Username,
resource.Pwd,
resource.ParentId);
hostDictionary.Add(host.No, host);
}
else if (((int)NodeType.MEDIASERVER).ToString().Equals(resource.TypeId))
{
//将流媒体(中间件)服务器加入缓存
MediaServer mediaServer = new MediaServer(
resource.Id,
resource.Ip,
resource.Port,
resource.Username,
resource.Pwd);
mediaServerDictionary.Add(mediaServer.No, mediaServer);
}
//递归处理
RecursionCamera(resource.items, tiandyCameraDictionary, hostDictionary, mediaServerDictionary);
}
}