string configPath;
string locationConfigPath;
-
- internal Configuration (Configuration parent)
+ string locationSubPath;
+
+ internal Configuration (Configuration parent, string locationSubPath)
{
this.parent = parent;
this.system = parent.system;
this.rootGroup = parent.rootGroup;
+ this.locationSubPath = locationSubPath;
}
internal Configuration (InternalConfigurationSystem system, string locationSubPath)
get { return locationConfigPath; }
}
+ internal string GetLocationSubPath ()
+ {
+ Configuration confg = parent;
+ string path = null;
+ while (confg != null) {
+ path = confg.locationSubPath;
+ if (!String.IsNullOrEmpty (path))
+ return path;
+ confg = confg.parent;
+ }
+ return path;
+ }
+
internal string ConfigPath {
get { return configPath; }
}
get { return (ConnectionStringsSection) GetSection ("connectionStrings"); }
}
+ // MSDN: If the value for this FilePath property represents a merged view and
+ // no actual file exists for the application, the path to the parent configuration
+ // file is returned.
public string FilePath {
- get { return streamName; }
+ get {
+ if (streamName == null && parent != null)
+ return parent.FilePath;
+ return streamName;
+ }
}
public bool HasFile {
}
}
- [MonoTODO ("HostingContext")]
ContextInformation evaluationContext;
public ContextInformation EvaluationContext {
get {
- if (evaluationContext == null)
- evaluationContext = new ContextInformation (this, null /* XXX */);
+ if (evaluationContext == null) {
+ object ctx = system.Host.CreateConfigurationContext (configPath, GetLocationSubPath() );
+ evaluationContext = new ContextInformation (this, ctx);
+ }
+
+
return evaluationContext;
}
}
section.ConfigHost = system.Host;
parentGroup.AddChild (section);
elementData [section] = sec;
+
+ sec.Initialize (this, section);
}
internal void RemoveConfigInfo (ConfigInfo config)
try {
Save (stream, mode, forceUpdateAll);
system.Host.WriteCompleted (streamName, true, ctx);
- } catch (Exception ex) {
+ } catch (Exception) {
system.Host.WriteCompleted (streamName, false, ctx);
throw;
} finally {
{
SaveAs (filename, mode, false);
}
-
- [MonoTODO ("Detect if file has changed")]
+
+ [MonoInternalNote ("Detect if file has changed")]
public void SaveAs (string filename, ConfigurationSaveMode mode, bool forceUpdateAll)
{
+ string dir = Path.GetDirectoryName (Path.GetFullPath (filename));
+ if (!Directory.Exists (dir))
+ Directory.CreateDirectory (dir);
Save (new FileStream (filename, FileMode.OpenOrCreate, FileAccess.Write), mode, forceUpdateAll);
}
bool Load ()
{
- if (streamName == null || streamName == "")
+ if (String.IsNullOrEmpty (streamName))
return true;
XmlTextReader reader = null;
Stream stream = null;
+ // FIXME: we should remove this kind of hack that
+ // hides the actual error
try {
stream = system.Host.OpenStreamForRead (streamName);
- } catch (Exception e) {
+ } catch (Exception) {
return false;
}