Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 10115 was 10114, checked in by ascheibe, 11 years ago

#1886 added tasks and hive tasks for RunCollectionModifiers

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