Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Experiment/3.3/JobItem.cs @ 4145

Last change on this file since 4145 was 4145, checked in by cneumuel, 12 years ago

worked on "request snapshot" feature (#1115)

File size: 4.6 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.Core;
6using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
7using HeuristicLab.Hive.Contracts.BusinessObjects;
8using HeuristicLab.Hive.Contracts;
9using System.Drawing;
10using HeuristicLab.Common;
11using System.Diagnostics;
12using HeuristicLab.Optimization;
13
14namespace HeuristicLab.Hive.Experiment {
15  public enum SnapshotRequestedState { Idle, Requested }
16
17  [StorableClass]
18  public class JobItem : Item {
19    private static object locker = new object();
20
21    public override Image ItemImage {
22      get {
23        if (jobDto.State == State.Offline) return HeuristicLab.Common.Resources.VS2008ImageLibrary.ExecutablePrepared;
24        else if (jobDto.State == State.Idle) return HeuristicLab.Common.Resources.VS2008ImageLibrary.ExecutablePrepared;
25        else if (jobDto.State == State.Calculating) return HeuristicLab.Common.Resources.VS2008ImageLibrary.ExecutableStarted;
26        else if (jobDto.State == State.Abort) return HeuristicLab.Common.Resources.VS2008ImageLibrary.ExecutableStopped;
27        else if (jobDto.State == State.Failed) return HeuristicLab.Common.Resources.VS2008ImageLibrary.Error;
28        else if (jobDto.State == State.Finished) return HeuristicLab.Common.Resources.VS2008ImageLibrary.ExecutableStopped;
29        else return HeuristicLab.Common.Resources.VS2008ImageLibrary.Event;
30      }
31    }
32
33    [Storable]
34    private JobDto jobDto;
35    public JobDto JobDto {
36      get { return jobDto; }
37      set {
38        if (jobDto != value) {
39          jobDto = value;
40          OnJobDtoChanged();
41          OnToStringChanged();
42          OnItemImageChanged();
43        }
44      }
45    }
46
47    [Storable]
48    private ResponseObject<SerializedJob> latestSnapshot;
49    public ResponseObject<SerializedJob> LatestSnapshot {
50      get { return latestSnapshot; }
51      set {
52        if (latestSnapshot != value) {
53          latestSnapshot = value;
54          latestSnapshotTime = DateTime.Now;
55          SnapshotRequestedState = Experiment.SnapshotRequestedState.Idle;
56          OnLatestSnapshotChanged();
57        }
58      }
59    }
60
61    [Storable]
62    private DateTime latestSnapshotTime;
63    public DateTime LatestSnapshotTime {
64      get { return latestSnapshotTime; }
65    }
66
67    [Storable]
68    private ILog log;
69    public ILog Log {
70      get { return log; }
71    }
72
73    [Storable]
74    private IOptimizer optimizer;
75    public IOptimizer Optimizer {
76      get { return optimizer; }
77      set { this.optimizer = value; }
78    }
79
80    [Storable]
81    private SnapshotRequestedState snapshotRequestedState;
82    public SnapshotRequestedState SnapshotRequestedState {
83      get { return snapshotRequestedState; }
84      private set {
85        this.snapshotRequestedState = value;
86        OnSnapshotRequestedStateChanged();
87      }
88    }
89
90    public JobItem() {
91      log = new Log();
92    }
93
94    public override string ToString() {
95      if (jobDto != null) {
96        return optimizer.Name;
97      } else {
98        return base.ToString();
99      }
100    }
101
102    public event EventHandler LatestSnapshotChanged;
103    private void OnLatestSnapshotChanged() {
104      LogMessage("LatestSnapshotChanged");
105      EventHandler handler = LatestSnapshotChanged;
106      if (handler != null) handler(this, EventArgs.Empty);
107    }
108
109    public event EventHandler JobDtoChanged;
110    private void OnJobDtoChanged() {
111      LogMessage("JobDtoChanged");
112      EventHandler handler = JobDtoChanged;
113      if (handler != null) handler(this, EventArgs.Empty);
114    }
115
116    public void LogMessage(string message) {
117      lock (locker) {
118        log.LogMessage(message);
119      }
120    }
121
122    public override IDeepCloneable Clone(Cloner cloner) {
123      LogMessage("I am beeing cloned");
124      JobItem clone = (JobItem)base.Clone(cloner);
125      clone.latestSnapshotTime = this.latestSnapshotTime;
126      clone.jobDto = (JobDto)cloner.Clone(this.jobDto);
127      clone.latestSnapshot = (ResponseObject<SerializedJob>)cloner.Clone(this.latestSnapshot);
128      clone.log = (ILog)cloner.Clone(this.log);
129      clone.optimizer = (IOptimizer)cloner.Clone(this.optimizer);
130      return clone;
131    }
132
133
134    public event EventHandler SnapshotRequestedStateChanged;
135    private void OnSnapshotRequestedStateChanged() {
136      EventHandler handler = SnapshotRequestedStateChanged;
137      if (handler != null) handler(this, EventArgs.Empty);
138    }
139
140    public void RequestSnapshot() {
141      this.SnapshotRequestedState = Experiment.SnapshotRequestedState.Requested;
142    }
143
144  }
145}
Note: See TracBrowser for help on using the repository browser.