Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataPreprocessing/HeuristicLab.Clients.Hive/3.3/Tasks/EngineTask.cs @ 10355

Last change on this file since 10355 was 9819, checked in by ascheibe, 11 years ago

#1099 adapted Hive NamedItems

File size: 4.8 KB
Line 
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
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(IOperation initialOperation, IEngine engine) {
53      this.initialOperation = initialOperation;
54      this.Item = engine;
55    }
56
57    [StorableConstructor]
58    protected EngineTask(bool deserializing) : base(deserializing) { }
59    protected EngineTask(EngineTask original, Cloner cloner)
60      : base(original, cloner) {
61      this.initialOperation = cloner.Clone(original.initialOperation);
62    }
63    public override IDeepCloneable Clone(Cloner cloner) {
64      return new EngineTask(this, cloner);
65    }
66    #endregion
67
68    public override bool IsParallelizable {
69      get { return false; }
70    }
71
72    public override void Prepare() { }
73
74    public override void Start() {
75      Item.Prepare(initialOperation);
76      Item.Start();
77    }
78
79    public override void Pause() {
80      Item.Pause();
81    }
82
83    public override void Stop() {
84      Item.Stop();
85    }
86
87    protected override void RegisterItemEvents() {
88      base.RegisterItemEvents();
89      Item.Stopped += new EventHandler(engine_Stopped);
90      Item.Paused += new EventHandler(Item_Paused);
91      Item.Started += new EventHandler(Item_Started);
92      Item.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(engine_ExceptionOccurred);
93      Item.ExecutionStateChanged += new EventHandler(Item_ExecutionStateChanged);
94      Item.ExecutionTimeChanged += new EventHandler(Item_ExecutionTimeChanged);
95    }
96
97    protected override void DeregisterItemEvents() {
98      Item.Stopped -= new EventHandler(engine_Stopped);
99      Item.Paused -= new EventHandler(Item_Paused);
100      Item.Started -= new EventHandler(Item_Started);
101      Item.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(engine_ExceptionOccurred);
102      Item.ExecutionStateChanged -= new EventHandler(Item_ExecutionStateChanged);
103      Item.ExecutionTimeChanged -= new EventHandler(Item_ExecutionTimeChanged);
104      base.DeregisterItemEvents();
105    }
106
107    private void engine_ExceptionOccurred(object sender, EventArgs<Exception> e) {
108      OnTaskFailed(e);
109    }
110
111    private void engine_Stopped(object sender, EventArgs e) {
112      OnTaskStopped();
113    }
114
115    private void Item_Paused(object sender, EventArgs e) {
116      OnTaskPaused();
117    }
118
119    private void Item_ExecutionTimeChanged(object sender, EventArgs e) {
120      OnExecutionTimeChanged();
121    }
122
123    private void Item_ExecutionStateChanged(object sender, EventArgs e) {
124      OnExecutionStateChanged();
125    }
126
127    private void Item_Started(object sender, EventArgs e) {
128      OnTaskStarted();
129    }
130
131    public override bool CanChangeDescription {
132      get { return false; }
133    }
134
135    public override bool CanChangeName {
136      get { return false; }
137    }
138
139    public override string Description {
140      get { return string.Empty; }
141      set { throw new NotSupportedException(); }
142    }
143
144    public override string Name {
145      get { return Item != null ? Item.ToString() : "Engine Task"; }
146      set { throw new NotSupportedException(); }
147    }
148
149    public static new Image StaticItemImage {
150      get { return HeuristicLab.Common.Resources.VSImageLibrary.Operator; }
151    }
152
153    public override string ItemName {
154      get { return "Engine Task"; }
155    }
156  }
157}
Note: See TracBrowser for help on using the repository browser.