ConfigurationLocation.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. //
  2. // System.Configuration.ConfigurationLocation.cs
  3. //
  4. // Authors:
  5. // Duncan Mak ([email protected])
  6. // Lluis Sanchez Gual ([email protected])
  7. //
  8. // Permission is hereby granted, free of charge, to any person obtaining
  9. // a copy of this software and associated documentation files (the
  10. // "Software"), to deal in the Software without restriction, including
  11. // without limitation the rights to use, copy, modify, merge, publish,
  12. // distribute, sublicense, and/or sell copies of the Software, and to
  13. // permit persons to whom the Software is furnished to do so, subject to
  14. // the following conditions:
  15. //
  16. // The above copyright notice and this permission notice shall be
  17. // included in all copies or substantial portions of the Software.
  18. //
  19. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  20. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  21. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  22. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  23. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  24. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  25. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  26. //
  27. // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
  28. //
  29. #if NET_2_0
  30. using System.Xml;
  31. using System.IO;
  32. namespace System.Configuration {
  33. public class ConfigurationLocation
  34. {
  35. string path;
  36. Configuration configuration;
  37. Configuration parent;
  38. string xmlContent;
  39. bool parentResolved;
  40. bool allowOverride;
  41. internal ConfigurationLocation()
  42. {
  43. }
  44. internal ConfigurationLocation (string path, string xmlContent, Configuration parent, bool allowOverride)
  45. {
  46. this.path = path;
  47. this.xmlContent = xmlContent;
  48. this.parent = parent;
  49. this.allowOverride = allowOverride;
  50. }
  51. public string Path {
  52. get { return path; }
  53. }
  54. internal bool AllowOverride {
  55. get { return allowOverride; }
  56. }
  57. internal string XmlContent {
  58. get { return xmlContent; }
  59. }
  60. internal Configuration OpenedConfiguration {
  61. get { return configuration; }
  62. }
  63. public Configuration OpenConfiguration ()
  64. {
  65. if (configuration == null) {
  66. if (!parentResolved) {
  67. Configuration parentFile = parent.GetParentWithFile ();
  68. if (parentFile != null) {
  69. string parentRelativePath = parent.ConfigHost.GetConfigPathFromLocationSubPath (parent.LocationConfigPath, path);
  70. parent = parentFile.FindLocationConfiguration (parentRelativePath, parent);
  71. }
  72. }
  73. configuration = new Configuration (parent, path);
  74. using (XmlTextReader tr = new ConfigXmlTextReader (new StringReader (xmlContent), path))
  75. configuration.ReadData (tr, allowOverride);
  76. xmlContent = null;
  77. }
  78. return configuration;
  79. }
  80. internal void SetParentConfiguration (Configuration parent)
  81. {
  82. parentResolved = true;
  83. this.parent = parent;
  84. if (configuration != null)
  85. configuration.Parent = parent;
  86. }
  87. }
  88. }
  89. #endif