Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.Clients.Hive/3.3/Tasks/EngineTask.cs @ 17507

Last change on this file since 17507 was 17468, checked in by jkarder, 5 years ago

#3060: merged r17445 into stable

File size: 5.2 KB
RevLine 
[6976]1#region License Information
2/* HeuristicLab
[17181]3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[6976]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;
[17097]26using HEAL.Attic;
[6976]27
28namespace HeuristicLab.Clients.Hive {
[17097]29  [StorableType("FFDE8A4B-FDEC-47AA-B8E2-B16E5B513055")]
[6976]30  public class EngineTask : ItemTask {
[11083]31    public override HiveTask CreateHiveTask() {
32      //only used when deserializing, so no problem with parentscope
33      return new EngineHiveTask(this, null);
34    }
35
[6976]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
[11083]62    public EngineTask(IEngine engine) : base(engine) { }
63
[6976]64    [StorableConstructor]
[17097]65    protected EngineTask(StorableConstructorFlag _) : base(_) { }
[6976]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
[15384]81    public override async void Start() {
[17468]82      try {
83        Item.Prepare(initialOperation);
84        await Item.StartAsync();
85      } catch (Exception e) {
86        engine_ExceptionOccurred(Item, new EventArgs<Exception>(e));
87      }
[6976]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      get { return false; }
144    }
145
146    public override bool CanChangeName {
147      get { return false; }
148    }
149
150    public override string Description {
151      get { return string.Empty; }
152      set { throw new NotSupportedException(); }
153    }
154
155    public override string Name {
[9886]156      get { return Item != null ? Item.ToString() : "Engine Task"; }
[6976]157      set { throw new NotSupportedException(); }
158    }
159
[7201]160    public static new Image StaticItemImage {
[6976]161      get { return HeuristicLab.Common.Resources.VSImageLibrary.Operator; }
162    }
163
164    public override string ItemName {
[9886]165      get { return "Engine Task"; }
[6976]166    }
167  }
168}
Note: See TracBrowser for help on using the repository browser.