Changeset 1406 for branches/New Persistence Exploration/Persistence
- Timestamp:
- 03/24/09 17:04:02 (16 years ago)
- Location:
- branches/New Persistence Exploration/Persistence
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/New Persistence Exploration/Persistence/HeuristicLab.Persistence.GUI/app.config
r1373 r1406 1 <?xml version="1.0" ?>1 <?xml version="1.0" encoding="utf-8" ?> 2 2 <configuration> 3 <startup><supportedRuntime version="v2.0.50727"/></startup></configuration> 3 <configSections> 4 <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" > 5 <section name="HeuristicLab.Persistence.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" /> 6 </sectionGroup> 7 </configSections> 8 <userSettings> 9 <HeuristicLab.Persistence.Properties.Settings> 10 <setting name="customConfigurations" serializeAs="String"> 11 <value /> 12 </setting> 13 <setting name="customConfigurationsTypeCache" serializeAs="String"> 14 <value /> 15 </setting> 16 </HeuristicLab.Persistence.Properties.Settings> 17 </userSettings> 18 </configuration> -
branches/New Persistence Exploration/Persistence/Persistence/Core/Configuration.cs
r1401 r1406 1 1 using System; 2 using System.Collections;3 2 using System.Collections.Generic; 4 3 using HeuristicLab.Persistence.Interfaces; … … 8 7 public class Configuration { 9 8 9 [Storable] 10 10 private readonly Dictionary<Type, IFormatter> formatters; 11 [Storable] 11 12 private readonly List<IDecomposer> decomposers; 12 13 private readonly Dictionary<Type, IDecomposer> decomposerCache; 14 [Storable] 13 15 public readonly IFormat Format; 16 17 private Configuration() {} 14 18 15 19 public Configuration(Dictionary<Type, IFormatter> formatters, IEnumerable<IDecomposer> decomposers) { … … 27 31 } 28 32 29 public IEnumerable Formatters {33 public IEnumerable<IFormatter> Formatters { 30 34 get { return formatters.Values; } 31 35 } -
branches/New Persistence Exploration/Persistence/Persistence/Core/ConfigurationService.cs
r1400 r1406 1 1 using System; 2 using System.Collections.Specialized; 3 using System.IO; 4 using System.Linq; 2 5 using System.Collections.Generic; 3 6 using System.Reflection; 7 using System.Text; 8 using HeuristicLab.Persistence.Default.Xml; 4 9 using HeuristicLab.Persistence.Interfaces; 5 10 … … 9 14 10 15 private static ConfigurationService instance; 11 private Dictionary<IFormat, Configuration> customConfigurations;16 private readonly Dictionary<IFormat, Configuration> customConfigurations; 12 17 public readonly Dictionary<IFormat, List<IFormatter>> Formatters; 13 18 public readonly List<IDecomposer> Decomposers; … … 24 29 Formatters = new Dictionary<IFormat, List<IFormatter>>(); 25 30 Decomposers = new List<IDecomposer>(); 26 customConfigurations = new Dictionary<IFormat, Configuration>(); 31 customConfigurations = new Dictionary<IFormat, Configuration>(); 27 32 Reset(); 33 LoadSettings(); 34 } 35 36 public void LoadSettings() { 37 if ( String.IsNullOrEmpty(Properties.Settings.Default.customConfigurations) || 38 String.IsNullOrEmpty(Properties.Settings.Default.customConfigurationsTypeCache) ) 39 return; 40 DeSerializer deSerializer = new DeSerializer( 41 XmlParser.ParseTypeCache( 42 new StringReader( 43 Properties.Settings.Default.customConfigurationsTypeCache))); 44 XmlParser parser = new XmlParser( 45 new StringReader( 46 Properties.Settings.Default.customConfigurations)); 47 var newCustomConfigurations = (Dictionary<IFormat, Configuration>) 48 deSerializer.DeSerialize(parser); 49 foreach ( var config in newCustomConfigurations ) { 50 customConfigurations[config.Key] = config.Value; 51 } 52 } 53 54 public void SaveSettings() { 55 Serializer serializer = new Serializer( 56 customConfigurations, 57 GetDefaultConfig(XmlFormat.Instance), 58 "CustomConfigurations"); 59 XmlGenerator generator = new XmlGenerator(); 60 StringBuilder configurationString = new StringBuilder(); 61 foreach (ISerializationToken token in serializer) { 62 configurationString.Append(generator.Format(token)); 63 } 64 StringBuilder configurationTypeCacheString = new StringBuilder(); 65 foreach (string s in generator.Format(serializer.TypeCache)) 66 configurationTypeCacheString.Append(s); 67 Properties.Settings.Default.customConfigurations = 68 configurationString.ToString(); 69 Properties.Settings.Default.customConfigurationsTypeCache = 70 configurationTypeCacheString.ToString(); 71 Properties.Settings.Default.Save(); 28 72 } 29 73 30 74 public void Reset() { 31 75 customConfigurations.Clear(); 76 Formatters.Clear(); 77 Decomposers.Clear(); 32 78 Assembly defaultAssembly = Assembly.GetExecutingAssembly(); 33 79 DiscoverFrom(defaultAssembly); … … 77 123 public void DefineConfiguration(IFormat format, Configuration configuration) { 78 124 customConfigurations[format] = configuration; 125 SaveSettings(); 79 126 } 80 127 -
branches/New Persistence Exploration/Persistence/Persistence/HeuristicLab.Persistence.csproj
r1400 r1406 45 45 <ItemGroup> 46 46 <Reference Include="System" /> 47 <Reference Include="System.configuration" /> 47 48 <Reference Include="System.Core"> 48 49 <RequiredTargetFramework>3.5</RequiredTargetFramework> … … 60 61 <Compile Include="Default\Decomposers\KeyValuePairDecomposer.cs" /> 61 62 <Compile Include="Default\Decomposers\DictionaryDecomposer.cs" /> 63 <Compile Include="Default\Decomposers\TypeDecomposer.cs" /> 62 64 <Compile Include="Default\Xml\Compact\IntArray2XmlFormatters.cs" /> 63 65 <Compile Include="Default\Xml\Compact\DoubleArray2XmlFormatters.cs" /> … … 81 83 <Compile Include="Core\Serializer.cs" /> 82 84 <Compile Include="Interfaces\Tokens.cs" /> 85 <Compile Include="Properties\Settings.Designer.cs"> 86 <AutoGen>True</AutoGen> 87 <DesignTimeSharedInput>True</DesignTimeSharedInput> 88 <DependentUpon>Settings.settings</DependentUpon> 89 </Compile> 83 90 <Compile Include="Util.cs" /> 84 91 <Compile Include="Core\StorableAttribute.cs" /> … … 97 104 </PropertyGroup> 98 105 <ItemGroup> 106 <None Include="app.config" /> 99 107 <None Include="HeuristicLab.snk" /> 108 <None Include="Properties\Settings.settings"> 109 <Generator>SettingsSingleFileGenerator</Generator> 110 <LastGenOutput>Settings.Designer.cs</LastGenOutput> 111 </None> 100 112 </ItemGroup> 101 113 <ItemGroup>
Note: See TracChangeset
for help on using the changeset viewer.