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;
        }
Exemple #2
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);
 }
 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;
     }
 }