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)
                {
	                lock (_threadLocker)
	                {
						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 log = new LogInfo {LogTypeKey = EventLogController.EventLogType.HOST_ALERT.ToString()};
                log.AddProperty("UrlRewriter.RewriterConfiguration", "GetConfig Failed");
                log.AddProperty("FilePath", filePath);
                log.AddProperty("ExceptionMessage", ex.Message);
                LogController.Instance.AddLog(log);
                Logger.Error(log);
            }
            finally
            {
                if (fileReader != null)
                {
					//Close the Reader
                    fileReader.Close();
                }
            }
            return config;
        }
        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 log = new LogInfo {
                    LogTypeKey = EventLogController.EventLogType.HOST_ALERT.ToString()
                };
                log.AddProperty("UrlRewriter.RewriterConfiguration", "GetConfig Failed");
                log.AddProperty("FilePath", filePath);
                log.AddProperty("ExceptionMessage", ex.Message);
                LogController.Instance.AddLog(log);
                Logger.Error(log);
            }
            finally
            {
                if (fileReader != null)
                {
                    //Close the Reader
                    fileReader.Close();
                }
            }
            return(config);
        }
Example #3
0
 public void Add(RewriterRule r)
 {
     InnerList.Add(r);
 }
 public void Add(RewriterRule r)
 {
     InnerList.Add(r);
 }