public static void SaveConfig(RewriterRuleCollection rules)
        {
            if (rules != null)
            {
                var config = new RewriterConfiguration {
                    Rules = rules
                };

                //Create a new Xml Serializer
                var ser = new XmlSerializer(typeof(RewriterConfiguration));

                //Create a FileStream for the Config file
                string filePath = Globals.ApplicationMapPath + "\\SiteUrls.config";
                if (File.Exists(filePath))
                {
                    //make sure file is not read-only
                    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 RewriterConfiguration
                ser.Serialize(writer, config);

                //Close the Writers
                writer.Close();
                fileWriter.Close();

                //Set Cache
                DataCache.SetCache("RewriterConfig", config, new DNNCacheDependency(filePath));
            }
        }
        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);
        }
Example #3
0
        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;
        }
        protected override void LoadViewState( object savedState )
        {
            object[] myState = (object[])savedState;
            if( ( myState[0] != null ) )
            {
                base.LoadViewState( myState[0] );
            }
            if( ( myState[1] != null ) )
            {
                RewriterConfiguration config = new RewriterConfiguration();

                // Deserialize into RewriterConfiguration
                config = (RewriterConfiguration)XmlUtils.Deserialize( myState[1].ToString(), config.GetType() );
                Rules = config.Rules;
            }
        }
        protected override object SaveViewState()
        {
            RewriterConfiguration config = new RewriterConfiguration();
            config.Rules = Rules;

            object baseState = base.SaveViewState();
            object[] allStates = new object[3];
            allStates[0] = baseState;
            allStates[1] = XmlUtils.Serialize( config );

            return allStates;
        }
        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 static void SaveConfig( RewriterRuleCollection rules )
        {
            if( rules != null )
            {
                RewriterConfiguration config = new RewriterConfiguration();
                config.Rules = rules;

                // Create a new Xml Serializer
                XmlSerializer ser = new XmlSerializer( typeof( RewriterConfiguration ) );

                //Create a FileStream for the Config file
                string filePath = Globals.ApplicationMapPath + "\\SiteUrls.config";
                if( File.Exists( filePath ) )
                {
                    // make sure file is not read-only
                    File.SetAttributes( filePath, FileAttributes.Normal );
                }
                FileStream fileWriter = new FileStream( filePath, FileMode.Create, FileAccess.Write, FileShare.Write );

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

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

                // Close the Writers
                writer.Close();
                fileWriter.Close();

                // Create a dependancy on SiteUrls.config
                CacheDependency dep = new CacheDependency( filePath );

                // Set Cache
                DataCache.SetCache( "RewriterConfig", config, dep );
            }
        }
        protected override void LoadViewState(object savedState)
        {
            var myState = (object[]) savedState;
            if ((myState[0] != null))
            {
                base.LoadViewState(myState[0]);
            }
            if ((myState[1] != null))
            {
                var config = new RewriterConfiguration();

                //Deserialize into RewriterConfiguration
            #pragma warning disable 612,618
                config = (RewriterConfiguration) XmlUtils.Deserialize(Convert.ToString(myState[1]), config.GetType());
            #pragma warning restore 612,618
                Rules = config.Rules;
            }
        }
Example #9
0
        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);
        }