Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.SolutionCaching/3.3/RunCollectionModifiers/RunCollectionModifierTask.cs @ 10131

Last change on this file since 10131 was 10131, checked in by ascheibe, 10 years ago

#1886 adapted the RunCollectionModifierTask to the changes of r10130

File size: 6.2 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 HeuristicLab.Clients.Hive;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27
28namespace HeuristicLab.Analysis.SolutionCaching {
29  [Item("RunCollectionModifierTask", "Represents task which executes a RunCollectionModifierExecutable.")]
30  [StorableClass]
31  public class RunCollectionModifierTask : ItemTask {
32    public new RunCollectionModifierExecutable Item {
33      get { return (RunCollectionModifierExecutable)base.Item; }
34      set { base.Item = value; }
35    }
36
37    public override HiveTask CreateHiveTask() {
38      return new RunCollectionModifierHiveTask(this);
39    }
40
41    [Storable]
42    private bool isParallelizable;
43    public override bool IsParallelizable {
44      get { return isParallelizable; }
45      set { isParallelizable = value; }
46    }
47
48    #region Constructors and Cloning
49    public RunCollectionModifierTask(RunCollectionModifierExecutable executable)
50      : base() {
51      Item = executable;
52      isParallelizable = true;
53    }
54    [StorableConstructor]
55    protected RunCollectionModifierTask(bool deserializing) { }
56    protected RunCollectionModifierTask(RunCollectionModifierTask original, Cloner cloner)
57      : base(original, cloner) {
58      isParallelizable = original.isParallelizable;
59    }
60    public override IDeepCloneable Clone(Cloner cloner) {
61      return new RunCollectionModifierTask(this, cloner);
62    }
63    #endregion
64
65    public override bool CanChangeDescription {
66      get {
67        if (Item == null)
68          return false;
69        else
70          return Item.CanChangeDescription;
71      }
72    }
73
74    public override bool CanChangeName {
75      get {
76        if (Item == null)
77          return false;
78        else
79          return Item.CanChangeName;
80      }
81    }
82
83    public override string Description {
84      get {
85        if (Item == null)
86          return string.Empty;
87        else
88          return Item.Description;
89      }
90      set { Item.Description = value; }
91    }
92
93    public override string Name {
94      get {
95        if (Item == null)
96          return "RunCollectionModifierTask";
97        else
98          return Item.Name;
99      }
100      set { Item.Name = value; }
101    }
102
103    public override ExecutionState ExecutionState {
104      get { return Item.ExecutionState; }
105    }
106
107    public override TimeSpan ExecutionTime {
108      get { return Item.ExecutionTime; }
109    }
110
111    public override void Pause() {
112      Item.Pause();
113    }
114
115    public override void Prepare() {
116      Item.Prepare();
117    }
118
119    public override void Start() {
120      Item.Start();
121    }
122
123    public override void Stop() {
124      Item.Stop();
125    }
126
127    protected override void RegisterItemEvents() {
128      base.RegisterItemEvents();
129      Item.Stopped += new EventHandler(executable_Stopped);
130      Item.Paused += new EventHandler(executable_Paused);
131      Item.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(executable_ExceptionOccurred);
132      Item.DescriptionChanged += new EventHandler(executable_DescriptionChanged);
133      Item.NameChanged += new EventHandler(executable_NameChanged);
134      Item.NameChanging += new EventHandler<CancelEventArgs<string>>(executable_NameChanging);
135      Item.ExecutionStateChanged += new EventHandler(executable_ExecutionStateChanged);
136      Item.ExecutionTimeChanged += new EventHandler(executable_ExecutionTimeChanged);
137      Item.Started += new EventHandler(executable_Started);
138    }
139
140    protected virtual void DeregisterOptimizerEvents() {
141      Item.Stopped -= new EventHandler(executable_Stopped);
142      Item.Paused -= new EventHandler(executable_Paused);
143      Item.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(executable_ExceptionOccurred);
144      Item.DescriptionChanged -= new EventHandler(executable_DescriptionChanged);
145      Item.NameChanged -= new EventHandler(executable_NameChanged);
146      Item.NameChanging -= new EventHandler<CancelEventArgs<string>>(executable_NameChanging);
147      Item.ExecutionStateChanged -= new EventHandler(executable_ExecutionStateChanged);
148      Item.ExecutionTimeChanged -= new EventHandler(executable_ExecutionTimeChanged);
149      Item.Started -= new EventHandler(executable_Started);
150      base.DeregisterItemEvents();
151    }
152
153    protected void executable_NameChanging(object sender, CancelEventArgs<string> e) {
154      OnNameChanging(new CancelEventArgs<string>(e.Value, e.Cancel));
155    }
156
157    protected void executable_NameChanged(object sender, EventArgs e) {
158      this.OnNameChanged();
159    }
160
161    protected void executable_DescriptionChanged(object sender, EventArgs e) {
162      OnDescriptionChanged();
163    }
164
165    protected virtual void executable_ExceptionOccurred(object sender, EventArgs<Exception> e) {
166      OnTaskFailed(e);
167    }
168
169    protected virtual void executable_Started(object sender, EventArgs e) {
170      OnTaskStarted();
171    }
172
173    protected virtual void executable_Stopped(object sender, EventArgs e) {
174      OnTaskStopped();
175    }
176
177    protected virtual void executable_Paused(object sender, EventArgs e) {
178      OnTaskPaused();
179    }
180
181    protected virtual void executable_ExecutionTimeChanged(object sender, EventArgs e) {
182      OnExecutionTimeChanged();
183    }
184
185    protected virtual void executable_ExecutionStateChanged(object sender, EventArgs e) {
186      OnExecutionStateChanged();
187    }
188  }
189}
Note: See TracBrowser for help on using the repository browser.