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 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.ComponentModel;
|
---|
25 | using System.Linq;
|
---|
26 | using HeuristicLab.Common;
|
---|
27 | using HeuristicLab.Core;
|
---|
28 |
|
---|
29 | namespace 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 bool isPrivileged;
|
---|
38 | public bool IsPrivileged {
|
---|
39 | get { return isPrivileged; }
|
---|
40 | set { isPrivileged = value; }
|
---|
41 | }
|
---|
42 |
|
---|
43 | private ExecutionState executionState;
|
---|
44 | public ExecutionState ExecutionState {
|
---|
45 | get { return executionState; }
|
---|
46 | internal set {
|
---|
47 | if (executionState != value) {
|
---|
48 | executionState = value;
|
---|
49 | OnExecutionStateChanged();
|
---|
50 | }
|
---|
51 | }
|
---|
52 | }
|
---|
53 |
|
---|
54 | private TimeSpan executionTime;
|
---|
55 | public TimeSpan ExecutionTime {
|
---|
56 | get { return executionTime; }
|
---|
57 | internal set {
|
---|
58 | if (executionTime != value) {
|
---|
59 | executionTime = value;
|
---|
60 | OnExecutionTimeChanged();
|
---|
61 | }
|
---|
62 | }
|
---|
63 | }
|
---|
64 |
|
---|
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 | private bool isProgressing;
|
---|
77 | public bool IsProgressing {
|
---|
78 | get { return isProgressing; }
|
---|
79 | set {
|
---|
80 | if (isProgressing != value) {
|
---|
81 | isProgressing = value;
|
---|
82 | OnIsProgressingChanged();
|
---|
83 | }
|
---|
84 | }
|
---|
85 | }
|
---|
86 |
|
---|
87 | private IProgress progress;
|
---|
88 | public IProgress Progress {
|
---|
89 | get { return progress; }
|
---|
90 | set { this.progress = value; }
|
---|
91 | }
|
---|
92 |
|
---|
93 | #region Constructors and Cloning
|
---|
94 | public HiveExperiment() {
|
---|
95 | this.ResourceNames = "HEAL";
|
---|
96 | this.HiveJobs = new ItemCollection<HiveJob>();
|
---|
97 | this.DateCreated = DateTime.Now;
|
---|
98 | }
|
---|
99 |
|
---|
100 | protected HiveExperiment(HiveExperiment original, Cloner cloner) {
|
---|
101 | cloner.RegisterClonedObject(original, this);
|
---|
102 | this.OwnerUserId = original.OwnerUserId;
|
---|
103 | this.DateCreated = original.DateCreated;
|
---|
104 | this.ResourceNames = original.ResourceNames;
|
---|
105 | this.LastAccessed = original.LastAccessed;
|
---|
106 | this.Name = original.Name;
|
---|
107 | this.Description = original.Description;
|
---|
108 | this.Id = original.Id;
|
---|
109 | this.HiveJobs = cloner.Clone(original.HiveJobs);
|
---|
110 | this.UseLocalPlugins = original.UseLocalPlugins;
|
---|
111 | this.ExecutionTime = original.ExecutionTime;
|
---|
112 | this.IsPrivileged = original.IsPrivileged;
|
---|
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 | protected virtual void OnExecutionTimeChanged() {
|
---|
122 | var handler = ExecutionTimeChanged;
|
---|
123 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
124 | }
|
---|
125 |
|
---|
126 | public event EventHandler ExecutionStateChanged;
|
---|
127 | protected virtual void OnExecutionStateChanged() {
|
---|
128 | var handler = ExecutionStateChanged;
|
---|
129 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
130 | }
|
---|
131 |
|
---|
132 | public event EventHandler HiveJobsChanged;
|
---|
133 | protected virtual void OnHiveJobsChanged() {
|
---|
134 | var handler = HiveJobsChanged;
|
---|
135 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
136 | }
|
---|
137 |
|
---|
138 | public event EventHandler IsProgressingChanged;
|
---|
139 | protected virtual void OnIsProgressingChanged() {
|
---|
140 | var handler = IsProgressingChanged;
|
---|
141 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
142 | }
|
---|
143 |
|
---|
144 | public event EventHandler Loaded;
|
---|
145 | public virtual void OnLoaded() {
|
---|
146 | var handler = Loaded;
|
---|
147 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
148 | }
|
---|
149 | #endregion
|
---|
150 |
|
---|
151 | protected override void OnPropertyChanged(PropertyChangedEventArgs e) {
|
---|
152 | base.OnPropertyChanged(e);
|
---|
153 | if (e.PropertyName == "Name") {
|
---|
154 | OnToStringChanged();
|
---|
155 | }
|
---|
156 | }
|
---|
157 |
|
---|
158 | protected override void RaisePropertyChanged(string propertyName) {
|
---|
159 | if (!(propertyName == "ExecutionTime")
|
---|
160 | && !(propertyName == "JobCount")
|
---|
161 | && !(propertyName == "CalculatingCount")
|
---|
162 | && !(propertyName == "FinishedCount")) {
|
---|
163 | base.RaisePropertyChanged(propertyName);
|
---|
164 | }
|
---|
165 | }
|
---|
166 |
|
---|
167 | public bool IsFinished() {
|
---|
168 | return HiveJobs != null
|
---|
169 | && HiveJobs.All(x => x.Job.DateFinished.HasValue && x.Job.DateCreated.HasValue);
|
---|
170 | }
|
---|
171 |
|
---|
172 | public IEnumerable<HiveJob> GetAllHiveJobs() {
|
---|
173 | var jobs = new List<HiveJob>();
|
---|
174 | foreach (HiveJob job in HiveJobs) {
|
---|
175 | jobs.AddRange(job.GetAllHiveJobs());
|
---|
176 | }
|
---|
177 | return jobs;
|
---|
178 | }
|
---|
179 |
|
---|
180 | public override string ToString() {
|
---|
181 | return Name;
|
---|
182 | }
|
---|
183 | }
|
---|
184 | }
|
---|