source: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ServiceClients/HiveExperiment.cs @ 6033

Last change on this file since 6033 was 6033, checked in by cneumuel, 9 years ago

#1233

  • created baseclass for jobs (ItemJob) which derives OperatorJobs and EngineJobs
  • created special view for OptimizerJobs which derives from a more general view
  • removed logic from domain class HiveExperiment and moved it into RefreshableHiveExperiment
  • improved ItemTreeView
  • corrected plugin dependencies
  • fixed bug in database trigger when deleting HiveExperiments
  • added delete cascade for Plugin and PluginData
  • lots of fixes
File size: 5.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.ComponentModel;
25using System.Linq;
26using HeuristicLab.Common;
27using HeuristicLab.Core;
28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
29
30namespace HeuristicLab.Clients.Hive {
31  [StorableClass]
32  public partial class HiveExperiment : IDeepCloneable, IContent, IProgressReporter {
33    [Storable]
34    private bool useLocalPlugins;
35    public bool UseLocalPlugins {
36      get { return useLocalPlugins; }
37      set { useLocalPlugins = value; }
38    }
39
40    [Storable]
41    private ExecutionState executionState;
42    public ExecutionState ExecutionState {
43      get { return executionState; }
44      internal set {
45        if (executionState != value) {
46          executionState = value;
47          OnExecutionStateChanged();
48        }
49      }
50    }
51
52    [Storable]
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    [Storable]
65    private ItemCollection<HiveJob> hiveJobs;
66    public ItemCollection<HiveJob> HiveJobs {
67      get { return hiveJobs; }
68      set {
69        if (hiveJobs != value) {
70          hiveJobs = value;
71          OnHiveJobsChanged();
72        }
73      }
74    }
75
76    [Storable]
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    [Storable]
89    private IProgress progress;
90    public IProgress Progress {
91      get { return progress; }
92      set { this.progress = value; }
93    }
94
95    #region Constructors and Cloning
96    public HiveExperiment() {
97      this.ResourceNames = "HEAL";
98      this.HiveJobs = new ItemCollection<HiveJob>();
99    }
100
101    protected HiveExperiment(HiveExperiment original, Cloner cloner) {
102      cloner.RegisterClonedObject(original, this);
103      this.OwnerUserId = original.OwnerUserId;
104      this.DateCreated = original.DateCreated;
105      this.ResourceNames = original.ResourceNames;
106      this.LastAccessed = original.LastAccessed;
107      this.Name = original.Name;
108      this.Description = original.Description;
109      this.Id = original.Id;
110      this.HiveJobs = cloner.Clone(original.HiveJobs);
111      this.UseLocalPlugins = original.UseLocalPlugins;
112      this.ExecutionTime = original.ExecutionTime;
113    }
114    public override IDeepCloneable Clone(Cloner cloner) {
115      return new HiveExperiment(this, cloner);
116    }
117    #endregion
118
119    #region Events
120    public event EventHandler ExecutionTimeChanged;
121    private void OnExecutionTimeChanged() {
122      EventHandler handler = ExecutionTimeChanged;
123      if (handler != null) handler(this, EventArgs.Empty);
124    }
125
126    public event EventHandler ExecutionStateChanged;
127    private void OnExecutionStateChanged() {
128      EventHandler handler = ExecutionStateChanged;
129      if (handler != null) handler(this, EventArgs.Empty);
130    }
131
132    public event EventHandler HiveJobsChanged;
133    protected virtual void OnHiveJobsChanged() {
134      EventHandler handler = HiveJobsChanged;
135      if (handler != null) handler(this, EventArgs.Empty);
136    }
137
138    public event EventHandler IsProgressingChanged;
139    private void OnIsProgressingChanged() {
140      EventHandler handler = IsProgressingChanged;
141      if (handler != null) handler(this, EventArgs.Empty);
142    }
143    #endregion
144   
145    protected override void OnPropertyChanged(PropertyChangedEventArgs e) {
146      base.OnPropertyChanged(e);
147      if (e.PropertyName == "Name") {
148        OnToStringChanged();
149      }
150    }
151   
152    protected override void RaisePropertyChanged(string propertyName) {
153      if (!(propertyName == "ExecutionTime")
154        && !(propertyName == "JobCount")
155        && !(propertyName == "CalculatingCount")
156        && !(propertyName == "FinishedCount")) {
157        base.RaisePropertyChanged(propertyName);
158      }
159    }
160
161    public bool IsFinished() {
162      return HiveJobs != null
163        && HiveJobs.All(x => x.Job.DateFinished.HasValue && x.Job.DateCreated.HasValue);
164    }
165
166    public IEnumerable<HiveJob> GetAllHiveJobs() {
167      var jobs = new List<HiveJob>();
168      foreach (HiveJob job in HiveJobs) {
169        jobs.AddRange(job.GetAllHiveJobs());
170      }
171      return jobs;
172    }
173
174    public override string ToString() {
175      return Name;
176    }
177
178    public virtual void OnLoaded() { }
179  }
180}
Note: See TracBrowser for help on using the repository browser.