public override void ExtractWebPartPersonalization(WebPart webPart) { base.ValidateWebPart(webPart); ProxyWebPart part = webPart as ProxyWebPart; if (part != null) { this.RoundTripWebPartPersonalization(part.OriginalID, part.GenericWebPartID); } else { System.Web.UI.WebControls.WebParts.PersonalizationScope personalizationScope = this.PersonalizationScope; if ((personalizationScope == System.Web.UI.WebControls.WebParts.PersonalizationScope.User) && !webPart.IsShared) { personalizationScope = System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared; } bool isStatic = webPart.IsStatic; string personalizationID = this.CreatePersonalizationID(webPart, null); this.ExtractPersonalization(webPart, personalizationID, false, personalizationScope, isStatic, null); GenericWebPart associatedGenericWebPart = webPart as GenericWebPart; if (associatedGenericWebPart != null) { Control childControl = associatedGenericWebPart.ChildControl; personalizationID = this.CreatePersonalizationID(childControl, associatedGenericWebPart); this.ExtractPersonalization(childControl, personalizationID, false, personalizationScope, isStatic, associatedGenericWebPart); } } }
public WebPart this[string id] { get { foreach (WebPart part in base.InnerList) { if (string.Equals(part.ID, id, StringComparison.OrdinalIgnoreCase)) { return(part); } GenericWebPart part2 = part as GenericWebPart; if (part2 != null) { Control childControl = part2.ChildControl; if ((childControl != null) && string.Equals(childControl.ID, id, StringComparison.OrdinalIgnoreCase)) { return(part2); } } ProxyWebPart part3 = part as ProxyWebPart; if ((part3 != null) && (string.Equals(part3.OriginalID, id, StringComparison.OrdinalIgnoreCase) || string.Equals(part3.GenericWebPartID, id, StringComparison.OrdinalIgnoreCase))) { return(part3); } } return(null); } }
protected ProxyWebPart(WebPart webPart) { if (webPart == null) { throw new ArgumentNullException("webPart"); } GenericWebPart genericWebPart = webPart as GenericWebPart; if (genericWebPart != null) { Control childControl = genericWebPart.ChildControl; if (childControl == null) { throw new ArgumentException(SR.GetString(SR.PropertyCannotBeNull, "ChildControl"), "webPart"); } _originalID = childControl.ID; if (String.IsNullOrEmpty(_originalID)) { throw new ArgumentException(SR.GetString(SR.PropertyCannotBeNullOrEmptyString, "ChildControl.ID"), "webPart"); } Type originalType; UserControl childUserControl = childControl as UserControl; if (childUserControl != null) { originalType = typeof(UserControl); _originalPath = childUserControl.AppRelativeVirtualPath; } else { originalType = childControl.GetType(); } _originalTypeName = WebPartUtil.SerializeType(originalType); _genericWebPartID = genericWebPart.ID; if (String.IsNullOrEmpty(_genericWebPartID)) { throw new ArgumentException(SR.GetString(SR.PropertyCannotBeNullOrEmptyString, "ID"), "webPart"); } ID = _genericWebPartID; } else { _originalID = webPart.ID; if (String.IsNullOrEmpty(_originalID)) { throw new ArgumentException(SR.GetString(SR.PropertyCannotBeNullOrEmptyString, "ID"), "webPart"); } _originalTypeName = WebPartUtil.SerializeType(webPart.GetType()); ID = _originalID; } }
protected ProxyWebPart(WebPart webPart) { if (webPart == null) { throw new ArgumentNullException("webPart"); } GenericWebPart part = webPart as GenericWebPart; if (part != null) { Type type; Control childControl = part.ChildControl; if (childControl == null) { throw new ArgumentException(System.Web.SR.GetString("PropertyCannotBeNull", new object[] { "ChildControl" }), "webPart"); } this._originalID = childControl.ID; if (string.IsNullOrEmpty(this._originalID)) { throw new ArgumentException(System.Web.SR.GetString("PropertyCannotBeNullOrEmptyString", new object[] { "ChildControl.ID" }), "webPart"); } UserControl control2 = childControl as UserControl; if (control2 != null) { type = typeof(UserControl); this._originalPath = control2.AppRelativeVirtualPath; } else { type = childControl.GetType(); } this._originalTypeName = WebPartUtil.SerializeType(type); this._genericWebPartID = part.ID; if (string.IsNullOrEmpty(this._genericWebPartID)) { throw new ArgumentException(System.Web.SR.GetString("PropertyCannotBeNullOrEmptyString", new object[] { "ID" }), "webPart"); } this.ID = this._genericWebPartID; } else { this._originalID = webPart.ID; if (string.IsNullOrEmpty(this._originalID)) { throw new ArgumentException(System.Web.SR.GetString("PropertyCannotBeNullOrEmptyString", new object[] { "ID" }), "webPart"); } this._originalTypeName = WebPartUtil.SerializeType(webPart.GetType()); this.ID = this._originalID; } }
// Extracts the personalization state from webPartA, and applies it to webPartB. // Assumes that webPartA and webPartB are the same type. If the WebParts are GenericWebParts, // then copies the personalization state from the ChildControl of webPartA to the // ChildControl of webPartB. protected internal virtual void CopyPersonalizationState(WebPart webPartA, WebPart webPartB) { if (webPartA == null) { throw new ArgumentNullException("webPartA"); } if (webPartB == null) { throw new ArgumentNullException("webPartB"); } if (webPartA.GetType() != webPartB.GetType()) { throw new ArgumentException(SR.GetString(SR.WebPartPersonalization_SameType, "webPartA", "webPartB")); } CopyPersonalizationState((Control)webPartA, (Control)webPartB); GenericWebPart genericWebPartA = webPartA as GenericWebPart; GenericWebPart genericWebPartB = webPartB as GenericWebPart; // Assert that the GenericWebParts are either both null or both non-null Debug.Assert((genericWebPartA == null) == (genericWebPartB == null)); if (genericWebPartA != null && genericWebPartB != null) { Control childControlA = genericWebPartA.ChildControl; Control childControlB = genericWebPartB.ChildControl; if (childControlA == null) { throw new ArgumentException(SR.GetString(SR.PropertyCannotBeNull, "ChildControl"), "webPartA"); } if (childControlB == null) { throw new ArgumentException(SR.GetString(SR.PropertyCannotBeNull, "ChildControl"), "webPartB"); } if (childControlA.GetType() != childControlB.GetType()) { throw new ArgumentException(SR.GetString(SR.WebPartPersonalization_SameType, "webPartA.ChildControl", "webPartB.ChildControl")); } CopyPersonalizationState(childControlA, childControlB); } // IPersonalizable.IsDirty should always be false on the new WebPart, since the only data // on the new WebPart was loaded via personalization, which should not cause the control // to be dirty. However, we want to save the IPersonalizable data on this request, so // we call SetDirty() to force the IPersonalizable data to be saved. SetDirty(webPartB); }
public override void SetWebPartDirty(WebPart webPart) { base.ValidateWebPart(webPart); string personalizationID = this.CreatePersonalizationID(webPart, null); this.SetControlDirty(webPart, personalizationID, false, false); GenericWebPart associatedGenericWebPart = webPart as GenericWebPart; if (associatedGenericWebPart != null) { Control childControl = associatedGenericWebPart.ChildControl; personalizationID = this.CreatePersonalizationID(childControl, associatedGenericWebPart); this.SetControlDirty(childControl, personalizationID, false, false); } }
internal Control ToControl() { GenericWebPart part = this as GenericWebPart; if (part == null) { return(this); } Control childControl = part.ChildControl; if (childControl == null) { throw new InvalidOperationException(System.Web.SR.GetString("GenericWebPart_ChildControlIsNull")); } return(childControl); }
public override void ApplyWebPartPersonalization(WebPart webPart) { base.ValidateWebPart(webPart); if (!(webPart is UnauthorizedWebPart)) { string personalizationID = this.CreatePersonalizationID(webPart, null); System.Web.UI.WebControls.WebParts.PersonalizationScope personalizationScope = this.PersonalizationScope; if ((personalizationScope == System.Web.UI.WebControls.WebParts.PersonalizationScope.User) && !webPart.IsShared) { personalizationScope = System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared; } this.ApplyPersonalization(webPart, personalizationID, false, personalizationScope, null); GenericWebPart associatedGenericWebPart = webPart as GenericWebPart; if (associatedGenericWebPart != null) { Control childControl = associatedGenericWebPart.ChildControl; personalizationID = this.CreatePersonalizationID(childControl, associatedGenericWebPart); this.ApplyPersonalization(childControl, personalizationID, false, personalizationScope, associatedGenericWebPart); } } }
// If this is a GenericWebPart, returns the ChildControl. Else, just returns a pointer to itself. // Used when you need the Control to pass to methods on ConnectionPoint. internal Control ToControl() { GenericWebPart genericWebPart = this as GenericWebPart; if (genericWebPart != null) { Control control = genericWebPart.ChildControl; if (control != null) { return(control); } else { throw new InvalidOperationException(SR.GetString(SR.GenericWebPart_ChildControlIsNull)); } } else { return(this); } }
protected internal virtual void CopyPersonalizationState(WebPart webPartA, WebPart webPartB) { if (webPartA == null) { throw new ArgumentNullException("webPartA"); } if (webPartB == null) { throw new ArgumentNullException("webPartB"); } if (webPartA.GetType() != webPartB.GetType()) { throw new ArgumentException(System.Web.SR.GetString("WebPartPersonalization_SameType", new object[] { "webPartA", "webPartB" })); } this.CopyPersonalizationState((Control)webPartA, (Control)webPartB); GenericWebPart part = webPartA as GenericWebPart; GenericWebPart part2 = webPartB as GenericWebPart; if ((part != null) && (part2 != null)) { Control childControl = part.ChildControl; Control controlB = part2.ChildControl; if (childControl == null) { throw new ArgumentException(System.Web.SR.GetString("PropertyCannotBeNull", new object[] { "ChildControl" }), "webPartA"); } if (controlB == null) { throw new ArgumentException(System.Web.SR.GetString("PropertyCannotBeNull", new object[] { "ChildControl" }), "webPartB"); } if (childControl.GetType() != controlB.GetType()) { throw new ArgumentException(System.Web.SR.GetString("WebPartPersonalization_SameType", new object[] { "webPartA.ChildControl", "webPartB.ChildControl" })); } this.CopyPersonalizationState(childControl, controlB); } this.SetDirty(webPartB); }
/// <devdoc> /// Returns the WebPart with the specified id, or the GenericWebPart containing a control with /// the specified id, or the ProxyWebPart with OriginalID or GenericWebPartID equal to the /// specified id, performing a case-insensitive comparison. Returns null if there are no matches. /// </devdoc> public WebPart this[string id] { // PERF: Use a hashtable for lookup, instead of a linear search get { foreach (WebPart webPart in InnerList) { if (String.Equals(webPart.ID, id, StringComparison.OrdinalIgnoreCase)) { return(webPart); } GenericWebPart genericWebPart = webPart as GenericWebPart; if (genericWebPart != null) { Control control = genericWebPart.ChildControl; if (control != null) { if (String.Equals(control.ID, id, StringComparison.OrdinalIgnoreCase)) { return(genericWebPart); } } } ProxyWebPart proxyWebPart = webPart as ProxyWebPart; if (proxyWebPart != null) { if ((String.Equals(proxyWebPart.OriginalID, id, StringComparison.OrdinalIgnoreCase)) || (String.Equals(proxyWebPart.GenericWebPartID, id, StringComparison.OrdinalIgnoreCase))) { return(proxyWebPart); } } } return(null); } }
// Called by other WebParts classes to create a GenericWebPart, if they do not have // a reference to a WebPartManager (i.e. at design time). This method centralizes // the creation of GenericWebParts. internal static GenericWebPart CreateWebPartStatic(Control control) { GenericWebPart genericWebPart = new GenericWebPart(control); // The ChildControl should be added to the GenericWebPart.Controls collection when CreateWebPart() // is called, instead of waiting until the GenericWebPart.Controls collection is accessed. // This is necessary since the caller has a direct reference to the ChildControl, and may // perform operations on the ChildControl that assume the ChildControl is parented. // (VSWhidbey 498039) genericWebPart.CreateChildControls(); return genericWebPart; }
private void ApplyPersonalization(Control control, string personalizationID, bool isWebPartManager, System.Web.UI.WebControls.WebParts.PersonalizationScope extractScope, GenericWebPart genericWebPart) { if (this._personalizedControls == null) { this._personalizedControls = new HybridDictionary(false); } else if (this._personalizedControls.Contains(personalizationID)) { throw new InvalidOperationException(System.Web.SR.GetString("BlobPersonalizationState_CantApply", new object[] { personalizationID })); } IDictionary personalizablePropertyEntries = PersonalizableAttribute.GetPersonalizablePropertyEntries(control.GetType()); if (this.SharedState == null) { throw new InvalidOperationException(System.Web.SR.GetString("BlobPersonalizationState_NotLoaded")); } PersonalizationInfo sharedInfo = (PersonalizationInfo)this.SharedState[personalizationID]; PersonalizationInfo userInfo = null; IDictionary dictionary2 = null; IDictionary dictionary3 = null; PersonalizationDictionary customInitialProperties = null; ControlInfo info3 = new ControlInfo { _allowSetDirty = false }; this._personalizedControls[personalizationID] = info3; if (((sharedInfo != null) && sharedInfo._isStatic) && !sharedInfo.IsMatchingControlType(control)) { sharedInfo = null; if (this.PersonalizationScope == System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared) { this.SetControlDirty(control, personalizationID, isWebPartManager, true); } } IPersonalizable personalizable = control as IPersonalizable; ITrackingPersonalizable personalizable2 = control as ITrackingPersonalizable; WebPart hasDataWebPart = null; if (!isWebPartManager) { if (genericWebPart != null) { hasDataWebPart = genericWebPart; } else { hasDataWebPart = (WebPart)control; } } try { if (personalizable2 != null) { personalizable2.BeginLoad(); } if (this.PersonalizationScope == System.Web.UI.WebControls.WebParts.PersonalizationScope.User) { if (this.UserState == null) { throw new InvalidOperationException(System.Web.SR.GetString("BlobPersonalizationState_NotLoaded")); } userInfo = (PersonalizationInfo)this.UserState[personalizationID]; if (((userInfo != null) && userInfo._isStatic) && !userInfo.IsMatchingControlType(control)) { userInfo = null; this.SetControlDirty(control, personalizationID, isWebPartManager, true); } if (personalizable != null) { PersonalizationDictionary state = this.MergeCustomProperties(sharedInfo, userInfo, isWebPartManager, hasDataWebPart, ref customInitialProperties); if (state != null) { info3._allowSetDirty = true; personalizable.Load(state); info3._allowSetDirty = false; } } if (!isWebPartManager) { IDictionary dictionary6 = null; IDictionary dictionary7 = null; if (sharedInfo != null) { IDictionary propertyState = sharedInfo._properties; if ((propertyState != null) && (propertyState.Count != 0)) { hasDataWebPart.SetHasSharedData(true); dictionary6 = SetPersonalizedProperties(control, personalizablePropertyEntries, propertyState, System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared); } } dictionary2 = GetPersonalizedProperties(control, personalizablePropertyEntries, null, null, extractScope); if (userInfo != null) { IDictionary dictionary9 = userInfo._properties; if ((dictionary9 != null) && (dictionary9.Count != 0)) { hasDataWebPart.SetHasUserData(true); dictionary7 = SetPersonalizedProperties(control, personalizablePropertyEntries, dictionary9, extractScope); } if ((personalizable2 == null) || !personalizable2.TracksChanges) { dictionary3 = dictionary9; } } if ((dictionary6 != null) || (dictionary7 != null)) { IVersioningPersonalizable personalizable3 = control as IVersioningPersonalizable; if (personalizable3 != null) { IDictionary unknownProperties = null; if (dictionary6 != null) { unknownProperties = dictionary6; if (dictionary7 != null) { foreach (DictionaryEntry entry in dictionary7) { unknownProperties[entry.Key] = entry.Value; } } } else { unknownProperties = dictionary7; } info3._allowSetDirty = true; personalizable3.Load(unknownProperties); info3._allowSetDirty = false; } else { this.SetControlDirty(control, personalizationID, isWebPartManager, true); } } } } else { if (personalizable != null) { PersonalizationDictionary dictionary11 = this.MergeCustomProperties(sharedInfo, userInfo, isWebPartManager, hasDataWebPart, ref customInitialProperties); if (dictionary11 != null) { info3._allowSetDirty = true; personalizable.Load(dictionary11); info3._allowSetDirty = false; } } if (!isWebPartManager) { IDictionary dictionary12 = null; dictionary2 = GetPersonalizedProperties(control, personalizablePropertyEntries, null, null, extractScope); if (sharedInfo != null) { IDictionary dictionary13 = sharedInfo._properties; if ((dictionary13 != null) && (dictionary13.Count != 0)) { hasDataWebPart.SetHasSharedData(true); dictionary12 = SetPersonalizedProperties(control, personalizablePropertyEntries, dictionary13, System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared); } if ((personalizable2 == null) || !personalizable2.TracksChanges) { dictionary3 = dictionary13; } } if (dictionary12 != null) { IVersioningPersonalizable personalizable4 = control as IVersioningPersonalizable; if (personalizable4 != null) { info3._allowSetDirty = true; personalizable4.Load(dictionary12); info3._allowSetDirty = false; } else { this.SetControlDirty(control, personalizationID, isWebPartManager, true); } } } } } finally { info3._allowSetDirty = true; if (personalizable2 != null) { personalizable2.EndLoad(); } } info3._control = control; info3._personalizableProperties = personalizablePropertyEntries; info3._defaultProperties = dictionary2; info3._initialProperties = dictionary3; info3._customInitialProperties = customInitialProperties; }
public GenericWebPartControlCollection(GenericWebPart owner) : base(owner) { SetCollectionReadOnly(SR.GenericWebPart_CannotModify); }
public GenericWebPartControlCollection(GenericWebPart owner) : base(owner) { base.SetCollectionReadOnly("GenericWebPart_CannotModify"); }
/// <devdoc> /// Does the actual work of extracting personalizated data from a control /// </devdoc> private void ExtractPersonalization(Control control, string personalizationID, bool isWebPartManager, PersonalizationScope scope, bool isStatic, GenericWebPart genericWebPart) { Debug.Assert(control != null); Debug.Assert(!String.IsNullOrEmpty(personalizationID)); if (_extractedState == null) { _extractedState = new HybridDictionary(/* caseInsensitive */ false); } if (_personalizedControls == null) { throw new InvalidOperationException(SR.GetString(SR.BlobPersonalizationState_NotApplied)); } ControlInfo ci = (ControlInfo)_personalizedControls[personalizationID]; // The ControlInfo should always have been already created in ApplyPersonalization(). // However, it will be null if the Control's ID has changed since we loaded personalization data. // This is not supported, but we should throw a helpful exception. (VSWhidbey 372354) if (ci == null) { throw new InvalidOperationException(SR.GetString(SR.BlobPersonalizationState_CantExtract, personalizationID)); } ITrackingPersonalizable trackingPersonalizable = control as ITrackingPersonalizable; IPersonalizable customPersonalizable = control as IPersonalizable; IDictionary properties = ci._initialProperties; PersonalizationDictionary customProperties = ci._customInitialProperties; bool changed = false; try { if (trackingPersonalizable != null) { trackingPersonalizable.BeginSave(); } if (!IsPostRequest) { // In non-POST requests, we only save those WebParts that indicated explicitely that // they have changed. For other WebParts, we just round-trip the initial state // that was loaded. if (ci._dirty) { // Always save IPersonalizable data if the WebPart has indicated that it is dirty if (customPersonalizable != null) { PersonalizationDictionary tempCustomProperties = new PersonalizationDictionary(); customPersonalizable.Save(tempCustomProperties); if ((tempCustomProperties.Count != 0) || ((customProperties != null) && (customProperties.Count != 0))) { if (scope == PersonalizationScope.User) { tempCustomProperties.RemoveSharedProperties(); } customProperties = tempCustomProperties; } } if (!isWebPartManager) { // WebPartManager does not have personalizable properties properties = GetPersonalizedProperties(control, ci._personalizableProperties, ci._defaultProperties, ci._initialProperties, scope); } changed = true; } } else { bool extractProperties = true; bool diffWithInitialProperties = true; if (ci._dirty) { // WebPart is indicating that it is dirty, so there is no need // for us to perform a diff diffWithInitialProperties = false; } else if ((trackingPersonalizable != null) && (trackingPersonalizable.TracksChanges) && (ci._dirty == false)) { // WebPart is indicating that it is not dirty, and since it // tracks dirty-ness, theres no need to do additional work. extractProperties = false; } if (extractProperties) { // Always save IPersonalizable data if the WebPart has indicated that it is dirty if (customPersonalizable != null && (ci._dirty || customPersonalizable.IsDirty)) { PersonalizationDictionary tempCustomProperties = new PersonalizationDictionary(); customPersonalizable.Save(tempCustomProperties); // The new custom properties should be used either if they are // non-empty, or they are, but the original ones weren't, since // that implies a change as well. if ((tempCustomProperties.Count != 0) || ((customProperties != null) && (customProperties.Count != 0))) { if (tempCustomProperties.Count != 0) { if (scope == PersonalizationScope.User) { tempCustomProperties.RemoveSharedProperties(); } customProperties = tempCustomProperties; } else { customProperties = null; } // No point doing the diff, since we've already determined that the // custom properties are dirty. diffWithInitialProperties = false; changed = true; } } if (!isWebPartManager) { // WebPartManager does not have personalizable properties IDictionary newProperties = GetPersonalizedProperties(control, ci._personalizableProperties, ci._defaultProperties, ci._initialProperties, scope); if (diffWithInitialProperties) { bool different = CompareProperties(newProperties, ci._initialProperties); if (different == false) { extractProperties = false; } } if (extractProperties) { properties = newProperties; changed = true; } } } } } finally { if (trackingPersonalizable != null) { trackingPersonalizable.EndSave(); } } PersonalizationInfo extractedInfo = new PersonalizationInfo(); extractedInfo._controlID = personalizationID; if (isStatic) { UserControl uc = control as UserControl; if (uc != null) { extractedInfo._controlType = typeof(UserControl); extractedInfo._controlVPath = uc.TemplateControlVirtualPath; } else { extractedInfo._controlType = control.GetType(); } } extractedInfo._isStatic = isStatic; extractedInfo._properties = properties; extractedInfo._customProperties = customProperties; _extractedState[personalizationID] = extractedInfo; if (changed) { SetDirty(); } if ((properties != null && properties.Count > 0) || (customProperties != null && customProperties.Count > 0)) { // The WebPart on which to set HasSharedData and HasUserData WebPart hasDataWebPart = null; if (!isWebPartManager) { if (genericWebPart != null) { hasDataWebPart = genericWebPart; } else { Debug.Assert(control is WebPart); hasDataWebPart = (WebPart)control; } } if (hasDataWebPart != null) { if (PersonalizationScope == PersonalizationScope.Shared) { hasDataWebPart.SetHasSharedData(true); } else { hasDataWebPart.SetHasUserData(true); } } } }
/// <devdoc> /// Does the work of applying personalization data into a control /// </devdoc> private void ApplyPersonalization(Control control, string personalizationID, bool isWebPartManager, PersonalizationScope extractScope, GenericWebPart genericWebPart) { Debug.Assert(control != null); Debug.Assert(!String.IsNullOrEmpty(personalizationID)); if (_personalizedControls == null) { _personalizedControls = new HybridDictionary(/* caseInsensitive */ false); } else { // We shouldn't be applying personalization to the same control more than once if (_personalizedControls.Contains(personalizationID)) { throw new InvalidOperationException(SR.GetString(SR.BlobPersonalizationState_CantApply, personalizationID)); } } IDictionary personalizableProperties = PersonalizableAttribute.GetPersonalizablePropertyEntries(control.GetType()); if (SharedState == null) { throw new InvalidOperationException(SR.GetString(SR.BlobPersonalizationState_NotLoaded)); } PersonalizationInfo sharedInfo = (PersonalizationInfo)SharedState[personalizationID]; PersonalizationInfo userInfo = null; IDictionary defaultProperties = null; IDictionary initialProperties = null; PersonalizationDictionary customInitialProperties = null; // WebPart.SetPersonalizationDirty() should only mark a control as dirty in the following circumstances: // 1. During its IPersonalizable.Load() method // 2. During its IVersioningPersonalizable.Load() method // 3. During or after its ITrackingPersonalizable.EndLoad() method // By exclusion, WebPart.SetPersonalizationDirty() should be a no-op in the following circumstances: // 1. Before its IPersonalizable.Load() method // 2. While we are setting the values of its [Personalizable] properties // (VSWhidbey 392533) ControlInfo ci = new ControlInfo(); ci._allowSetDirty = false; _personalizedControls[personalizationID] = ci; if (sharedInfo != null && sharedInfo._isStatic && !sharedInfo.IsMatchingControlType(control)) { // Mismatch in saved data, so ignore it sharedInfo = null; if (PersonalizationScope == PersonalizationScope.Shared) { SetControlDirty(control, personalizationID, isWebPartManager, true); } } IPersonalizable customPersonalizable = control as IPersonalizable; ITrackingPersonalizable trackingPersonalizable = control as ITrackingPersonalizable; // The WebPart on which to set HasSharedData and HasUserData WebPart hasDataWebPart = null; if (!isWebPartManager) { if (genericWebPart != null) { hasDataWebPart = genericWebPart; } else { Debug.Assert(control is WebPart); hasDataWebPart = (WebPart)control; } } try { if (trackingPersonalizable != null) { trackingPersonalizable.BeginLoad(); } if (PersonalizationScope == PersonalizationScope.User) { if (UserState == null) { throw new InvalidOperationException(SR.GetString(SR.BlobPersonalizationState_NotLoaded)); } userInfo = (PersonalizationInfo)UserState[personalizationID]; if (userInfo != null && userInfo._isStatic && !userInfo.IsMatchingControlType(control)) { // Mismatch in saved data, so ignore it userInfo = null; SetControlDirty(control, personalizationID, isWebPartManager, true); } if (customPersonalizable != null) { PersonalizationDictionary customProperties = MergeCustomProperties( sharedInfo, userInfo, isWebPartManager, hasDataWebPart, ref customInitialProperties); if (customProperties != null) { ci._allowSetDirty = true; customPersonalizable.Load(customProperties); ci._allowSetDirty = false; } } if (!isWebPartManager) { // Properties do not apply to the WebPartManager IDictionary unusedSharedProperties = null; IDictionary unusedUserProperties = null; // To compute default properties in user scope, we must first // apply the shared properties. Only differences detected from // shared scope are to be persisted. if (sharedInfo != null) { IDictionary properties = sharedInfo._properties; if ((properties != null) && (properties.Count != 0)) { hasDataWebPart.SetHasSharedData(true); unusedSharedProperties = SetPersonalizedProperties(control, personalizableProperties, properties, PersonalizationScope.Shared); } } defaultProperties = GetPersonalizedProperties(control, personalizableProperties, null, null, extractScope); // Now apply the user properties and hang on to the initial values if (userInfo != null) { IDictionary properties = userInfo._properties; if ((properties != null) && (properties.Count != 0)) { hasDataWebPart.SetHasUserData(true); // We pass the extractScope as the PersonalizationScope in which to set the properties. For // a shared WebPart, we want to only apply the user values to user properties, and not to // shared properties. However, for an unshared WebPart, we want to apply the user values // to both user and shared properties, since there is effectively no difference for an // unshared WebPart. (VSWhidbey 349356) unusedUserProperties = SetPersonalizedProperties(control, personalizableProperties, properties, extractScope); } if ((trackingPersonalizable == null) || (trackingPersonalizable.TracksChanges == false)) { initialProperties = properties; } } bool hasUnusedProperties = ((unusedSharedProperties != null) || (unusedUserProperties != null)); if (hasUnusedProperties) { IVersioningPersonalizable versioningPersonalizable = control as IVersioningPersonalizable; if (versioningPersonalizable != null) { IDictionary unusedProperties = null; // Merge any unused properties, so they can be handed off to the // control via IVersioningPersonalizable if (unusedSharedProperties != null) { unusedProperties = unusedSharedProperties; if (unusedUserProperties != null) { foreach (DictionaryEntry entry in unusedUserProperties) { unusedProperties[entry.Key] = entry.Value; } } } else { unusedProperties = unusedUserProperties; } ci._allowSetDirty = true; versioningPersonalizable.Load(unusedProperties); ci._allowSetDirty = false; } else { // There were some unused properties, and they couldn't be loaded. // Mark this control as dirty, so we clean up its personalization // state later... SetControlDirty(control, personalizationID, isWebPartManager, true); } } } } else { // Shared Personalization Scope if (customPersonalizable != null) { PersonalizationDictionary customProperties = MergeCustomProperties( sharedInfo, userInfo, isWebPartManager, hasDataWebPart, ref customInitialProperties); if (customProperties != null) { ci._allowSetDirty = true; customPersonalizable.Load(customProperties); ci._allowSetDirty = false; } } if (!isWebPartManager) { IDictionary unusedProperties = null; // Compute default properties. These are basically what was persisted // in the markup defaultProperties = GetPersonalizedProperties(control, personalizableProperties, null, null, extractScope); // Now apply shared properties and hang on to the initial values if (sharedInfo != null) { IDictionary properties = sharedInfo._properties; if ((properties != null) && (properties.Count != 0)) { hasDataWebPart.SetHasSharedData(true); unusedProperties = SetPersonalizedProperties(control, personalizableProperties, properties, PersonalizationScope.Shared); } if ((trackingPersonalizable == null) || (trackingPersonalizable.TracksChanges == false)) { initialProperties = properties; } } if (unusedProperties != null) { IVersioningPersonalizable versioningPersonalizable = control as IVersioningPersonalizable; if (versioningPersonalizable != null) { ci._allowSetDirty = true; versioningPersonalizable.Load(unusedProperties); ci._allowSetDirty = false; } else { // There were some unused properties, and they couldn't be loaded. // Mark this control as dirty, so we clean up its personalization // state later... SetControlDirty(control, personalizationID, isWebPartManager, true); } } } } } finally { ci._allowSetDirty = true; if (trackingPersonalizable != null) { trackingPersonalizable.EndLoad(); } } // Track this as one of the personalized controls ci._control = control; ci._personalizableProperties = personalizableProperties; ci._defaultProperties = defaultProperties; ci._initialProperties = initialProperties; ci._customInitialProperties = customInitialProperties; }
private void ExtractPersonalization(Control control, string personalizationID, bool isWebPartManager, System.Web.UI.WebControls.WebParts.PersonalizationScope scope, bool isStatic, GenericWebPart genericWebPart) { if (this._extractedState == null) { this._extractedState = new HybridDictionary(false); } if (this._personalizedControls == null) { throw new InvalidOperationException(System.Web.SR.GetString("BlobPersonalizationState_NotApplied")); } ControlInfo info = (ControlInfo)this._personalizedControls[personalizationID]; if (info == null) { throw new InvalidOperationException(System.Web.SR.GetString("BlobPersonalizationState_CantExtract", new object[] { personalizationID })); } ITrackingPersonalizable personalizable = control as ITrackingPersonalizable; IPersonalizable personalizable2 = control as IPersonalizable; IDictionary dictionary = info._initialProperties; PersonalizationDictionary dictionary2 = info._customInitialProperties; bool flag = false; try { if (personalizable != null) { personalizable.BeginSave(); } if (!this.IsPostRequest) { if (info._dirty) { if (personalizable2 != null) { PersonalizationDictionary state = new PersonalizationDictionary(); personalizable2.Save(state); if ((state.Count != 0) || ((dictionary2 != null) && (dictionary2.Count != 0))) { if (scope == System.Web.UI.WebControls.WebParts.PersonalizationScope.User) { state.RemoveSharedProperties(); } dictionary2 = state; } } if (!isWebPartManager) { dictionary = GetPersonalizedProperties(control, info._personalizableProperties, info._defaultProperties, info._initialProperties, scope); } flag = true; } } else { bool flag2 = true; bool flag3 = true; if (info._dirty) { flag3 = false; } else if (((personalizable != null) && personalizable.TracksChanges) && !info._dirty) { flag2 = false; } if (flag2) { if ((personalizable2 != null) && (info._dirty || personalizable2.IsDirty)) { PersonalizationDictionary dictionary4 = new PersonalizationDictionary(); personalizable2.Save(dictionary4); if ((dictionary4.Count != 0) || ((dictionary2 != null) && (dictionary2.Count != 0))) { if (dictionary4.Count != 0) { if (scope == System.Web.UI.WebControls.WebParts.PersonalizationScope.User) { dictionary4.RemoveSharedProperties(); } dictionary2 = dictionary4; } else { dictionary2 = null; } flag3 = false; flag = true; } } if (!isWebPartManager) { IDictionary newProperties = GetPersonalizedProperties(control, info._personalizableProperties, info._defaultProperties, info._initialProperties, scope); if (flag3 && !this.CompareProperties(newProperties, info._initialProperties)) { flag2 = false; } if (flag2) { dictionary = newProperties; flag = true; } } } } } finally { if (personalizable != null) { personalizable.EndSave(); } } PersonalizationInfo info2 = new PersonalizationInfo { _controlID = personalizationID }; if (isStatic) { UserControl control2 = control as UserControl; if (control2 != null) { info2._controlType = typeof(UserControl); info2._controlVPath = control2.TemplateControlVirtualPath; } else { info2._controlType = control.GetType(); } } info2._isStatic = isStatic; info2._properties = dictionary; info2._customProperties = dictionary2; this._extractedState[personalizationID] = info2; if (flag) { base.SetDirty(); } if (((dictionary != null) && (dictionary.Count > 0)) || ((dictionary2 != null) && (dictionary2.Count > 0))) { WebPart part = null; if (!isWebPartManager) { if (genericWebPart != null) { part = genericWebPart; } else { part = (WebPart)control; } } if (part != null) { if (this.PersonalizationScope == System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared) { part.SetHasSharedData(true); } else { part.SetHasUserData(true); } } } }
internal static GenericWebPart CreateWebPartStatic(Control control) { GenericWebPart part = new GenericWebPart(control); part.CreateChildControls(); return part; }