[System.Configuration] Rename method parameters to match .NET contract
[mono.git] / mcs / class / System.Configuration / System.Configuration / Configuration.cs
index c845fa045383f311cdcc2051423a16a66bd4052b..7e78b1b325f1946ab1bcbb8e95c0ee43ffa7681f 100644 (file)
@@ -26,7 +26,7 @@
 //
 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
 //
-#if NET_2_0
+
 using System;
 using System.Collections;
 using System.Collections.Specialized;
@@ -133,8 +133,12 @@ namespace System.Configuration {
                                rootGroup.StreamName = streamName;
                        }
                        
-                       if (streamName != null)
-                               Load ();
+                       try {
+                               if (streamName != null)
+                                       Load ();
+                       } catch (XmlException ex) {
+                               throw new ConfigurationErrorsException (ex.Message, ex, streamName, 0);
+                       }
                }
                
                internal Configuration Parent {
@@ -247,9 +251,9 @@ namespace System.Configuration {
                        get { return RootSectionGroup.Sections; }
                }
                
-               public ConfigurationSection GetSection (string path)
+               public ConfigurationSection GetSection (string sectionName)
                {
-                       string[] parts = path.Split ('/');
+                       string[] parts = sectionName.Split ('/');
                        if (parts.Length == 1)
                                return Sections [parts[0]];
 
@@ -263,9 +267,9 @@ namespace System.Configuration {
                                return null;
                }
                
-               public ConfigurationSectionGroup GetSectionGroup (string path)
+               public ConfigurationSectionGroup GetSectionGroup (string sectionGroupName)
                {
-                       string[] parts = path.Split ('/');
+                       string[] parts = sectionGroupName.Split ('/');
                        ConfigurationSectionGroup group = SectionGroups [parts[0]];
                        for (int n=1; group != null && n<parts.Length; n++)
                                group = group.SectionGroups [parts [n]];
@@ -300,7 +304,7 @@ namespace System.Configuration {
                        sec.RawXml = xml;
                        sec.Reset (parentSection);
 
-                       if (xml != null && xml == data) {
+                       if (xml != null) {
                                XmlTextReader r = new ConfigXmlTextReader (new StringReader (xml), FilePath);
                                sec.DeserializeSection (r);
                                r.Close ();
@@ -356,6 +360,7 @@ namespace System.Configuration {
                        section.ConfigHost = system.Host;
                        group.AddChild (section);
                        elementData [section] = sec;
+                       sec.Configuration = this;
                }
                
                internal void CreateSectionGroup (SectionGroupInfo parentGroup, string name, ConfigurationSectionGroup sec)
@@ -383,13 +388,18 @@ namespace System.Configuration {
                        Save (ConfigurationSaveMode.Modified, false);
                }
                
-               public void Save (ConfigurationSaveMode mode)
+               public void Save (ConfigurationSaveMode saveMode)
                {
-                       Save (mode, false);
+                       Save (saveMode, false);
                }
                
-               public void Save (ConfigurationSaveMode mode, bool forceUpdateAll)
+               public void Save (ConfigurationSaveMode saveMode, bool forceSaveAll)
                {
+                       if (!forceSaveAll && (saveMode != ConfigurationSaveMode.Full) && !HasValues (saveMode)) {
+                               ResetModified ();
+                               return;
+                       }
+
                        ConfigurationSaveEventHandler saveStart = SaveStart;
                        ConfigurationSaveEventHandler saveEnd = SaveEnd;
                        
@@ -400,7 +410,7 @@ namespace System.Configuration {
                                if (saveStart != null)
                                        saveStart (this, new ConfigurationSaveEventArgs (streamName, true, null, ctx));
                                
-                               Save (stream, mode, forceUpdateAll);
+                               Save (stream, saveMode, forceSaveAll);
                                system.Host.WriteCompleted (streamName, true, ctx);
                        } catch (Exception ex) {
                                saveEx = ex;
@@ -418,18 +428,23 @@ namespace System.Configuration {
                        SaveAs (filename, ConfigurationSaveMode.Modified, false);
                }
                
-               public void SaveAs (string filename, ConfigurationSaveMode mode)
+               public void SaveAs (string filename, ConfigurationSaveMode saveMode)
                {
-                       SaveAs (filename, mode, false);
+                       SaveAs (filename, saveMode, false);
                }
 
                [MonoInternalNote ("Detect if file has changed")]
-               public void SaveAs (string filename, ConfigurationSaveMode mode, bool forceUpdateAll)
+               public void SaveAs (string filename, ConfigurationSaveMode saveMode, bool forceSaveAll)
                {
+                       if (!forceSaveAll && (saveMode != ConfigurationSaveMode.Full) && !HasValues (saveMode)) {
+                               ResetModified ();
+                               return;
+                       }
+                       
                        string dir = Path.GetDirectoryName (Path.GetFullPath (filename));
                        if (!Directory.Exists (dir))
                                Directory.CreateDirectory (dir);
-                       Save (new FileStream (filename, FileMode.OpenOrCreate, FileAccess.Write), mode, forceUpdateAll);
+                       Save (new FileStream (filename, FileMode.OpenOrCreate, FileAccess.Write), saveMode, forceSaveAll);
                }
 
                void Save (Stream stream, ConfigurationSaveMode mode, bool forceUpdateAll)
@@ -463,6 +478,7 @@ namespace System.Configuration {
                                
                                SaveData (tw, mode, forceUpdateAll);
                                tw.WriteEndElement ();
+                               ResetModified ();
                        }
                        finally {
                                tw.Flush ();
@@ -474,6 +490,29 @@ namespace System.Configuration {
                {
                        rootGroup.WriteRootData (tw, this, mode);
                }
+
+               bool HasValues (ConfigurationSaveMode mode)
+               {
+                       foreach (ConfigurationLocation loc in Locations) {
+                               if (loc.OpenedConfiguration == null)
+                                       continue;
+                               if (loc.OpenedConfiguration.HasValues (mode))
+                                       return true;
+                       }
+
+                       return rootGroup.HasValues (this, mode);
+               }
+
+               void ResetModified ()
+               {
+                       foreach (ConfigurationLocation loc in Locations) {
+                               if (loc.OpenedConfiguration == null)
+                                       continue;
+                               loc.OpenedConfiguration.ResetModified ();
+                       }
+                       
+                       rootGroup.ResetModified (this);
+               }
                
                bool Load ()
                {
@@ -492,6 +531,7 @@ namespace System.Configuration {
                        using (XmlTextReader reader = new ConfigXmlTextReader (stream, streamName)) {
                                ReadConfigFile (reader, streamName);
                        }
+                       ResetModified ();
                        return true;
                }
 
@@ -546,4 +586,3 @@ namespace System.Configuration {
        }
 }
 
-#endif