public SmcErr Load()
{
NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
logEx.Info("Enter: VideoMonitorManage.Load()");
SmcErr err = new CgwError();
XmlElement monitorsRootElement = ConfigSettings.MonitorSettings;
if (monitorsRootElement == null)
{
err.SetErrorNo(CgwError.MONITOR_CONFIG_FILE_INVALID);
logEx.Error("Monitor config file is invalid.Can not found monitorSettings node.");
return err;
}
foreach (XmlNode monitorNode in monitorsRootElement)
{
XmlElement monitorElement = monitorNode as XmlElement;
if (monitorElement == null)
{
continue;
}
else if (CgwConst.MONITOR_TAG.Equals(monitorElement.Name))
{
//判断监控平台是否启用
string isEnable = monitorElement.GetAttribute(CgwConst.ENABLE_TAG).Trim();
if (!CgwConst.TRUE_TAG.Equals(isEnable.ToLower()))
{
logEx.Warn("This monitor is disable.");
continue;
}
string monitorId;
string className;
err = GetMonitorConfig(monitorElement, out monitorId, out className);
if (!err.IsSuccess())
{
return err;
}
IVideoMonitor videoMonitor;
//加载监控平台
err = CreateMonitor(monitorId, className, out videoMonitor);
if (!err.IsSuccess())
{
logEx.Error("Create monitor failed.monitorId:{0}, className:{1}, Error code:{2}", monitorId, className, err.ErrNo);
return err;
}
err = videoMonitor.Load(monitorElement);
if (err.IsSuccess())
{
if (this.monitorsOperateLock.TryEnterWriteLock(CgwConst.ENTER_LOCK_WAIT_TIME))
{
try
{
monitorsDictionary.Add(monitorId, videoMonitor);
}
catch (Exception e)
{
logEx.Error("Load monitor failed.Execption message:{0}", e.Message);
return err;
}
finally
{
this.monitorsOperateLock.ExitWriteLock();
}
}
}
else
{
logEx.Error("Load monitor failed.MonitorId:{0},Error code:{1}", monitorId, err.ErrNo);
return err;
}
}
}
logEx.Info("Load all monitors success.");
return err;
}