private void OnPageLoad(object sender, EventArgs e)
 {
     try
     {
         AnalyticsEngineCollection analyticsEngines = AnalyticsEngineConfiguration.GetConfig().AnalyticsEngines;
         if (analyticsEngines == null || analyticsEngines.Count == 0)
         {
             return;
         }
         var page = (Page)sender;
         if ((page == null))
         {
             return;
         }
         foreach (AnalyticsEngine engine in analyticsEngines)
         {
             if ((!String.IsNullOrEmpty(engine.ElementId)))
             {
                 AnalyticsEngineBase objEngine = null;
                 if ((!String.IsNullOrEmpty(engine.EngineType)))
                 {
                     Type engineType = Type.GetType(engine.EngineType);
                     if (engineType == null)
                     {
                         objEngine = new GenericAnalyticsEngine();
                     }
                     else
                     {
                         objEngine = (AnalyticsEngineBase)Activator.CreateInstance(engineType);
                     }
                 }
                 else
                 {
                     objEngine = new GenericAnalyticsEngine();
                 }
                 if (objEngine != null)
                 {
                     string script = engine.ScriptTemplate;
                     if ((!String.IsNullOrEmpty(script)))
                     {
                         script = objEngine.RenderScript(script);
                         if ((!String.IsNullOrEmpty(script)))
                         {
                             var element = (HtmlContainerControl)page.FindControl(engine.ElementId);
                             if (element != null)
                             {
                                 var scriptControl = new LiteralControl();
                                 scriptControl.Text = script;
                                 if (engine.InjectTop)
                                 {
                                     element.Controls.AddAt(0, scriptControl);
                                 }
                                 else
                                 {
                                     element.Controls.Add(scriptControl);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         var log = new LogInfo {
             LogTypeKey = EventLogController.EventLogType.HOST_ALERT.ToString()
         };
         log.AddProperty("Analytics.AnalyticsModule", "OnPageLoad");
         log.AddProperty("ExceptionMessage", ex.Message);
         LogController.Instance.AddLog(log);
         Logger.Error(ex);
     }
 }
예제 #2
0
        private static void InitializeAnalyticsControls(Page page, bool injectTop)
        {
            try
            {
                var analyticsEngines = AnalyticsEngineConfiguration.GetConfig().AnalyticsEngines;
                if (analyticsEngines == null || analyticsEngines.Count == 0)
                {
                    return;
                }

                if (page == null)
                {
                    return;
                }

                foreach (AnalyticsEngine engine in analyticsEngines)
                {
                    if (string.IsNullOrEmpty(engine.ElementId) || engine.InjectTop != injectTop)
                    {
                        continue;
                    }

                    AnalyticsEngineBase objEngine;
                    if ((!string.IsNullOrEmpty(engine.EngineType)))
                    {
                        var engineType = Type.GetType(engine.EngineType);
                        if (engineType == null)
                        {
                            objEngine = new GenericAnalyticsEngine();
                        }
                        else
                        {
                            objEngine = (AnalyticsEngineBase)Activator.CreateInstance(engineType);
                        }
                    }
                    else
                    {
                        objEngine = new GenericAnalyticsEngine();
                    }
                    if (objEngine == null)
                    {
                        continue;
                    }

                    var script = engine.ScriptTemplate;
                    if ((string.IsNullOrEmpty(script)))
                    {
                        continue;
                    }

                    script = objEngine.RenderScript(script);
                    if ((string.IsNullOrEmpty(script)))
                    {
                        continue;
                    }

                    var element = (HtmlContainerControl)page.FindControl(engine.ElementId);
                    if (element == null)
                    {
                        continue;
                    }

                    var scriptControl = new LiteralControl {
                        Text = script
                    };
                    if (engine.InjectTop)
                    {
                        element.Controls.AddAt(0, scriptControl);
                    }
                    else
                    {
                        element.Controls.Add(scriptControl);
                    }
                }
            }
            catch (Exception ex)
            {
                var log = new LogInfo {
                    LogTypeKey = EventLogController.EventLogType.HOST_ALERT.ToString()
                };
                log.AddProperty("Analytics.AnalyticsModule", "OnPagePreRender");
                log.AddProperty("ExceptionMessage", ex.Message);
                LogController.Instance.AddLog(log);
                Logger.Error(ex);
            }
        }