Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/01/14 10:53:46 (10 years ago)
Author:
mkommend
Message:

#2206: Updated data preprocessing branch with trunk changes.

Location:
branches/DataPreprocessing
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/DataPreprocessing

  • branches/DataPreprocessing/HeuristicLab.Scripting/3.3/CSharpScript.cs

    r11009 r11064  
    7878    protected CSharpScript(CSharpScript original, Cloner cloner)
    7979      : base(original, cloner) {
    80       variableStore = new VariableStore();
     80      variableStore = cloner.Clone(original.variableStore);
    8181    }
    8282    public CSharpScript() {
  • branches/DataPreprocessing/HeuristicLab.Scripting/3.3/VariableStore.cs

    r10506 r11064  
    2020#endregion
    2121
     22using System;
     23using System.IO;
    2224using HeuristicLab.Collections;
    2325using HeuristicLab.Common;
    2426using HeuristicLab.Core;
     27using HeuristicLab.Persistence.Core;
    2528using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     29using HeuristicLab.Persistence.Default.Xml;
    2630
    2731namespace HeuristicLab.Scripting {
    2832  [Item("VariableStore", "Represents a variable store.")]
    2933  [StorableClass]
    30   public class VariableStore : ObservableDictionary<string, object>, IContent {
     34  public class VariableStore : ObservableDictionary<string, object>, IContent, IDeepCloneable {
    3135    [StorableConstructor]
    3236    protected VariableStore(bool deserializing) : base(deserializing) { }
     37    protected VariableStore(VariableStore original, Cloner cloner) {
     38      cloner.RegisterClonedObject(original, this);
     39      foreach (var kvp in original.dict) {
     40        var clonedValue = kvp.Value as IDeepCloneable;
     41        if (clonedValue != null) {
     42          dict[kvp.Key] = cloner.Clone(clonedValue);
     43        } else {
     44          try {
     45            dict[kvp.Key] = CloneByPersistence(kvp.Value);
     46          } catch (PersistenceException pe) {
     47            throw new NotSupportedException("VariableStore: Variable " + kvp.Key + " could not be cloned.", pe);
     48          }
     49        }
     50      }
     51    }
    3352    public VariableStore() : base() { }
     53
     54    public object Clone() {
     55      return Clone(new Cloner());
     56    }
     57    public IDeepCloneable Clone(Cloner cloner) {
     58      return new VariableStore(this, cloner);
     59    }
     60
     61    protected object CloneByPersistence(object value) {
     62      using (var serializerStream = new MemoryStream()) {
     63        XmlGenerator.Serialize(value, serializerStream);
     64        var bytes = serializerStream.GetBuffer();
     65        using (var deserializerStream = new MemoryStream(bytes)) {
     66          return XmlParser.Deserialize<VariableStore>(deserializerStream);
     67        }
     68      }
     69    }
    3470  }
    3571}
Note: See TracChangeset for help on using the changeset viewer.