[5602] | 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 |
|
---|
[5955] | 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
| 24 | using System.ComponentModel;
|
---|
| 25 | using System.Linq;
|
---|
[5614] | 26 | using HeuristicLab.Common;
|
---|
[5955] | 27 | using HeuristicLab.Core;
|
---|
[6006] | 28 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
[5602] | 29 |
|
---|
| 30 | namespace HeuristicLab.Clients.Hive {
|
---|
[6006] | 31 | [StorableClass]
|
---|
[5955] | 32 | public partial class HiveExperiment : IDeepCloneable, IContent, IProgressReporter {
|
---|
[6006] | 33 | [Storable]
|
---|
[5955] | 34 | private bool useLocalPlugins;
|
---|
| 35 | public bool UseLocalPlugins {
|
---|
| 36 | get { return useLocalPlugins; }
|
---|
| 37 | set { useLocalPlugins = value; }
|
---|
| 38 | }
|
---|
[5602] | 39 |
|
---|
[6006] | 40 | [Storable]
|
---|
[5955] | 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 |
|
---|
[6006] | 52 | [Storable]
|
---|
[5955] | 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 |
|
---|
[6006] | 64 | [Storable]
|
---|
| 65 | private ItemCollection<HiveJob> hiveJobs;
|
---|
| 66 | public ItemCollection<HiveJob> HiveJobs {
|
---|
| 67 | get { return hiveJobs; }
|
---|
[5955] | 68 | set {
|
---|
[6006] | 69 | if (hiveJobs != value) {
|
---|
| 70 | hiveJobs = value;
|
---|
| 71 | OnHiveJobsChanged();
|
---|
[5955] | 72 | }
|
---|
| 73 | }
|
---|
| 74 | }
|
---|
| 75 |
|
---|
[6006] | 76 | [Storable]
|
---|
[5955] | 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 |
|
---|
[6006] | 88 | [Storable]
|
---|
[5955] | 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";
|
---|
[6033] | 98 | this.HiveJobs = new ItemCollection<HiveJob>();
|
---|
[5955] | 99 | }
|
---|
| 100 |
|
---|
[5614] | 101 | protected HiveExperiment(HiveExperiment original, Cloner cloner) {
|
---|
[5779] | 102 | cloner.RegisterClonedObject(original, this);
|
---|
[5614] | 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;
|
---|
[6033] | 110 | this.HiveJobs = cloner.Clone(original.HiveJobs);
|
---|
[5955] | 111 | this.UseLocalPlugins = original.UseLocalPlugins;
|
---|
| 112 | this.ExecutionTime = original.ExecutionTime;
|
---|
[5614] | 113 | }
|
---|
[5955] | 114 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
[5614] | 115 | return new HiveExperiment(this, cloner);
|
---|
| 116 | }
|
---|
[5955] | 117 | #endregion
|
---|
[5614] | 118 |
|
---|
[5955] | 119 | #region Events
|
---|
| 120 | public event EventHandler ExecutionTimeChanged;
|
---|
| 121 | private void OnExecutionTimeChanged() {
|
---|
| 122 | EventHandler handler = ExecutionTimeChanged;
|
---|
| 123 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
[5614] | 124 | }
|
---|
[5955] | 125 |
|
---|
| 126 | public event EventHandler ExecutionStateChanged;
|
---|
| 127 | private void OnExecutionStateChanged() {
|
---|
| 128 | EventHandler handler = ExecutionStateChanged;
|
---|
| 129 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
| 130 | }
|
---|
| 131 |
|
---|
[6006] | 132 | public event EventHandler HiveJobsChanged;
|
---|
[6033] | 133 | protected virtual void OnHiveJobsChanged() {
|
---|
[6006] | 134 | EventHandler handler = HiveJobsChanged;
|
---|
[5955] | 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
|
---|
[6033] | 144 |
|
---|
[5955] | 145 | protected override void OnPropertyChanged(PropertyChangedEventArgs e) {
|
---|
| 146 | base.OnPropertyChanged(e);
|
---|
| 147 | if (e.PropertyName == "Name") {
|
---|
| 148 | OnToStringChanged();
|
---|
| 149 | }
|
---|
| 150 | }
|
---|
[6033] | 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);
|
---|
[5955] | 158 | }
|
---|
| 159 | }
|
---|
| 160 |
|
---|
[6033] | 161 | public bool IsFinished() {
|
---|
| 162 | return HiveJobs != null
|
---|
| 163 | && HiveJobs.All(x => x.Job.DateFinished.HasValue && x.Job.DateCreated.HasValue);
|
---|
[5955] | 164 | }
|
---|
| 165 |
|
---|
[6006] | 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 |
|
---|
[6033] | 174 | public override string ToString() {
|
---|
| 175 | return Name;
|
---|
[5955] | 176 | }
|
---|
| 177 |
|
---|
[6033] | 178 | public virtual void OnLoaded() { }
|
---|
[5602] | 179 | }
|
---|
| 180 | }
|
---|