Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive_Milestone3/sources/HeuristicLab.Hive.Engine/3.2/HiveEngineEditor.cs @ 5726

Last change on this file since 5726 was 2032, checked in by gkronber, 15 years ago

Worked on asynchronous result polling in HiveEngine. #545 (Engine which can be executed in the Hive).

File size: 4.3 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.ComponentModel;
25using System.Drawing;
26using System.Data;
27using System.Text;
28using System.Windows.Forms;
29using HeuristicLab.Core;
30using HeuristicLab.Tracing;
31
32namespace HeuristicLab.Hive.Engine {
33  /// <summary>
34  /// Visual representation of a <see cref="HiveEngine"/>.
35  /// </summary>
36  public partial class HiveEngineEditor : EngineBaseEditor {
37    /// <summary>
38    /// Gets or set the engine to represent visually.
39    /// </summary>
40    /// <remarks>Uses property <see cref="EngineBaseEditor.Engine"/> of base class
41    /// <see cref="EngineBaseEditor"/>. No own data storage present.</remarks>
42    public HiveEngine HiveEngine {
43      get { return (HiveEngine)Engine; }
44      set {
45        if (base.Engine != null) RemoveItemEvents();
46        base.Engine = value;
47        AddItemEvents();
48        SetDataBinding();
49      }
50    }
51
52    /// <summary>
53    /// Initializes a new instance of <see cref="HiveEngineEditor"/>.
54    /// </summary>
55    public HiveEngineEditor() {
56      InitializeComponent();
57    }
58    /// <summary>
59    /// Initializes a new instance of <see cref="HiveEngineEditor"/> with the given
60    /// <paramref name="hiveEngine"/>.
61    /// </summary>
62    /// <param name="hiveEngine">The engine to display.</param>
63    public HiveEngineEditor(HiveEngine hiveEngine)
64      : this() {
65      HiveEngine = hiveEngine;
66      base.executeButton.Click += new EventHandler(executeButton_Click);
67      base.abortButton.Click += new EventHandler(abortButton_Click);
68    }
69
70    void abortButton_Click(object sender, EventArgs e) {
71      snapshotButton.Enabled = false;
72    }
73
74    void executeButton_Click(object sender, EventArgs e) {
75      abortButton.Enabled = true;
76      snapshotButton.Enabled = true;
77    }
78
79    private void SetDataBinding() {
80      urlTextBox.DataBindings.Add("Text", HiveEngine, "HiveServerUrl");
81    }
82
83    protected override void RemoveItemEvents() {
84      Engine.Initialized -= new EventHandler(Engine_Initialized);
85      Engine.Finished -= new EventHandler(Engine_Finished);
86      base.RemoveItemEvents();
87    }
88
89    protected override void AddItemEvents() {
90      base.AddItemEvents();
91      Engine.Finished += new EventHandler(Engine_Finished);
92      Engine.Initialized += new EventHandler(Engine_Initialized);
93    }
94
95    void Engine_Initialized(object sender, EventArgs e) {
96      if (InvokeRequired) {
97        Invoke((EventHandler)Engine_Initialized, sender, e);
98      } else {
99        abortButton.Enabled = false;
100        snapshotButton.Enabled = false;
101      }
102    }
103
104    void Engine_Finished(object sender, EventArgs e) {
105      if (InvokeRequired) {
106        Invoke((EventHandler)Engine_Initialized, sender, e);
107      } else {
108        abortButton.Enabled = false;
109        snapshotButton.Enabled = false;
110      }
111    }
112
113    private void snapshotButton_Click(object sender, EventArgs e) {
114      BackgroundWorker worker = new BackgroundWorker();
115      worker.DoWork += (s, args) => {
116        HiveEngine.RequestSnapshot();
117      };
118      worker.RunWorkerCompleted += (s, args) => {
119        Logger.Debug("HiveEngineEditor: RunWorkerCompleted");
120        this.Cursor = Cursors.Default;
121        abortButton.Enabled = true;
122        snapshotButton.Enabled = true;
123      };
124      this.Cursor = Cursors.WaitCursor;
125      abortButton.Enabled = false;
126      snapshotButton.Enabled = false;
127      Logger.Debug("HiveEngineEditor: RunWorkerAsync");
128      worker.RunWorkerAsync();
129    }
130  }
131}
Note: See TracBrowser for help on using the repository browser.