Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OaaS/HeuristicLab.Clients.Hive/3.3/Tasks/EngineTask.cs @ 14778

Last change on this file since 14778 was 7532, checked in by ascheibe, 13 years ago

#1778

  • tried to clean up ItemTask/EngineTask overrides without breaking anything
  • added a unit test to check if ToString methods of IItems work
  • fixed ToString method of the Hive Plugin dto
File size: 4.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 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
22using System;
23using System.Drawing;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27
28namespace HeuristicLab.Clients.Hive {
29  [StorableClass]
30  public class EngineTask : ItemTask {
31    [Storable]
32    protected IOperation initialOperation;
33    public IOperation InitialOperation {
34      get { return initialOperation; }
35      set { initialOperation = value; }
36    }
37
38    public new IEngine Item {
39      get { return (IEngine)base.Item; }
40      set { base.Item = value; }
41    }
42
43    public override TimeSpan ExecutionTime {
44      get { return Item.ExecutionTime; }
45    }
46
47    public override ExecutionState ExecutionState {
48      get { return Item.ExecutionState; }
49    }
50
51    #region constructors and cloning
52    public EngineTask() { }
53    public EngineTask(IOperation initialOperation, IEngine engine) {
54      this.initialOperation = initialOperation;
55      this.Item = engine;
56    }
57
58    [StorableConstructor]
59    protected EngineTask(bool deserializing) : base(deserializing) { }
60    protected EngineTask(EngineTask original, Cloner cloner)
61      : base(original, cloner) {
62      this.initialOperation = cloner.Clone(original.initialOperation);
63    }
64    public override IDeepCloneable Clone(Cloner cloner) {
65      return new EngineTask(this, cloner);
66    }
67    #endregion
68
69    public override bool IsParallelizable {
70      get { return false; }
71    }
72
73    public override void Prepare() { }
74
75    public override void Start() {
76      Item.Prepare(initialOperation);
77      Item.Start();
78    }
79
80    public override void Pause() {
81      Item.Pause();
82    }
83
84    public override void Stop() {
85      Item.Stop();
86    }
87
88    protected override void RegisterItemEvents() {
89      base.RegisterItemEvents();
90      Item.Stopped += new EventHandler(engine_Stopped);
91      Item.Paused += new EventHandler(Item_Paused);
92      Item.Started += new EventHandler(Item_Started);
93      Item.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(engine_ExceptionOccurred);
94      Item.ExecutionStateChanged += new EventHandler(Item_ExecutionStateChanged);
95      Item.ExecutionTimeChanged += new EventHandler(Item_ExecutionTimeChanged);
96    }
97
98    protected override void DeregisterItemEvents() {
99      Item.Stopped -= new EventHandler(engine_Stopped);
100      Item.Paused -= new EventHandler(Item_Paused);
101      Item.Started -= new EventHandler(Item_Started);
102      Item.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(engine_ExceptionOccurred);
103      Item.ExecutionStateChanged -= new EventHandler(Item_ExecutionStateChanged);
104      Item.ExecutionTimeChanged -= new EventHandler(Item_ExecutionTimeChanged);
105      base.DeregisterItemEvents();
106    }
107
108    private void engine_ExceptionOccurred(object sender, EventArgs<Exception> e) {
109      OnTaskFailed(e);
110    }
111
112    private void engine_Stopped(object sender, EventArgs e) {
113      OnTaskStopped();
114    }
115
116    private void Item_Paused(object sender, EventArgs e) {
117      OnTaskPaused();
118    }
119
120    private void Item_ExecutionTimeChanged(object sender, EventArgs e) {
121      OnExecutionTimeChanged();
122    }
123
124    private void Item_ExecutionStateChanged(object sender, EventArgs e) {
125      OnExecutionStateChanged();
126    }
127
128    private void Item_Started(object sender, EventArgs e) {
129      OnTaskStarted();
130    }
131
132    public override bool CanChangeDescription {
133      get { return false; }
134    }
135
136    public override bool CanChangeName {
137      get { return false; }
138    }
139
140    public override string Description {
141      get { return string.Empty; }
142      set { throw new NotSupportedException(); }
143    }
144
145    public override string Name {
146      get { return Item != null ? Item.ToString() : null; }
147      set { throw new NotSupportedException(); }
148    }
149
150    public static new Image StaticItemImage {
151      get { return HeuristicLab.Common.Resources.VSImageLibrary.Operator; }
152    }
153
154    public override string ItemName {
155      get { return "EngineTask"; }
156    }
157  }
158}
Note: See TracBrowser for help on using the repository browser.