Changeset 1542 for trunk/sources/HeuristicLab.Persistence/3.3/Core
- Timestamp:
- 04/08/09 17:05:17 (16 years ago)
- Location:
- trunk/sources/HeuristicLab.Persistence/3.3/Core
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Persistence/3.3/Core/Configuration.cs
r1454 r1542 13 13 private readonly Dictionary<Type, IDecomposer> decomposerCache; 14 14 [Storable] 15 public readonly IFormat Format;15 public IFormat Format { get; set; } 16 16 17 17 private Configuration() { -
trunk/sources/HeuristicLab.Persistence/3.3/Core/ConfigurationService.cs
r1539 r1542 7 7 using HeuristicLab.Persistence.Interfaces; 8 8 using HeuristicLab.Tracing; 9 using HeuristicLab.Persistence.Interfaces.Tokens; 9 10 10 11 namespace HeuristicLab.Persistence.Core { … … 14 15 private static ConfigurationService instance; 15 16 private readonly Dictionary<IFormat, Configuration> customConfigurations; 16 public readonly Dictionary<IFormat, List<IFormatter>> Formatters;17 public readonly List<IDecomposer> Decomposers;17 public Dictionary<IFormat, List<IFormatter>> Formatters { get; private set; } 18 public List<IDecomposer> Decomposers { get; private set; } 18 19 19 20 public static ConfigurationService Instance { … … 25 26 } 26 27 27 p ublicConfigurationService() {28 private ConfigurationService() { 28 29 Formatters = new Dictionary<IFormat, List<IFormatter>>(); 29 30 Decomposers = new List<IDecomposer>(); … … 35 36 public void LoadSettings() { 36 37 try { 37 if (String.IsNullOrEmpty(Properties.Settings.Default. customConfigurations) ||38 String.IsNullOrEmpty(Properties.Settings.Default. customConfigurationsTypeCache))38 if (String.IsNullOrEmpty(Properties.Settings.Default.CustomConfigurations) || 39 String.IsNullOrEmpty(Properties.Settings.Default.CustomConfigurationsTypeCache)) 39 40 return; 40 De Serializer deSerializer = new DeSerializer(41 Deserializer deSerializer = new Deserializer( 41 42 XmlParser.ParseTypeCache( 42 43 new StringReader( 43 Properties.Settings.Default. customConfigurationsTypeCache)));44 Properties.Settings.Default.CustomConfigurationsTypeCache))); 44 45 XmlParser parser = new XmlParser( 45 46 new StringReader( 46 Properties.Settings.Default. customConfigurations));47 Properties.Settings.Default.CustomConfigurations)); 47 48 var newCustomConfigurations = (Dictionary<IFormat, Configuration>) 48 deSerializer.De Serialize(parser);49 deSerializer.Deserialize(parser); 49 50 foreach (var config in newCustomConfigurations) { 50 51 customConfigurations[config.Key] = config.Value; … … 68 69 foreach (string s in generator.Format(serializer.TypeCache)) 69 70 configurationTypeCacheString.Append(s); 70 Properties.Settings.Default. customConfigurations =71 Properties.Settings.Default.CustomConfigurations = 71 72 configurationString.ToString(); 72 Properties.Settings.Default. customConfigurationsTypeCache =73 Properties.Settings.Default.CustomConfigurationsTypeCache = 73 74 configurationTypeCacheString.ToString(); 74 75 Properties.Settings.Default.Save(); -
trunk/sources/HeuristicLab.Persistence/3.3/Core/DataMemberAccessor.cs
r1454 r1542 16 16 public DataMemberAccessor( 17 17 MemberInfo memberInfo, 18 StorableAttribute autoStorableAttribute,18 StorableAttribute storableAttribute, 19 19 object obj) { 20 20 if (memberInfo.MemberType == MemberTypes.Field) { … … 34 34 "The Storable attribute can only be applied to fields and properties."); 35 35 } 36 Name = autoStorableAttribute.Name ?? memberInfo.Name;37 DefaultValue = autoStorableAttribute.DefaultValue;36 Name = storableAttribute.Name ?? memberInfo.Name; 37 DefaultValue = storableAttribute.DefaultValue; 38 38 } 39 39 -
trunk/sources/HeuristicLab.Persistence/3.3/Core/DeSerializer.cs
r1494 r1542 2 2 using System; 3 3 using HeuristicLab.Persistence.Interfaces; 4 using HeuristicLab.Persistence.Interfaces.Tokens; 4 5 5 6 namespace HeuristicLab.Persistence.Core { 6 7 7 public structParentReference {}8 public class ParentReference {} 8 9 9 10 class CompositeObject { … … 18 19 19 20 public void AddValue(string name, object value, List<Thunk> finalFixes) { 20 Tag t = new Tag(name, value) { finalFixes = finalFixes};21 Tag t = new Tag(name, value) {globalFinalFixes = finalFixes}; 21 22 customValues.Add(t); 22 23 } … … 30 31 public delegate void Thunk(); 31 32 32 public class De Serializer {33 public class Deserializer { 33 34 34 35 private readonly Dictionary<int, object> id2obj; … … 38 39 private List<Thunk> finalFixes; 39 40 40 public De Serializer(41 public Deserializer( 41 42 IEnumerable<TypeMapping> typeCache) { 42 43 id2obj = new Dictionary<int, object>(); 43 44 parentStack = new Stack<CompositeObject>(); 44 45 typeIds = new Dictionary<int, Type>(); 45 serializerMapping = createSerializers(typeCache);46 serializerMapping = CreateSerializers(typeCache); 46 47 } 47 48 48 private Dictionary<Type, object> createSerializers(IEnumerable<TypeMapping> typeCache) {49 private Dictionary<Type, object> CreateSerializers(IEnumerable<TypeMapping> typeCache) { 49 50 var map = new Dictionary<Type, object>(); 50 51 foreach (var typeMapping in typeCache) { … … 59 60 } 60 61 61 public object De Serialize(IEnumerable<ISerializationToken> tokens) {62 public object Deserialize(IEnumerable<ISerializationToken> tokens) { 62 63 finalFixes = new List<Thunk>(); 63 64 foreach (ISerializationToken token in tokens) { -
trunk/sources/HeuristicLab.Persistence/3.3/Core/Serializer.cs
r1454 r1542 3 3 using System; 4 4 using HeuristicLab.Persistence.Interfaces; 5 using HeuristicLab.Persistence.Interfaces.Tokens; 5 6 6 7 namespace HeuristicLab.Persistence.Core { … … 49 50 50 51 public IEnumerator<ISerializationToken> GetEnumerator() { 51 DataMemberAccessor rootAccessor = new DataMemberAccessor( 52 rootName, null, () => obj, null); 53 IEnumerator<ISerializationToken> iterator = Serialize(rootAccessor); 54 while (iterator.MoveNext()) 55 yield return iterator.Current; 52 return Serialize(new DataMemberAccessor(rootName, null, () => obj, null)); 56 53 } 57 54 … … 75 72 IDecomposer decomposer = configuration.GetDecomposer(value.GetType()); 76 73 if (decomposer != null) 77 return CompositeEnumerator(accessor.Name, decomposer.De Compose(value), id, typeId);74 return CompositeEnumerator(accessor.Name, decomposer.Decompose(value), id, typeId); 78 75 throw new ApplicationException( 79 76 String.Format( … … 92 89 private IEnumerator<ISerializationToken> PrimitiveEnumerator(string name, 93 90 int typeId, object serializedValue, int? id) { 94 yield return new PrimitiveToken(name, typeId, serializedValue, id);91 yield return new PrimitiveToken(name, typeId, id, serializedValue); 95 92 } 96 93 -
trunk/sources/HeuristicLab.Persistence/3.3/Core/Tag.cs
r1454 r1542 4 4 5 5 public class Tag { 6 public List<Thunk> finalFixes;6 internal List<Thunk> globalFinalFixes; // reference to final fixes of Deserializer 7 7 public string Name { get; private set; } 8 public object Value ;8 public object Value { get; set; } 9 9 10 10 public Tag(string name, object value) { … … 17 17 } 18 18 public void SafeSet(Setter setter) { 19 if ( Value != null && Value.GetType() == typeof(ParentReference))20 finalFixes.Add(() => setter(Value));19 if ( Value as ParentReference != null) 20 globalFinalFixes.Add(() => setter(Value)); 21 21 else 22 22 setter(Value); -
trunk/sources/HeuristicLab.Persistence/3.3/Core/TypeMapping.cs
r1454 r1542 3 3 namespace HeuristicLab.Persistence.Core { 4 4 5 public structTypeMapping {5 public class TypeMapping { 6 6 public readonly int Id; 7 7 public readonly string TypeName;
Note: See TracChangeset
for help on using the changeset viewer.