Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/22/11 17:11:27 (13 years ago)
Author:
epitzer
Message:

Automatically generate TCPChannel, ProcessChannel and ServiceClient names form parameters (#1526).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.3/Drivers/EvaluationServiceClient.cs

    r5445 r6470  
    3131  [StorableClass]
    3232  public class EvaluationServiceClient : ParameterizedNamedItem, IEvaluationServiceClient {
     33
    3334    public override bool CanChangeName { get { return false; } }
    3435    public override bool CanChangeDescription { get { return false; } }
    3536
     37    #region Parameters
    3638    public IValueParameter<IEvaluationChannel> ChannelParameter {
    3739      get { return (IValueParameter<IEvaluationChannel>)Parameters["Channel"]; }
     
    4446      get { return ChannelParameter.Value; }
    4547    }
     48    #endregion
    4649
    4750
     51    #region Construction & Cloning
    4852    [StorableConstructor]
    4953    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     }
     54    protected EvaluationServiceClient(EvaluationServiceClient original, Cloner cloner) : base(original, cloner) {
     55      RegisterEvents();
     56    }   
    5457    public EvaluationServiceClient()
    5558      : base() {
    5659      Parameters.Add(new ValueParameter<IEvaluationChannel>("Channel", "The channel over which to call the remote function."));
    5760      Parameters.Add(new ValueParameter<IntValue>("Retry", "How many times the client should retry obtaining a quality in case there is an exception. Note that it immediately aborts when the channel cannot be opened.", new IntValue(10)));
     61      RegisterEvents();
    5862    }
     63    public override IDeepCloneable Clone(Cloner cloner) {
     64      return new EvaluationServiceClient(this, cloner);
     65    }
     66    [StorableHook(HookType.AfterDeserialization)]
     67    private void AfterDeserialization() {
     68      ChannelParameter_ValueChanged(this, EventArgs.Empty);
     69      RegisterEvents();
     70    }
     71    #endregion
    5972
    6073    #region IEvaluationServiceClient Members
    61 
    6274    public QualityMessage Evaluate(SolutionMessage solution) {
    6375      int tries = 0, maxTries = RetryParameter.Value.Value;
     
    103115      System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(ReceiveAsync), callback);
    104116    }
    105 
    106117    #endregion
    107118
     119    #region Auxiliary Methods
    108120    private void CheckAndOpenChannel() {
    109121      if (Channel == null) throw new InvalidOperationException(Name + ": The channel is not defined.");
     
    126138      ((Action<QualityMessage>)callback).Invoke(message);
    127139    }
     140
     141    private void RegisterEvents() {
     142      ChannelParameter.ValueChanged += new EventHandler(ChannelParameter_ValueChanged);
     143    }
     144
     145    void ChannelParameter_ValueChanged(object sender, EventArgs e) {
     146      if (ChannelParameter.Value == null)
     147        name = "Empty EvaluationServiceClient";
     148      else
     149        name = String.Format("{0} ServiceClient", ChannelParameter.Value.Name);
     150      OnNameChanged();
     151    }
     152    #endregion
    128153  }
    129154}
Note: See TracChangeset for help on using the changeset viewer.