Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Hive.Engine/3.2/Job.cs @ 1619

Last change on this file since 1619 was 1530, checked in by gkronber, 16 years ago

Moved source files of plugins Hive ... Visualization.Test into version-specific sub-folders. #576

File size: 3.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 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 System.Collections.Generic;
24using System.Text;
25using HeuristicLab.Core;
26using System.Threading;
27using HeuristicLab.Hive.JobBase;
28using System.Xml;
29
30namespace HeuristicLab.Hive.Engine {
31  /// <summary>
32  /// Represents an job that wraps an engine that should be executed in the hive.
33  /// </summary>
34  public class Job : StorableBase, IJob {
35    private IEngine engine;
36    public IEngine Engine {
37      get { return engine; }
38    }
39
40    public Job()
41      : base() {
42      engine = new SequentialEngine.SequentialEngine();
43      RegisterEvents();
44    }
45
46    private void RegisterEvents() {
47      engine.Finished += new EventHandler(engine_Finished);
48    }
49
50    private void DeregisterEvents() {
51      engine.Finished -= new EventHandler(engine_Finished);
52    }
53
54    void engine_Finished(object sender, EventArgs e) {
55      if (JobStopped != null)
56        JobStopped(this, new EventArgs());
57    }
58
59    #region IJob Members
60
61    public event EventHandler JobStopped;
62
63    public long JobId {
64      get;
65      set;
66    }
67
68    public double Progress {
69      get { return 0.0; }
70      set { throw new NotSupportedException(); }
71    }
72
73    public bool Running {
74      get {
75        return Engine.Running;
76      }
77      set {
78        throw new NotSupportedException();
79      }
80    }
81
82    public void Run() {
83      throw new NotSupportedException();
84    }
85
86    public void Start() {
87      Engine.Execute();
88    }
89
90    public void Stop() {
91      Engine.Abort();
92    }
93
94    #endregion
95
96    public override System.Xml.XmlNode GetXmlNode(string name, System.Xml.XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
97      XmlNode node = base.GetXmlNode(name, document, persistedObjects);
98      node.AppendChild(PersistenceManager.Persist("Engine", Engine, document, persistedObjects));
99      return node;
100    }
101    public override void Populate(System.Xml.XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
102      base.Populate(node, restoredObjects);
103      DeregisterEvents();
104      engine = (SequentialEngine.SequentialEngine)PersistenceManager.Restore(node.SelectSingleNode("Engine"), restoredObjects);
105      RegisterEvents();
106    }
107  }
108}
Note: See TracBrowser for help on using the repository browser.