public static void SaveConfig(string analyticsEngineName, AnalyticsConfiguration config)
        {
            string cacheKey = analyticsEngineName + "." + PortalSettings.Current.PortalId;

            if (config.Settings != null)
            {
                //Create a new Xml Serializer
                var    ser      = new XmlSerializer(typeof(AnalyticsConfiguration));
                string filePath = "";

                //Create a FileStream for the Config file
                filePath = PortalSettings.Current.HomeDirectoryMapPath + "\\" + analyticsEngineName + ".config";
                if (File.Exists(filePath))
                {
                    File.SetAttributes(filePath, FileAttributes.Normal);
                }
                using (var fileWriter = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.Write))
                    using (var writer = new StreamWriter(fileWriter))
                    {
                        //Serialize the AnalyticsConfiguration
                        ser.Serialize(writer, config);

                        //Close the Writers
                        writer.Close();
                        fileWriter.Close();
                    }
                DataCache.SetCache(cacheKey, config, new DNNCacheDependency(filePath));
            }
        }
 protected void OnUpdateClick(object sender, EventArgs e)
 {
     try
     {
         var config = new AnalyticsConfiguration();
         var setting = new AnalyticsSetting();
         config.Settings = new AnalyticsSettingCollection();
         setting.SettingName = "TrackingId";
         setting.SettingValue = txtTrackingId.Text;
         config.Settings.Add(setting);
         setting = new AnalyticsSetting();
         setting.SettingName = "UrlParameter";
         setting.SettingValue = txtUrlParameter.Text;
         config.Settings.Add(setting);
         AnalyticsConfiguration.SaveConfig("GoogleAnalytics", config);
         UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("Updated", LocalResourceFile), ModuleMessage.ModuleMessageType.GreenSuccess);
     }
     catch (Exception exc)
     {
         Exceptions.ProcessModuleLoadException(this, exc);
     }
 }
        public static AnalyticsConfiguration GetConfig(string analyticsEngineName)
        {
            string cacheKey = analyticsEngineName + "." + PortalSettings.Current.PortalId;

            var Config = new AnalyticsConfiguration();

            Config.Rules    = new AnalyticsRuleCollection();
            Config.Settings = new AnalyticsSettingCollection();

            FileStream fileReader = null;
            string     filePath   = "";

            try
            {
                Config = (AnalyticsConfiguration)DataCache.GetCache(cacheKey);
                if ((Config == null))
                {
                    filePath = PortalSettings.Current.HomeDirectoryMapPath + "\\" + analyticsEngineName + ".config";

                    if (!File.Exists(filePath))
                    {
                        return(null);
                    }

                    //Create a FileStream for the Config file
                    fileReader = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);

                    var doc = new XPathDocument(fileReader);
                    Config          = new AnalyticsConfiguration();
                    Config.Rules    = new AnalyticsRuleCollection();
                    Config.Settings = new AnalyticsSettingCollection();

                    var allSettings = new Hashtable();
                    foreach (XPathNavigator nav in doc.CreateNavigator().Select("AnalyticsConfig/Settings/AnalyticsSetting"))
                    {
                        var setting = new AnalyticsSetting();
                        setting.SettingName  = nav.SelectSingleNode("SettingName").Value;
                        setting.SettingValue = nav.SelectSingleNode("SettingValue").Value;
                        Config.Settings.Add(setting);
                    }
                    foreach (XPathNavigator nav in doc.CreateNavigator().Select("AnalyticsConfig/Rules/AnalyticsRule"))
                    {
                        var rule = new AnalyticsRule();
                        rule.RoleId = Convert.ToInt32(nav.SelectSingleNode("RoleId").Value);
                        rule.TabId  = Convert.ToInt32(nav.SelectSingleNode("TabId").Value);
                        rule.Label  = nav.SelectSingleNode("Label").Value;
                        var valueNode = nav.SelectSingleNode("Value");
                        if (valueNode != null)
                        {
                            rule.Value = valueNode.Value;
                        }
                        Config.Rules.Add(rule);
                    }
                    if (File.Exists(filePath))
                    {
                        //Set back into Cache
                        DataCache.SetCache(cacheKey, Config, new DNNCacheDependency(filePath));
                    }
                }
            }
            catch (Exception ex)
            {
                //log it
                var log = new LogInfo {
                    LogTypeKey = EventLogController.EventLogType.ADMIN_ALERT.ToString()
                };
                log.AddProperty("Analytics.AnalyticsConfiguration", "GetConfig Failed");
                log.AddProperty("FilePath", filePath);
                log.AddProperty("ExceptionMessage", ex.Message);
                LogController.Instance.AddLog(log);
                Logger.Error(ex);
            }
            finally
            {
                if (fileReader != null)
                {
                    //Close the Reader
                    fileReader.Close();
                }
            }
            return(Config);
        }
Пример #4
0
 public virtual string RenderCustomScript(AnalyticsConfiguration config)
 {
     return "";
 }
        public static AnalyticsConfiguration GetConfig(string analyticsEngineName)
        {
            string cacheKey = analyticsEngineName + "." + PortalSettings.Current.PortalId;

            var Config = new AnalyticsConfiguration();
            Config.Rules = new AnalyticsRuleCollection();
            Config.Settings = new AnalyticsSettingCollection();

            FileStream fileReader = null;
            string filePath = "";
            try
            {
                Config = (AnalyticsConfiguration) DataCache.GetCache(cacheKey);
                if ((Config == null))
                {
                    filePath = PortalSettings.Current.HomeDirectoryMapPath + "\\" + analyticsEngineName + ".config";

                    if (!File.Exists(filePath))
                    {
                        return null;
                    }
					
                    //Create a FileStream for the Config file
                    fileReader = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);

                    var doc = new XPathDocument(fileReader);
                    Config = new AnalyticsConfiguration();
                    Config.Rules = new AnalyticsRuleCollection();
                    Config.Settings = new AnalyticsSettingCollection();

                    var allSettings = new Hashtable();
                    foreach (XPathNavigator nav in doc.CreateNavigator().Select("AnalyticsConfig/Settings/AnalyticsSetting"))
                    {
                        var setting = new AnalyticsSetting();
                        setting.SettingName = nav.SelectSingleNode("SettingName").Value;
                        setting.SettingValue = nav.SelectSingleNode("SettingValue").Value;
                        Config.Settings.Add(setting);
                    }
                    foreach (XPathNavigator nav in doc.CreateNavigator().Select("AnalyticsConfig/Rules/AnalyticsRule"))
                    {
                        var rule = new AnalyticsRule();
                        rule.RoleId = Convert.ToInt32(nav.SelectSingleNode("RoleId").Value);
                        rule.TabId = Convert.ToInt32(nav.SelectSingleNode("TabId").Value);
                        rule.Label = nav.SelectSingleNode("Label").Value;
                        var valueNode = nav.SelectSingleNode("Value");
                        if (valueNode != null)
                        {
                            rule.Value = valueNode.Value;
                        }
                        Config.Rules.Add(rule);
                    }
                    if (File.Exists(filePath))
                    {
						//Set back into Cache
                        DataCache.SetCache(cacheKey, Config, new DNNCacheDependency(filePath));
                    }
                }
            }
            catch (Exception ex)
            {
				//log it
                var log = new LogInfo {LogTypeKey = EventLogController.EventLogType.ADMIN_ALERT.ToString()};
                log.AddProperty("Analytics.AnalyticsConfiguration", "GetConfig Failed");
                log.AddProperty("FilePath", filePath);
                log.AddProperty("ExceptionMessage", ex.Message);
                LogController.Instance.AddLog(log);
                Logger.Error(ex);
            }
            finally
            {
                if (fileReader != null)
                {
					//Close the Reader
                    fileReader.Close();
                }
            }
            return Config;
        }
        public static void SaveConfig(string analyticsEngineName, AnalyticsConfiguration config)
        {
            string cacheKey = analyticsEngineName + "." + PortalSettings.Current.PortalId;
            if (config.Settings != null)
            {
                //Create a new Xml Serializer
                var ser = new XmlSerializer(typeof (AnalyticsConfiguration));
                string filePath = "";

                //Create a FileStream for the Config file
                filePath = PortalSettings.Current.HomeDirectoryMapPath + "\\" + analyticsEngineName + ".config";
                if (File.Exists(filePath))
                {
                    File.SetAttributes(filePath, FileAttributes.Normal);
                }
                var fileWriter = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.Write);

                //Open up the file to serialize
                var writer = new StreamWriter(fileWriter);

                //Serialize the AnalyticsConfiguration
                ser.Serialize(writer, config);

                //Close the Writers
                writer.Close();
                fileWriter.Close();
                DataCache.SetCache(cacheKey, config, new DNNCacheDependency(filePath));
            }
        }