Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/29/10 19:47:39 (14 years ago)
Author:
mkommend
Message:

Refactored ExternalEvaluation.* and fixed some errors and warnings (ticket #922).

Location:
branches/CloningRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.3
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • branches/CloningRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.3/Converters/BoolConverter.cs

    r3881 r4682  
    2222using System;
    2323using System.Linq;
     24using HeuristicLab.Common;
    2425using HeuristicLab.Core;
    2526using HeuristicLab.Data;
     
    3132  public class BoolConverter : Item, IItemToSolutionMessageConverter {
    3233    private static readonly Type[] itemTypes = new Type[] { typeof(ValueTypeValue<bool>), typeof(ValueTypeArray<bool>), typeof(ValueTypeMatrix<bool>) };
     34    [StorableConstructor]
     35    protected BoolConverter(bool deserializing) : base(deserializing) { }
     36    protected BoolConverter(BoolConverter original, Cloner cloner) : base(original, cloner) { }
     37    public override IDeepCloneable Clone(Cloner cloner) {
     38      return new BoolConverter(this, cloner);
     39    }
     40    public BoolConverter() : base() { }
    3341
    3442    #region IItemToSolutionMessageConverter Members
    35    
     43
    3644    public Type[] ItemTypes {
    3745      get { return itemTypes; }
  • branches/CloningRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.3/Converters/DateTimeValueConverter.cs

    r4068 r4682  
    2121
    2222using System;
     23using HeuristicLab.Common;
    2324using HeuristicLab.Core;
    2425using HeuristicLab.Data;
     
    3031  public class DateTimeValueConverter : Item, IItemToSolutionMessageConverter {
    3132    private static readonly Type[] itemTypes = new Type[] { typeof(DateTimeValue) };
     33    [StorableConstructor]
     34    protected DateTimeValueConverter(bool deserializing) : base(deserializing) { }
     35    protected DateTimeValueConverter(DateTimeValueConverter original, Cloner cloner) : base(original, cloner) { }
     36    public override IDeepCloneable Clone(Cloner cloner) {
     37      return new DateTimeValueConverter(this, cloner);
     38    }
     39    public DateTimeValueConverter() : base() { }
    3240
    3341    #region IItemToSolutionMessageConverter Members
  • branches/CloningRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.3/Converters/DoubleConverter.cs

    r3881 r4682  
    2222using System;
    2323using System.Linq;
     24using HeuristicLab.Common;
    2425using HeuristicLab.Core;
    2526using HeuristicLab.Data;
     
    3233    private static readonly Type[] itemTypes = new Type[] { typeof(ValueTypeValue<double>), typeof(ValueTypeArray<double>), typeof(ValueTypeMatrix<double>) };
    3334
     35    [StorableConstructor]
     36    protected DoubleConverter(bool deserializing) : base(deserializing) { }
     37    protected DoubleConverter(DoubleConverter original, Cloner cloner) : base(original, cloner) { }
     38    public override IDeepCloneable Clone(Cloner cloner) {
     39      return new DoubleConverter(this, cloner);
     40    }
     41    public DoubleConverter() : base() { }
     42
    3443    #region IItemToSolutionMessageConverter Members
    35    
     44
    3645    public Type[] ItemTypes {
    3746      get { return itemTypes; }
  • branches/CloningRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.3/Converters/IntegerConverter.cs

    r3881 r4682  
    2222using System;
    2323using System.Linq;
     24using HeuristicLab.Common;
    2425using HeuristicLab.Core;
    2526using HeuristicLab.Data;
     
    3233    private static readonly Type[] itemTypes = new Type[] { typeof(ValueTypeValue<int>), typeof(ValueTypeArray<int>), typeof(ValueTypeMatrix<int>) };
    3334
     35    [StorableConstructor]
     36    protected IntegerConverter(bool deserializing) : base(deserializing) { }
     37    protected IntegerConverter(IntegerConverter original, Cloner cloner) : base(original, cloner) { }
     38    public override IDeepCloneable Clone(Cloner cloner) {
     39      return new IntegerConverter(this, cloner);
     40    }
     41    public IntegerConverter() : base() { }
     42
    3443    #region IItemToSolutionMessageConverter Members
    35    
     44
    3645    public Type[] ItemTypes {
    3746      get { return itemTypes; }
  • branches/CloningRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.3/Converters/StringConverter.cs

    r4068 r4682  
    2121
    2222using System;
     23using HeuristicLab.Common;
    2324using HeuristicLab.Core;
    2425using HeuristicLab.Data;
     
    3031  public class StringConverter : Item, IItemToSolutionMessageConverter {
    3132    private static readonly Type[] itemTypes = new Type[] { typeof(StringValue), typeof(StringArray), typeof(StringMatrix), typeof(IStringConvertibleValue), typeof(IStringConvertibleArray), typeof(IStringConvertibleMatrix) };
     33
     34    [StorableConstructor]
     35    protected StringConverter(bool deserializing) : base(deserializing) { }
     36    protected StringConverter(StringConverter original, Cloner cloner) : base(original, cloner) { }
     37    public override IDeepCloneable Clone(Cloner cloner) {
     38      return new StringConverter(this, cloner);
     39    }
     40    public StringConverter() : base() { }
    3241
    3342    #region IItemToSolutionMessageConverter Members
  • branches/CloningRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.3/Converters/TimeSpanValueConverter.cs

    r4068 r4682  
    2121
    2222using System;
     23using HeuristicLab.Common;
    2324using HeuristicLab.Core;
    2425using HeuristicLab.Data;
     
    3031  public class TimeSpanValueConverter : Item, IItemToSolutionMessageConverter {
    3132    private static readonly Type[] itemTypes = new Type[] { typeof(TimeSpanValue) };
     33
     34    [StorableConstructor]
     35    protected TimeSpanValueConverter(bool deserializing) : base(deserializing) { }
     36    protected TimeSpanValueConverter(TimeSpanValueConverter original, Cloner cloner) : base(original, cloner) { }
     37    public override IDeepCloneable Clone(Cloner cloner) {
     38      return new TimeSpanValueConverter(this, cloner);
     39    }
     40    public TimeSpanValueConverter() : base() { }
    3241
    3342    #region IItemToSolutionMessageConverter Members
  • branches/CloningRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.3/Drivers/EvaluationChannel.cs

    r4068 r4682  
    2121
    2222using Google.ProtocolBuffers;
     23using HeuristicLab.Common;
    2324using HeuristicLab.Core;
    2425using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    3334    [StorableConstructor]
    3435    protected EvaluationChannel(bool deserializing) : base(deserializing) { }
     36    protected EvaluationChannel(EvaluationChannel original, Cloner cloner) : base(original, cloner) { }
    3537    protected EvaluationChannel()
    3638      : base() {
  • branches/CloningRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.3/Drivers/EvaluationProcessChannel.cs

    r3895 r4682  
    5858    private EvaluationStreamChannel streamingChannel;
    5959
     60    [StorableConstructor]
     61    protected EvaluationProcessChannel(bool deserializing) : base(deserializing) { }
     62    protected EvaluationProcessChannel(EvaluationProcessChannel original, Cloner cloner)
     63      : base(original, cloner) {
     64      executable = original.executable;
     65      arguments = original.arguments;
     66    }
     67    public override IDeepCloneable Clone(Cloner cloner) {
     68      return new EvaluationProcessChannel(this, cloner);
     69    }
     70
    6071    public EvaluationProcessChannel() : this(String.Empty, String.Empty) { }
    6172    public EvaluationProcessChannel(string executable, string arguments)
     
    6374      this.executable = executable;
    6475      this.arguments = arguments;
    65     }
    66 
    67     public override IDeepCloneable Clone(Cloner cloner) {
    68       EvaluationProcessChannel clone = (EvaluationProcessChannel)base.Clone(cloner);
    69       clone.executable = executable;
    70       clone.arguments = arguments;
    71       return clone;
    7276    }
    7377
     
    96100      try {
    97101        streamingChannel.Send(message);
    98       } catch {
     102      }
     103      catch {
    99104        Close();
    100105        throw;
     
    105110      try {
    106111        return streamingChannel.Receive(builder);
    107       } catch {
     112      }
     113      catch {
    108114        Close();
    109115        throw;
     
    121127              process.WaitForExit(1000);
    122128              process.Close();
    123             } catch { }
     129            }
     130            catch { }
    124131          }
    125132          // for some reasons the event process_Exited does not fire
  • branches/CloningRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.3/Drivers/EvaluationServiceClient.cs

    r4068 r4682  
    2121
    2222using System;
     23using HeuristicLab.Common;
    2324using HeuristicLab.Core;
    2425using HeuristicLab.Data;
     
    4445    }
    4546
     47
     48    [StorableConstructor]
     49    protected EvaluationServiceClient(bool deserializing) : base(deserializing) { }
     50    protected EvaluationServiceClient(EvaluationServiceClient original, Cloner cloner) : base(original, cloner) { }
     51    public override IDeepCloneable Clone(Cloner cloner) {
     52      return new EvaluationServiceClient(this, cloner);
     53    }
    4654    public EvaluationServiceClient()
    4755      : base() {
  • branches/CloningRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.3/Drivers/EvaluationStreamChannel.cs

    r3872 r4682  
    2323using System.IO;
    2424using Google.ProtocolBuffers;
     25using HeuristicLab.Common;
    2526using HeuristicLab.Core;
    2627using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    3334    private Stream input;
    3435    private Stream output;
     36
     37    [StorableConstructor]
     38    protected EvaluationStreamChannel(bool deserializing) : base(deserializing) { }
     39    protected EvaluationStreamChannel(EvaluationStreamChannel original, Cloner cloner) : base(original, cloner) { }
     40    public override IDeepCloneable Clone(Cloner cloner) {
     41      return new EvaluationStreamChannel(this, cloner);
     42    }
    3543
    3644    public EvaluationStreamChannel() : base() { }
  • branches/CloningRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.3/Drivers/EvaluationTCPChannel.cs

    r3895 r4682  
    5858    private Socket socket;
    5959
     60    [StorableConstructor]
     61    protected EvaluationTCPChannel(bool deserializing) : base(deserializing) { }
     62    protected EvaluationTCPChannel(EvaluationTCPChannel original, Cloner cloner)
     63      : base(original, cloner) {
     64      ipAddress = original.ipAddress;
     65      port = original.port;
     66    }
     67    public override IDeepCloneable Clone(Cloner cloner) {
     68      return new EvaluationTCPChannel(this, cloner);
     69    }
     70
    6071    public EvaluationTCPChannel() : this(String.Empty, 0) { }
    6172    public EvaluationTCPChannel(string ip, int port)
     
    6374      this.ipAddress = ip;
    6475      this.port = port;
    65     }
    66 
    67     public override IDeepCloneable Clone(Cloner cloner) {
    68       EvaluationTCPChannel clone = (EvaluationTCPChannel)base.Clone(cloner);
    69       clone.ipAddress = ipAddress;
    70       clone.port = port;
    71       return clone;
    7276    }
    7377
     
    8791        byte[] buffer = EncodeDelimited(message);
    8892        socket.Send(buffer);
    89       } catch (SocketException) {
    90         Close();
    91         throw;
    92       } catch (ObjectDisposedException) {
     93      }
     94      catch (SocketException) {
     95        Close();
     96        throw;
     97      }
     98      catch (ObjectDisposedException) {
    9399        socket = null;
    94100        Close();
     
    122128        byte[] buffer = GetMessageBuffer();
    123129        return builder.WeakMergeFrom(ByteString.CopyFrom(buffer)).WeakBuild();
    124       } catch (SocketException) {
    125         Close();
    126         throw;
    127       } catch (ObjectDisposedException) {
     130      }
     131      catch (SocketException) {
     132        Close();
     133        throw;
     134      }
     135      catch (ObjectDisposedException) {
    128136        socket = null;
    129137        Close();
     
    164172            socket.Disconnect(false);
    165173          socket.Close();
    166         } catch { }
     174        }
     175        catch { }
    167176        socket = null;
    168177      }
  • branches/CloningRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.3/ExternalEvaluationProblem.cs

    r4419 r4682  
    124124    [StorableConstructor]
    125125    private ExternalEvaluationProblem(bool deserializing) : base(deserializing) { }
     126    [StorableHook(HookType.AfterDeserialization)]
     127    private void AfterDeserializationHook() {
     128      AttachEventHandlers();
     129    }
     130
     131    private ExternalEvaluationProblem(ExternalEvaluationProblem original, Cloner cloner)
     132      : base(original, cloner) {
     133      AttachEventHandlers();
     134    }
     135    public override IDeepCloneable Clone(Cloner cloner) {
     136      return new ExternalEvaluationProblem(this, cloner);
     137    }
    126138    public ExternalEvaluationProblem()
    127139      : base() {
     
    141153    }
    142154
    143     public override IDeepCloneable Clone(Cloner cloner) {
    144       ExternalEvaluationProblem clone = (ExternalEvaluationProblem)base.Clone(cloner);
    145       clone.AttachEventHandlers();
    146       return clone;
    147     }
    148 
    149155    #region Events
    150156    public event EventHandler SolutionCreatorChanged;
     
    194200    #endregion
    195201
    196     #region Helpers
    197     [StorableHook(HookType.AfterDeserialization)]
    198     private void AfterDeserializationHook() {
    199       AttachEventHandlers();
    200     }
    201 
     202    #region Helper
    202203    private void AttachEventHandlers() {
    203204      SolutionCreatorParameter.ValueChanged += new EventHandler(SolutionCreatorParameter_ValueChanged);
  • branches/CloningRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.3/ExternalEvaluator.cs

    r3881 r4682  
    2121
    2222using System;
     23using HeuristicLab.Common;
    2324using HeuristicLab.Core;
    2425using HeuristicLab.Data;
     
    4647    }
    4748
     49    [StorableConstructor]
     50    protected ExternalEvaluator(bool deserializing) : base(deserializing) { }
     51    protected ExternalEvaluator(ExternalEvaluator original, Cloner cloner) : base(original, cloner) { }
     52    public override IDeepCloneable Clone(Cloner cloner) {
     53      return new ExternalEvaluator(this, cloner);
     54    }
    4855    public ExternalEvaluator()
    4956      : base() {
     
    6471          try {
    6572            MessageBuilder.AddToMessage(value, name, protobufBuilder);
    66           } catch (ArgumentException ex) {
     73          }
     74          catch (ArgumentException ex) {
    6775            throw new InvalidOperationException("ERROR in " + Name + ": Parameter " + name + " cannot be added to the message.", ex);
    6876          }
  • branches/CloningRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.3/SolutionMessageBuilder.cs

    r4643 r4682  
    5050    [StorableConstructor]
    5151    protected SolutionMessageBuilder(bool deserializing) : base(deserializing) { }
     52    [StorableHook(HookType.AfterDeserialization)]
     53    private void AfterDeserialization() {
     54      AttachEventHandlers();
     55    }
     56
     57    protected SolutionMessageBuilder(SolutionMessageBuilder original, Cloner cloner)
     58      : base(original, cloner) {
     59      convertersList = cloner.Clone(original.convertersList);
     60      AttachEventHandlers();
     61    }
     62    public override IDeepCloneable Clone(Cloner cloner) {
     63      return new SolutionMessageBuilder(this, cloner);
     64    }
    5265    public SolutionMessageBuilder()
    5366      : base() {
     
    6376
    6477      AttachEventHandlers();
    65     }
    66 
    67     public override IDeepCloneable Clone(Cloner cloner) {
    68       SolutionMessageBuilder clone = (SolutionMessageBuilder)base.Clone(cloner);
    69       clone.convertersList = (CheckedItemList<IItemToSolutionMessageConverter>)cloner.Clone(convertersList);
    70       clone.AttachEventHandlers();
    71       return clone;
    7278    }
    7379
     
    8793    }
    8894
    89     [StorableHook(HookType.AfterDeserialization)]
    9095    private void AttachEventHandlers() {
    9196      // BackwardsCompatibility3.3
    9297      #region Backwards compatible code, remove with 3.4
    93       #pragma warning disable 0612
     98#pragma warning disable 0612
    9499      if (converters != null) {
    95100        if (convertersList == null) convertersList = new CheckedItemList<IItemToSolutionMessageConverter>();
     
    99104        converters = null;
    100105      }
    101       #pragma warning restore 0612
     106#pragma warning restore 0612
    102107      #endregion
    103108      convertersList.ItemsAdded += new CollectionItemsChangedEventHandler<IndexedItem<IItemToSolutionMessageConverter>>(convertersList_Changed);
Note: See TracChangeset for help on using the changeset viewer.