public static RewriterConfiguration GetConfig() { var config = new RewriterConfiguration { Rules = new RewriterRuleCollection() }; FileStream fileReader = null; string filePath = ""; try { config = (RewriterConfiguration)DataCache.GetCache("RewriterConfig"); if ((config == null)) { filePath = Common.Utilities.Config.GetPathToFile(Common.Utilities.Config.ConfigFileType.SiteUrls); //Create a FileStream for the Config file fileReader = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read); var doc = new XPathDocument(fileReader); config = new RewriterConfiguration { Rules = new RewriterRuleCollection() }; foreach (XPathNavigator nav in doc.CreateNavigator().Select("RewriterConfig/Rules/RewriterRule")) { var rule = new RewriterRule { LookFor = nav.SelectSingleNode("LookFor").Value, SendTo = nav.SelectSingleNode("SendTo").Value }; config.Rules.Add(rule); } if (File.Exists(filePath)) { //Set back into Cache DataCache.SetCache("RewriterConfig", config, new DNNCacheDependency(filePath)); } } } catch (Exception ex) { //log it var objEventLog = new EventLogController(); var objEventLogInfo = new LogInfo(); objEventLogInfo.AddProperty("UrlRewriter.RewriterConfiguration", "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 RewriterConfiguration GetConfig() { var config = new RewriterConfiguration(); config.Rules = new RewriterRuleCollection(); FileStream fileReader = null; string filePath = ""; try { config = (RewriterConfiguration) DataCache.GetCache("RewriterConfig"); if ((config == null)) { filePath = Common.Utilities.Config.GetPathToFile(Common.Utilities.Config.ConfigFileType.SiteUrls); //Create a FileStream for the Config file fileReader = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read); var doc = new XPathDocument(fileReader); config = new RewriterConfiguration {Rules = new RewriterRuleCollection()}; foreach (XPathNavigator nav in doc.CreateNavigator().Select("RewriterConfig/Rules/RewriterRule")) { var rule = new RewriterRule {LookFor = nav.SelectSingleNode("LookFor").Value, SendTo = nav.SelectSingleNode("SendTo").Value}; config.Rules.Add(rule); } if (File.Exists(filePath)) { //Set back into Cache DataCache.SetCache("RewriterConfig", config, new DNNCacheDependency(filePath)); } } } catch (Exception ex) { //log it var objEventLog = new EventLogController(); var objEventLogInfo = new LogInfo(); objEventLogInfo.AddProperty("UrlRewriter.RewriterConfiguration", "GetConfig Failed"); objEventLogInfo.AddProperty("FilePath", filePath); objEventLogInfo.AddProperty("ExceptionMessage", ex.Message); objEventLogInfo.LogTypeKey = EventLogController.EventLogType.HOST_ALERT.ToString(); objEventLog.AddLog(objEventLogInfo); DnnLog.Error(objEventLogInfo); } finally { if (fileReader != null) { //Close the Reader fileReader.Close(); } } return config; }
public void Add(RewriterRule r) { InnerList.Add(r); }
public static RewriterConfiguration GetConfig() { RewriterConfiguration Config = new RewriterConfiguration(); Config.Rules = new RewriterRuleCollection(); FileStream fileReader = null; string filePath = ""; try { Config = (RewriterConfiguration)(DataCache.GetCache("RewriterConfig")); if (Config == null) { filePath = Globals.ApplicationMapPath + "\\SiteUrls.config"; if (!(File.Exists(filePath))) { //Copy from \Config if (File.Exists(Globals.ApplicationMapPath + Globals.glbConfigFolder + "SiteUrls.config")) { File.Copy(Globals.ApplicationMapPath + Globals.glbConfigFolder + "SiteUrls.config", Globals.ApplicationMapPath + "\\SiteUrls.config", true); } } //Create a FileStream for the Config file fileReader = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read); XPathDocument doc = new XPathDocument(fileReader); Config = new RewriterConfiguration(); Config.Rules = new RewriterRuleCollection(); foreach (XPathNavigator nav in doc.CreateNavigator().Select("RewriterConfig/Rules/RewriterRule")) { RewriterRule rule = new RewriterRule(); rule.LookFor = nav.SelectSingleNode("LookFor").Value; rule.SendTo = nav.SelectSingleNode("SendTo").Value; Config.Rules.Add(rule); } if (File.Exists(filePath)) { // Create a dependancy on SiteUrls.config CacheDependency dep = new CacheDependency(filePath); // Set back into Cache DataCache.SetCache("RewriterConfig", Config, dep); } } } catch (Exception ex) { //log it Services.Log.EventLog.EventLogController objEventLog = new Services.Log.EventLog.EventLogController(); Services.Log.EventLog.LogInfo objEventLogInfo = new Services.Log.EventLog.LogInfo(); objEventLogInfo.AddProperty("UrlRewriter.RewriterConfiguration", "GetConfig Failed"); objEventLogInfo.AddProperty("FilePath", filePath); objEventLogInfo.AddProperty("ExceptionMessage", ex.Message); objEventLogInfo.LogTypeKey = Services.Log.EventLog.EventLogController.EventLogType.HOST_ALERT.ToString(); objEventLog.AddLog(objEventLogInfo); } finally { if (fileReader != null) { //Close the Reader fileReader.Close(); } } return Config; }
public void Add(RewriterRule r) { this.InnerList.Add(r); }
public static RewriterConfiguration GetConfig() { RewriterConfiguration Config = new RewriterConfiguration(); Config.Rules = new RewriterRuleCollection(); FileStream fileReader = null; string filePath = ""; try { Config = (RewriterConfiguration)(DataCache.GetCache("RewriterConfig")); if (Config == null) { filePath = Globals.ApplicationMapPath + "\\SiteUrls.config"; if (!(File.Exists(filePath))) { //Copy from \Config if (File.Exists(Globals.ApplicationMapPath + Globals.glbConfigFolder + "SiteUrls.config")) { File.Copy(Globals.ApplicationMapPath + Globals.glbConfigFolder + "SiteUrls.config", Globals.ApplicationMapPath + "\\SiteUrls.config", true); } } //Create a FileStream for the Config file fileReader = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read); XPathDocument doc = new XPathDocument(fileReader); Config = new RewriterConfiguration(); Config.Rules = new RewriterRuleCollection(); foreach (XPathNavigator nav in doc.CreateNavigator().Select("RewriterConfig/Rules/RewriterRule")) { RewriterRule rule = new RewriterRule(); rule.LookFor = nav.SelectSingleNode("LookFor").Value; rule.SendTo = nav.SelectSingleNode("SendTo").Value; Config.Rules.Add(rule); } if (File.Exists(filePath)) { // Create a dependancy on SiteUrls.config CacheDependency dep = new CacheDependency(filePath); // Set back into Cache DataCache.SetCache("RewriterConfig", Config, dep); } } } catch (Exception ex) { //log it Services.Log.EventLog.EventLogController objEventLog = new Services.Log.EventLog.EventLogController(); Services.Log.EventLog.LogInfo objEventLogInfo = new Services.Log.EventLog.LogInfo(); objEventLogInfo.AddProperty("UrlRewriter.RewriterConfiguration", "GetConfig Failed"); objEventLogInfo.AddProperty("FilePath", filePath); objEventLogInfo.AddProperty("ExceptionMessage", ex.Message); objEventLogInfo.LogTypeKey = Services.Log.EventLog.EventLogController.EventLogType.HOST_ALERT.ToString(); objEventLog.AddLog(objEventLogInfo); } finally { if (fileReader != null) { //Close the Reader fileReader.Close(); } } return(Config); }