2010-01-09 Marek Habersack <mhabersack@novell.com>
[mono.git] / mcs / class / System.Configuration / System.Configuration / SectionInfo.cs
index 8ea69b8edcd6a32a234ed46d91f16f88a2c94186..c9a99aff3b24a771e758dacf1272fc0ab872656a 100644 (file)
@@ -39,6 +39,7 @@ namespace System.Configuration
        {
                bool allowLocation = true;
                bool requirePermission = true;
+               bool restartOnExternalChanges;
                ConfigurationAllowDefinition allowDefinition = ConfigurationAllowDefinition.Everywhere;
                ConfigurationAllowExeDefinition allowExeDefinition = ConfigurationAllowExeDefinition.MachineToApplication;
 
@@ -54,6 +55,7 @@ namespace System.Configuration
                        this.allowDefinition = info.AllowDefinition;
                        this.allowExeDefinition = info.AllowExeDefinition;
                        this.requirePermission = info.RequirePermission;
+                       this.restartOnExternalChanges = info.RestartOnExternalChanges;
                }
                
                public override object CreateInstance ()
@@ -65,6 +67,7 @@ namespace System.Configuration
                                sec.SectionInformation.AllowDefinition = allowDefinition;
                                sec.SectionInformation.AllowExeDefinition = allowExeDefinition;
                                sec.SectionInformation.RequirePermission = requirePermission;
+                               sec.SectionInformation.RestartOnExternalChanges = restartOnExternalChanges;
                                sec.SectionInformation.SetName (Name);
                        }
                        return ob;
@@ -80,7 +83,7 @@ namespace System.Configuration
                        return StreamName == cfg.FileName;
                }
 
-               public override void ReadConfig (Configuration cfg, string streamName, XmlTextReader reader)
+               public override void ReadConfig (Configuration cfg, string streamName, XmlReader reader)
                {
                        StreamName = streamName;
                        ConfigHost = cfg.ConfigHost;
@@ -133,6 +136,14 @@ namespace System.Configuration
                                                requirePermission = reqPermValue;
                                                break;
 
+                                       case "restartOnExternalChanges":
+                                               string restart = reader.Value;
+                                               bool restartValue = (restart == "true");
+                                               if (!restartValue && restart != "false")
+                                                       ThrowException ("Invalid attribute value", reader);
+                                               restartOnExternalChanges = restartValue;
+                                               break;
+
                                        default:
                                                ThrowException (String.Format ("Unrecognized attribute: {0}", reader.Name), reader);
                                                break;
@@ -162,7 +173,7 @@ namespace System.Configuration
                        writer.WriteEndElement ();
                }
                
-               public override void ReadData (Configuration config, XmlTextReader reader, bool overrideAllowed)
+               public override void ReadData (Configuration config, XmlReader reader, bool overrideAllowed)
                {
                        if (!config.HasFile && !allowLocation)
                                throw new ConfigurationErrorsException ("The configuration section <" + Name + "> cannot be defined inside a <location> element.", reader); 
@@ -184,6 +195,16 @@ namespace System.Configuration
                                ConfigurationSection parentSection = config.Parent != null ? config.Parent.GetSectionInstance (this, false) : null;
                                xml = section.SerializeSection (parentSection, Name, mode);
 
+                               string externalDataXml = section.ExternalDataXml;
+                               string filePath = config.FilePath;
+                               
+                               if (!String.IsNullOrEmpty (filePath) && !String.IsNullOrEmpty (externalDataXml)) {
+                                       string path = Path.Combine (Path.GetDirectoryName (filePath), section.SectionInformation.ConfigSource);
+                                       using (StreamWriter sw = new StreamWriter (path)) {
+                                               sw.Write (externalDataXml);
+                                       }
+                               }
+                               
                                if (section.SectionInformation.IsProtected) {
                                        StringBuilder sb = new StringBuilder ();
                                        sb.AppendFormat ("<{0} configProtectionProvider=\"{1}\">\n",