From: Dion O. <dol...@us...> - 2005-11-20 20:04:33
|
Update of /cvsroot/magicajax/magicajax/Core/UI/Controls In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24881/magicajax/Core/UI/Controls Modified Files: AjaxPanel.cs Log Message: Fingerprints are now configurable (default HashCode, MD5 or FullHtml). Now used for all modes (so not only NoStore). Index: AjaxPanel.cs =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/UI/Controls/AjaxPanel.cs,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** AjaxPanel.cs 20 Nov 2005 13:46:28 -0000 1.18 --- AjaxPanel.cs 20 Nov 2005 20:04:24 -0000 1.19 *************** *** 28,31 **** --- 28,32 ---- using System.Web.UI.HtmlControls; using System.Globalization; + using System.Text; namespace MagicAjax.UI.Controls *************** *** 82,87 **** private ArrayList _addedControls = new ArrayList(); private ArrayList _removedControls = new ArrayList(); ! private Hashtable _controlHtmls = new Hashtable(); ! private Hashtable _controlHtmlHashes = new Hashtable(); private ControlCollectionState _controlState; --- 83,87 ---- private ArrayList _addedControls = new ArrayList(); private ArrayList _removedControls = new ArrayList(); ! private Hashtable _controlHtmlFingerprints = new Hashtable(); private ControlCollectionState _controlState; *************** *** 183,190 **** ExtendedRenderControl (control, litewriter); ! if (IsPageNoStoreMode) ! _controlHtmlHashes[control] = Util.GetBase64MD5Sum(sb.ToString()); ! else ! _controlHtmls[control] = sb.ToString(); sb.Length = 0; --- 183,187 ---- ExtendedRenderControl (control, litewriter); ! _controlHtmlFingerprints[control] = Util.GetFingerprint(sb.ToString()); sb.Length = 0; *************** *** 203,208 **** _addedControls.Clear(); _removedControls.Clear(); ! _controlHtmls.Clear(); ! _controlHtmlHashes.Clear(); } #endregion --- 200,204 ---- _addedControls.Clear(); _removedControls.Clear(); ! _controlHtmlFingerprints.Clear(); } #endregion *************** *** 326,333 **** writer.Write (sbFull.ToString()); ! if (IsPageNoStoreMode) ! _controlHtmlHashes[con] = Util.GetBase64MD5Sum(sb.ToString()); ! else ! _controlHtmls[con] = sb.ToString(); sbFull.Length = 0; --- 322,326 ---- writer.Write (sbFull.ToString()); ! _controlHtmlFingerprints[con] = Util.GetFingerprint(sb.ToString()); sbFull.Length = 0; *************** *** 348,352 **** { //note:only for NoStore mode ! _controlState.SetControlIDs(_controlHtmlHashes); _controlState.Save (this.ClientID, this.Page); } --- 341,345 ---- { //note:only for NoStore mode ! _controlState.SetControlIDs(_controlHtmlFingerprints); _controlState.Save (this.ClientID, this.Page); } *************** *** 363,373 **** // Find new and previous controls _addedControls.Clear(); ! _controlHtmlHashes.Clear(); foreach (Control con in this.Controls) { ! if ( _controlState.ControlIDHtmls.ContainsKey(con.ClientID) ) { ! _controlHtmlHashes[con] = _controlState.ControlIDHtmls[con.ClientID]; } else --- 356,366 ---- // Find new and previous controls _addedControls.Clear(); ! _controlHtmlFingerprints.Clear(); foreach (Control con in this.Controls) { ! if (_controlState.ControlHtmlFingerprints.ContainsKey(con.ClientID)) { ! _controlHtmlFingerprints[con] = _controlState.ControlHtmlFingerprints[con.ClientID]; } else *************** *** 379,383 **** // Find removed controls _removedControls.Clear(); ! foreach (string clientID in _controlState.ControlIDHtmls.Keys) { int i; --- 372,376 ---- // Find removed controls _removedControls.Clear(); ! foreach (string clientID in _controlState.ControlHtmlFingerprints.Keys) { int i; *************** *** 444,453 **** fullwriter.WriteEndTag ("span"); ! ! if (IsPageNoStoreMode) ! _controlHtmlHashes[con] = Util.GetBase64MD5Sum(sb.ToString()); ! else ! _controlHtmls[con] = sb.ToString(); ! sb.Length = 0; } --- 437,441 ---- fullwriter.WriteEndTag ("span"); ! _controlHtmlFingerprints[con] = Util.GetFingerprint(sb.ToString()); sb.Length = 0; } *************** *** 463,471 **** foreach (Control con in _removedControls) { ! if (IsPageNoStoreMode) ! _controlHtmlHashes.Remove(con); ! else ! _controlHtmls.Remove(con); ! AjaxCallHelper.WriteRemoveElementScript (ClientID, GetAjaxElemID(ClientID + "_" + con.ClientID)); } --- 451,455 ---- foreach (Control con in _removedControls) { ! _controlHtmlFingerprints.Remove(con); AjaxCallHelper.WriteRemoveElementScript (ClientID, GetAjaxElemID(ClientID + "_" + con.ClientID)); } *************** *** 486,493 **** AjaxCallHelper.WriteAddElementScript (ClientID, "span", GetAjaxElemID(con), html, GetNextExistingElement(i)); ! if (IsPageNoStoreMode) ! _controlHtmlHashes[con] = Util.GetBase64MD5Sum(sb.ToString()); ! else ! _controlHtmls[con] = sb.ToString(); } else --- 470,474 ---- AjaxCallHelper.WriteAddElementScript (ClientID, "span", GetAjaxElemID(con), html, GetNextExistingElement(i)); ! _controlHtmlFingerprints[con] = Util.GetFingerprint(sb.ToString()); } else *************** *** 505,528 **** html = sb.ToString(); ! if (IsPageNoStoreMode) ! { ! string htmlHashCode = Util.GetBase64MD5Sum(html); ! ! // If it's html rendering sha1 hash is the same, ignore it. ! if (htmlHashCode != (string)_controlHtmlHashes[con]) ! { ! ExtendedWriteSetHtmlOfElementScript(html, GetAjaxElemID(con)); ! _controlHtmlHashes[con] = htmlHashCode; ! } ! } ! else { ! // If it's html rendering is the same, ignore it. ! if (html != (string)_controlHtmls[con]) ! { ! ExtendedWriteSetHtmlOfElementScript(html, GetAjaxElemID(con)); ! _controlHtmls[con] = html; ! } } --- 486,496 ---- html = sb.ToString(); + string htmlFingerprint = Util.GetFingerprint(html); ! // If it's html rendering fingerprint is the same, ignore it. ! if (htmlFingerprint != (string)_controlHtmlFingerprints[con]) { ! ExtendedWriteSetHtmlOfElementScript(html, GetAjaxElemID(con)); ! _controlHtmlFingerprints[con] = htmlFingerprint; } *************** *** 770,774 **** Control con = Controls[i]; ! if (!_addedControls.Contains(con) && ((IsPageNoStoreMode && _controlHtmlHashes[con] != null) || (!IsPageNoStoreMode && _controlHtmls[con] != null))) return GetAjaxElemID(con); } --- 738,742 ---- Control con = Controls[i]; ! if (!_addedControls.Contains(con) && _controlHtmlFingerprints[con] != null) return GetAjaxElemID(con); } *************** *** 824,828 **** private class ControlCollectionState { ! private SortedList _controlIDHtmlHashes; private Control _owner; --- 792,796 ---- private class ControlCollectionState { ! private SortedList _controlHtmlFingerprints; private Control _owner; *************** *** 833,847 **** { _owner = owner; ! _controlIDHtmlHashes = new SortedList(); } /// <summary> ! /// Constructs a new ControlCollectionState with a list of controlIDHtmlHashes /// </summary> ! /// <param name="controlIDHtmlHashes"></param> ! public ControlCollectionState(SortedList controlIDHtmlHashes, Control owner) { _owner = owner; ! _controlIDHtmlHashes = controlIDHtmlHashes; } --- 801,815 ---- { _owner = owner; ! _controlHtmlFingerprints = new SortedList(); } /// <summary> ! /// Constructs a new ControlCollectionState with a list of controlHtmlFingerprints /// </summary> ! /// <param name="controlHtmlFingerprints"></param> ! public ControlCollectionState(SortedList controlHtmlFingerprints, Control owner) { _owner = owner; ! _controlHtmlFingerprints = controlHtmlFingerprints; } *************** *** 854,873 **** { string panelKey = GetControlFingerprintsField(panelClientID); ! string panelControlStates = HttpContext.Current.Request.Form[panelKey]; ! if (panelControlStates != null) { ! SortedList controlIDHtmlHashes = new SortedList(); ! if (panelControlStates != String.Empty) { ! string[] namevaluepairs = panelControlStates.Split(';'); for (int i = 0; i < namevaluepairs.Length; i++) { string namevaluepair = namevaluepairs[i]; string[] namevalue = namevaluepair.Split('#'); ! controlIDHtmlHashes.Add(string.Format("{0}_{1}", panelClientID, namevalue[0]), namevalue[1]); } } ! return new ControlCollectionState(controlIDHtmlHashes, owner); } else --- 822,849 ---- { string panelKey = GetControlFingerprintsField(panelClientID); ! string panelControlFingerprints = HttpContext.Current.Request.Form[panelKey]; ! if (panelControlFingerprints != null) { ! SortedList controlHtmlFingerprints = new SortedList(); ! if (panelControlFingerprints != String.Empty) { ! string[] namevaluepairs = panelControlFingerprints.Split(';'); for (int i = 0; i < namevaluepairs.Length; i++) { string namevaluepair = namevaluepairs[i]; string[] namevalue = namevaluepair.Split('#'); ! ! if (MagicAjaxModule.Instance.Configuration.PageStore.CompareMode == MagicAjax.Configuration.OutputCompareMode.FullHtml) ! { ! controlHtmlFingerprints.Add(string.Format("{0}_{1}", panelClientID, namevalue[0]), UnicodeEncoding.Default.GetString(Convert.FromBase64String(namevalue[1]))); ! } ! else ! { ! controlHtmlFingerprints.Add(string.Format("{0}_{1}", panelClientID, namevalue[0]), namevalue[1]); ! } } } ! return new ControlCollectionState(controlHtmlFingerprints, owner); } else *************** *** 887,905 **** } ! public System.Collections.SortedList ControlIDHtmls { ! get { return _controlIDHtmlHashes; } } ! public void SetControlIDs (Hashtable controlHtmlHashes) { ! _controlIDHtmlHashes.Clear(); ! foreach (Control con in controlHtmlHashes.Keys) ! _controlIDHtmlHashes.Add(con.ClientID, (string)controlHtmlHashes[con]); } /// <summary> ! /// Saves the ControlState hashes. ! /// When in AjaxCall mode, creates SetFieldScript to set hidden field when last ControlState hashes were changed. /// </summary> /// <param name="panelClientID"></param> --- 863,881 ---- } ! public System.Collections.SortedList ControlHtmlFingerprints { ! get { return _controlHtmlFingerprints; } } ! public void SetControlIDs(Hashtable controlHtmlFingerprints) { ! _controlHtmlFingerprints.Clear(); ! foreach (Control con in controlHtmlFingerprints.Keys) ! _controlHtmlFingerprints.Add(con.ClientID, (string)controlHtmlFingerprints[con]); } /// <summary> ! /// Saves the ControlState fingerprints. ! /// When in AjaxCall mode, creates SetFieldScript to set hidden field when last Control fingerprints were changed. /// </summary> /// <param name="panelClientID"></param> *************** *** 909,915 **** System.Text.StringBuilder sbuilder = new System.Text.StringBuilder(); ! foreach (string key in _controlIDHtmlHashes.Keys) { ! if (_controlIDHtmlHashes.IndexOfKey(key) > 0) { sbuilder.Append(';'); --- 885,891 ---- System.Text.StringBuilder sbuilder = new System.Text.StringBuilder(); ! foreach (string key in _controlHtmlFingerprints.Keys) { ! if (_controlHtmlFingerprints.IndexOfKey(key) > 0) { sbuilder.Append(';'); *************** *** 918,933 **** string keyWithoutNamingcontainer = key.Substring(panelClientID.Length + 1); ! sbuilder.AppendFormat("{0}#{1}", keyWithoutNamingcontainer, _controlIDHtmlHashes[key]); } ! string serializedPanelStateHashes = sbuilder.ToString(); string panelKey = GetControlFingerprintsField(panelClientID); if ( AjaxCallHelper.IsAjaxCallForPage(_owner.Page) ) { ! //if ajax callback, generate javascript to set panelstate's hidden field value ! if (HttpContext.Current.Request.Form[panelKey] != serializedPanelStateHashes) { ! AjaxCallHelper.WriteSetFieldScript(panelKey, serializedPanelStateHashes); } } --- 894,916 ---- string keyWithoutNamingcontainer = key.Substring(panelClientID.Length + 1); ! if (MagicAjaxModule.Instance.Configuration.PageStore.CompareMode == MagicAjax.Configuration.OutputCompareMode.FullHtml) ! { ! sbuilder.AppendFormat("{0}#{1}", keyWithoutNamingcontainer, Convert.ToBase64String(UnicodeEncoding.Default.GetBytes((string)_controlHtmlFingerprints[key]))); ! } ! else ! { ! sbuilder.AppendFormat("{0}#{1}", keyWithoutNamingcontainer, _controlHtmlFingerprints[key]); ! } } ! string serializedPanelFingerprints = sbuilder.ToString(); string panelKey = GetControlFingerprintsField(panelClientID); if ( AjaxCallHelper.IsAjaxCallForPage(_owner.Page) ) { ! //if ajax callback, generate javascript to set panelfingerprints's hidden field value ! if (HttpContext.Current.Request.Form[panelKey] != serializedPanelFingerprints) { ! AjaxCallHelper.WriteSetFieldScript(panelKey, serializedPanelFingerprints); } } *************** *** 936,940 **** // The hidden field is already registered at OnLoad event. // Set its value by javascript. ! page.RegisterStartupScript(panelKey + "VALUESET", String.Format("<script type='text/javascript'>AJAXCbo.SetFieldIfEmptyScript(\"{0}\",{1});</script>", panelKey, AjaxCallHelper.EncodeString(serializedPanelStateHashes))); } --- 919,923 ---- // The hidden field is already registered at OnLoad event. // Set its value by javascript. ! page.RegisterStartupScript(panelKey + "VALUESET", String.Format("<script type='text/javascript'>AJAXCbo.SetFieldIfEmptyScript(\"{0}\",{1});</script>", panelKey, AjaxCallHelper.EncodeString(serializedPanelFingerprints))); } |