Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/Jobs/EngineJob.cs @ 6200

Last change on this file since 6200 was 6200, checked in by cneumuel, 13 years ago

#1233

  • stability improvements for HiveEngine
File size: 4.4 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Drawing;
4using HeuristicLab.Common;
5using HeuristicLab.Core;
6using HeuristicLab.Hive;
7using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
8
9namespace HeuristicLab.Clients.Hive {
10  [StorableClass]
11  public class EngineJob : ItemJob {
12    [Storable]
13    protected IOperation initialOperation;
14    public IOperation InitialOperation {
15      get { return initialOperation; }
16      set { initialOperation = value; }
17    }
18
19    public new IEngine Item {
20      get { return (IEngine)base.Item; }
21      set { base.Item = value; }
22    }
23
24    public override TimeSpan ExecutionTime {
25      get { return Item.ExecutionTime; }
26    }
27
28    public override ExecutionState ExecutionState {
29      get { return Item.ExecutionState; }
30    }
31
32    #region constructors and cloning
33    public EngineJob() { }
34    public EngineJob(IOperation initialOperation, IEngine engine) {
35      this.initialOperation = initialOperation;
36      this.Item = engine;
37    }
38
39    [StorableConstructor]
40    protected EngineJob(bool deserializing) : base(deserializing) { }
41    protected EngineJob(EngineJob original, Cloner cloner)
42      : base(original, cloner) {
43      this.initialOperation = cloner.Clone(original.initialOperation);
44    }
45    public override IDeepCloneable Clone(Cloner cloner) {
46      return new EngineJob(this, cloner);
47    }
48    #endregion
49
50    public override bool IsParallelizable {
51      get { return false; }
52    }
53
54    public override void Prepare() { }
55
56    public override void Start() {
57      Item.Prepare(initialOperation);
58      Item.Start();
59    }
60   
61    public override void Pause() {
62      Item.Pause();
63    }
64
65    public override void Stop() {
66      Item.Stop();
67    }
68   
69    public override void Resume(IEnumerable<IJob> childJobs) {
70      throw new NotImplementedException();
71    }
72
73    protected override void RegisterItemEvents() {
74      base.RegisterItemEvents();
75      Item.Stopped += new EventHandler(engine_Stopped);
76      Item.Paused += new EventHandler(Item_Paused);
77      Item.Started += new EventHandler(Item_Started);
78      Item.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(engine_ExceptionOccurred);
79      Item.ExecutionStateChanged += new EventHandler(Item_ExecutionStateChanged);
80      Item.ExecutionTimeChanged += new EventHandler(Item_ExecutionTimeChanged);
81    }
82
83    protected override void DeregisterItemEvents() {
84      Item.Stopped -= new EventHandler(engine_Stopped);
85      Item.Paused -= new EventHandler(Item_Paused);
86      Item.Started -= new EventHandler(Item_Started);
87      Item.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(engine_ExceptionOccurred);
88      Item.ExecutionStateChanged -= new EventHandler(Item_ExecutionStateChanged);
89      Item.ExecutionTimeChanged -= new EventHandler(Item_ExecutionTimeChanged);
90      base.DeregisterItemEvents();
91    }
92
93    private void engine_ExceptionOccurred(object sender, EventArgs<Exception> e) {
94      OnJobFailed(e);
95    }
96
97    private void engine_Stopped(object sender, EventArgs e) {
98      OnJobStopped();
99    }
100
101    private void Item_Paused(object sender, EventArgs e) {
102      OnJobPaused();
103    }
104
105    private void Item_ExecutionTimeChanged(object sender, EventArgs e) {
106      OnExecutionTimeChanged();
107    }
108
109    private void Item_ExecutionStateChanged(object sender, EventArgs e) {
110      OnExecutionStateChanged();
111    }
112
113    private void Item_Started(object sender, EventArgs e) {
114      OnJobStarted();
115    }
116
117    public override bool CanChangeDescription {
118      get { return false; }
119    }
120
121    public override bool CanChangeName {
122      get { return false; }
123    }
124
125    public override string Description {
126      get { return string.Empty; }
127      set { throw new NotSupportedException(); }
128    }
129
130    public override string Name {
131      get { return Item != null ? Item.ToString() : null; }
132      set { throw new NotSupportedException(); }
133    }
134
135    public override string ItemDescription {
136      get { return Description; }
137    }
138
139    public override Image ItemImage {
140      get { return HeuristicLab.Common.Resources.VSImageLibrary.Operator; }
141    }
142   
143    public override string ItemName {
144      get { return "EngineJob"; }
145    }
146
147    public override Version ItemVersion {
148      get { return null; }
149    }
150  }
151}
Note: See TracBrowser for help on using the repository browser.