+2003-10-01 Gonzalo Paniagua Javier <gonzalo@ximian.com>
+
+ * ConfigurationSettings.cs: patch by Eric Lindvall (eric@5stops.com)
+ that improves performance by not reading the file more than once.
+
2003-07-15 Andreas Nahr <ClassDevelopment@A-SoftTech.com>
- * ConfigurationSettings.cs: Removed unused exception variable, fixes compiler warning
+ * ConfigurationSettings.cs: Removed unused exception variable, fixes
+ compiler warning
2003-06-16 Lluis Sanchez Gual <lluis@ximian.com>
- * ConfigurationSettings.cs: Avoid chicken-egg problem when reading machine.config.
- Cannot use an uri to read mechine.config because web request module handelrs are
- defined in machine.config.
+ * ConfigurationSettings.cs: Avoid chicken-egg problem when reading
+ machine.config. Cannot use an uri to read mechine.config because web
+ request module handelrs are defined in machine.config.
2003-03-02 Gonzalo Paniagua Javier <gonzalo@ximian.com>
// Author:
// Christopher Podurgiel (cpodurgiel@msn.com)
// Gonzalo Paniagua Javier (gonzalo@ximian.com)
+// Eric Lindvall (eric@5stops.com)
//
// C) Christopher Podurgiel
// (c) 2002 Ximian, Inc. (http://www.ximian.com)
}
}
+ //
+ // TODO: this should be changed to use the FileSystemWatcher
+ //
+ // -eric@5stops.com 9.20.2003
+ //
+ class FileWatcherCache
+ {
+ Hashtable _cacheTable;
+ FileInfo _lastInfo;
+ string _filename;
+
+ public FileWatcherCache (string filename)
+ {
+ _cacheTable = Hashtable.Synchronized (new Hashtable());
+ _lastInfo = new FileInfo (filename);
+ _filename = filename;
+ }
+
+ private bool HasFileChanged()
+ {
+ FileInfo currentInfo = new FileInfo (_filename);
+
+ if (_lastInfo.LastWriteTime != currentInfo.LastWriteTime)
+ return (true);
+
+ if (_lastInfo.CreationTime != currentInfo.CreationTime)
+ return (true);
+
+ if (_lastInfo.Length != currentInfo.Length)
+ return (true);
+
+ return (false);
+ }
+
+ private void CheckFileChange()
+ {
+ if (HasFileChanged() == true)
+ {
+ _lastInfo = new FileInfo (_filename);
+
+ _cacheTable.Clear();
+ }
+ }
+
+ public void Set (string key, object value)
+ {
+ CheckFileChange();
+
+ _cacheTable[key] = value;
+ }
+
+ public object Get (string key)
+ {
+ CheckFileChange();
+
+ return (_cacheTable[key]);
+ }
+ }
+
class ConfigurationData
{
ConfigurationData parent;
string fileName;
object removedMark = new object ();
object groupMark = new object ();
+ object emptyMark = new object ();
+ FileWatcherCache fileCache = null;
public ConfigurationData () : this (null)
{
reader.Close();
}
+ fileCache = new FileWatcherCache (fileName);
+
return true;
}
return doc;
}
- public object GetConfig (string sectionName)
+ object GetConfigInternal (string sectionName)
{
object handler = GetHandler (sectionName);
if (handler == null)
return ((IConfigurationSectionHandler) handler).Create (parentConfig, null, doc.DocumentElement);
}
+ public object GetConfig (string sectionName)
+ {
+ object config;
+
+ // check to see if the handler is in the cache
+ config = fileCache.Get (sectionName);
+
+ if (config == emptyMark)
+ return (null);
+ else if (config != null)
+ return (config);
+ else
+ {
+ config = GetConfigInternal (sectionName);
+
+ if (config == null)
+ fileCache.Set (sectionName, emptyMark);
+ else
+ fileCache.Set (sectionName, config);
+
+ return (config);
+ }
+ }
+
private object LookForFactory (string key)
{
object o = factories [key];