Changeset 5955 for branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ServiceClients
- Timestamp:
- 04/05/11 15:37:04 (13 years ago)
- Location:
- branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ServiceClients
- Files:
-
- 2 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ServiceClients/Appointment.cs
r5779 r5955 37 37 } 38 38 39 public IDeepCloneable Clone(Cloner cloner) {39 public override IDeepCloneable Clone(Cloner cloner) { 40 40 return new Appointment(this, cloner); 41 }42 43 public object Clone() {44 return Clone(new Cloner());45 41 } 46 42 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ServiceClients/HiveExperiment.cs
r5779 r5955 20 20 #endregion 21 21 22 using System; 23 using System.Collections.Generic; 24 using System.ComponentModel; 25 using System.Linq; 26 using HeuristicLab.Clients.Hive.Jobs; 22 27 using HeuristicLab.Common; 28 using HeuristicLab.Core; 29 using HeuristicLab.Optimization; 23 30 24 31 namespace HeuristicLab.Clients.Hive { 25 32 26 public partial class HiveExperiment : IDeepCloneable, IContent { 27 28 public HiveExperiment() { } 33 public partial class HiveExperiment : IDeepCloneable, IContent, IProgressReporter { 34 private JobResultPoller jobResultPoller; 35 36 private bool useLocalPlugins; 37 public bool UseLocalPlugins { 38 get { return useLocalPlugins; } 39 set { useLocalPlugins = value; } 40 } 41 42 private ExecutionState executionState; 43 public ExecutionState ExecutionState { 44 get { return executionState; } 45 internal set { 46 if (executionState != value) { 47 executionState = value; 48 OnExecutionStateChanged(); 49 } 50 } 51 } 52 53 private TimeSpan executionTime; 54 public TimeSpan ExecutionTime { 55 get { return executionTime; } 56 internal set { 57 if (executionTime != value) { 58 executionTime = value; 59 OnExecutionTimeChanged(); 60 } 61 } 62 } 63 64 private HiveJob hiveJob; 65 public HiveJob HiveJob { 66 get { return hiveJob; } 67 set { 68 DeregisterHiveJobEvents(); 69 if (hiveJob != value) { 70 hiveJob = value; 71 RegisterHiveJobEvents(); 72 OnHiveJobChanged(); 73 } 74 } 75 } 76 77 private bool isProgressing; 78 public bool IsProgressing { 79 get { return isProgressing; } 80 set { 81 if (isProgressing != value) { 82 isProgressing = value; 83 OnIsProgressingChanged(); 84 } 85 } 86 } 87 88 /** include jobs when refreshing **/ 89 private bool includeJobs; 90 public bool IncludeJobs { 91 get { return includeJobs; } 92 set { includeJobs = value; } 93 } 94 95 private bool refreshAutomatically; 96 public bool RefreshAutomatically { 97 get { return refreshAutomatically; } 98 set { 99 if (refreshAutomatically != value) { 100 refreshAutomatically = value; 101 OnRefreshAutomaticallyChanged(); 102 if (RefreshAutomatically) { 103 StartResultPolling(); 104 } else { 105 StopResultPolling(); 106 } 107 } 108 } 109 } 110 111 private IProgress progress; 112 public IProgress Progress { 113 get { return progress; } 114 set { this.progress = value; } 115 } 116 117 #region Constructors and Cloning 118 public HiveExperiment() { 119 this.ResourceNames = "HEAL"; 120 this.includeJobs = true; 121 this.refreshAutomatically = true; 122 } 29 123 30 124 protected HiveExperiment(HiveExperiment original, Cloner cloner) { … … 38 132 this.Description = original.Description; 39 133 this.Id = original.Id; 40 } 41 public IDeepCloneable Clone(Cloner cloner) { 134 135 this.UseLocalPlugins = original.UseLocalPlugins; 136 this.ExecutionTime = original.ExecutionTime; 137 } 138 public override IDeepCloneable Clone(Cloner cloner) { 42 139 return new HiveExperiment(this, cloner); 43 140 } 141 #endregion 44 142 45 143 public override string ToString() { 46 return base.ToString() + "Name: " + Name + ", Description: " + Description; 47 } 48 49 public object Clone() { 50 return Clone(new Cloner()); 144 return Name; 145 } 146 147 #region Events 148 public event EventHandler ExecutionTimeChanged; 149 private void OnExecutionTimeChanged() { 150 EventHandler handler = ExecutionTimeChanged; 151 if (handler != null) handler(this, EventArgs.Empty); 152 } 153 154 public event EventHandler ExecutionStateChanged; 155 private void OnExecutionStateChanged() { 156 EventHandler handler = ExecutionStateChanged; 157 if (handler != null) handler(this, EventArgs.Empty); 158 } 159 160 public event EventHandler HiveJobChanged; 161 private void OnHiveJobChanged() { 162 if (jobResultPoller != null && jobResultPoller.IsPolling) { 163 jobResultPoller.Stop(); 164 DeregisterResultPollingEvents(); 165 } 166 if (HiveJob != null && HiveJob.Job.Id != Guid.Empty) { 167 if (this.RefreshAutomatically) 168 StartResultPolling(); 169 } 170 EventHandler handler = HiveJobChanged; 171 if (handler != null) handler(this, EventArgs.Empty); 172 } 173 174 public event EventHandler IsProgressingChanged; 175 private void OnIsProgressingChanged() { 176 EventHandler handler = IsProgressingChanged; 177 if (handler != null) handler(this, EventArgs.Empty); 178 } 179 180 public event EventHandler RefreshAutomaticallyChanged; 181 private void OnRefreshAutomaticallyChanged() { 182 EventHandler handler = RefreshAutomaticallyChanged; 183 if (handler != null) handler(this, EventArgs.Empty); 184 } 185 #endregion 186 187 private void RegisterHiveJobEvents() { 188 if (HiveJob != null) { 189 HiveJob.JobStateChanged += new EventHandler(HiveJob_JobStateChanged); 190 } 191 } 192 193 private void DeregisterHiveJobEvents() { 194 if (HiveJob != null) { 195 HiveJob.JobStateChanged -= new EventHandler(HiveJob_JobStateChanged); 196 } 197 } 198 199 private void HiveJob_JobStateChanged(object sender, EventArgs e) { 200 if (this.HiveJob != null) { 201 this.RootJobId = HiveJob.Job.Id; 202 } 203 } 204 205 public Experiment GetExperiment() { 206 if (this.HiveJob != null) { 207 return HiveJob.OptimizerJob.OptimizerAsExperiment; 208 } 209 return null; 210 } 211 212 public void SetExperiment(Experiment experiment) { 213 this.HiveJob = new HiveJob(experiment); 214 } 215 216 protected override void OnPropertyChanged(PropertyChangedEventArgs e) { 217 base.OnPropertyChanged(e); 218 if (e.PropertyName == "Name") { 219 OnToStringChanged(); 220 } 221 } 222 223 #region JobResultPoller Events 224 225 public void StartResultPolling() { 226 if (jobResultPoller == null) { 227 jobResultPoller = new JobResultPoller(HiveJob, /*ApplicationConstants.ResultPollingInterval*/new TimeSpan(0, 0, 5)); //TODO: find a better place for ApplicationConstants 228 RegisterResultPollingEvents(); 229 } 230 231 if (!jobResultPoller.IsPolling) { 232 jobResultPoller.Start(); 233 } 234 } 235 236 public void StopResultPolling() { 237 if (jobResultPoller.IsPolling) { 238 jobResultPoller.Stop(); 239 } 240 } 241 242 private void RegisterResultPollingEvents() { 243 jobResultPoller.ExceptionOccured += new EventHandler<EventArgs<Exception>>(jobResultPoller_ExceptionOccured); 244 jobResultPoller.JobResultsReceived += new EventHandler<EventArgs<IEnumerable<LightweightJob>>>(jobResultPoller_JobResultReceived); 245 jobResultPoller.IsPollingChanged += new EventHandler(jobResultPoller_IsPollingChanged); 246 } 247 private void DeregisterResultPollingEvents() { 248 jobResultPoller.ExceptionOccured -= new EventHandler<EventArgs<Exception>>(jobResultPoller_ExceptionOccured); 249 jobResultPoller.JobResultsReceived -= new EventHandler<EventArgs<IEnumerable<LightweightJob>>>(jobResultPoller_JobResultReceived); 250 jobResultPoller.IsPollingChanged -= new EventHandler(jobResultPoller_IsPollingChanged); 251 } 252 private void jobResultPoller_IsPollingChanged(object sender, EventArgs e) { 253 this.refreshAutomatically = jobResultPoller.IsPolling; 254 OnRefreshAutomaticallyChanged(); 255 } 256 private void jobResultPoller_JobResultReceived(object sender, EventArgs<IEnumerable<LightweightJob>> e) { 257 foreach (LightweightJob lightweightJob in e.Value) { 258 HiveJob hj = hiveJob.GetHiveJobByJobId(lightweightJob.Id); 259 if (hj != null) { 260 DateTime lastJobDataUpdate = hj.Job.LastJobDataUpdate; 261 hj.UpdateFromLightweightJob(lightweightJob); 262 263 // lastJobDataUpdate equals DateTime.MinValue right after it was uploaded. When the first results are polled, this value is updated 264 if (lastJobDataUpdate != DateTime.MinValue && lastJobDataUpdate < hj.Job.LastJobDataUpdate) { 265 OptimizerJob optimizerJob = ExperimentManagerClient.LoadOptimizerJob(hj.Job.Id); 266 if (optimizerJob == null) { 267 // something bad happened to this job. bad job, BAAAD job! 268 } else { 269 // if the job is paused, download but don't integrate into parent optimizer (to avoid Prepare) 270 if (hj.Job.State == JobState.Paused) { 271 hj.OptimizerJob = optimizerJob; 272 } else { 273 if (lightweightJob.ParentJobId.HasValue) { 274 HiveJob parentHiveJob = HiveJob.GetHiveJobByJobId(lightweightJob.ParentJobId.Value); 275 parentHiveJob.UpdateChildOptimizer(optimizerJob, hj.Job.Id); 276 } 277 } 278 } 279 } 280 } 281 } 282 GC.Collect(); // force GC, because .NET is too lazy here (deserialization takes a lot of memory) 283 if (AllJobsFinished()) { 284 this.ExecutionState = Core.ExecutionState.Stopped; 285 StopResultPolling(); 286 //OnStopped(); 287 } 288 UpdateTotalExecutionTime(); 289 UpdateStats(); 290 } 291 292 private void UpdateStats() { 293 var jobs = HiveJob.GetAllHiveJobs(); 294 this.JobCount = jobs.Count(); 295 this.CalculatingCount = jobs.Count(j => j.Job.State == JobState.Calculating); 296 this.FinishedCount = jobs.Count(j => j.Job.State == JobState.Finished); 297 } 298 299 private bool AllJobsFinished() { 300 return HiveJob.GetAllHiveJobs().All(j => j.Job.State == JobState.Finished 301 || j.Job.State == JobState.Aborted 302 || j.Job.State == JobState.Failed); 303 } 304 305 private void jobResultPoller_ExceptionOccured(object sender, EventArgs<Exception> e) { 306 //OnExceptionOccured(e.Value); 307 } 308 309 public void UpdateTotalExecutionTime() { 310 this.ExecutionTime = TimeSpan.FromMilliseconds(HiveJob.GetAllHiveJobs().Sum(x => x.Job.ExecutionTime.HasValue ? x.Job.ExecutionTime.Value.TotalMilliseconds : 0)); 311 } 312 #endregion 313 314 protected override void RaisePropertyChanged(string propertyName) { 315 if (!(propertyName == "ExecutionTime") 316 && !(propertyName == "JobCount") 317 && !(propertyName == "CalculatingCount") 318 && !(propertyName == "FinishedCount")) { 319 base.RaisePropertyChanged(propertyName); 320 } 51 321 } 52 322 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ServiceClients/HiveItem.cs
r5718 r5955 23 23 using System.ComponentModel; 24 24 using System.Drawing; 25 using System.Runtime.Serialization; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; … … 28 29 namespace HeuristicLab.Clients.Hive { 29 30 30 public partial class HiveItem : IItem { 31 public partial class HiveItem : IHiveItem { 32 public string ItemName { 33 get { return ItemAttribute.GetName(this.GetType()); } 34 } 35 public string ItemDescription { 36 get { return ItemAttribute.GetDescription(this.GetType()); } 37 } 38 public Version ItemVersion { 39 get { return ItemAttribute.GetVersion(this.GetType()); } 40 } 41 public virtual Image ItemImage { 42 get { 43 if (Modified) 44 return HeuristicLab.Common.Resources.VSImageLibrary.DatabaseModified; 45 else 46 return HeuristicLab.Common.Resources.VSImageLibrary.Database; 47 } 48 } 31 49 32 public HiveItem() { } 50 private bool modified; 51 public bool Modified { 52 get { return modified; } 53 private set { 54 if (value != modified) { 55 modified = value; 56 OnModifiedChanged(); 57 RaisePropertyChanged("Modified"); 58 OnItemImageChanged(); 59 RaisePropertyChanged("ItemImage"); 60 } 61 } 62 } 63 64 #region Constructor and Cloning 65 public HiveItem() { 66 modified = true; 67 } 68 69 [OnDeserialized] 70 private void OnDeserialized(StreamingContext context) { 71 modified = false; 72 } 33 73 34 74 protected HiveItem(HiveItem original, Cloner cloner) { 35 75 cloner.RegisterClonedObject(original, this); 36 76 this.Id = original.Id; 77 modified = true; 37 78 } 38 39 79 public virtual IDeepCloneable Clone(Cloner cloner) { 40 80 return new HiveItem(this, cloner); … … 44 84 return Clone(new Cloner()); 45 85 } 86 #endregion 46 87 47 protected void RaisePropertyChanged(string propertyName) { 88 public void Store() { 89 ExperimentManagerClient.Store(this); 90 Modified = false; 91 } 92 93 protected virtual void RaisePropertyChanged(string propertyName) { 48 94 OnPropertyChanged(new PropertyChangedEventArgs(propertyName)); 49 95 if ((propertyName != "Id") && (propertyName != "Modified") && (propertyName != "ItemImage")) { … … 56 102 } 57 103 58 #region IItem Members 59 public string ItemName { 60 get { return ItemAttribute.GetName(this.GetType()); } 61 } 62 public string ItemDescription { 63 get { return ItemAttribute.GetDescription(this.GetType()); } 64 } 65 public Version ItemVersion { 66 get { return ItemAttribute.GetVersion(this.GetType()); } 67 } 68 public Image ItemImage { 69 get { return HeuristicLab.Common.Resources.VSImageLibrary.Class; } 70 } 71 72 private bool modified; 73 public bool Modified { 74 get { return modified; } 75 private set { 76 if (value != modified) { 77 modified = value; 78 OnModifiedChanged(); 79 RaisePropertyChanged("Modified"); 80 //OnItemImageChanged(); ?? 81 //RaisePropertyChanged("ItemImage"); ?? 82 } 83 } 84 } 85 104 #region Event handler 86 105 public event EventHandler ItemImageChanged; 87 106 protected virtual void OnItemImageChanged() { … … 99 118 if (handler != null) handler(this, EventArgs.Empty); 100 119 } 120 #endregion 121 101 122 public override string ToString() { 102 123 return ItemName; 103 124 } 104 #endregion105 125 } 106 126 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ServiceClients/HiveServiceClient.cs
r5786 r5955 549 549 550 550 [System.Runtime.Serialization.OptionalFieldAttribute()] 551 private int CalculatingCountField; 552 553 [System.Runtime.Serialization.OptionalFieldAttribute()] 551 554 private System.DateTime DateCreatedField; 552 555 553 556 [System.Runtime.Serialization.OptionalFieldAttribute()] 557 private int FinishedCountField; 558 559 [System.Runtime.Serialization.OptionalFieldAttribute()] 560 private int JobCountField; 561 562 [System.Runtime.Serialization.OptionalFieldAttribute()] 554 563 private System.Nullable<System.DateTime> LastAccessedField; 555 564 … … 562 571 [System.Runtime.Serialization.OptionalFieldAttribute()] 563 572 private System.Guid RootJobIdField; 573 574 [System.Runtime.Serialization.DataMemberAttribute()] 575 public int CalculatingCount 576 { 577 get 578 { 579 return this.CalculatingCountField; 580 } 581 set 582 { 583 if ((this.CalculatingCountField.Equals(value) != true)) 584 { 585 this.CalculatingCountField = value; 586 this.RaisePropertyChanged("CalculatingCount"); 587 } 588 } 589 } 564 590 565 591 [System.Runtime.Serialization.DataMemberAttribute()] … … 576 602 this.DateCreatedField = value; 577 603 this.RaisePropertyChanged("DateCreated"); 604 } 605 } 606 } 607 608 [System.Runtime.Serialization.DataMemberAttribute()] 609 public int FinishedCount 610 { 611 get 612 { 613 return this.FinishedCountField; 614 } 615 set 616 { 617 if ((this.FinishedCountField.Equals(value) != true)) 618 { 619 this.FinishedCountField = value; 620 this.RaisePropertyChanged("FinishedCount"); 621 } 622 } 623 } 624 625 [System.Runtime.Serialization.DataMemberAttribute()] 626 public int JobCount 627 { 628 get 629 { 630 return this.JobCountField; 631 } 632 set 633 { 634 if ((this.JobCountField.Equals(value) != true)) 635 { 636 this.JobCountField = value; 637 this.RaisePropertyChanged("JobCount"); 578 638 } 579 639 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ServiceClients/Plugin.cs
r5779 r5955 36 36 } 37 37 38 public IDeepCloneable Clone(Cloner cloner) {38 public override IDeepCloneable Clone(Cloner cloner) { 39 39 return new Plugin(this, cloner); 40 }41 42 public object Clone() {43 return Clone(new Cloner());44 40 } 45 41 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ServiceClients/PluginData.cs
r5779 r5955 38 38 } 39 39 40 public IDeepCloneable Clone(Cloner cloner) {40 public override IDeepCloneable Clone(Cloner cloner) { 41 41 return new PluginData(this, cloner); 42 }43 44 public object Clone() {45 return Clone(new Cloner());46 42 } 47 43 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ServiceClients/Resource.cs
r5779 r5955 33 33 } 34 34 35 public IDeepCloneable Clone(Cloner cloner) {35 public override IDeepCloneable Clone(Cloner cloner) { 36 36 return new Resource(this, cloner); 37 }38 39 public object Clone() {40 return Clone(new Cloner());41 37 } 42 38 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ServiceClients/Slave.cs
r5614 r5955 44 44 } 45 45 46 public IDeepCloneable Clone(Cloner cloner) {46 public override IDeepCloneable Clone(Cloner cloner) { 47 47 return new Slave(this, cloner); 48 48 } … … 51 51 return string.Format("Cores: {0}, FreeCores: {1}", Cores, FreeCores); 52 52 } 53 54 public object Clone() {55 return Clone(new Cloner());56 }57 53 } 58 54 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ServiceClients/SlaveGroup.cs
r5614 r5955 30 30 protected SlaveGroup(SlaveGroup original, Cloner cloner) : base(original, cloner) { } 31 31 32 public IDeepCloneable Clone(Cloner cloner) {32 public override IDeepCloneable Clone(Cloner cloner) { 33 33 return new SlaveGroup(this, cloner); 34 }35 36 public object Clone() {37 return Clone(new Cloner());38 34 } 39 35 } -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ServiceClients/StateLog.cs
r5779 r5955 38 38 } 39 39 40 public IDeepCloneable Clone(Cloner cloner) {40 public override IDeepCloneable Clone(Cloner cloner) { 41 41 return new StateLog(this, cloner); 42 }43 44 public object Clone() {45 return Clone(new Cloner());46 42 } 47 43
Note: See TracChangeset
for help on using the changeset viewer.