private static string GetLanguageDisplayMode(int portalId) { string viewTypePersonalizationKey = "LanguageDisplayMode:ViewType" + portalId; PersonalizationController personalizationController = new PersonalizationController(); PersonalizationInfo personalization = personalizationController.LoadProfile(PortalSettings.Current.UserInfo.UserID, portalId); string viewType = Convert.ToString(personalization.Profile[viewTypePersonalizationKey]); return(string.IsNullOrEmpty(viewType) ? "NATIVE" : viewType); }
private PersonalizationDictionary MergeCustomProperties(PersonalizationInfo sharedInfo, PersonalizationInfo userInfo, bool isWebPartManager, WebPart hasDataWebPart, ref PersonalizationDictionary customInitialProperties) { PersonalizationDictionary dictionary = null; bool flag = (sharedInfo != null) && (sharedInfo._customProperties != null); bool flag2 = (userInfo != null) && (userInfo._customProperties != null); if (flag && flag2) { dictionary = new PersonalizationDictionary(); foreach (DictionaryEntry entry in sharedInfo._customProperties) { dictionary[(string)entry.Key] = (PersonalizationEntry)entry.Value; } foreach (DictionaryEntry entry2 in userInfo._customProperties) { dictionary[(string)entry2.Key] = (PersonalizationEntry)entry2.Value; } } else if (flag) { dictionary = sharedInfo._customProperties; } else if (flag2) { dictionary = userInfo._customProperties; } if ((this.PersonalizationScope == System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared) && flag) { customInitialProperties = sharedInfo._customProperties; } else if ((this.PersonalizationScope == System.Web.UI.WebControls.WebParts.PersonalizationScope.User) && flag2) { customInitialProperties = userInfo._customProperties; } if (flag && !isWebPartManager) { hasDataWebPart.SetHasSharedData(true); } if (flag2 && !isWebPartManager) { hasDataWebPart.SetHasUserData(true); } return(dictionary); }
private void ApplyPersonalizationState(Control control, PersonalizationInfo info) { ITrackingPersonalizable personalizable = control as ITrackingPersonalizable; IPersonalizable personalizable2 = control as IPersonalizable; if (personalizable != null) { personalizable.BeginLoad(); } if (((personalizable2 != null) && (info.CustomProperties != null)) && (info.CustomProperties.Count > 0)) { personalizable2.Load(info.CustomProperties); } if ((info.Properties != null) && (info.Properties.Count > 0)) { BlobPersonalizationState.SetPersonalizedProperties(control, info.Properties); } if (personalizable != null) { personalizable.EndLoad(); } }
private void ApplyPersonalizationState(Control control, PersonalizationInfo info) { ITrackingPersonalizable personalizable = control as ITrackingPersonalizable; IPersonalizable personalizable2 = control as IPersonalizable; if (personalizable != null) { personalizable.BeginLoad(); } if (((personalizable2 != null) && (info.CustomProperties != null)) && (info.CustomProperties.Count > 0)) { personalizable2.Load(info.CustomProperties); } if ((info.Properties != null) && (info.Properties.Count > 0)) { BlobPersonalizationState.SetPersonalizedProperties(control, info.Properties); } if (personalizable != null) { personalizable.EndLoad(); } }
private PersonalizationInfo ExtractPersonalizationState(Control control) { ITrackingPersonalizable personalizable = control as ITrackingPersonalizable; IPersonalizable personalizable2 = control as IPersonalizable; if (personalizable != null) { personalizable.BeginSave(); } PersonalizationInfo info = new PersonalizationInfo(); if (personalizable2 != null) { info.CustomProperties = new PersonalizationDictionary(); personalizable2.Save(info.CustomProperties); } info.Properties = BlobPersonalizationState.GetPersonalizedProperties(control, PersonalizationScope.Shared); if (personalizable != null) { personalizable.EndSave(); } return(info); }
/// <summary> /// Handles reset button click. Resets zones of specified type to default settings. /// </summary> protected void btnReset_Click(object sender, EventArgs e) { // Security check if (!DisplayResetButton || !resetAllowed) { return; } PageInfo pi = DocumentContext.CurrentPageInfo; if (pi == null) { return; } // Delete user personalization info PersonalizationInfo up = PersonalizationInfoProvider.GetDashBoardPersonalization(MembershipContext.AuthenticatedUser.UserID, PortalContext.DashboardName, PortalContext.DashboardSiteName); PersonalizationInfoProvider.DeletePersonalizationInfo(up); // Clear cached page template if (pi.UsedPageTemplateInfo != null) { CacheHelper.TouchKey("cms.pagetemplate|byid|" + pi.UsedPageTemplateInfo.PageTemplateId); } // Make redirect to see changes after load string url = RequestContext.CurrentURL; if (ViewMode.IsEdit(true) || ViewMode.IsEditLive()) { // Ensure that the widgets will be loaded from the session layer (not from database) url = URLHelper.UpdateParameterInUrl(url, "cmscontentchanged", "true"); } URLHelper.Redirect(url); }
// Returns a PersonalizationDictionary containing a merged view of the custom properties // in both the sharedInfo and the userInfo. private PersonalizationDictionary MergeCustomProperties(PersonalizationInfo sharedInfo, PersonalizationInfo userInfo, bool isWebPartManager, WebPart hasDataWebPart, ref PersonalizationDictionary customInitialProperties) { PersonalizationDictionary customProperties = null; bool hasSharedCustomProperties = (sharedInfo != null && sharedInfo._customProperties != null); bool hasUserCustomProperties = (userInfo != null && userInfo._customProperties != null); // Fill or set the customProperties dictionary if (hasSharedCustomProperties && hasUserCustomProperties) { customProperties = new PersonalizationDictionary(); foreach (DictionaryEntry entry in sharedInfo._customProperties) { customProperties[(string)entry.Key] = (PersonalizationEntry)entry.Value; } foreach (DictionaryEntry entry in userInfo._customProperties) { customProperties[(string)entry.Key] = (PersonalizationEntry)entry.Value; } } else if (hasSharedCustomProperties) { customProperties = sharedInfo._customProperties; } else if (hasUserCustomProperties) { customProperties = userInfo._customProperties; } // Set the customInitialProperties dictionary if (PersonalizationScope == PersonalizationScope.Shared && hasSharedCustomProperties) { customInitialProperties = sharedInfo._customProperties; } else if (PersonalizationScope == PersonalizationScope.User && hasUserCustomProperties) { customInitialProperties = userInfo._customProperties; } // Set the HasSharedData and HasUserData flags if (hasSharedCustomProperties && !isWebPartManager) { hasDataWebPart.SetHasSharedData(true); } if (hasUserCustomProperties && !isWebPartManager) { hasDataWebPart.SetHasUserData(true); } return customProperties; }
/// <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> /// Deserializes personalization data packed as a blob of binary data /// into a dictionary with personalization IDs mapped to /// PersonalizationInfo objects. /// </devdoc> private static IDictionary DeserializeData(byte[] data) { IDictionary deserializedData = null; if ((data != null) && (data.Length > 0)) { Exception deserializationException = null; int version = -1; object[] items = null; int offset = 0; // Deserialize the data try { ObjectStateFormatter formatter = new ObjectStateFormatter(null /* Page(used to determine encryption mode) */, false /*throwOnErrorDeserializing*/); if (!HttpRuntime.DisableProcessRequestInApplicationTrust) { // This is more of a consistency and defense-in-depth fix. Currently we believe // only user code or code with restricted permissions will be running on the stack. // However, to mirror the fix for Session State, and also to hedge against future // scenarios where our current assumptions may change, we should restrict the running // thread to only the permission set currently defined for the app domain. // VSWhidbey 427533 if (HttpRuntime.NamedPermissionSet != null && HttpRuntime.ProcessRequestInApplicationTrust) { HttpRuntime.NamedPermissionSet.PermitOnly(); } } items = (object[])formatter.DeserializeWithAssert(new MemoryStream(data)); if (items != null && items.Length != 0) { version = (int)items[offset++]; } } catch (Exception e) { deserializationException = e; } if (version == (int)PersonalizationVersions.WhidbeyBeta2 || version == (int)PersonalizationVersions.WhidbeyRTM) { try { // Build up the dictionary of PersonalizationInfo objects int infoListCount = (int)items[offset++]; if (infoListCount > 0) { deserializedData = new HybridDictionary(infoListCount, /* caseInsensitive */ false); } for (int i = 0; i < infoListCount; i++) { string controlID; bool isStatic; Type controlType = null; VirtualPath controlVPath = null; // If this is a dynamic WebPart or control, the Type is not saved in personalization, // so the first item is the controlID. If this is a static WebPart or control, the // first item is the control Type. object item = items[offset++]; if (item is string) { controlID = (string)item; isStatic = false; } else { controlType = (Type)item; if (controlType == typeof(UserControl)) { controlVPath = VirtualPath.CreateNonRelativeAllowNull((string)items[offset++]); } controlID = (string)items[offset++]; isStatic = true; } IDictionary properties = null; int propertyCount = (int)items[offset++]; if (propertyCount > 0) { properties = new HybridDictionary(propertyCount, /* caseInsensitive */ false); for (int j = 0; j < propertyCount; j++) { string propertyName = ((IndexedString)items[offset++]).Value; object propertyValue = items[offset++]; properties[propertyName] = propertyValue; } } PersonalizationDictionary customProperties = null; int customPropertyCount = (int)items[offset++]; if (customPropertyCount > 0) { customProperties = new PersonalizationDictionary(customPropertyCount); for (int j = 0; j < customPropertyCount; j++) { string propertyName = ((IndexedString)items[offset++]).Value; object propertyValue = items[offset++]; PersonalizationScope propertyScope = (bool)items[offset++] ? PersonalizationScope.Shared : PersonalizationScope.User; bool isSensitive = false; if (version == (int)PersonalizationVersions.WhidbeyRTM) { isSensitive = (bool)items[offset++]; } customProperties[propertyName] = new PersonalizationEntry(propertyValue, propertyScope, isSensitive); } } PersonalizationInfo info = new PersonalizationInfo(); info._controlID = controlID; info._controlType = controlType; info._controlVPath = controlVPath; info._isStatic = isStatic; info._properties = properties; info._customProperties = customProperties; deserializedData[controlID] = info; } } catch (Exception e) { deserializationException = e; } } // Check that there was no deserialization error, and that // the data conforms to our known version if ((deserializationException != null) || (version != (int)PersonalizationVersions.WhidbeyBeta2 && version != (int)PersonalizationVersions.WhidbeyRTM)) { throw new ArgumentException(SR.GetString(SR.BlobPersonalizationState_DeserializeError), "data", deserializationException); } } if (deserializedData == null) { deserializedData = new HybridDictionary(/* caseInsensitive */ false); } return deserializedData; }
/// <summary> /// Handles reset button click. Resets zones of specified type to default settings. /// </summary> protected void btnReset_Click(object sender, EventArgs e) { // Disable the reset action when document editing is not allowed (i.e. non-editable workflow step) if (!WidgetActionsEnabled) { resetAllowed = false; } // Security check if (!DisplayResetButton || !resetAllowed) { return; } PageInfo pi = CurrentPageInfo; if (pi == null) { return; } if ((zoneType == WidgetZoneTypeEnum.Editor) || (zoneType == WidgetZoneTypeEnum.Group)) { // Clear document webparts/group webparts TreeNode node = DocumentHelper.GetDocument(pi.DocumentID, TreeProvider); if (node != null) { bool updateDocument = true; if (zoneType == WidgetZoneTypeEnum.Editor) { if (ViewMode.IsEdit(true) || ViewMode.IsEditLive()) { // Do not save the document to the database, keep it in only in the memory updateDocument = false; // Get the default template widgets PortalContext.SaveEditorWidgets(pi.DocumentID, pi.UsedPageTemplateInfo.TemplateInstance.GetZonesXML(WidgetZoneTypeEnum.Editor)); } else { node.SetValue("DocumentWebParts", String.Empty); } ClearEditorWidgetsContent(node, pi.UsedPageTemplateInfo.TemplateInstance, updateDocument); // Delete all variants if (pi.UsedPageTemplateInfo != null) { foreach (WebPartZoneInstance zoneInstance in zoneInstances) { if (zoneInstance.WebPartsContainVariants) { VariantHelper.DeleteWidgetVariants(zoneInstance.ZoneID, pi.UsedPageTemplateInfo.PageTemplateId, node.DocumentID); } } } } else if (zoneType == WidgetZoneTypeEnum.Group) { node.SetValue("DocumentGroupWebParts", String.Empty); } if (updateDocument) { // Save the document DocumentHelper.UpdateDocument(node, TreeProvider); } } } else if (zoneType == WidgetZoneTypeEnum.User) { // Delete user personalization info PersonalizationInfo up = PersonalizationInfoProvider.GetUserPersonalization(MembershipContext.AuthenticatedUser.UserID, pi.DocumentID); PersonalizationInfoProvider.DeletePersonalizationInfo(up); // Clear cached values TreeNode node = DocumentHelper.GetDocument(pi.DocumentID, TreeProvider); if (node != null) { node.ClearCache(); } } else if (zoneType == WidgetZoneTypeEnum.Dashboard) { // Delete user personalization info PersonalizationInfo up = PersonalizationInfoProvider.GetDashBoardPersonalization(MembershipContext.AuthenticatedUser.UserID, PortalContext.DashboardName, PortalContext.DashboardSiteName); PersonalizationInfoProvider.DeletePersonalizationInfo(up); // Clear cached page template if (pi.UsedPageTemplateInfo != null) { CacheHelper.TouchKey("cms.pagetemplate|byid|" + pi.UsedPageTemplateInfo.PageTemplateId); } } // Make redirect to see changes after load string url = RequestContext.CurrentURL; if (ViewMode.IsEdit(true) || ViewMode.IsEditLive()) { // Ensure that the widgets will be loaded from the session layer (not from database) url = URLHelper.UpdateParameterInUrl(url, "cmscontentchanged", "true"); } URLHelper.Redirect(url); }
// Helper method used by CopyPersonalizationState() private void ApplyPersonalizationState(Control control, PersonalizationInfo info) { ITrackingPersonalizable trackingPersonalizable = control as ITrackingPersonalizable; IPersonalizable customPersonalizable = control as IPersonalizable; if (trackingPersonalizable != null) { trackingPersonalizable.BeginLoad(); } // If customPersonalizable is null, then info.CustomProperties should also be null Debug.Assert(!(customPersonalizable == null && info.CustomProperties != null)); if (customPersonalizable != null && info.CustomProperties != null && info.CustomProperties.Count > 0) { customPersonalizable.Load(info.CustomProperties); } if (info.Properties != null && info.Properties.Count > 0) { BlobPersonalizationState.SetPersonalizedProperties(control, info.Properties); } if (trackingPersonalizable != null) { trackingPersonalizable.EndLoad(); } }
/// <summary> /// Handles reset button click. Resets zones of specified type to default settings. /// </summary> protected void btnReset_Click(object sender, EventArgs e) { // Security check if (!DisplayResetButton || !resetAllowed) { return; } if (pi == null) { return; } if ((zoneType == WidgetZoneTypeEnum.Editor) || (zoneType == WidgetZoneTypeEnum.Group)) { // Clear document webparts/group webparts TreeNode node = DocumentHelper.GetDocument(pi.DocumentID, TreeProvider); if (node != null) { if (zoneType == WidgetZoneTypeEnum.Editor) { node.SetValue("DocumentWebParts", String.Empty); // Delete all variants if (pi.UsedPageTemplateInfo != null) { foreach (WebPartZoneInstance zoneInstance in zoneInstances) { if (zoneInstance.WebPartsContainVariants) { ModuleCommands.OnlineMarketingResetMVTWidgetZone(zoneInstance.ZoneID, pi.UsedPageTemplateInfo.PageTemplateId, node.DocumentID); ModuleCommands.OnlineMarketingResetContentPersonalizationWidgetZone(zoneInstance.ZoneID, pi.UsedPageTemplateInfo.PageTemplateId, node.DocumentID); } } } } else if (zoneType == WidgetZoneTypeEnum.Group) { node.SetValue("DocumentGroupWebParts", String.Empty); } // Save the document DocumentHelper.UpdateDocument(node, TreeProvider); } } else if (zoneType == WidgetZoneTypeEnum.User) { // Delete user personalization info PersonalizationInfo up = PersonalizationInfoProvider.GetUserPersonalization(CMSContext.CurrentUser.UserID, pi.DocumentID); PersonalizationInfoProvider.DeletePersonalizationInfo(up); // Clear cached values TreeNode node = DocumentHelper.GetDocument(pi.DocumentID, TreeProvider); if (node != null) { CacheHelper.TouchKeys(TreeProvider.GetDependencyCacheKeys(node, CMSContext.CurrentSiteName)); } } else if (zoneType == WidgetZoneTypeEnum.Dashboard) { // Delete user personalization info PersonalizationInfo up = PersonalizationInfoProvider.GetDashBoardPersonalization(CMSContext.CurrentUser.UserID, PortalContext.DashboardName, PortalContext.DashboardSiteName); PersonalizationInfoProvider.DeletePersonalizationInfo(up); // Clear cached page template if (pi.UsedPageTemplateInfo != null) { CacheHelper.TouchKey("cms.pagetemplate|byid|" + pi.UsedPageTemplateInfo.PageTemplateId); } } // Make redirect to see changes after load string url = URLRewriter.CurrentURL; URLHelper.Redirect(url); }
private static byte[] SerializeData(IDictionary data) { byte[] buffer = null; if ((data == null) || (data.Count == 0)) { return(buffer); } ArrayList list = new ArrayList(); foreach (DictionaryEntry entry in data) { PersonalizationInfo info = (PersonalizationInfo)entry.Value; if (((info._properties != null) && (info._properties.Count != 0)) || ((info._customProperties != null) && (info._customProperties.Count != 0))) { list.Add(info); } } if (list.Count == 0) { return(buffer); } ArrayList list2 = new ArrayList(); list2.Add(2); list2.Add(list.Count); foreach (PersonalizationInfo info2 in list) { if (info2._isStatic) { list2.Add(info2._controlType); if (info2._controlVPath != null) { list2.Add(info2._controlVPath.AppRelativeVirtualPathString); } } list2.Add(info2._controlID); int count = 0; if (info2._properties != null) { count = info2._properties.Count; } list2.Add(count); if (count != 0) { foreach (DictionaryEntry entry2 in info2._properties) { list2.Add(new IndexedString((string)entry2.Key)); list2.Add(entry2.Value); } } int num2 = 0; if (info2._customProperties != null) { num2 = info2._customProperties.Count; } list2.Add(num2); if (num2 != 0) { foreach (DictionaryEntry entry3 in info2._customProperties) { list2.Add(new IndexedString((string)entry3.Key)); PersonalizationEntry entry4 = (PersonalizationEntry)entry3.Value; list2.Add(entry4.Value); list2.Add(entry4.Scope == System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared); list2.Add(entry4.IsSensitive); } } } if (list2.Count == 0) { return(buffer); } ObjectStateFormatter formatter = new ObjectStateFormatter(null, false); MemoryStream outputStream = new MemoryStream(0x400); object[] stateGraph = list2.ToArray(); if ((!HttpRuntime.DisableProcessRequestInApplicationTrust && (HttpRuntime.NamedPermissionSet != null)) && HttpRuntime.ProcessRequestInApplicationTrust) { HttpRuntime.NamedPermissionSet.PermitOnly(); } formatter.SerializeWithAssert(outputStream, stateGraph); return(outputStream.ToArray()); }
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); } } } }
private static IDictionary DeserializeData(byte[] data) { IDictionary dictionary = null; if ((data != null) && (data.Length > 0)) { Exception innerException = null; int num = -1; object[] objArray = null; int num2 = 0; try { ObjectStateFormatter formatter = new ObjectStateFormatter(null, false); if ((!HttpRuntime.DisableProcessRequestInApplicationTrust && (HttpRuntime.NamedPermissionSet != null)) && HttpRuntime.ProcessRequestInApplicationTrust) { HttpRuntime.NamedPermissionSet.PermitOnly(); } objArray = (object[])formatter.DeserializeWithAssert(new MemoryStream(data)); if ((objArray != null) && (objArray.Length != 0)) { num = (int)objArray[num2++]; } } catch (Exception exception2) { innerException = exception2; } switch (num) { case 1: case 2: try { int initialSize = (int)objArray[num2++]; if (initialSize > 0) { dictionary = new HybridDictionary(initialSize, false); } for (int i = 0; i < initialSize; i++) { string str; bool flag; Type type = null; VirtualPath path = null; object obj2 = objArray[num2++]; if (obj2 is string) { str = (string)obj2; flag = false; } else { type = (Type)obj2; if (type == typeof(UserControl)) { path = VirtualPath.CreateNonRelativeAllowNull((string)objArray[num2++]); } str = (string)objArray[num2++]; flag = true; } IDictionary dictionary2 = null; int num5 = (int)objArray[num2++]; if (num5 > 0) { dictionary2 = new HybridDictionary(num5, false); for (int j = 0; j < num5; j++) { string str2 = ((IndexedString)objArray[num2++]).Value; object obj3 = objArray[num2++]; dictionary2[str2] = obj3; } } PersonalizationDictionary dictionary3 = null; int num7 = (int)objArray[num2++]; if (num7 > 0) { dictionary3 = new PersonalizationDictionary(num7); for (int k = 0; k < num7; k++) { string str3 = ((IndexedString)objArray[num2++]).Value; object obj4 = objArray[num2++]; System.Web.UI.WebControls.WebParts.PersonalizationScope scope = ((bool)objArray[num2++]) ? System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared : System.Web.UI.WebControls.WebParts.PersonalizationScope.User; bool isSensitive = false; if (num == 2) { isSensitive = (bool)objArray[num2++]; } dictionary3[str3] = new PersonalizationEntry(obj4, scope, isSensitive); } } PersonalizationInfo info = new PersonalizationInfo { _controlID = str, _controlType = type, _controlVPath = path, _isStatic = flag, _properties = dictionary2, _customProperties = dictionary3 }; dictionary[str] = info; } } catch (Exception exception3) { innerException = exception3; } break; } if ((innerException != null) || ((num != 1) && (num != 2))) { throw new ArgumentException(System.Web.SR.GetString("BlobPersonalizationState_DeserializeError"), "data", innerException); } } if (dictionary == null) { dictionary = new HybridDictionary(false); } return(dictionary); }
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; }
private void CopyPersonalizationState(Control controlA, Control controlB) { PersonalizationInfo info = ExtractPersonalizationState(controlA); ApplyPersonalizationState(controlB, info); }
// Helper method used by CopyPersonalizationState() private PersonalizationInfo ExtractPersonalizationState(Control control) { ITrackingPersonalizable trackingPersonalizable = control as ITrackingPersonalizable; IPersonalizable customPersonalizable = control as IPersonalizable; if (trackingPersonalizable != null) { trackingPersonalizable.BeginSave(); } PersonalizationInfo info = new PersonalizationInfo(); if (customPersonalizable != null) { info.CustomProperties = new PersonalizationDictionary(); customPersonalizable.Save(info.CustomProperties); } info.Properties = BlobPersonalizationState.GetPersonalizedProperties(control, PersonalizationScope.Shared); if (trackingPersonalizable != null) { trackingPersonalizable.EndSave(); } return info; }