1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2013 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 HeuristicLab.Clients.Hive;
|
---|
24 | using HeuristicLab.Common;
|
---|
25 | using HeuristicLab.Core;
|
---|
26 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
27 |
|
---|
28 | namespace HeuristicLab.Analysis.SolutionCaching {
|
---|
29 | [Item("RunCollectionModifierTask", "Represents task which executes a RunCollectionModifierExecutable.")]
|
---|
30 | [StorableClass]
|
---|
31 | public class RunCollectionModifierTask : ItemTask {
|
---|
32 | public new RunCollectionModifierExecutable Item {
|
---|
33 | get { return (RunCollectionModifierExecutable)base.Item; }
|
---|
34 | set { base.Item = value; }
|
---|
35 | }
|
---|
36 |
|
---|
37 | public override HiveTask CreateHiveTask() {
|
---|
38 | return new RunCollectionModifierHiveTask(this);
|
---|
39 | }
|
---|
40 |
|
---|
41 | [Storable]
|
---|
42 | private bool isParallelizable;
|
---|
43 | public override bool IsParallelizable {
|
---|
44 | get { return isParallelizable; }
|
---|
45 | set { isParallelizable = value; }
|
---|
46 | }
|
---|
47 |
|
---|
48 | #region Constructors and Cloning
|
---|
49 | public RunCollectionModifierTask(RunCollectionModifierExecutable executable)
|
---|
50 | : base(executable) {
|
---|
51 | isParallelizable = true;
|
---|
52 | }
|
---|
53 | [StorableConstructor]
|
---|
54 | protected RunCollectionModifierTask(bool deserializing) { }
|
---|
55 | protected RunCollectionModifierTask(RunCollectionModifierTask original, Cloner cloner)
|
---|
56 | : base(original, cloner) {
|
---|
57 | isParallelizable = original.isParallelizable;
|
---|
58 | }
|
---|
59 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
60 | return new RunCollectionModifierTask(this, cloner);
|
---|
61 | }
|
---|
62 | #endregion
|
---|
63 |
|
---|
64 | public override bool CanChangeDescription {
|
---|
65 | get {
|
---|
66 | if (Item == null)
|
---|
67 | return false;
|
---|
68 | else
|
---|
69 | return Item.CanChangeDescription;
|
---|
70 | }
|
---|
71 | }
|
---|
72 |
|
---|
73 | public override bool CanChangeName {
|
---|
74 | get {
|
---|
75 | if (Item == null)
|
---|
76 | return false;
|
---|
77 | else
|
---|
78 | return Item.CanChangeName;
|
---|
79 | }
|
---|
80 | }
|
---|
81 |
|
---|
82 | public override string Description {
|
---|
83 | get {
|
---|
84 | if (Item == null)
|
---|
85 | return string.Empty;
|
---|
86 | else
|
---|
87 | return Item.Description;
|
---|
88 | }
|
---|
89 | set { Item.Description = value; }
|
---|
90 | }
|
---|
91 |
|
---|
92 | public override string Name {
|
---|
93 | get {
|
---|
94 | if (Item == null)
|
---|
95 | return "RunCollectionModifierTask";
|
---|
96 | else
|
---|
97 | return Item.Name;
|
---|
98 | }
|
---|
99 | set { Item.Name = value; }
|
---|
100 | }
|
---|
101 |
|
---|
102 | public override ExecutionState ExecutionState {
|
---|
103 | get { return Item.ExecutionState; }
|
---|
104 | }
|
---|
105 |
|
---|
106 | public override TimeSpan ExecutionTime {
|
---|
107 | get { return Item.ExecutionTime; }
|
---|
108 | }
|
---|
109 |
|
---|
110 | public override void Pause() {
|
---|
111 | Item.Pause();
|
---|
112 | }
|
---|
113 |
|
---|
114 | public override void Prepare() {
|
---|
115 | Item.Prepare();
|
---|
116 | }
|
---|
117 |
|
---|
118 | public override void Start() {
|
---|
119 | Item.Start();
|
---|
120 | }
|
---|
121 |
|
---|
122 | public override void Stop() {
|
---|
123 | Item.Stop();
|
---|
124 | }
|
---|
125 |
|
---|
126 | protected override void RegisterItemEvents() {
|
---|
127 | base.RegisterItemEvents();
|
---|
128 | Item.Stopped += new EventHandler(executable_Stopped);
|
---|
129 | Item.Paused += new EventHandler(executable_Paused);
|
---|
130 | Item.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(executable_ExceptionOccurred);
|
---|
131 | Item.DescriptionChanged += new EventHandler(executable_DescriptionChanged);
|
---|
132 | Item.NameChanged += new EventHandler(executable_NameChanged);
|
---|
133 | Item.NameChanging += new EventHandler<CancelEventArgs<string>>(executable_NameChanging);
|
---|
134 | Item.ExecutionStateChanged += new EventHandler(executable_ExecutionStateChanged);
|
---|
135 | Item.ExecutionTimeChanged += new EventHandler(executable_ExecutionTimeChanged);
|
---|
136 | Item.Started += new EventHandler(executable_Started);
|
---|
137 | }
|
---|
138 |
|
---|
139 | protected virtual void DeregisterOptimizerEvents() {
|
---|
140 | Item.Stopped -= new EventHandler(executable_Stopped);
|
---|
141 | Item.Paused -= new EventHandler(executable_Paused);
|
---|
142 | Item.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(executable_ExceptionOccurred);
|
---|
143 | Item.DescriptionChanged -= new EventHandler(executable_DescriptionChanged);
|
---|
144 | Item.NameChanged -= new EventHandler(executable_NameChanged);
|
---|
145 | Item.NameChanging -= new EventHandler<CancelEventArgs<string>>(executable_NameChanging);
|
---|
146 | Item.ExecutionStateChanged -= new EventHandler(executable_ExecutionStateChanged);
|
---|
147 | Item.ExecutionTimeChanged -= new EventHandler(executable_ExecutionTimeChanged);
|
---|
148 | Item.Started -= new EventHandler(executable_Started);
|
---|
149 | base.DeregisterItemEvents();
|
---|
150 | }
|
---|
151 |
|
---|
152 | protected void executable_NameChanging(object sender, CancelEventArgs<string> e) {
|
---|
153 | OnNameChanging(new CancelEventArgs<string>(e.Value, e.Cancel));
|
---|
154 | }
|
---|
155 |
|
---|
156 | protected void executable_NameChanged(object sender, EventArgs e) {
|
---|
157 | this.OnNameChanged();
|
---|
158 | }
|
---|
159 |
|
---|
160 | protected void executable_DescriptionChanged(object sender, EventArgs e) {
|
---|
161 | OnDescriptionChanged();
|
---|
162 | }
|
---|
163 |
|
---|
164 | protected virtual void executable_ExceptionOccurred(object sender, EventArgs<Exception> e) {
|
---|
165 | OnTaskFailed(e);
|
---|
166 | }
|
---|
167 |
|
---|
168 | protected virtual void executable_Started(object sender, EventArgs e) {
|
---|
169 | OnTaskStarted();
|
---|
170 | }
|
---|
171 |
|
---|
172 | protected virtual void executable_Stopped(object sender, EventArgs e) {
|
---|
173 | OnTaskStopped();
|
---|
174 | }
|
---|
175 |
|
---|
176 | protected virtual void executable_Paused(object sender, EventArgs e) {
|
---|
177 | OnTaskPaused();
|
---|
178 | }
|
---|
179 |
|
---|
180 | protected virtual void executable_ExecutionTimeChanged(object sender, EventArgs e) {
|
---|
181 | OnExecutionTimeChanged();
|
---|
182 | }
|
---|
183 |
|
---|
184 | protected virtual void executable_ExecutionStateChanged(object sender, EventArgs e) {
|
---|
185 | OnExecutionStateChanged();
|
---|
186 | }
|
---|
187 | }
|
---|
188 | } |
---|