From: Argiris K. <be...@us...> - 2005-11-24 13:13:16
|
Update of /cvsroot/magicajax/magicajax/Core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17446/Core Modified Files: MagicAjaxContext.cs MagicAjaxModule.cs Util.cs Web.config 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: Web.config =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/Web.config,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Web.config 21 Nov 2005 12:18:36 -0000 1.5 --- Web.config 24 Nov 2005 13:13:04 -0000 1.6 *************** *** 48,52 **** <httpModules> ! <add name="MagicAjaxModule" type="MagicAjax.MagicAjaxModule, MagicAjax" /> </httpModules> --- 48,52 ---- <httpModules> ! <add name="MagicAjax" type="MagicAjax.MagicAjaxModule, MagicAjax" /> </httpModules> Index: MagicAjaxContext.cs =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/MagicAjaxContext.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** MagicAjaxContext.cs 24 Nov 2005 00:43:13 -0000 1.4 --- MagicAjaxContext.cs 24 Nov 2005 13:13:04 -0000 1.5 *************** *** 37,44 **** private bool _isBrowserSupported = false; private StoredPageInfo _storedPageInfo = null; #endregion #region Public properties ! /// <summary> /// Returns true if request was made from the browser's XmlHttpRequest object --- 37,60 ---- private bool _isBrowserSupported = false; private StoredPageInfo _storedPageInfo = null; + private MagicAjaxConfiguration _configuration = null; #endregion #region Public properties ! ! /// <summary> ! /// Configuration settings for MagicAjax. ! /// </summary> ! /// <remarks> ! /// During a page request/postback, configuration settings are getting initialized ! /// by the settings of web.config but can change for a particular page request/postback ! /// at the Load event. ! /// During an AjaxCall, the configuration settings will be the same as the page request ! /// that the AjaxCall belongs to. Changes during an AjaxCall are not allowed. ! /// </remarks> ! public MagicAjaxConfiguration Configuration ! { ! get { return _configuration; } ! } ! /// <summary> /// Returns true if request was made from the browser's XmlHttpRequest object *************** *** 51,55 **** /// <summary> ! /// True of ajax call was completed /// </summary> public bool CompletedAjaxCall --- 67,71 ---- /// <summary> ! /// True if ajax call was completed /// </summary> public bool CompletedAjaxCall *************** *** 99,103 **** public bool IsPageNoStoreMode { ! get { return MagicAjaxContext.Configuration.PageStore.Mode == MagicAjax.Configuration.PageStoreMode.NoStore; } } --- 115,119 ---- public bool IsPageNoStoreMode { ! get { return _configuration.PageStore.Mode == MagicAjax.Configuration.PageStoreMode.NoStore; } } *************** *** 150,153 **** --- 166,176 ---- public MagicAjaxContext() { + // Load configuration from web.config + _configuration = (MagicAjaxConfiguration)ConfigurationSettings.GetConfig("magicAjax"); + if (_configuration == null) + { + _configuration = new MagicAjaxConfiguration(null); + } + //store initial settings on first call (per request) if (HttpContext.Current != null) *************** *** 200,222 **** } } - - private static MagicAjaxConfiguration _configuration = null; - public static MagicAjaxConfiguration Configuration - { - get - { - if (_configuration == null) - { - // Note: there is no need to cache this as singleton, .NET framework does this automatically (only a single instance is created) - _configuration = (MagicAjaxConfiguration)ConfigurationSettings.GetConfig("magicAjax"); - if (_configuration == null) - { - _configuration = new MagicAjaxConfiguration(null); - } - } - - return _configuration; - } - } #endregion } --- 223,226 ---- Index: Util.cs =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/Util.cs,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** Util.cs 23 Nov 2005 15:28:28 -0000 1.7 --- Util.cs 24 Nov 2005 13:13:04 -0000 1.8 *************** *** 20,24 **** public static string GetFingerprint(string input) { ! MagicAjax.Configuration.OutputCompareMode compareMode = MagicAjaxContext.Configuration.PageStore.CompareMode; switch (compareMode) { --- 20,24 ---- public static string GetFingerprint(string input) { ! MagicAjax.Configuration.OutputCompareMode compareMode = MagicAjaxContext.Current.Configuration.PageStore.CompareMode; switch (compareMode) { Index: MagicAjaxModule.cs =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/MagicAjaxModule.cs,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -d -r1.30 -r1.31 *** MagicAjaxModule.cs 24 Nov 2005 12:59:12 -0000 1.30 --- MagicAjaxModule.cs 24 Nov 2005 13:13:04 -0000 1.31 *************** *** 92,100 **** public static void EnableAjaxOnPage(Page page) { ! if (page == null || MagicAjaxContext.Current.IsAjaxCallForPage(page)) return; // Enable AJAX only MagicAjax-supported browsers. // Other browsers will get a plain postback page. ! if (!MagicAjaxContext.Current.IsBrowserSupported) return; --- 92,101 ---- public static void EnableAjaxOnPage(Page page) { ! MagicAjaxContext magicAjaxContext = MagicAjaxContext.Current; ! if (page == null || magicAjaxContext.IsAjaxCallForPage(page)) return; // Enable AJAX only MagicAjax-supported browsers. // Other browsers will get a plain postback page. ! if (!magicAjaxContext.IsBrowserSupported) return; *************** *** 110,114 **** { // Provides the location of the script file. ! string location = MagicAjaxContext.Configuration.ScriptPath; string includeScript; --- 111,115 ---- { // Provides the location of the script file. ! string location = magicAjaxContext.Configuration.ScriptPath; string includeScript; *************** *** 131,135 **** page.RegisterClientScriptBlock( "AJAXCALL_FOR_MAGICAJAX", includeScript ); ! bool pageIsStored = (MagicAjaxContext.Configuration.PageStore.Mode != PageStoreMode.NoStore); if ( pageIsStored ) --- 132,136 ---- page.RegisterClientScriptBlock( "AJAXCALL_FOR_MAGICAJAX", includeScript ); ! bool pageIsStored = (magicAjaxContext.Configuration.PageStore.Mode != PageStoreMode.NoStore); if ( pageIsStored ) *************** *** 146,151 **** } ! bool unloadStoredPage = MagicAjaxContext.Configuration.PageStore.UnloadStoredPage; ! page.RegisterStartupScript("AJAXCALL_HOOK", String.Format(STARTUP_SCRIPT_FORMAT, location, "AjaxCallObject.js", pageIsStored.ToString().ToLower(), unloadStoredPage.ToString().ToLower(), MagicAjaxContext.Configuration.Tracing.ToString().ToLower())); } } --- 147,157 ---- } ! // Save to page any changes that may occured to Configuration ! string configState = magicAjaxContext.Configuration.GetState(); ! if ( configState != null) ! page.RegisterHiddenField ("__MAGICAJAX_CONFIG", configState); ! ! bool unloadStoredPage = magicAjaxContext.Configuration.PageStore.UnloadStoredPage; ! page.RegisterStartupScript("AJAXCALL_HOOK", String.Format(STARTUP_SCRIPT_FORMAT, location, "AjaxCallObject.js", pageIsStored.ToString().ToLower(), unloadStoredPage.ToString().ToLower(), magicAjaxContext.Configuration.Tracing.ToString().ToLower())); } } *************** *** 170,174 **** if (capabilities.Win32 && (capabilities.MSDomVersion.CompareTo(new Version(5, 5)) >= 0)) { ! string location = MagicAjaxContext.Configuration.ScriptPath; if (location == null) { --- 176,180 ---- if (capabilities.Win32 && (capabilities.MSDomVersion.CompareTo(new Version(5, 5)) >= 0)) { ! string location = MagicAjaxContext.Current.Configuration.ScriptPath; if (location == null) { *************** *** 220,224 **** StoredPageInfo pageInfo = new StoredPageInfo(page); ! if (storedPages.Count < MagicAjaxContext.Configuration.PageStore.MaxConcurrentPages) { pageInfoIndex = storedPages.Add(pageInfo); --- 226,230 ---- StoredPageInfo pageInfo = new StoredPageInfo(page); ! if (storedPages.Count < MagicAjaxContext.Current.Configuration.PageStore.MaxConcurrentPages) { pageInfoIndex = storedPages.Add(pageInfo); *************** *** 251,255 **** } ! if (MagicAjaxContext.Configuration.PageStore.MaxPagesLimitAlert) { page.RegisterStartupScript("__AJAX_PAGENOTSTOREDWARNING", --- 257,261 ---- } ! if (MagicAjaxContext.Current.Configuration.PageStore.MaxPagesLimitAlert) { page.RegisterStartupScript("__AJAX_PAGENOTSTOREDWARNING", *************** *** 263,267 **** if (saveStoredPagesList) { ! switch (MagicAjaxContext.Configuration.PageStore.Mode) { case PageStoreMode.Session: --- 269,273 ---- if (saveStoredPagesList) { ! switch (MagicAjaxContext.Current.Configuration.PageStore.Mode) { case PageStoreMode.Session: *************** *** 270,277 **** case PageStoreMode.Cache: HttpContext.Current.Cache.Add(key, storedPages, null, System.Web.Caching.Cache.NoAbsoluteExpiration, ! TimeSpan.FromMinutes(MagicAjaxContext.Configuration.PageStore.CacheTimeout), System.Web.Caching.CacheItemPriority.Default, null); break; default: ! throw new ConfigurationException(String.Format("MagicAjax configuration: The pageStore mode '{0}' is not supported for storing the page.", MagicAjaxContext.Configuration.PageStore.Mode)); } } --- 276,283 ---- case PageStoreMode.Cache: HttpContext.Current.Cache.Add(key, storedPages, null, System.Web.Caching.Cache.NoAbsoluteExpiration, ! TimeSpan.FromMinutes(MagicAjaxContext.Current.Configuration.PageStore.CacheTimeout), System.Web.Caching.CacheItemPriority.Default, null); break; default: ! throw new ConfigurationException(String.Format("MagicAjax configuration: The pageStore mode '{0}' is not supported for storing the page.", MagicAjaxContext.Current.Configuration.PageStore.Mode)); } } *************** *** 339,343 **** return null; ! switch (MagicAjaxContext.Configuration.PageStore.Mode) { case PageStoreMode.Session: --- 345,349 ---- return null; ! switch (MagicAjaxContext.Current.Configuration.PageStore.Mode) { case PageStoreMode.Session: *************** *** 354,358 **** default: ! throw new ConfigurationException(String.Format("MagicAjax configuration: The pageStore mode '{0}' is not supported for storing the page.", MagicAjaxContext.Configuration.PageStore.Mode)); } } --- 360,364 ---- default: ! throw new ConfigurationException(String.Format("MagicAjax configuration: The pageStore mode '{0}' is not supported for storing the page.", MagicAjaxContext.Current.Configuration.PageStore.Mode)); } } *************** *** 360,364 **** protected static string GetStoredPagesKey(Page page) { ! switch (MagicAjaxContext.Configuration.PageStore.Mode) { case PageStoreMode.Session: --- 366,370 ---- protected static string GetStoredPagesKey(Page page) { ! switch (MagicAjaxContext.Current.Configuration.PageStore.Mode) { case PageStoreMode.Session: *************** *** 369,373 **** default: ! throw new ConfigurationException(String.Format("MagicAjax configuration: The pageStore mode '{0}' is not supported for storing the page.", MagicAjaxContext.Configuration.PageStore.Mode)); } } --- 375,379 ---- default: ! throw new ConfigurationException(String.Format("MagicAjax configuration: The pageStore mode '{0}' is not supported for storing the page.", MagicAjaxContext.Current.Configuration.PageStore.Mode)); } } *************** *** 449,455 **** _magicAjaxContext.IsAjaxCall = (_request.Form["__AJAXCALL"] != null); ! NameValueCollection _form = _request.Form; ! if ( PageStoreMode.NoStore == MagicAjaxContext.Configuration.PageStore.Mode ) { // The page is not stored --- 455,469 ---- _magicAjaxContext.IsAjaxCall = (_request.Form["__AJAXCALL"] != null); ! string configState = _request.Form["__MAGICAJAX_CONFIG"]; ! if (configState != null) ! { ! _magicAjaxContext.Configuration.LoadState (configState); ! if (_magicAjaxContext.IsAjaxCall) ! _magicAjaxContext.Configuration.IsLocked = true; ! } ! pageKey = _request.Form[PageKeyFieldName]; ! ! if ( pageKey == null ) { // The page is not stored *************** *** 490,494 **** string vsValue = _filter.GetViewStateFieldValue(); ! if (vsValue != null && _form["__VIEWSTATE"] != vsValue) { AjaxCallHelper.WriteSetFieldScript("__VIEWSTATE", vsValue); --- 504,508 ---- string vsValue = _filter.GetViewStateFieldValue(); ! if (vsValue != null && _request.Form["__VIEWSTATE"] != vsValue) { AjaxCallHelper.WriteSetFieldScript("__VIEWSTATE", vsValue); *************** *** 498,502 **** // Check if this request is to add/remove/replace a WebPart // If so, send back updated WebPartManager drag&drop javascript (IE only) ! if (!string.IsNullOrEmpty(_form["__WPPS"])) { string wpmValue = _filter.GetWebPartManagerScriptValue(requestPage.Form.ClientID); --- 512,516 ---- // Check if this request is to add/remove/replace a WebPart // If so, send back updated WebPartManager drag&drop javascript (IE only) ! if (!string.IsNullOrEmpty(_request.Form["__WPPS"])) { string wpmValue = _filter.GetWebPartManagerScriptValue(requestPage.Form.ClientID); *************** *** 518,531 **** // The page is stored - pageKey = _form[PageKeyFieldName]; - - if (pageKey == null) - { - if ( _magicAjaxContext.IsAjaxCall ) - throw new MagicAjaxException(String.Format("Hidden field '{0}' wasn't found. Page isn't AJAX enabled.", PageKeyFieldName)); - else - return; - } - _magicAjaxContext.StoredPageInfo = GetStoredPageInfo(pageKey); if (_magicAjaxContext.StoredPageInfo == null) --- 532,535 ---- *************** *** 533,537 **** if (_magicAjaxContext.IsAjaxCall) { ! // Stored Page wasn't found, could be that the session expired. // Have the browser do a refresh. // It will stop the current execution and will throw Application_EndRequest event --- 537,542 ---- if (_magicAjaxContext.IsAjaxCall) { ! // Stored Page wasn't found, could be that the session expired or ! // the client returned to an unloaded page. // Have the browser do a refresh. // It will stop the current execution and will throw Application_EndRequest event |