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