Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/24/09 17:04:02 (15 years ago)
Author:
epitzer
Message:

Incorporate settings infrastructure. (#506)

Location:
branches/New Persistence Exploration/Persistence/Persistence
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/New Persistence Exploration/Persistence/Persistence/Core/Configuration.cs

    r1401 r1406  
    11using System;
    2 using System.Collections;
    32using System.Collections.Generic;
    43using HeuristicLab.Persistence.Interfaces;
     
    87  public class Configuration {
    98
     9    [Storable]
    1010    private readonly Dictionary<Type, IFormatter> formatters;
     11    [Storable]
    1112    private readonly List<IDecomposer> decomposers;
    1213    private readonly Dictionary<Type, IDecomposer> decomposerCache;
     14    [Storable]
    1315    public readonly IFormat Format;
     16
     17    private Configuration() {}
    1418
    1519    public Configuration(Dictionary<Type, IFormatter> formatters, IEnumerable<IDecomposer> decomposers) {     
     
    2731    }
    2832
    29     public IEnumerable Formatters {
     33    public IEnumerable<IFormatter> Formatters {
    3034      get { return formatters.Values; }
    3135    }
  • branches/New Persistence Exploration/Persistence/Persistence/Core/ConfigurationService.cs

    r1400 r1406  
    11using System;
     2using System.Collections.Specialized;
     3using System.IO;
     4using System.Linq;
    25using System.Collections.Generic;
    36using System.Reflection;
     7using System.Text;
     8using HeuristicLab.Persistence.Default.Xml;
    49using HeuristicLab.Persistence.Interfaces;
    510
     
    914
    1015    private static ConfigurationService instance;
    11     private Dictionary<IFormat, Configuration> customConfigurations;
     16    private readonly Dictionary<IFormat, Configuration> customConfigurations;
    1217    public readonly Dictionary<IFormat, List<IFormatter>> Formatters;
    1318    public readonly List<IDecomposer> Decomposers;
     
    2429      Formatters = new Dictionary<IFormat, List<IFormatter>>();
    2530      Decomposers = new List<IDecomposer>();
    26       customConfigurations = new Dictionary<IFormat, Configuration>();
     31      customConfigurations = new Dictionary<IFormat, Configuration>();     
    2732      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();
    2872    }
    2973
    3074    public void Reset() {     
    3175      customConfigurations.Clear();
     76      Formatters.Clear();
     77      Decomposers.Clear();
    3278      Assembly defaultAssembly = Assembly.GetExecutingAssembly();
    3379      DiscoverFrom(defaultAssembly);
     
    77123    public void DefineConfiguration(IFormat format, Configuration configuration) {
    78124      customConfigurations[format] = configuration;
     125      SaveSettings();
    79126    }
    80127
  • branches/New Persistence Exploration/Persistence/Persistence/HeuristicLab.Persistence.csproj

    r1400 r1406  
    4545  <ItemGroup>
    4646    <Reference Include="System" />
     47    <Reference Include="System.configuration" />
    4748    <Reference Include="System.Core">
    4849      <RequiredTargetFramework>3.5</RequiredTargetFramework>
     
    6061    <Compile Include="Default\Decomposers\KeyValuePairDecomposer.cs" />
    6162    <Compile Include="Default\Decomposers\DictionaryDecomposer.cs" />
     63    <Compile Include="Default\Decomposers\TypeDecomposer.cs" />
    6264    <Compile Include="Default\Xml\Compact\IntArray2XmlFormatters.cs" />
    6365    <Compile Include="Default\Xml\Compact\DoubleArray2XmlFormatters.cs" />
     
    8183    <Compile Include="Core\Serializer.cs" />
    8284    <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>
    8390    <Compile Include="Util.cs" />
    8491    <Compile Include="Core\StorableAttribute.cs" />
     
    97104  </PropertyGroup>
    98105  <ItemGroup>
     106    <None Include="app.config" />
    99107    <None Include="HeuristicLab.snk" />
     108    <None Include="Properties\Settings.settings">
     109      <Generator>SettingsSingleFileGenerator</Generator>
     110      <LastGenOutput>Settings.Designer.cs</LastGenOutput>
     111    </None>
    100112  </ItemGroup>
    101113  <ItemGroup>
Note: See TracChangeset for help on using the changeset viewer.