private AggregatedUserConfigurationPart(IUserConfiguration config)
 {
     this.memento = new AggregatedUserConfigurationPart.MementoClass
     {
         ConfigurationName = config.ConfigurationName,
         DataTypes         = config.DataTypes,
         FolderId          = config.FolderId,
         Id               = config.Id,
         VersionedId      = config.VersionedId,
         LastModifiedTime = config.LastModifiedTime.ToBinary()
     };
     if ((config.DataTypes & UserConfigurationTypes.Dictionary) != (UserConfigurationTypes)0)
     {
         using (StringWriter stringWriter = new StringWriter())
         {
             using (XmlWriter xmlWriter = AggregatedUserConfigurationPart.InternalGetXmlWriter(stringWriter))
             {
                 config.GetConfigurationDictionary().WriteXml(xmlWriter);
                 xmlWriter.Flush();
                 this.memento.DictionaryXmlString = stringWriter.ToString();
             }
         }
     }
     if ((config.DataTypes & UserConfigurationTypes.XML) != (UserConfigurationTypes)0)
     {
         using (Stream xmlStream = config.GetXmlStream())
         {
             using (StreamReader streamReader = new StreamReader(xmlStream))
             {
                 this.memento.XmlString = streamReader.ReadToEnd();
             }
         }
     }
 }
 private AggregatedUserConfiguration.MementoClass ReadMemento(IUserConfiguration aggregated)
 {
     AggregatedUserConfiguration.MementoClass mementoClass = null;
     try
     {
         if (aggregated != null)
         {
             DataContractSerializer dataContractSerializer = new DataContractSerializer(typeof(AggregatedUserConfiguration.MementoClass));
             using (Stream xmlStream = aggregated.GetXmlStream())
             {
                 if (xmlStream != null && xmlStream.Length > 0L)
                 {
                     mementoClass = (AggregatedUserConfiguration.MementoClass)dataContractSerializer.ReadObject(xmlStream);
                 }
             }
         }
     }
     catch (SerializationException arg)
     {
         ExTraceGlobals.StorageTracer.TraceError <SerializationException>((long)this.GetHashCode(), "The aggregated configuration exists, but it could not be deserialized into a memento", arg);
     }
     catch (XmlException arg2)
     {
         ExTraceGlobals.StorageTracer.TraceError <XmlException>((long)this.GetHashCode(), "The aggregated configuration exists, but it could not be deserialized memento", arg2);
     }
     catch (ArgumentException arg3)
     {
         ExTraceGlobals.StorageTracer.TraceError <ArgumentException>((long)this.GetHashCode(), "The aggregated configuration exists, but it could not be deserialized into a memento", arg3);
     }
     if (mementoClass == null || 1 != mementoClass.Version)
     {
         mementoClass = (mementoClass ?? new AggregatedUserConfiguration.MementoClass());
     }
     mementoClass.Version           = 1;
     mementoClass.Parts             = (mementoClass.Parts ?? new Dictionary <UserConfigurationDescriptor.MementoClass, AggregatedUserConfigurationPart.MementoClass>());
     mementoClass.Pending           = (mementoClass.Pending ?? new List <AggregatedUserConfiguration.PendingUpdate>());
     mementoClass.ConcurrentUpdates = (mementoClass.ConcurrentUpdates ?? new HashSet <UserConfigurationDescriptor.MementoClass>());
     mementoClass.FailedToLoad      = (mementoClass.FailedToLoad ?? new HashSet <UserConfigurationDescriptor.MementoClass>());
     mementoClass.TypeBag           = (mementoClass.TypeBag ?? new Dictionary <string, SerializableDataBase>());
     return(mementoClass);
 }