public static AnalyticsEngineConfiguration GetConfig() { var config = new AnalyticsEngineConfiguration {AnalyticsEngines = new AnalyticsEngineCollection()}; FileStream fileReader = null; string filePath = ""; try { config = (AnalyticsEngineConfiguration) DataCache.GetCache("AnalyticsEngineConfig"); if ((config == null)) { filePath = Common.Utilities.Config.GetPathToFile(Common.Utilities.Config.ConfigFileType.SiteAnalytics); //Create a FileStream for the Config file fileReader = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read); var doc = new XPathDocument(fileReader); config = new AnalyticsEngineConfiguration {AnalyticsEngines = new AnalyticsEngineCollection()}; foreach (XPathNavigator nav in doc.CreateNavigator().Select("AnalyticsEngineConfig/Engines/AnalyticsEngine")) { var analyticsEngine = new AnalyticsEngine { EngineType = nav.SelectSingleNode("EngineType").Value, ElementId = nav.SelectSingleNode("ElementId").Value, InjectTop = Convert.ToBoolean(nav.SelectSingleNode("InjectTop").Value), ScriptTemplate = nav.SelectSingleNode("ScriptTemplate").Value }; config.AnalyticsEngines.Add(analyticsEngine); } if (File.Exists(filePath)) { //Set back into Cache DataCache.SetCache("AnalyticsEngineConfig", config, new DNNCacheDependency(filePath)); } } } catch (Exception ex) { //log it var objEventLog = new EventLogController(); var objEventLogInfo = new LogInfo(); objEventLogInfo.AddProperty("Analytics.AnalyticsEngineConfiguration", "GetConfig Failed"); objEventLogInfo.AddProperty("FilePath", filePath); objEventLogInfo.AddProperty("ExceptionMessage", ex.Message); objEventLogInfo.LogTypeKey = EventLogController.EventLogType.HOST_ALERT.ToString(); objEventLog.AddLog(objEventLogInfo); Logger.Error(objEventLogInfo); } finally { if (fileReader != null) { //Close the Reader fileReader.Close(); } } return config; }
public static AnalyticsEngineConfiguration GetConfig() { var config = new AnalyticsEngineConfiguration { AnalyticsEngines = new AnalyticsEngineCollection() }; FileStream fileReader = null; string filePath = ""; try { config = (AnalyticsEngineConfiguration)DataCache.GetCache("AnalyticsEngineConfig"); if ((config == null)) { filePath = Common.Utilities.Config.GetPathToFile(Common.Utilities.Config.ConfigFileType.SiteAnalytics); //Create a FileStream for the Config file fileReader = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read); var doc = new XPathDocument(fileReader); config = new AnalyticsEngineConfiguration { AnalyticsEngines = new AnalyticsEngineCollection() }; foreach (XPathNavigator nav in doc.CreateNavigator().Select("AnalyticsEngineConfig/Engines/AnalyticsEngine")) { var analyticsEngine = new AnalyticsEngine { EngineType = nav.SelectSingleNode("EngineType").Value, ElementId = nav.SelectSingleNode("ElementId").Value, InjectTop = Convert.ToBoolean(nav.SelectSingleNode("InjectTop").Value), ScriptTemplate = nav.SelectSingleNode("ScriptTemplate").Value }; config.AnalyticsEngines.Add(analyticsEngine); } if (File.Exists(filePath)) { //Set back into Cache DataCache.SetCache("AnalyticsEngineConfig", config, new DNNCacheDependency(filePath)); } } } catch (Exception ex) { //log it var objEventLog = new EventLogController(); var objEventLogInfo = new LogInfo(); objEventLogInfo.AddProperty("Analytics.AnalyticsEngineConfiguration", "GetConfig Failed"); objEventLogInfo.AddProperty("FilePath", filePath); objEventLogInfo.AddProperty("ExceptionMessage", ex.Message); objEventLogInfo.LogTypeKey = EventLogController.EventLogType.HOST_ALERT.ToString(); objEventLog.AddLog(objEventLogInfo); Logger.Error(objEventLogInfo); } finally { if (fileReader != null) { //Close the Reader fileReader.Close(); } } return(config); }