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