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