private SmcErr CreateMonitor(string monitorId, string className, out IVideoMonitor videoMonitor)
{
NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
logEx.Trace("Enter: VideoMonitorManage.CreateMonitor().");
SmcErr err = new CgwError();
videoMonitor = null;
if (this.monitorsOperateLock.TryEnterWriteLock(CgwConst.ENTER_LOCK_WAIT_TIME))
{
try
{
if (monitorsDictionary.ContainsKey(monitorId))
{
//监控平台的id重复
err.SetErrorNo(CgwError.MONITOR_CONFIG_FILE_INVALID_ID_EXIST);
logEx.Error("Monitor id has been exist. Monitor id:{0}.", monitorId);
return err;
}
}
catch (Exception e)
{
logEx.Error("CreateMonitor failed..Execption message:{0}", e.Message);
}
finally
{
this.monitorsOperateLock.ExitWriteLock();
}
}
Type monitorType = Type.GetType(className);
if (monitorType == null)
{
//class不合法
err.SetErrorNo(CgwError.MONITOR_CONFIG_FILE_INVALID_CLASS_INVALID);
logEx.Error("The class of Monitor is invalid. Class:{0}, Monitor id:{1}.", className, monitorId);
return err;
}
try
{
//create instance
logEx.Info("VideoMonitorManage.className = {0}", className);
if (className == "CgwMonitorManage.eLTE.eLTEVideoMonitor,CgwMonitorManage.eLTE")
{
//eLTE dll放在eLTeSDK目录下,否则跟ivs DLL冲突
string strPath = System.AppDomain.CurrentDomain.BaseDirectory;
System.Reflection.Assembly assembly = System.Reflection.Assembly.LoadFrom(strPath + @"eLTeSDK\CgwMonitorManage.eLTE.dll");
Type[] types = assembly.GetTypes();
if (types.Length > 0)
{
monitorType = types.First((x) => x.FullName == "CgwMonitorManage.eLTE.eLTEVideoMonitor");
}
}
else if (className == "CgwMonitorManage.Ivs.IvsVideoMonitor,CgwMonitorManage.Ivs")
{
string strPath = System.AppDomain.CurrentDomain.BaseDirectory;
System.Reflection.Assembly assembly = System.Reflection.Assembly.LoadFrom(strPath + @"IVSSDK\CgwMonitorManage.Ivs.dll");
Type[] types = assembly.GetTypes();
if (types.Length > 0)
{
monitorType = types.First((x) => x.FullName == "CgwMonitorManage.Ivs.IvsVideoMonitor");
}
}
logEx.Info("VideoMonitorManage.monitorType = {0}", monitorType);
videoMonitor = Activator.CreateInstance(monitorType) as CgwMonitorManage.Common.IVideoMonitor;
}
catch (Exception e)
{
//无法加载指定的类
err.SetErrorNo(CgwError.MONITOR_CONFIG_FILE_INVALID_CLASS_INVALID);
logEx.Error("The class of Monitor is invalid. May be not as IVideoMonitor. Class:{0}, Monitor id:{1},Exception message:{2}.",
className, monitorId, e.Message);
return err;
}
if (videoMonitor == null)
{
//无法加载指定的类
err.SetErrorNo(CgwError.MONITOR_CONFIG_FILE_INVALID_CLASS_INVALID);
logEx.Error("The class of Monitor is invalid. May be not as IVideoMonitor. Class:{0}, Monitor id:{1}.", className, monitorId);
return err;
}
return err;
}