From: Argiris K. <be...@us...> - 2005-11-24 00:43:22
|
Update of /cvsroot/magicajax/magicajax/Core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14689/Core Modified Files: MagicAjaxContext.cs MagicAjaxModule.cs Log Message: Added some private fields to MagicAjaxModule and moved ExceptionThrown to it. Index: MagicAjaxContext.cs =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/MagicAjaxContext.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** MagicAjaxContext.cs 23 Nov 2005 19:34:22 -0000 1.3 --- MagicAjaxContext.cs 24 Nov 2005 00:43:13 -0000 1.4 *************** *** 35,39 **** private bool _isAjaxCall = false; private bool _completedAjaxCall = false; - private bool _exceptionThrown = false; private bool _isBrowserSupported = false; private StoredPageInfo _storedPageInfo = null; --- 35,38 ---- *************** *** 61,73 **** /// <summary> - /// Has an exception been thrown during this callback - /// </summary> - public bool ExceptionThrown - { - get { return _exceptionThrown; } - set { _exceptionThrown = value; } - } - - /// <summary> /// Returns if this browser is supported by MagicAjax. /// For now (version 0.2) only IE and FireFox are supported. --- 60,63 ---- Index: MagicAjaxModule.cs =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/MagicAjaxModule.cs,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** MagicAjaxModule.cs 23 Nov 2005 19:34:23 -0000 1.27 --- MagicAjaxModule.cs 24 Nov 2005 00:43:13 -0000 1.28 *************** *** 54,58 **** --- 54,62 ---- public class MagicAjaxModule: IHttpModule { + private bool _exceptionThrown; private PageFilter _filter; + private HttpRequest _request; + private HttpResponse _response; + private MagicAjaxContext _magicAjaxContext; #region IHttpModule implementation *************** *** 382,385 **** --- 386,396 ---- HttpContext context = ((HttpApplication)sender).Context; + // Init private fields + _exceptionThrown = false; + _request = context.Request; + _response = context.Response; + _magicAjaxContext = MagicAjaxContext.Current; + + // Check if the request is for the embedded AjaxCallObject.js script if (context.Request.RawUrl.EndsWith("AjaxCallObject.js.aspx")) *************** *** 415,419 **** } ! string pageKey = HttpContext.Current.Request.QueryString["__AJAX_PAGEUNLOAD"]; if (pageKey != null) { --- 426,430 ---- } ! string pageKey = _request.QueryString["__AJAX_PAGEUNLOAD"]; if (pageKey != null) { *************** *** 421,425 **** // Don't let the browser cache it or the next page unload request // will not reach the server. ! HttpContext.Current.Response.Cache.SetNoStore(); application.CompleteRequest(); } --- 432,436 ---- // Don't let the browser cache it or the next page unload request // will not reach the server. ! _response.Cache.SetNoStore(); application.CompleteRequest(); } *************** *** 434,442 **** // Continue only if it is a postback or an AjaxCall ! if ( "GET" == HttpContext.Current.Request.HttpMethod ) return; ! MagicAjaxContext.Current.IsAjaxCall = (HttpContext.Current.Request.Form["__AJAXCALL"] != null); ! NameValueCollection _form = HttpContext.Current.Request.Form; if ( PageStoreMode.NoStore == MagicAjaxContext.Configuration.PageStore.Mode ) --- 445,453 ---- // Continue only if it is a postback or an AjaxCall ! if ( "GET" == _request.HttpMethod ) return; ! _magicAjaxContext.IsAjaxCall = (_request.Form["__AJAXCALL"] != null); ! NameValueCollection _form = _request.Form; if ( PageStoreMode.NoStore == MagicAjaxContext.Configuration.PageStore.Mode ) *************** *** 444,452 **** // The page is not stored ! if (MagicAjaxContext.Current.IsAjaxCall) { //insert output filter ! _filter = new PageFilter(HttpContext.Current.Response.Filter); ! HttpContext.Current.Response.Filter = _filter; AjaxCallHelper.Init(); --- 455,463 ---- // The page is not stored ! if (_magicAjaxContext.IsAjaxCall) { //insert output filter ! _filter = new PageFilter(_response.Filter); ! _response.Filter = _filter; AjaxCallHelper.Init(); *************** *** 454,458 **** try { ! MagicAjaxContext.Current.ExceptionThrown = true; HttpContext.Current.Handler.ProcessRequest (HttpContext.Current); } --- 465,469 ---- try { ! _exceptionThrown = true; HttpContext.Current.Handler.ProcessRequest (HttpContext.Current); } *************** *** 461,469 **** // ThreadAbortException is for Server.Transfer, Response.Redirect // and AjaxCallHelper.End ! MagicAjaxContext.Current.ExceptionThrown = false; throw; } ! HttpContext.Current.Response.Flush(); string vsValue = _filter.GetViewStateFieldValue(); --- 472,480 ---- // ThreadAbortException is for Server.Transfer, Response.Redirect // and AjaxCallHelper.End ! _exceptionThrown = false; throw; } ! _response.Flush(); string vsValue = _filter.GetViewStateFieldValue(); *************** *** 500,504 **** if (pageKey == null) { ! if ( MagicAjaxContext.Current.IsAjaxCall ) throw new MagicAjaxException(String.Format("Hidden field '{0}' wasn't found. Page isn't AJAX enabled.", PageKeyFieldName)); else --- 511,515 ---- if (pageKey == null) { ! if ( _magicAjaxContext.IsAjaxCall ) throw new MagicAjaxException(String.Format("Hidden field '{0}' wasn't found. Page isn't AJAX enabled.", PageKeyFieldName)); else *************** *** 506,518 **** } ! MagicAjaxContext.Current.StoredPageInfo = GetStoredPageInfo(pageKey); ! if (MagicAjaxContext.Current.StoredPageInfo == null) { ! if (MagicAjaxContext.Current.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 ! AjaxCallHelper.Redirect (HttpContext.Current.Request.RawUrl); } else --- 517,529 ---- } ! _magicAjaxContext.StoredPageInfo = GetStoredPageInfo(pageKey); ! if (_magicAjaxContext.StoredPageInfo == null) { ! 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 ! AjaxCallHelper.Redirect (_request.RawUrl); } else *************** *** 522,535 **** } ! if (!MagicAjaxContext.Current.IsAjaxCall) { // PostBack. Do some really hacky stuff to get the real viewstate. ! string vs = GetViewStateOfPage(MagicAjaxContext.Current.StoredPageInfo.Page); if (vs != null) { ! Util.SetPrivateField(HttpContext.Current.Request.Form, typeof(NameObjectCollectionBase), "_readOnly", false); ! HttpContext.Current.Request.Form["__VIEWSTATE"] = vs; ! Util.SetPrivateField(HttpContext.Current.Request.Form, typeof(NameObjectCollectionBase), "_readOnly", true); } } --- 533,546 ---- } ! if (!_magicAjaxContext.IsAjaxCall) { // PostBack. Do some really hacky stuff to get the real viewstate. ! string vs = GetViewStateOfPage(_magicAjaxContext.StoredPageInfo.Page); if (vs != null) { ! Util.SetPrivateField(_request.Form, typeof(NameObjectCollectionBase), "_readOnly", false); ! _request.Form["__VIEWSTATE"] = vs; ! Util.SetPrivateField(_request.Form, typeof(NameObjectCollectionBase), "_readOnly", true); } } *************** *** 537,559 **** { // AjaxCall ! _filter = new PageFilter(HttpContext.Current.Response.Filter); ! HttpContext.Current.Response.Filter = _filter; ! if (MagicAjaxContext.Current.StoredPageInfo.AjaxCallsCount == 0) { // For bypassing the VerifyRenderingInServerForm check ! Util.SetPrivateField(MagicAjaxContext.Current.StoredPageInfo.Page, typeof(Page), "_inOnFormRender", true); ! if (MagicAjaxContext.Current.StoredPageInfo.Page.Validators.Count == 0) { // Restore the validators ! ArrayList validators = Util.GetChildControlsOfType(MagicAjaxContext.Current.StoredPageInfo.Page, typeof(IValidator), false); foreach (IValidator valid in validators) ! MagicAjaxContext.Current.StoredPageInfo.Page.Validators.Add(valid); } } ! MagicAjaxContext.Current.StoredPageInfo.AjaxCallsCount++; ! MagicAjaxContext.Current.StoredPageInfo.LastAccess = DateTime.Now; AjaxCallHelper.Init(); --- 548,570 ---- { // AjaxCall ! _filter = new PageFilter(_response.Filter); ! _response.Filter = _filter; ! if (_magicAjaxContext.StoredPageInfo.AjaxCallsCount == 0) { // For bypassing the VerifyRenderingInServerForm check ! Util.SetPrivateField(_magicAjaxContext.StoredPageInfo.Page, typeof(Page), "_inOnFormRender", true); ! if (_magicAjaxContext.StoredPageInfo.Page.Validators.Count == 0) { // Restore the validators ! ArrayList validators = Util.GetChildControlsOfType(_magicAjaxContext.StoredPageInfo.Page, typeof(IValidator), false); foreach (IValidator valid in validators) ! _magicAjaxContext.StoredPageInfo.Page.Validators.Add(valid); } } ! _magicAjaxContext.StoredPageInfo.AjaxCallsCount++; ! _magicAjaxContext.StoredPageInfo.LastAccess = DateTime.Now; AjaxCallHelper.Init(); *************** *** 561,566 **** try { ! MagicAjaxContext.Current.ExceptionThrown = true; ! ProcessAjaxCall(MagicAjaxContext.Current.StoredPageInfo.Page); } catch (System.Threading.ThreadAbortException) --- 572,577 ---- try { ! _exceptionThrown = true; ! ProcessAjaxCall(_magicAjaxContext.StoredPageInfo.Page); } catch (System.Threading.ThreadAbortException) *************** *** 568,572 **** // ThreadAbortException is for Server.Transfer, Response.Redirect // and AjaxCallHelper.End ! MagicAjaxContext.Current.ExceptionThrown = false; throw; } --- 579,583 ---- // ThreadAbortException is for Server.Transfer, Response.Redirect // and AjaxCallHelper.End ! _exceptionThrown = false; throw; } *************** *** 589,612 **** protected void Application_EndRequest(object sender, EventArgs e) { ! if (!MagicAjaxContext.Current.IsAjaxCall || MagicAjaxContext.Current.CompletedAjaxCall || MagicAjaxContext.Current.ExceptionThrown) ! return; ! ! // There was a Response.Redirect or Server.Transfer during AjaxCall ! ! if (HttpContext.Current.Response.RedirectLocation != null) ! { ! // Handle Response.Redirect ! AjaxCallHelper.Redirect (HttpContext.Current.Response.RedirectLocation); ! } ! else { ! // Handle Server.Transfer ! AjaxCallHelper.Init(); ! if (_filter != null) { ! string html = _filter.GetHtmlPage(); ! AjaxCallHelper.WriteSetHtmlOfPageScript(html); } ! AjaxCallHelper.End(); } } --- 600,634 ---- protected void Application_EndRequest(object sender, EventArgs e) { ! try { ! if (_magicAjaxContext.IsAjaxCall && !_magicAjaxContext.CompletedAjaxCall && !_exceptionThrown) { ! // There was a Response.Redirect or Server.Transfer during AjaxCall ! ! if (_response.RedirectLocation != null) ! { ! // Handle Response.Redirect ! AjaxCallHelper.Redirect (_response.RedirectLocation); ! } ! else ! { ! // Handle Server.Transfer ! AjaxCallHelper.Init(); ! if (_filter != null) ! { ! string html = _filter.GetHtmlPage(); ! AjaxCallHelper.WriteSetHtmlOfPageScript(html); ! } ! AjaxCallHelper.End(); ! } } ! } ! finally ! { ! // Clear private fields ! _request = null; ! _response = null; ! _magicAjaxContext = null; ! _filter = null; } } *************** *** 632,639 **** RaiseAjaxCallEvent (page); ! if (MagicAjaxContext.Current.AjaxCallType == AjaxCallType.Control) { ! string target = HttpContext.Current.Request.Form["__EVENTTARGET"]; ! string argument = HttpContext.Current.Request.Form["__EVENTARGUMENT"]; RaisePostBackEventInChild (page, target, argument); } --- 654,661 ---- RaiseAjaxCallEvent (page); ! if (_magicAjaxContext.AjaxCallType == AjaxCallType.Control) { ! string target = _request.Form["__EVENTTARGET"]; ! string argument = _request.Form["__EVENTARGUMENT"]; RaisePostBackEventInChild (page, target, argument); } *************** *** 764,770 **** // an AjaxCall occurs. So, do a manual check. RadioButtonList rbList = (RadioButtonList) con; ! if (HttpContext.Current.Request.Form[rbList.UniqueID] != rbList.SelectedValue) { ! if (handler.LoadPostData(con.UniqueID, HttpContext.Current.Request.Form)) list.Add (con); } --- 786,792 ---- // an AjaxCall occurs. So, do a manual check. RadioButtonList rbList = (RadioButtonList) con; ! if (_request.Form[rbList.UniqueID] != rbList.SelectedValue) { ! if (handler.LoadPostData(con.UniqueID, _request.Form)) list.Add (con); } *************** *** 777,781 **** { bool oldSelected = cbList.Items[listItem].Selected; ! handler.LoadPostData(String.Format("{0}:{1}", con.UniqueID, listItem), HttpContext.Current.Request.Form); if (oldSelected != cbList.Items[listItem].Selected) changed = true; --- 799,803 ---- { bool oldSelected = cbList.Items[listItem].Selected; ! handler.LoadPostData(String.Format("{0}:{1}", con.UniqueID, listItem), _request.Form); if (oldSelected != cbList.Items[listItem].Selected) changed = true; *************** *** 787,791 **** else { ! if (handler.LoadPostData(con.UniqueID, HttpContext.Current.Request.Form)) { list.Add (con); --- 809,813 ---- else { ! if (handler.LoadPostData(con.UniqueID, _request.Form)) { list.Add (con); |