source: trunk/sources/HeuristicLab.Clients.Hive/3.3/Tasks/EngineTask.cs @ 10130

Last change on this file since 10130 was 10130, checked in by ascheibe, 9 years ago

#2117

  • fixed drag and drop check in the RefreshableHiveJobView to be more generic
  • fixed TaskDownloader to generate the correct HiveTasks when downloading tasks
  • fixed some variable names (job => task) which were forgotten
  • the IsParallelizable property of a task can now be set (e.g. if a task gets parallelized, the generated child tasks should sometimes not be able to get further parallelized)
File size: 5.1 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    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) {
63      this.Item = engine;
64    }
65
66    [StorableConstructor]
67    protected EngineTask(bool deserializing) : base(deserializing) { }
68    protected EngineTask(EngineTask original, Cloner cloner)
69      : base(original, cloner) {
70      this.initialOperation = cloner.Clone(original.initialOperation);
71    }
72    public override IDeepCloneable Clone(Cloner cloner) {
73      return new EngineTask(this, cloner);
74    }
75    #endregion
76
77    public override bool IsParallelizable {
78      get { return false; }
79    }
80
81    public override void Prepare() { }
82
83    public override void Start() {
84      Item.Prepare(initialOperation);
85      Item.Start();
86    }
87
88    public override void Pause() {
89      Item.Pause();
90    }
91
92    public override void Stop() {
93      Item.Stop();
94    }
95
96    protected override void RegisterItemEvents() {
97      base.RegisterItemEvents();
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    }
105
106    protected override void DeregisterItemEvents() {
107      Item.Stopped -= new EventHandler(engine_Stopped);
108      Item.Paused -= new EventHandler(Item_Paused);
109      Item.Started -= new EventHandler(Item_Started);
110      Item.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(engine_ExceptionOccurred);
111      Item.ExecutionStateChanged -= new EventHandler(Item_ExecutionStateChanged);
112      Item.ExecutionTimeChanged -= new EventHandler(Item_ExecutionTimeChanged);
113      base.DeregisterItemEvents();
114    }
115
116    private void engine_ExceptionOccurred(object sender, EventArgs<Exception> e) {
117      OnTaskFailed(e);
118    }
119
120    private void engine_Stopped(object sender, EventArgs e) {
121      OnTaskStopped();
122    }
123
124    private void Item_Paused(object sender, EventArgs e) {
125      OnTaskPaused();
126    }
127
128    private void Item_ExecutionTimeChanged(object sender, EventArgs e) {
129      OnExecutionTimeChanged();
130    }
131
132    private void Item_ExecutionStateChanged(object sender, EventArgs e) {
133      OnExecutionStateChanged();
134    }
135
136    private void Item_Started(object sender, EventArgs e) {
137      OnTaskStarted();
138    }
139
140    public override bool CanChangeDescription {
141      get { return false; }
142    }
143
144    public override bool CanChangeName {
145      get { return false; }
146    }
147
148    public override string Description {
149      get { return string.Empty; }
150      set { throw new NotSupportedException(); }
151    }
152
153    public override string Name {
154      get { return Item != null ? Item.ToString() : "Engine Task"; }
155      set { throw new NotSupportedException(); }
156    }
157
158    public static new Image StaticItemImage {
159      get { return HeuristicLab.Common.Resources.VSImageLibrary.Operator; }
160    }
161
162    public override string ItemName {
163      get { return "Engine Task"; }
164    }
165  }
166}
Note: See TracBrowser for help on using the repository browser.