From: Argiris K. <be...@us...> - 2005-11-24 13:13:12
|
Update of /cvsroot/magicajax/magicajax/Core/Configuration In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17446/Core/Configuration Modified Files: MagicAjaxConfiguration.cs Log Message: Moved Configuration to MagicAjaxContext.Current so that configuration options can be set for a specific page. Any changes that occur to Configuration settings are stored in a hidden field on page and restored at a postback/ajaxcall Index: MagicAjaxConfiguration.cs =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/Configuration/MagicAjaxConfiguration.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** MagicAjaxConfiguration.cs 23 Nov 2005 15:28:28 -0000 1.6 --- MagicAjaxConfiguration.cs 24 Nov 2005 13:13:03 -0000 1.7 *************** *** 2,6 **** using System.Xml; using System.Configuration; ! using System.Collections.Specialized; namespace MagicAjax.Configuration --- 2,7 ---- using System.Xml; using System.Configuration; ! using System.Collections; ! using System.Web.UI; namespace MagicAjax.Configuration *************** *** 22,25 **** --- 23,38 ---- public struct PageStore { + #region Private Fields + private Hashtable _state; + private bool _isLocked; + + // web.config settings + private PageStoreMode _origMode; + private bool _origUnloadStoredPage; + private int _origCacheTimeout; + private int _origMaxConcurrentPages; + private bool _origMaxPagesLimitAlert; + private OutputCompareMode _origCompareMode; + // active settings private PageStoreMode _mode; private bool _unloadStoredPage; *************** *** 28,35 **** --- 41,65 ---- private bool _maxPagesLimitAlert; private OutputCompareMode _compareMode; + #endregion + #region Public Properties public PageStoreMode Mode { get { return _mode; } + set + { + if ( _isLocked && value != _mode ) + throw new MagicAjaxException("Configuration settings have been locked and cannot change."); + + if ( value != _origMode ) + { + _mode = value; + _state["Mode"] = _mode; + } + else + { + _state.Remove("Mode"); + } + } } *************** *** 37,40 **** --- 67,85 ---- { get { return _unloadStoredPage; } + set + { + if ( _isLocked && value != _unloadStoredPage ) + throw new MagicAjaxException("Configuration settings have been locked and cannot change."); + + if ( value != _origUnloadStoredPage ) + { + _unloadStoredPage = value; + _state["UnloadStoredPage"] = _unloadStoredPage; + } + else + { + _state.Remove("UnloadStoredPage"); + } + } } *************** *** 42,45 **** --- 87,105 ---- { get { return _cacheTimeout; } + set + { + if ( _isLocked && value != _cacheTimeout ) + throw new MagicAjaxException("Configuration settings have been locked and cannot change."); + + if ( value != _origCacheTimeout ) + { + _cacheTimeout = value; + _state["CacheTimeout"] = _cacheTimeout; + } + else + { + _state.Remove("CacheTimeout"); + } + } } *************** *** 47,50 **** --- 107,125 ---- { get { return _maxConcurrentPages; } + set + { + if ( _isLocked && value != _maxConcurrentPages ) + throw new MagicAjaxException("Configuration settings have been locked and cannot change."); + + if ( value != _origMaxConcurrentPages ) + { + _maxConcurrentPages = value; + _state["MaxConcurrentPages"] = _maxConcurrentPages; + } + else + { + _state.Remove("MaxConcurrentPages"); + } + } } *************** *** 52,55 **** --- 127,145 ---- { get { return _maxPagesLimitAlert; } + set + { + if ( _isLocked && value != _maxPagesLimitAlert ) + throw new MagicAjaxException("Configuration settings have been locked and cannot change."); + + if ( value != _origMaxPagesLimitAlert ) + { + _maxPagesLimitAlert = value; + _state["MaxPagesLimitAlert"] = _maxPagesLimitAlert; + } + else + { + _state.Remove("MaxPagesLimitAlert"); + } + } } *************** *** 57,70 **** { get { return _compareMode; } } public PageStore(PageStoreMode mode, bool unloadStoredPage, int cacheTimeout, int maxConcurrentPages, bool maxPagesLimitAlert, OutputCompareMode compareMode) { ! _mode = mode; ! _cacheTimeout = cacheTimeout; ! _maxConcurrentPages = maxConcurrentPages; ! _maxPagesLimitAlert = maxPagesLimitAlert; ! _compareMode = compareMode; ! _unloadStoredPage = unloadStoredPage; } } --- 147,230 ---- { get { return _compareMode; } + set + { + if ( _isLocked && value != _compareMode ) + throw new MagicAjaxException("Configuration settings have been locked and cannot change."); + + if ( value != _origCompareMode ) + { + _compareMode = value; + _state["CompareMode"] = _compareMode; + } + else + { + _state.Remove("CompareMode"); + } + } + } + #endregion + + internal bool IsDirty + { + get { return ( _state.Keys.Count > 0 ); } + } + + internal bool IsLocked + { + get { return _isLocked; } + set { _isLocked = value; } + } + + internal string GetState() + { + if ( ! IsDirty ) + return null; + + System.IO.StringWriter writer = new System.IO.StringWriter(); + new LosFormatter().Serialize(writer, _state); + return writer.ToString(); + } + + internal void LoadState(string stateString) + { + Hashtable state = new LosFormatter().Deserialize(stateString) as Hashtable; + foreach (string key in state.Keys) + { + switch (key) + { + case "Mode": + Mode = (PageStoreMode) state[key]; + break; + case "CacheTimeout": + CacheTimeout = (int) state[key]; + break; + case "MaxConcurrentPages": + MaxConcurrentPages = (int) state[key]; + break; + case "MaxPagesLimitAlert": + MaxPagesLimitAlert = (bool) state[key]; + break; + case "CompareMode": + CompareMode = (OutputCompareMode) state[key]; + break; + case "UnloadStoredPage": + UnloadStoredPage = (bool) state[key]; + break; + default: + throw new MagicAjaxException(String.Format("PageStore.LoadState: Unknown property '{0}'.", key)); + } + } } public PageStore(PageStoreMode mode, bool unloadStoredPage, int cacheTimeout, int maxConcurrentPages, bool maxPagesLimitAlert, OutputCompareMode compareMode) { ! _state = new Hashtable(); ! _isLocked = false; ! _origMode = _mode = mode; ! _origCacheTimeout = _cacheTimeout = cacheTimeout; ! _origMaxConcurrentPages = _maxConcurrentPages = maxConcurrentPages; ! _origMaxPagesLimitAlert = _maxPagesLimitAlert = maxPagesLimitAlert; ! _origCompareMode = _compareMode = compareMode; ! _origUnloadStoredPage = _unloadStoredPage = unloadStoredPage; } } *************** *** 75,85 **** public class MagicAjaxConfiguration { private string _scriptPath; private bool _tracing; ! private PageStore _pageStore; public string ScriptPath { get { return _scriptPath; } } --- 235,270 ---- public class MagicAjaxConfiguration { + #region Private Fields + private Hashtable _state = new Hashtable(); + private bool _isLocked = false; + + private PageStore _pageStore; + // web.config settings + private string _origScriptPath; + private bool _origTracing; + // active settings private string _scriptPath; private bool _tracing; ! #endregion + #region Public Properties public string ScriptPath { get { return _scriptPath; } + set + { + if ( _isLocked && value != _scriptPath ) + throw new MagicAjaxException("Configuration settings have been locked and cannot change."); + + if ( value != _origScriptPath ) + { + _scriptPath = value; + _state["ScriptPath"] = _scriptPath; + } + else + { + _state.Remove("ScriptPath"); + } + } } *************** *** 87,90 **** --- 272,290 ---- { get { return _tracing; } + set + { + if ( _isLocked && value != _tracing ) + throw new MagicAjaxException("Configuration settings have been locked and cannot change."); + + if ( value != _origTracing ) + { + _tracing = value; + _state["Tracing"] = _tracing; + } + else + { + _state.Remove("Tracing"); + } + } } *************** *** 93,96 **** --- 293,349 ---- get { return _pageStore; } } + #endregion + + internal bool IsDirty + { + get { return ( _state.Keys.Count > 0 || _pageStore.IsDirty ); } + } + + internal bool IsLocked + { + get { return _isLocked; } + set + { + _isLocked = value; + _pageStore.IsLocked = value; + } + } + + internal string GetState() + { + if ( ! IsDirty ) + return null; + + if ( _pageStore.IsDirty ) + _state["PageStoreState"] = _pageStore.GetState(); + + System.IO.StringWriter writer = new System.IO.StringWriter(); + new LosFormatter().Serialize(writer, _state); + + _state.Remove("PageStoreState"); + return writer.ToString(); + } + + internal void LoadState(string stateString) + { + Hashtable state = new LosFormatter().Deserialize(stateString) as Hashtable; + foreach (string key in state.Keys) + { + switch (key) + { + case "ScriptPath": + ScriptPath = (string) state[key]; + break; + case "Tracing": + Tracing = (bool) state[key]; + break; + case "PageStoreState": + _pageStore.LoadState((string)state[key]); + break; + default: + throw new MagicAjaxException(String.Format("MagicAjaxConfiguration.LoadState: Unknown property '{0}'.", key)); + } + } + } public MagicAjaxConfiguration(XmlNode xml) *************** *** 225,228 **** --- 478,483 ---- _pageStore = new PageStore(mode, unloadStoredPage, cacheTimeout, maxPages, maxPagesLimitAlert, compareMode); + _origScriptPath = _scriptPath; + _origTracing = _tracing; } } |