Changeset 6479 for branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ServiceClients/HiveExperiment.cs
- Timestamp:
- 06/27/11 15:20:23 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ServiceClients/HiveExperiment.cs
r6426 r6479 21 21 22 22 using System; 23 using System.Collections.Generic;24 23 using System.ComponentModel; 25 using System.Linq;26 using HeuristicLab.Collections;27 24 using HeuristicLab.Common; 28 using HeuristicLab.Core;29 25 30 26 namespace HeuristicLab.Clients.Hive { 31 public partial class HiveExperiment : IDeepCloneable, IContent , IProgressReporter{27 public partial class HiveExperiment : IDeepCloneable, IContent { 32 28 33 29 private bool isPrivileged; … … 37 33 } 38 34 39 private ExecutionState executionState;40 public ExecutionState ExecutionState {41 get { return executionState; }42 internal set {43 if (executionState != value) {44 executionState = value;45 OnExecutionStateChanged();46 }47 }48 }49 50 private TimeSpan executionTime;51 public TimeSpan ExecutionTime {52 get { return executionTime; }53 internal set {54 if (executionTime != value) {55 executionTime = value;56 OnExecutionTimeChanged();57 }58 }59 }60 61 private ItemCollection<HiveJob> hiveJobs;62 public ItemCollection<HiveJob> HiveJobs {63 get { return hiveJobs; }64 set {65 if (hiveJobs != value) {66 if (hiveJobs != null) DeregisterHiveJobsEvents();67 hiveJobs = value;68 if (hiveJobs != null) RegisterHiveJobsEvents();69 OnHiveJobsChanged();70 }71 }72 }73 74 private bool isProgressing;75 public bool IsProgressing {76 get { return isProgressing; }77 set {78 if (isProgressing != value) {79 isProgressing = value;80 OnIsProgressingChanged();81 }82 }83 }84 85 private IProgress progress;86 public IProgress Progress {87 get { return progress; }88 set { this.progress = value; }89 }90 91 public StateLogListList StateLogList {92 get { return new StateLogListList(this.GetAllHiveJobs().Select(x => x.StateLog)); }93 }94 95 35 #region Constructors and Cloning 96 36 public HiveExperiment() { 97 37 this.ResourceNames = "HEAL"; 98 this.HiveJobs = new ItemCollection<HiveJob>();99 38 this.DateCreated = DateTime.Now; 39 this.Permission = Permission.Full; 100 40 } 101 41 … … 109 49 this.Description = original.Description; 110 50 this.Id = original.Id; 111 this.HiveJobs = cloner.Clone(original.HiveJobs);112 this.ExecutionTime = original.ExecutionTime;113 51 this.IsPrivileged = original.IsPrivileged; 52 this.Permission = original.Permission; 114 53 } 115 54 public override IDeepCloneable Clone(Cloner cloner) { … … 119 58 120 59 #region Events 121 public event EventHandler ExecutionTimeChanged;122 protected virtual void OnExecutionTimeChanged() {123 var handler = ExecutionTimeChanged;124 if (handler != null) handler(this, EventArgs.Empty);125 }126 127 public event EventHandler ExecutionStateChanged;128 protected virtual void OnExecutionStateChanged() {129 var handler = ExecutionStateChanged;130 if (handler != null) handler(this, EventArgs.Empty);131 }132 133 public event EventHandler HiveJobsChanged;134 protected virtual void OnHiveJobsChanged() {135 var handler = HiveJobsChanged;136 if (handler != null) handler(this, EventArgs.Empty);137 }138 139 public event EventHandler IsProgressingChanged;140 protected virtual void OnIsProgressingChanged() {141 var handler = IsProgressingChanged;142 if (handler != null) handler(this, EventArgs.Empty);143 }144 145 public event EventHandler Loaded;146 public virtual void OnLoaded() {147 var handler = Loaded;148 if (handler != null) handler(this, EventArgs.Empty);149 }150 151 public event EventHandler<CollectionItemsChangedEventArgs<HiveJob>> HiveJobsAdded;152 private void OnHiveJobsAdded(CollectionItemsChangedEventArgs<HiveJob> e) {153 var handler = HiveJobsAdded;154 if (handler != null) handler(this, e);155 }156 157 public event EventHandler<CollectionItemsChangedEventArgs<HiveJob>> HiveJobsRemoved;158 private void OnHiveJobsRemoved(CollectionItemsChangedEventArgs<HiveJob> e) {159 var handler = HiveJobsRemoved;160 if (handler != null) handler(this, e);161 }162 163 public event EventHandler<CollectionItemsChangedEventArgs<HiveJob>> HiveJobsReset;164 private void OnHiveJobsReset(CollectionItemsChangedEventArgs<HiveJob> e) {165 var handler = HiveJobsReset;166 if (handler != null) handler(this, e);167 }168 169 60 public event EventHandler StateLogListChanged; 170 61 private void OnStateLogListChanged() { 171 62 var handler = StateLogListChanged; 172 63 if (handler != null) handler(this, EventArgs.Empty); 173 }174 #endregion175 176 #region HiveJobs Events177 private void RegisterHiveJobsEvents() {178 this.hiveJobs.ItemsAdded += new CollectionItemsChangedEventHandler<HiveJob>(hiveJobs_ItemsAdded);179 this.hiveJobs.ItemsRemoved += new CollectionItemsChangedEventHandler<HiveJob>(hiveJobs_ItemsRemoved);180 this.hiveJobs.CollectionReset += new CollectionItemsChangedEventHandler<HiveJob>(hiveJobs_CollectionReset);181 }182 183 private void DeregisterHiveJobsEvents() {184 this.hiveJobs.ItemsAdded -= new CollectionItemsChangedEventHandler<HiveJob>(hiveJobs_ItemsAdded);185 this.hiveJobs.ItemsRemoved -= new CollectionItemsChangedEventHandler<HiveJob>(hiveJobs_ItemsRemoved);186 this.hiveJobs.CollectionReset -= new CollectionItemsChangedEventHandler<HiveJob>(hiveJobs_CollectionReset);187 }188 189 private void hiveJobs_CollectionReset(object sender, CollectionItemsChangedEventArgs<HiveJob> e) {190 foreach (var item in e.Items) {191 item.StateLogChanged -= new EventHandler(item_StateLogChanged);192 }193 OnHiveJobsReset(e);194 }195 196 private void hiveJobs_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<HiveJob> e) {197 foreach (var item in e.Items) {198 item.StateLogChanged -= new EventHandler(item_StateLogChanged);199 }200 OnHiveJobsRemoved(e);201 }202 203 private void hiveJobs_ItemsAdded(object sender, CollectionItemsChangedEventArgs<HiveJob> e) {204 foreach (var item in e.Items) {205 item.StateLogChanged += new EventHandler(item_StateLogChanged);206 }207 OnHiveJobsAdded(e);208 }209 210 private void item_StateLogChanged(object sender, EventArgs e) {211 OnStateLogListChanged();212 64 } 213 65 #endregion … … 229 81 } 230 82 231 public bool IsFinished() {232 return HiveJobs != null233 && HiveJobs.All(x => x.Job.DateFinished.HasValue && x.Job.DateCreated.HasValue);234 }235 236 public IEnumerable<HiveJob> GetAllHiveJobs() {237 if (hiveJobs == null) return Enumerable.Empty<HiveJob>();238 239 var jobs = new List<HiveJob>();240 foreach (HiveJob job in HiveJobs) {241 jobs.AddRange(job.GetAllHiveJobs());242 }243 return jobs;244 }245 246 83 public override string ToString() { 247 84 return Name;
Note: See TracChangeset
for help on using the changeset viewer.