コード例 #1
0
        public override void SavePersonalizationState(PersonalizationState state)
        {
            if (this.IsEnabled)
            {
                DictionaryPersonalizationState dictionaryState = state as DictionaryPersonalizationState;
                if (null == dictionaryState)
                {
                    throw new ArgumentException("state is not a DictionaryPersonalizationState");
                }

                if (!dictionaryState.ReadOnly)
                {
                    StringBuilder personalizationBuilder = new StringBuilder();
                    using (StringWriter stringWriter = new StringWriter(personalizationBuilder))
                    {
                        using (XmlTextWriter writer = new XmlTextWriter(stringWriter))
                        {
                            writer.Formatting = Formatting.Indented;
                            writer.WriteStartDocument();
                            writer.WriteStartElement("personalization");
                            writer.WriteAttributeString("version", ReflectionServices.Version());
                            foreach (string id in dictionaryState.States.Keys)
                            {
                                if (dictionaryState.IsPartPresent(id))
                                {
                                    writer.WriteStartElement("part");
                                    writer.WriteAttributeString("id", id);
                                    foreach (string propertyName in dictionaryState.States[id].Keys)
                                    {
                                        writer.WriteStartElement("property");
                                        writer.WriteAttributeString("name", propertyName);
                                        writer.WriteStartAttribute("sensitive");
                                        writer.WriteValue(dictionaryState.States[id][propertyName].IsSensitive);
                                        writer.WriteEndAttribute();
                                        writer.WriteStartAttribute("scope");
                                        writer.WriteValue((int)dictionaryState.States[id][propertyName].Scope);
                                        writer.WriteEndAttribute();
                                        object value = dictionaryState.States[id][propertyName].Value;
                                        if (null != value)
                                        {
                                            writer.WriteStartElement("value");
                                            writer.WriteStartAttribute("type");
                                            writer.WriteValue(SerializationServices.ShortAssemblyQualifiedName(value.GetType().AssemblyQualifiedName));
                                            writer.WriteEndAttribute();
                                            SerializationServices.Serialize(value, writer);
                                            writer.WriteEndElement();
                                        }
                                        writer.WriteEndElement();
                                    }
                                    writer.WriteEndElement();
                                }
                            }
                            writer.WriteEndElement();
                            writer.WriteEndDocument();
                        }
                    }
                    PersonalizationStorage.Instance.Write(XmlPersonalizationProvider.StorageKey, personalizationBuilder.ToString());
                }
            }
        }
コード例 #2
0
 public override void WriteXml(XmlWriter writer)
 {
     if (null == writer)
     {
         throw new ArgumentNullException("writer");
     }
     writer.WriteStartElement("attribute");
     base.WriteXml(writer);
     if (null == this._value)
     {
         this._value = string.Empty;
     }
     writer.WriteAttributeString("value", this._value.ToString());
     writer.WriteAttributeString("type", SerializationServices.ShortAssemblyQualifiedName(this._value.GetType().AssemblyQualifiedName));
     writer.WriteEndElement();
 }