Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 6372 was 6372, checked in by ascheibe, 13 years ago

#1233 changed year to 2011

File size: 5.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 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;
28
29namespace HeuristicLab.Clients.Hive {
30  public partial class HiveExperiment : IDeepCloneable, IContent, IProgressReporter {
31    private bool useLocalPlugins;
32    public bool UseLocalPlugins {
33      get { return useLocalPlugins; }
34      set { useLocalPlugins = value; }
35    }
36
37    private ExecutionState executionState;
38    public ExecutionState ExecutionState {
39      get { return executionState; }
40      internal set {
41        if (executionState != value) {
42          executionState = value;
43          OnExecutionStateChanged();
44        }
45      }
46    }
47
48    private TimeSpan executionTime;
49    public TimeSpan ExecutionTime {
50      get { return executionTime; }
51      internal set {
52        if (executionTime != value) {
53          executionTime = value;
54          OnExecutionTimeChanged();
55        }
56      }
57    }
58
59    private ItemCollection<HiveJob> hiveJobs;
60    public ItemCollection<HiveJob> HiveJobs {
61      get { return hiveJobs; }
62      set {
63        if (hiveJobs != value) {
64          hiveJobs = value;
65          OnHiveJobsChanged();
66        }
67      }
68    }
69
70    private bool isProgressing;
71    public bool IsProgressing {
72      get { return isProgressing; }
73      set {
74        if (isProgressing != value) {
75          isProgressing = value;
76          OnIsProgressingChanged();
77        }
78      }
79    }
80
81    private IProgress progress;
82    public IProgress Progress {
83      get { return progress; }
84      set { this.progress = value; }
85    }
86
87    #region Constructors and Cloning
88    public HiveExperiment() {
89      this.ResourceNames = "HEAL";
90      this.HiveJobs = new ItemCollection<HiveJob>();
91    }
92
93    protected HiveExperiment(HiveExperiment original, Cloner cloner) {
94      cloner.RegisterClonedObject(original, this);
95      this.OwnerUserId = original.OwnerUserId;
96      this.DateCreated = original.DateCreated;
97      this.ResourceNames = original.ResourceNames;
98      this.LastAccessed = original.LastAccessed;
99      this.Name = original.Name;
100      this.Description = original.Description;
101      this.Id = original.Id;
102      this.HiveJobs = cloner.Clone(original.HiveJobs);
103      this.UseLocalPlugins = original.UseLocalPlugins;
104      this.ExecutionTime = original.ExecutionTime;
105    }
106    public override IDeepCloneable Clone(Cloner cloner) {
107      return new HiveExperiment(this, cloner);
108    }
109    #endregion
110
111    #region Events
112    public event EventHandler ExecutionTimeChanged;
113    protected virtual void OnExecutionTimeChanged() {
114      var handler = ExecutionTimeChanged;
115      if (handler != null) handler(this, EventArgs.Empty);
116    }
117
118    public event EventHandler ExecutionStateChanged;
119    protected virtual void OnExecutionStateChanged() {
120      var handler = ExecutionStateChanged;
121      if (handler != null) handler(this, EventArgs.Empty);
122    }
123
124    public event EventHandler HiveJobsChanged;
125    protected virtual void OnHiveJobsChanged() {
126      var handler = HiveJobsChanged;
127      if (handler != null) handler(this, EventArgs.Empty);
128    }
129
130    public event EventHandler IsProgressingChanged;
131    protected virtual void OnIsProgressingChanged() {
132      var handler = IsProgressingChanged;
133      if (handler != null) handler(this, EventArgs.Empty);
134    }
135
136    public event EventHandler Loaded;
137    public virtual void OnLoaded() {
138      var handler = Loaded;
139      if (handler != null) handler(this, EventArgs.Empty);
140    }
141    #endregion
142
143    protected override void OnPropertyChanged(PropertyChangedEventArgs e) {
144      base.OnPropertyChanged(e);
145      if (e.PropertyName == "Name") {
146        OnToStringChanged();
147      }
148    }
149
150    protected override void RaisePropertyChanged(string propertyName) {
151      if (!(propertyName == "ExecutionTime")
152        && !(propertyName == "JobCount")
153        && !(propertyName == "CalculatingCount")
154        && !(propertyName == "FinishedCount")) {
155        base.RaisePropertyChanged(propertyName);
156      }
157    }
158
159    public bool IsFinished() {
160      return HiveJobs != null
161        && HiveJobs.All(x => x.Job.DateFinished.HasValue && x.Job.DateCreated.HasValue);
162    }
163
164    public IEnumerable<HiveJob> GetAllHiveJobs() {
165      var jobs = new List<HiveJob>();
166      foreach (HiveJob job in HiveJobs) {
167        jobs.AddRange(job.GetAllHiveJobs());
168      }
169      return jobs;
170    }
171
172    public override string ToString() {
173      return Name;
174    }
175  }
176}
Note: See TracBrowser for help on using the repository browser.