Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/05/10 10:54:00 (14 years ago)
Author:
mkommend
Message:

Added persistence of Constraints to RunCollection (ticket #1124).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Optimization/3.3/RunCollection.cs

    r4068 r4164  
    3434  [StorableClass]
    3535  public class RunCollection : ItemCollection<IRun>, IStringConvertibleMatrix {
     36    [StorableConstructor]
     37    protected RunCollection(bool deserializing) : base(deserializing) { }
    3638    public RunCollection() : base() { Initialize(); }
    3739    public RunCollection(int capacity) : base(capacity) { Initialize(); }
     
    4244      dataTypes = new Dictionary<string, HashSet<Type>>();
    4345      constraints = new RunCollectionConstraintCollection();
    44       constraints.ItemsAdded += new CollectionItemsChangedEventHandler<IRunCollectionConstraint>(Constraints_ItemsAdded);
    45       constraints.ItemsRemoved += new CollectionItemsChangedEventHandler<IRunCollectionConstraint>(Constraints_ItemsRemoved);
    46       constraints.CollectionReset += new CollectionItemsChangedEventHandler<IRunCollectionConstraint>(Constraints_CollectionReset);
    47     }
     46      RegisterConstraintsEvents();
     47    }
     48
    4849    [Storable]
    4950    private Dictionary<string, HashSet<Type>> dataTypes;
     
    5354      return dataTypes[columnName];
    5455    }
     56
     57    [Storable]
    5558    private RunCollectionConstraintCollection constraints;
    5659    public RunCollectionConstraintCollection Constraints {
     
    160163    }
    161164
     165    [StorableHook(HookType.AfterDeserialization)]
     166    private void AfterDeserializationHook() {
     167      if (constraints == null) constraints = new RunCollectionConstraintCollection();
     168      RegisterConstraintsEvents();
     169      UpdateFiltering(true);
     170    }
    162171
    163172    public override IDeepCloneable Clone(Cloner cloner) {
     
    168177      foreach (string s in this.dataTypes.Keys)
    169178        clone.dataTypes[s] = new HashSet<Type>(this.dataTypes[s]);
     179
     180      clone.constraints = new RunCollectionConstraintCollection(this.constraints.Select(x => (IRunCollectionConstraint)cloner.Clone(x)));
     181      foreach (IRunCollectionConstraint constraint in clone.constraints)
     182        constraint.ConstrainedValue = clone;
     183      clone.RegisterConstraintsEvents();
     184      clone.RegisterConstraintEvents(clone.constraints);
     185
     186      clone.UpdateFiltering(true);
    170187      return clone;
    171188    }
     
    261278    }
    262279
     280    private void RegisterConstraintsEvents() {
     281      constraints.ItemsAdded += new CollectionItemsChangedEventHandler<IRunCollectionConstraint>(Constraints_ItemsAdded);
     282      constraints.ItemsRemoved += new CollectionItemsChangedEventHandler<IRunCollectionConstraint>(Constraints_ItemsRemoved);
     283      constraints.CollectionReset += new CollectionItemsChangedEventHandler<IRunCollectionConstraint>(Constraints_CollectionReset);
     284    }
     285
    263286    protected virtual void RegisterConstraintEvents(IEnumerable<IRunCollectionConstraint> constraints) {
    264287      foreach (IRunCollectionConstraint constraint in constraints) {
Note: See TracChangeset for help on using the changeset viewer.