1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2015 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.Common;
|
---|
24 | using HeuristicLab.Core;
|
---|
25 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
26 |
|
---|
27 | namespace HeuristicLab.Clients.Hive {
|
---|
28 | [StorableClass]
|
---|
29 | public class EngineTask : ItemTask {
|
---|
30 | public override HiveTask CreateHiveTask() {
|
---|
31 | //only used when deserializing, so no problem with parentscope
|
---|
32 | return new EngineHiveTask(this, null);
|
---|
33 | }
|
---|
34 |
|
---|
35 | [Storable]
|
---|
36 | protected IOperation initialOperation;
|
---|
37 | public IOperation InitialOperation
|
---|
38 | {
|
---|
39 | get { return initialOperation; }
|
---|
40 | set { initialOperation = value; }
|
---|
41 | }
|
---|
42 |
|
---|
43 | public new IEngine Item
|
---|
44 | {
|
---|
45 | get { return (IEngine)base.Item; }
|
---|
46 | set { base.Item = value; }
|
---|
47 | }
|
---|
48 |
|
---|
49 | public override TimeSpan ExecutionTime
|
---|
50 | {
|
---|
51 | get { return Item.ExecutionTime; }
|
---|
52 | }
|
---|
53 |
|
---|
54 | public override ExecutionState ExecutionState
|
---|
55 | {
|
---|
56 | get { return Item.ExecutionState; }
|
---|
57 | }
|
---|
58 |
|
---|
59 | #region constructors and cloning
|
---|
60 | public EngineTask(IOperation initialOperation, IEngine engine) {
|
---|
61 | this.initialOperation = initialOperation;
|
---|
62 | this.Item = engine;
|
---|
63 | }
|
---|
64 |
|
---|
65 | public EngineTask(IEngine engine) : base(engine) { }
|
---|
66 |
|
---|
67 | [StorableConstructor]
|
---|
68 | protected EngineTask(bool deserializing) : base(deserializing) { }
|
---|
69 | protected EngineTask(EngineTask original, Cloner cloner)
|
---|
70 | : base(original, cloner) {
|
---|
71 | this.initialOperation = cloner.Clone(original.initialOperation);
|
---|
72 | }
|
---|
73 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
74 | return new EngineTask(this, cloner);
|
---|
75 | }
|
---|
76 | #endregion
|
---|
77 |
|
---|
78 | public override bool IsParallelizable
|
---|
79 | {
|
---|
80 | get { return false; }
|
---|
81 | }
|
---|
82 |
|
---|
83 | public override void Prepare() { }
|
---|
84 |
|
---|
85 | public override void Start() {
|
---|
86 | Item.Prepare(initialOperation);
|
---|
87 | Item.Start();
|
---|
88 | }
|
---|
89 |
|
---|
90 | public override void Pause() {
|
---|
91 | Item.Pause();
|
---|
92 | }
|
---|
93 |
|
---|
94 | public override void Stop() {
|
---|
95 | Item.Stop();
|
---|
96 | }
|
---|
97 |
|
---|
98 | protected override void RegisterItemEvents() {
|
---|
99 | base.RegisterItemEvents();
|
---|
100 | Item.Stopped += new EventHandler(engine_Stopped);
|
---|
101 | Item.Paused += new EventHandler(Item_Paused);
|
---|
102 | Item.Started += new EventHandler(Item_Started);
|
---|
103 | Item.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(engine_ExceptionOccurred);
|
---|
104 | Item.ExecutionStateChanged += new EventHandler(Item_ExecutionStateChanged);
|
---|
105 | Item.ExecutionTimeChanged += new EventHandler(Item_ExecutionTimeChanged);
|
---|
106 | }
|
---|
107 |
|
---|
108 | protected override void DeregisterItemEvents() {
|
---|
109 | Item.Stopped -= new EventHandler(engine_Stopped);
|
---|
110 | Item.Paused -= new EventHandler(Item_Paused);
|
---|
111 | Item.Started -= new EventHandler(Item_Started);
|
---|
112 | Item.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(engine_ExceptionOccurred);
|
---|
113 | Item.ExecutionStateChanged -= new EventHandler(Item_ExecutionStateChanged);
|
---|
114 | Item.ExecutionTimeChanged -= new EventHandler(Item_ExecutionTimeChanged);
|
---|
115 | base.DeregisterItemEvents();
|
---|
116 | }
|
---|
117 |
|
---|
118 | private void engine_ExceptionOccurred(object sender, EventArgs<Exception> e) {
|
---|
119 | OnTaskFailed(e);
|
---|
120 | }
|
---|
121 |
|
---|
122 | private void engine_Stopped(object sender, EventArgs e) {
|
---|
123 | OnTaskStopped();
|
---|
124 | }
|
---|
125 |
|
---|
126 | private void Item_Paused(object sender, EventArgs e) {
|
---|
127 | OnTaskPaused();
|
---|
128 | }
|
---|
129 |
|
---|
130 | private void Item_ExecutionTimeChanged(object sender, EventArgs e) {
|
---|
131 | OnExecutionTimeChanged();
|
---|
132 | }
|
---|
133 |
|
---|
134 | private void Item_ExecutionStateChanged(object sender, EventArgs e) {
|
---|
135 | OnExecutionStateChanged();
|
---|
136 | }
|
---|
137 |
|
---|
138 | private void Item_Started(object sender, EventArgs e) {
|
---|
139 | OnTaskStarted();
|
---|
140 | }
|
---|
141 |
|
---|
142 | public override bool CanChangeDescription
|
---|
143 | {
|
---|
144 | get { return false; }
|
---|
145 | }
|
---|
146 |
|
---|
147 | public override bool CanChangeName
|
---|
148 | {
|
---|
149 | get { return false; }
|
---|
150 | }
|
---|
151 |
|
---|
152 | public override string Description
|
---|
153 | {
|
---|
154 | get { return string.Empty; }
|
---|
155 | set { throw new NotSupportedException(); }
|
---|
156 | }
|
---|
157 |
|
---|
158 | public override string Name
|
---|
159 | {
|
---|
160 | get { return Item != null ? Item.ToString() : "Engine Task"; }
|
---|
161 | set { throw new NotSupportedException(); }
|
---|
162 | }
|
---|
163 |
|
---|
164 |
|
---|
165 |
|
---|
166 | public override string ItemName
|
---|
167 | {
|
---|
168 | get { return "Engine Task"; }
|
---|
169 | }
|
---|
170 | }
|
---|
171 | }
|
---|