Ejemplo n.º 1
0
        // 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);
        }
        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);
                    }
                }
            }
        }