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);
        }
        public virtual void ApplyPersonalization(Control target, PersonalizationDictionary personalizations)
        {
            if (target is ITrackingPersonalizable)
                ((ITrackingPersonalizable)target).BeginLoad();

            if (target is IPersonalizable)
                ((IPersonalizable)target).Load(personalizations);

            if (target is IVersioningPersonalizable)
                ((IVersioningPersonalizable)target).Load(personalizations);

            foreach (string key in personalizations.Keys)
            {
                if (null != target.GetType().GetProperty(key))
                    ReflectionServices.SetValue(target, key, personalizations[key].Value, true);
            }

            if (target is ITrackingPersonalizable)
                ((ITrackingPersonalizable)target).EndLoad();
        }
        protected virtual void SaveCustomPersonalizationState(PersonalizationDictionary state) {
            PersonalizationScope scope = Personalization.Scope;

            int webPartsCount = Controls.Count;
            if (webPartsCount > 0) {
                object[] webPartState = new object[webPartsCount * 4];
                for (int i=0; i < webPartsCount; i++) {
                    WebPart webPart = (WebPart)Controls[i];
                    webPartState[4*i] = webPart.ID;
                    webPartState[4*i + 1] = Internals.GetZoneID(webPart);
                    webPartState[4*i + 2] = webPart.ZoneIndex;
                    webPartState[4*i + 3] = webPart.IsClosed;
                }
                if (scope == PersonalizationScope.Shared) {
                    state["WebPartStateShared"] =
                        new PersonalizationEntry(webPartState, PersonalizationScope.Shared);
                }
                else {
                    state["WebPartStateUser"] =
                        new PersonalizationEntry(webPartState, PersonalizationScope.User);
                }
            }

            // Select only the dynamic WebParts that should be saved for this mode
            ArrayList dynamicWebParts = new ArrayList();
            foreach (WebPart webPart in Controls) {
                if (!webPart.IsStatic &&
                    ((scope == PersonalizationScope.User && !webPart.IsShared) ||
                     (scope == PersonalizationScope.Shared && webPart.IsShared))) {
                    dynamicWebParts.Add(webPart);
                }
            }

            int dynamicWebPartsCount = dynamicWebParts.Count;
            if (dynamicWebPartsCount > 0) {
                // Use a 1-dimensional array for smallest storage space
                object[] dynamicWebPartState = new object[dynamicWebPartsCount * 4];
                for (int i = 0; i < dynamicWebPartsCount; i++) {
                    WebPart webPart = (WebPart)dynamicWebParts[i];

                    string id;
                    string typeName;
                    string path = null;
                    string genericWebPartID = null;
                    ProxyWebPart proxyWebPart = webPart as ProxyWebPart;
                    if (proxyWebPart != null) {
                        id = proxyWebPart.OriginalID;
                        typeName = proxyWebPart.OriginalTypeName;
                        path = proxyWebPart.OriginalPath;
                        genericWebPartID = proxyWebPart.GenericWebPartID;
                    }
                    else {
                        GenericWebPart genericWebPart = webPart as GenericWebPart;
                        if (genericWebPart != null) {
                            Control childControl = genericWebPart.ChildControl;
                            UserControl userControl = childControl as UserControl;

                            id = childControl.ID;
                            if (userControl != null) {
                                typeName = WebPartUtil.SerializeType(typeof(UserControl));
                                path = userControl.AppRelativeVirtualPath;
                            }
                            else {
                                typeName = WebPartUtil.SerializeType(childControl.GetType());
                            }
                            genericWebPartID = genericWebPart.ID;
                        }
                        else {
                            id = webPart.ID;
                            typeName = WebPartUtil.SerializeType(webPart.GetType());
                        }
                    }

                    dynamicWebPartState[4*i] = id;
                    dynamicWebPartState[4*i + 1] = typeName;
                    if (!String.IsNullOrEmpty(path)) {
                        dynamicWebPartState[4*i + 2] = path;
                    }
                    if (!String.IsNullOrEmpty(genericWebPartID)) {
                        dynamicWebPartState[4*i + 3] = genericWebPartID;
                    }
                }
                if (scope == PersonalizationScope.Shared) {
                    state["DynamicWebPartsShared"] =
                        new PersonalizationEntry(dynamicWebPartState, PersonalizationScope.Shared);
                }
                else {
                    state["DynamicWebPartsUser"] =
                        new PersonalizationEntry(dynamicWebPartState, PersonalizationScope.User);
                }
            }

            // Save deleted connections
            // 

            ArrayList deletedConnections = new ArrayList();
            // PERF: Use the StaticConnections and DynamicConnections collections separately, instead
            // of using the Connections property which is created on every call.
            foreach (WebPartConnection connection in StaticConnections) {
                if (Internals.ConnectionDeleted(connection)) {
                    deletedConnections.Add(connection);
                }
            }
            foreach (WebPartConnection connection in DynamicConnections) {
                if (Internals.ConnectionDeleted(connection)) {
                    deletedConnections.Add(connection);
                }
            }

            int deletedConnectionsCount = deletedConnections.Count;
            if (deletedConnections.Count > 0) {
                string[] deletedConnectionsState = new string[deletedConnectionsCount];
                for (int i=0; i < deletedConnectionsCount; i++) {
                    WebPartConnection deletedConnection = (WebPartConnection)deletedConnections[i];
                    // Only shared connections can be deleted
                    Debug.Assert(deletedConnection.IsShared);
                    // In shared scope, only static connections should be deleted
                    // In user scope, static and dynamic connections can be deleted
                    Debug.Assert(deletedConnection.IsStatic || scope == PersonalizationScope.User);
                    deletedConnectionsState[i] = deletedConnection.ID;
                }
                if (scope == PersonalizationScope.Shared) {
                    state["DeletedConnectionsShared"] =
                        new PersonalizationEntry(deletedConnectionsState, PersonalizationScope.Shared);
                }
                else {
                    state["DeletedConnectionsUser"] =
                        new PersonalizationEntry(deletedConnectionsState, PersonalizationScope.User);
                }
            }

            // Select only the dynamic Connections that should be saved for this mode
            ArrayList dynamicConnections = new ArrayList();
            foreach (WebPartConnection connection in DynamicConnections) {
                if (((scope == PersonalizationScope.User) && (!connection.IsShared)) ||
                    ((scope == PersonalizationScope.Shared) && (connection.IsShared))) {
                    dynamicConnections.Add(connection);
                }
            }

            int dynamicConnectionsCount = dynamicConnections.Count;
            if (dynamicConnectionsCount > 0) {
                // Use a 1-dimensional array for smallest storage space
                object[] dynamicConnectionState = new object[dynamicConnectionsCount * 7];
                for (int i = 0; i < dynamicConnectionsCount; i++) {
                    WebPartConnection connection = (WebPartConnection)dynamicConnections[i];
                    WebPartTransformer transformer = connection.Transformer;

                    // We should never be saving a deleted dynamic connection.  If the User has deleted a
                    // a shared connection, the connection will be saved in the Shared data, not here.
                    Debug.Assert(!Internals.ConnectionDeleted(connection));

                    dynamicConnectionState[7*i] = connection.ID;
                    dynamicConnectionState[7*i + 1] = connection.ConsumerID;
                    dynamicConnectionState[7*i + 2] = connection.ConsumerConnectionPointID;
                    dynamicConnectionState[7*i + 3] = connection.ProviderID;
                    dynamicConnectionState[7*i + 4] = connection.ProviderConnectionPointID;
                    if (transformer != null) {
                        dynamicConnectionState[7*i + 5] = transformer.GetType();
                        dynamicConnectionState[7*i + 6] = Internals.SaveConfigurationState(transformer);
                    }
                }

                if (scope == PersonalizationScope.Shared) {
                    state["DynamicConnectionsShared"] =
                        new PersonalizationEntry(dynamicConnectionState, PersonalizationScope.Shared);
                }
                else {
                    state["DynamicConnectionsUser"] =
                        new PersonalizationEntry(dynamicConnectionState, PersonalizationScope.User);
                }
            }
        }
 void IPersonalizable.Load(PersonalizationDictionary state)
 {
     this.LoadCustomPersonalizationState(state);
 }
 protected virtual void LoadCustomPersonalizationState(PersonalizationDictionary state)
 {
     this._personalizationState = state;
 }
 private void ExportIPersonalizable(XmlWriter writer, Control control, bool excludeSensitive)
 {
     IPersonalizable personalizable = control as IPersonalizable;
     if (personalizable != null)
     {
         PersonalizationDictionary state = new PersonalizationDictionary();
         personalizable.Save(state);
         if (state.Count > 0)
         {
             writer.WriteStartElement("ipersonalizable");
             this.ExportToWriter(state, writer, true, excludeSensitive);
             writer.WriteEndElement();
         }
     }
 }
 protected virtual new void SaveCustomPersonalizationState(PersonalizationDictionary state)
 {
 }
        /// <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);
                    }
                }
            }
        }
        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;
        }
 void System.Web.UI.WebControls.WebParts.IPersonalizable.Save(PersonalizationDictionary state)
 {
 }
 protected virtual new void SaveCustomPersonalizationState(PersonalizationDictionary state)
 {
     Contract.Requires(this.Personalization != null);
     Contract.Requires(state != null);
 }
 protected virtual new void LoadCustomPersonalizationState(PersonalizationDictionary state)
 {
 }
 protected virtual new void SaveCustomPersonalizationState (PersonalizationDictionary state)
 {
   Contract.Requires (this.Personalization != null);
   Contract.Requires (state != null);
 }
        /// <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;
        }
        public override PersonalizationState LoadPersonalizationState(WebPartManager webPartManager, bool ignoreCurrentUser)
        {
            if (null == webPartManager) throw new ArgumentNullException("webPartManager is null");
            DictionaryPersonalizationState state = new DictionaryPersonalizationState(webPartManager);
            string suid = this.GetScreenUniqueIdentifier();

            Cache cache = HttpRuntime.Cache;
            lock (SyncRoot)
            {
                Dictionary<string, PersonalizationDictionary> cachedstates = cache[suid] as Dictionary<string, PersonalizationDictionary>;
                if ((this.IsEnabled && !state.ReadOnly)  || null == cachedstates)
                {
                    string storage = PersonalizationStorage.Instance.Read(XmlPersonalizationProvider.StorageKey, XmlPersonalizationProvider.StorageTemplate);
                    if (!string.IsNullOrEmpty(storage))
                    {
                        using (XmlTextReader reader = new XmlTextReader(new StringReader(storage)))
                        {
                            reader.MoveToContent();
                            if (reader.MoveToAttribute("readOnly"))
                            {
                                bool isReadOnly = false;
                                bool.TryParse(reader.Value, out isReadOnly);
                                state.ReadOnly = isReadOnly;
                                reader.MoveToElement();
                            }
                            if (reader.ReadToDescendant("part"))
                            {
                                int partDepth = reader.Depth;
                                do
                                {
                                    reader.MoveToElement();
                                    reader.MoveToAttribute("id");
                                    string id = reader.Value;
                                    PersonalizationDictionary dictionary = new PersonalizationDictionary();
                                    reader.MoveToContent();
                                    if (reader.ReadToDescendant("property"))
                                    {
                                        int propertyDepth = reader.Depth;
                                        do
                                        {
                                            reader.MoveToElement();
                                            reader.MoveToAttribute("name");
                                            string name = reader.Value;
                                            reader.MoveToAttribute("sensitive");
                                            bool sensitive = bool.Parse(reader.Value);
                                            reader.MoveToAttribute("scope");
                                            PersonalizationScope scope = (PersonalizationScope)int.Parse(reader.Value);
                                            object value = null;
                                            reader.MoveToContent();
                                            if (reader.ReadToDescendant("value"))
                                            {
                                                reader.MoveToAttribute("type");
                                                if (reader.HasValue)
                                                {
                                                    Type type = Type.GetType(reader.Value);
                                                    if (type == null && name == "Configuration")
                                                    {
                                                        type = Type.GetType("LWAS.Infrastructure.Configuration.Configuration, LWAS");
                                                    }
                                                    reader.MoveToContent();
                                                    value = SerializationServices.Deserialize(type, reader);
                                                }
                                            }
                                            dictionary.Add(name, new PersonalizationEntry(value, scope, sensitive));
                                            reader.MoveToElement();
                                            while (propertyDepth < reader.Depth && reader.Read())
                                            {
                                            }
                                        }
                                        while (reader.ReadToNextSibling("property"));
                                    }
                                    state.States.Add(id, dictionary);
                                    reader.MoveToElement();
                                    while (partDepth < reader.Depth && reader.Read())
                                    {
                                    }
                                }
                                while (reader.ReadToNextSibling("part"));
                            }
                        }
                    }

                    string fileToMonitor = PersonalizationStorage.Instance.BuildPath(StorageKey);
                    if (!PersonalizationStorage.Instance.Agent.HasKey(fileToMonitor))
                        fileToMonitor = PersonalizationStorage.Instance.BuildPath(StorageTemplate);
                    cache.Insert(suid, state.States, new CacheDependency(HttpContext.Current.Server.MapPath(fileToMonitor)));
                }
                else
                    state.States = cachedstates;
            }

            return state;
        }
        // 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;
        }
Beispiel #19
0
 protected override void SaveCustomPersonalizationState(PersonalizationDictionary state)
 {
     object[] parts = new object[6 * base.WebParts.Count];
     int count = 0;
     foreach (WebPart webPart in base.WebParts)
     {
         parts[count++] = webPart.ID;
         parts[count++] = webPart.Title;
         parts[count++] = SerializationServices.ShortAssemblyQualifiedName(webPart.GetType().AssemblyQualifiedName);
         if (null != webPart.Zone)
         {
             parts[count++] = webPart.Zone.ID;
         }
         else
         {
             parts[count++] = null;
         }
         parts[count++] = (webPart is IContainerWebPart);
         parts[count++] = (webPart is IProxyWebPart);
     }
     if (!state.Contains("lwas.info"))
     {
         state.Add("lwas.info", new PersonalizationEntry(parts, base.Personalization.Scope));
     }
     else
     {
         state["lwas.info"] = new PersonalizationEntry(parts, base.Personalization.Scope);
     }
     base.SaveCustomPersonalizationState(state);
 }
 void System.Web.UI.WebControls.WebParts.IPersonalizable.Save(PersonalizationDictionary state)
 {
 }
 private void ExportIPersonalizable(XmlWriter writer, Control control, bool excludeSensitive) {
     IPersonalizable personalizableControl = control as IPersonalizable;
     if (personalizableControl != null) {
         PersonalizationDictionary personalizableData = new PersonalizationDictionary();
         personalizableControl.Save(personalizableData);
         if (personalizableData.Count > 0) {
             writer.WriteStartElement(ExportIPersonalizableElement);
             ExportToWriter(personalizableData, writer, /* isIPersonalizable */ true, excludeSensitive);
             writer.WriteEndElement(); // ipersonalizable
         }
     }
 }
 private void ImportFromReader(IDictionary personalizableProperties, Control target, XmlReader reader)
 {
     ImportReadTo(reader, "property");
     bool flag = false;
     if (this.UsePermitOnly)
     {
         this.MinimalPermissionSet.PermitOnly();
         flag = true;
     }
     try
     {
         try
         {
             IDictionary dictionary;
             if (personalizableProperties != null)
             {
                 dictionary = new HybridDictionary();
             }
             else
             {
                 dictionary = new PersonalizationDictionary();
             }
             while (reader.Name == "property")
             {
                 string attribute = reader.GetAttribute("name");
                 string str2 = reader.GetAttribute("type");
                 string a = reader.GetAttribute("scope");
                 bool flag2 = string.Equals(reader.GetAttribute("null"), "true", StringComparison.OrdinalIgnoreCase);
                 if (((attribute == "AuthorizationFilter") || (attribute == "ZoneID")) || (attribute == "ZoneIndex"))
                 {
                     reader.ReadElementString();
                     if (!reader.Read())
                     {
                         throw new XmlException();
                     }
                     goto Label_03AA;
                 }
                 string s = reader.ReadElementString();
                 object obj2 = null;
                 bool flag3 = false;
                 PropertyInfo element = null;
                 if (personalizableProperties != null)
                 {
                     PersonalizablePropertyEntry entry = (PersonalizablePropertyEntry) personalizableProperties[attribute];
                     if (entry != null)
                     {
                         element = entry.PropertyInfo;
                         if ((Attribute.GetCustomAttribute(element, typeof(UrlPropertyAttribute), true) is UrlPropertyAttribute) && CrossSiteScriptingValidation.IsDangerousUrl(s))
                         {
                             throw new InvalidDataException(System.Web.SR.GetString("WebPart_BadUrl", new object[] { s }));
                         }
                     }
                 }
                 Type exportType = null;
                 if (!string.IsNullOrEmpty(str2))
                 {
                     if (this.UsePermitOnly)
                     {
                         CodeAccessPermission.RevertPermitOnly();
                         flag = false;
                         this.MediumPermissionSet.PermitOnly();
                         flag = true;
                     }
                     exportType = GetExportType(str2);
                     if (this.UsePermitOnly)
                     {
                         CodeAccessPermission.RevertPermitOnly();
                         flag = false;
                         this.MinimalPermissionSet.PermitOnly();
                         flag = true;
                     }
                 }
                 if ((element != null) && ((element.PropertyType == exportType) || (exportType == null)))
                 {
                     TypeConverterAttribute attribute2 = Attribute.GetCustomAttribute(element, typeof(TypeConverterAttribute), true) as TypeConverterAttribute;
                     if (attribute2 != null)
                     {
                         if (this.UsePermitOnly)
                         {
                             CodeAccessPermission.RevertPermitOnly();
                             flag = false;
                             this.MediumPermissionSet.PermitOnly();
                             flag = true;
                         }
                         Type type = WebPartUtil.DeserializeType(attribute2.ConverterTypeName, false);
                         if (this.UsePermitOnly)
                         {
                             CodeAccessPermission.RevertPermitOnly();
                             flag = false;
                             this.MinimalPermissionSet.PermitOnly();
                             flag = true;
                         }
                         if ((type != null) && type.IsSubclassOf(typeof(TypeConverter)))
                         {
                             TypeConverter converter = (TypeConverter) this.Internals.CreateObjectFromType(type);
                             if (Util.CanConvertToFrom(converter, typeof(string)))
                             {
                                 if (!flag2)
                                 {
                                     obj2 = converter.ConvertFromInvariantString(s);
                                 }
                                 flag3 = true;
                             }
                         }
                     }
                     if (!flag3)
                     {
                         TypeConverter converter2 = TypeDescriptor.GetConverter(element.PropertyType);
                         if (Util.CanConvertToFrom(converter2, typeof(string)))
                         {
                             if (!flag2)
                             {
                                 obj2 = converter2.ConvertFromInvariantString(s);
                             }
                             flag3 = true;
                         }
                     }
                 }
                 if (!flag3 && (exportType != null))
                 {
                     if (exportType == typeof(string))
                     {
                         if (!flag2)
                         {
                             obj2 = s;
                         }
                         flag3 = true;
                     }
                     else
                     {
                         TypeConverter converter3 = TypeDescriptor.GetConverter(exportType);
                         if (Util.CanConvertToFrom(converter3, typeof(string)))
                         {
                             if (!flag2)
                             {
                                 obj2 = converter3.ConvertFromInvariantString(s);
                             }
                             flag3 = true;
                         }
                     }
                 }
                 if (flag2 && (personalizableProperties == null))
                 {
                     flag3 = true;
                 }
                 if (flag3)
                 {
                     if (personalizableProperties != null)
                     {
                         dictionary.Add(attribute, obj2);
                     }
                     else
                     {
                         PersonalizationScope scope = string.Equals(a, PersonalizationScope.Shared.ToString(), StringComparison.OrdinalIgnoreCase) ? PersonalizationScope.Shared : PersonalizationScope.User;
                         dictionary.Add(attribute, new PersonalizationEntry(obj2, scope));
                     }
                     goto Label_03AA;
                 }
                 throw new HttpException(System.Web.SR.GetString("WebPartManager_ImportInvalidData", new object[] { attribute }));
             Label_035C:
                 if (((reader.EOF || (reader.Name == "genericWebPartProperties")) || (reader.Name == "properties")) || ((reader.Name == "ipersonalizable") && (reader.NodeType == XmlNodeType.EndElement)))
                 {
                     break;
                 }
                 reader.Skip();
             Label_03AA:
                 if (reader.Name != "property")
                 {
                     goto Label_035C;
                 }
             }
             if (personalizableProperties != null)
             {
                 IDictionary unknownProperties = BlobPersonalizationState.SetPersonalizedProperties(target, dictionary);
                 if ((unknownProperties != null) && (unknownProperties.Count > 0))
                 {
                     IVersioningPersonalizable personalizable = target as IVersioningPersonalizable;
                     if (personalizable != null)
                     {
                         personalizable.Load(unknownProperties);
                     }
                 }
             }
             else
             {
                 ((IPersonalizable) target).Load((PersonalizationDictionary) dictionary);
             }
         }
         finally
         {
             if (flag)
             {
                 CodeAccessPermission.RevertPermitOnly();
             }
         }
     }
     catch
     {
         throw;
     }
 }
        private void ImportFromReader(IDictionary personalizableProperties,
                                      Control target,
                                      XmlReader reader) {

            Debug.Assert(target != null);

            ImportReadTo(reader, ExportPropertyElement);

            bool permitOnly = false;

            if (UsePermitOnly) {
                MinimalPermissionSet.PermitOnly();
                permitOnly = true;
            }

            try {
                try {
                    IDictionary properties;
                    if (personalizableProperties != null) {
                        properties = new HybridDictionary();
                    }
                    else {
                        properties = new PersonalizationDictionary();
                    }
                    // Set properties from the xml document
                    while (reader.Name == ExportPropertyElement) {
                        // Get the name of the property
                        string propertyName = reader.GetAttribute(ExportPropertyNameAttribute);
                        string typeName = reader.GetAttribute(ExportPropertyTypeAttribute);
                        string scope = reader.GetAttribute(ExportPropertyScopeAttribute);
                        bool isNull = String.Equals(
                            reader.GetAttribute(ExportPropertyNullAttribute),
                            "true",
                            StringComparison.OrdinalIgnoreCase);

                        // Do not import Zone information or AuthorizationFilter or custom data
                        if (propertyName == AuthorizationFilterName ||
                             propertyName == ZoneIDName ||
                             propertyName == ZoneIndexName) {

                            reader.ReadElementString();
                            if (!reader.Read()) {
                                throw new XmlException();
                            }
                        }
                        else {
                            string valString = reader.ReadElementString();
                            object val = null;
                            bool valueComputed = false;
                            PropertyInfo pi = null;
                            if (personalizableProperties != null) {
                                // Get the relevant personalizable property on the target (no need to check the property is personalizable)
                                PersonalizablePropertyEntry entry = (PersonalizablePropertyEntry)(personalizableProperties[propertyName]);
                                if (entry != null) {
                                    pi = entry.PropertyInfo;
                                    Debug.Assert(pi != null);
                                    // If the property is a url, validate protocol (VSWhidbey 290418)
                                    UrlPropertyAttribute urlAttr = Attribute.GetCustomAttribute(pi, typeof(UrlPropertyAttribute), true) as UrlPropertyAttribute;
                                    if (urlAttr != null && CrossSiteScriptingValidation.IsDangerousUrl(valString)) {
                                        throw new InvalidDataException(SR.GetString(SR.WebPart_BadUrl, valString));
                                    }
                                }
                            }

                            Type type = null;
                            if (!String.IsNullOrEmpty(typeName)) {
                                if (UsePermitOnly) {
                                    // Need medium trust to call BuildManager.GetType()
                                    CodeAccessPermission.RevertPermitOnly();
                                    permitOnly = false;
                                    MediumPermissionSet.PermitOnly();
                                    permitOnly = true;
                                }
                                type = GetExportType(typeName);

                                if (UsePermitOnly) {
                                    CodeAccessPermission.RevertPermitOnly();
                                    permitOnly = false;
                                    MinimalPermissionSet.PermitOnly();
                                    permitOnly = true;
                                }
                            }

                            if ((pi != null) && ((pi.PropertyType == type) || (type == null))) {
                                // Look at the target property
                                // See if the property itself has a type converter associated with it
                                TypeConverterAttribute attr = Attribute.GetCustomAttribute(pi, typeof(TypeConverterAttribute), true) as TypeConverterAttribute;
                                if (attr != null) {
                                    if (UsePermitOnly) {
                                        // Need medium trust to call BuildManager.GetType()
                                        CodeAccessPermission.RevertPermitOnly();
                                        permitOnly = false;
                                        MediumPermissionSet.PermitOnly();
                                        permitOnly = true;
                                    }

                                    Type converterType = WebPartUtil.DeserializeType(attr.ConverterTypeName, false);

                                    if (UsePermitOnly) {
                                        CodeAccessPermission.RevertPermitOnly();
                                        permitOnly = false;
                                        MinimalPermissionSet.PermitOnly();
                                        permitOnly = true;
                                    }

                                    // SECURITY: Check that the type is a subclass of TypeConverter before instantiating.
                                    if (converterType != null && converterType.IsSubclassOf(typeof(TypeConverter))) {
                                        TypeConverter converter = (TypeConverter)(Internals.CreateObjectFromType(converterType));
                                        if (Util.CanConvertToFrom(converter, typeof(string))) {
                                            if (!isNull) {
                                                val = converter.ConvertFromInvariantString(valString);
                                            }
                                            valueComputed = true;
                                        }
                                    }
                                }
                                // Then, look at the converters on the property type
                                if (!valueComputed) {
                                    // Use the type converter associated with the type itself
                                    TypeConverter converter = TypeDescriptor.GetConverter(pi.PropertyType);
                                    if (Util.CanConvertToFrom(converter, typeof(string))) {
                                        if (!isNull) {
                                            val = converter.ConvertFromInvariantString(valString);
                                        }
                                        valueComputed = true;
                                        // Not importing anything else for security reasons
                                    }
                                }
                            }
                            // finally, use the XML-specified type
                            if (!valueComputed && (type != null)) {
                                // Look at the XML-declared type
                                if (type == typeof(string)) {
                                    if (!isNull) {
                                        val = valString;
                                    }
                                    valueComputed = true;
                                }
                                else {
                                    TypeConverter typeConverter = TypeDescriptor.GetConverter(type);
                                    if (Util.CanConvertToFrom(typeConverter, typeof(string))) {
                                        if (!isNull) {
                                            val = typeConverter.ConvertFromInvariantString(valString);
                                        }
                                        valueComputed = true;
                                    }
                                }
                            }

                            // Always want to import a null IPersonalizable value, since we will never have a type
                            // converter for the value.  However, we should not import a null Personalizable value
                            // unless the PropertyInfo had a type converter, since the property may be a value type
                            // that cannot accept null as a value. (VSWhidbey 537895)
                            if (isNull && personalizableProperties == null) {
                                valueComputed = true;
                            }

                            // Now we should have a value (val)
                            if (valueComputed) {
                                if (personalizableProperties != null) {
                                    properties.Add(propertyName, val);
                                }
                                else {
                                    // Determine scope:
                                    PersonalizationScope personalizationScope =
                                        String.Equals(scope, PersonalizationScope.Shared.ToString(), StringComparison.OrdinalIgnoreCase) ?
                                        PersonalizationScope.Shared : PersonalizationScope.User;
                                    properties.Add(propertyName, new PersonalizationEntry(val, personalizationScope));
                                }
                            }
                            else {
                                throw new HttpException(SR.GetString(SR.WebPartManager_ImportInvalidData, propertyName));
                            }
                        }
                        while (reader.Name != ExportPropertyElement) {
                            if (reader.EOF ||
                                (reader.Name == ExportGenericPartPropertiesElement) ||
                                (reader.Name == ExportPropertiesElement) ||
                                ((reader.Name == ExportIPersonalizableElement) && (reader.NodeType == XmlNodeType.EndElement))) {
                                goto EndOfData;
                            }
                            reader.Skip();
                        }
                    }
                    EndOfData:
                    if (personalizableProperties != null) {
                        IDictionary unused = BlobPersonalizationState.SetPersonalizedProperties(target, properties);
                        if ((unused != null) && (unused.Count > 0)) {
                            IVersioningPersonalizable versioningTarget = target as IVersioningPersonalizable;
                            if (versioningTarget != null) {
                                versioningTarget.Load(unused);
                            }
                        }
                    }
                    else {
                        Debug.Assert(target is IPersonalizable);
                        ((IPersonalizable)target).Load((PersonalizationDictionary)properties);
                    }
                }
                finally {
                    if (permitOnly) {
                        // revert if you're not just exiting the stack frame anyway
                        CodeAccessPermission.RevertPermitOnly();
                    }
                }
            }
            catch {
                throw;
            }
        }
 protected virtual void SaveCustomPersonalizationState(PersonalizationDictionary state)
 {
     PersonalizationScope scope = this.Personalization.Scope;
     int count = this.Controls.Count;
     if (count > 0)
     {
         object[] objArray = new object[count * 4];
         for (int i = 0; i < count; i++)
         {
             WebPart webPart = (WebPart) this.Controls[i];
             objArray[4 * i] = webPart.ID;
             objArray[(4 * i) + 1] = this.Internals.GetZoneID(webPart);
             objArray[(4 * i) + 2] = webPart.ZoneIndex;
             objArray[(4 * i) + 3] = webPart.IsClosed;
         }
         if (scope == PersonalizationScope.Shared)
         {
             state["WebPartStateShared"] = new PersonalizationEntry(objArray, PersonalizationScope.Shared);
         }
         else
         {
             state["WebPartStateUser"] = new PersonalizationEntry(objArray, PersonalizationScope.User);
         }
     }
     ArrayList list = new ArrayList();
     foreach (WebPart part2 in this.Controls)
     {
         if (!part2.IsStatic && (((scope == PersonalizationScope.User) && !part2.IsShared) || ((scope == PersonalizationScope.Shared) && part2.IsShared)))
         {
             list.Add(part2);
         }
     }
     int num3 = list.Count;
     if (num3 > 0)
     {
         object[] objArray2 = new object[num3 * 4];
         for (int j = 0; j < num3; j++)
         {
             string originalID;
             string originalTypeName;
             WebPart part3 = (WebPart) list[j];
             string originalPath = null;
             string genericWebPartID = null;
             ProxyWebPart part4 = part3 as ProxyWebPart;
             if (part4 != null)
             {
                 originalID = part4.OriginalID;
                 originalTypeName = part4.OriginalTypeName;
                 originalPath = part4.OriginalPath;
                 genericWebPartID = part4.GenericWebPartID;
             }
             else
             {
                 GenericWebPart part5 = part3 as GenericWebPart;
                 if (part5 != null)
                 {
                     Control childControl = part5.ChildControl;
                     UserControl control2 = childControl as UserControl;
                     originalID = childControl.ID;
                     if (control2 != null)
                     {
                         originalTypeName = WebPartUtil.SerializeType(typeof(UserControl));
                         originalPath = control2.AppRelativeVirtualPath;
                     }
                     else
                     {
                         originalTypeName = WebPartUtil.SerializeType(childControl.GetType());
                     }
                     genericWebPartID = part5.ID;
                 }
                 else
                 {
                     originalID = part3.ID;
                     originalTypeName = WebPartUtil.SerializeType(part3.GetType());
                 }
             }
             objArray2[4 * j] = originalID;
             objArray2[(4 * j) + 1] = originalTypeName;
             if (!string.IsNullOrEmpty(originalPath))
             {
                 objArray2[(4 * j) + 2] = originalPath;
             }
             if (!string.IsNullOrEmpty(genericWebPartID))
             {
                 objArray2[(4 * j) + 3] = genericWebPartID;
             }
         }
         if (scope == PersonalizationScope.Shared)
         {
             state["DynamicWebPartsShared"] = new PersonalizationEntry(objArray2, PersonalizationScope.Shared);
         }
         else
         {
             state["DynamicWebPartsUser"] = new PersonalizationEntry(objArray2, PersonalizationScope.User);
         }
     }
     ArrayList list2 = new ArrayList();
     foreach (WebPartConnection connection in this.StaticConnections)
     {
         if (this.Internals.ConnectionDeleted(connection))
         {
             list2.Add(connection);
         }
     }
     foreach (WebPartConnection connection2 in this.DynamicConnections)
     {
         if (this.Internals.ConnectionDeleted(connection2))
         {
             list2.Add(connection2);
         }
     }
     int num5 = list2.Count;
     if (list2.Count > 0)
     {
         string[] strArray = new string[num5];
         for (int k = 0; k < num5; k++)
         {
             WebPartConnection connection3 = (WebPartConnection) list2[k];
             strArray[k] = connection3.ID;
         }
         if (scope == PersonalizationScope.Shared)
         {
             state["DeletedConnectionsShared"] = new PersonalizationEntry(strArray, PersonalizationScope.Shared);
         }
         else
         {
             state["DeletedConnectionsUser"] = new PersonalizationEntry(strArray, PersonalizationScope.User);
         }
     }
     ArrayList list3 = new ArrayList();
     foreach (WebPartConnection connection4 in this.DynamicConnections)
     {
         if (((scope == PersonalizationScope.User) && !connection4.IsShared) || ((scope == PersonalizationScope.Shared) && connection4.IsShared))
         {
             list3.Add(connection4);
         }
     }
     int num7 = list3.Count;
     if (num7 > 0)
     {
         object[] objArray3 = new object[num7 * 7];
         for (int m = 0; m < num7; m++)
         {
             WebPartConnection connection5 = (WebPartConnection) list3[m];
             WebPartTransformer transformer = connection5.Transformer;
             objArray3[7 * m] = connection5.ID;
             objArray3[(7 * m) + 1] = connection5.ConsumerID;
             objArray3[(7 * m) + 2] = connection5.ConsumerConnectionPointID;
             objArray3[(7 * m) + 3] = connection5.ProviderID;
             objArray3[(7 * m) + 4] = connection5.ProviderConnectionPointID;
             if (transformer != null)
             {
                 objArray3[(7 * m) + 5] = transformer.GetType();
                 objArray3[(7 * m) + 6] = this.Internals.SaveConfigurationState(transformer);
             }
         }
         if (scope == PersonalizationScope.Shared)
         {
             state["DynamicConnectionsShared"] = new PersonalizationEntry(objArray3, PersonalizationScope.Shared);
         }
         else
         {
             state["DynamicConnectionsUser"] = new PersonalizationEntry(objArray3, PersonalizationScope.User);
         }
     }
 }
 protected virtual void LoadCustomPersonalizationState(PersonalizationDictionary state) {
     // The state must be loaded after the Static Connections and WebParts have been added
     // to the WebPartManager (after the WebPartZone's and ProxyWebPartManager's Init methods)
     _personalizationState = state;
 }
 void IPersonalizable.Save(PersonalizationDictionary state)
 {
     this.SaveCustomPersonalizationState(state);
 }
 public void FillPersonalizationDictionary(Control control, ICollection propertyInfos, PersonalizationDictionary personalizations)
 {
     foreach (PropertyInfo propertyInfo in propertyInfos)
     {
         PersonalizableAttribute attribute = (PersonalizableAttribute)Attribute.GetCustomAttribute(propertyInfo, typeof(PersonalizableAttribute));
         PersonalizationEntry entry = new PersonalizationEntry(ReflectionServices.ExtractValue(control, propertyInfo.Name), attribute.Scope, attribute.IsSensitive);
         if (!personalizations.Contains(propertyInfo.Name))
             personalizations.Add(propertyInfo.Name, entry);
         else
             personalizations[propertyInfo.Name] = entry;
     }
 }