// 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();
            }
        }
示例#2
0
        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 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;
        }