Changeset 6470 for trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.3/Drivers/EvaluationServiceClient.cs
- Timestamp:
- 06/22/11 17:11:27 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.3/Drivers/EvaluationServiceClient.cs
r5445 r6470 31 31 [StorableClass] 32 32 public class EvaluationServiceClient : ParameterizedNamedItem, IEvaluationServiceClient { 33 33 34 public override bool CanChangeName { get { return false; } } 34 35 public override bool CanChangeDescription { get { return false; } } 35 36 37 #region Parameters 36 38 public IValueParameter<IEvaluationChannel> ChannelParameter { 37 39 get { return (IValueParameter<IEvaluationChannel>)Parameters["Channel"]; } … … 44 46 get { return ChannelParameter.Value; } 45 47 } 48 #endregion 46 49 47 50 51 #region Construction & Cloning 48 52 [StorableConstructor] 49 53 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 } 54 57 public EvaluationServiceClient() 55 58 : base() { 56 59 Parameters.Add(new ValueParameter<IEvaluationChannel>("Channel", "The channel over which to call the remote function.")); 57 60 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(); 58 62 } 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 59 72 60 73 #region IEvaluationServiceClient Members 61 62 74 public QualityMessage Evaluate(SolutionMessage solution) { 63 75 int tries = 0, maxTries = RetryParameter.Value.Value; … … 103 115 System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(ReceiveAsync), callback); 104 116 } 105 106 117 #endregion 107 118 119 #region Auxiliary Methods 108 120 private void CheckAndOpenChannel() { 109 121 if (Channel == null) throw new InvalidOperationException(Name + ": The channel is not defined."); … … 126 138 ((Action<QualityMessage>)callback).Invoke(message); 127 139 } 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 128 153 } 129 154 }
Note: See TracChangeset
for help on using the changeset viewer.