Ejemplo n.º 1
0
 public override void Load(PersonalizationDictionary state)
 {
     if (_loading == false)
     {
         throw new InvalidOperationException();
     }
 }
Ejemplo n.º 2
0
        public virtual void ExtractPersonalization(Control source)
        {
            if (!this.States.ContainsKey(source.ID))
            {
                this.States.Add(source.ID, new PersonalizationDictionary());
            }

            PersonalizationDictionary personalizations = this.States[source.ID];

            if (source is ITrackingPersonalizable)
            {
                ((ITrackingPersonalizable)source).BeginSave();
            }

            if (source is IPersonalizable)
            {
                ((IPersonalizable)source).Save(personalizations);
            }

            this.FillPersonalizationDictionary(source, PersonalizableAttribute.GetPersonalizableProperties(source.GetType()), personalizations);

            if (source is ITrackingPersonalizable)
            {
                ((ITrackingPersonalizable)source).EndSave();
            }

            if (!this.States.ContainsKey(source.ID))
            {
                this.States.Add(source.ID, personalizations);
            }
        }
Ejemplo n.º 3
0
        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();
            }
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
 public new void Load(PersonalizationDictionary state)
 {
     if (state.Contains("Script"))
     {
         _script = state["Script"].Value as String;
     }
 }
Ejemplo n.º 6
0
 public override void Save(PersonalizationDictionary state)
 {
     if (_saving == false)
     {
         throw new InvalidOperationException();
     }
     base.Save(state);
 }
Ejemplo n.º 7
0
        // </snippet1>

        // <snippet2>
        public virtual void Save(PersonalizationDictionary state)
        {
            if ((_sharedUrls != null) && (_sharedUrls.Count != 0))
            {
                state["sharedUrls"] = new PersonalizationEntry(_sharedUrls, PersonalizationScope.Shared);
            }
            if ((_userUrls != null) && (_userUrls.Count != 0))
            {
                state["userUrls"] = new PersonalizationEntry(_userUrls, PersonalizationScope.User);
            }
        }
Ejemplo n.º 8
0
        // <snippet1>
        public new virtual void Load(PersonalizationDictionary state)
        {
            if (state != null)
            {
                PersonalizationEntry sharedUrlsEntry = state["sharedUrls"];
                if (sharedUrlsEntry != null)
                {
                    _sharedUrls = (ArrayList)sharedUrlsEntry.Value;
                }

                PersonalizationEntry userUrlsEntry = state["userUrls"];
                if (userUrlsEntry != null)
                {
                    _userUrls = (ArrayList)userUrlsEntry.Value;
                }
            }
        }
Ejemplo n.º 9
0
 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;
         }
     }
 }
Ejemplo n.º 10
0
 public void Save(PersonalizationDictionary state)
 {
     state["Script"] = new PersonalizationEntry(_script, PersonalizationScope.Shared, true);
 }
Ejemplo n.º 11
0
        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);
        }