Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Hive.Engine/3.2/HiveEngineEditor.cs @ 2273

Last change on this file since 2273 was 2032, checked in by gkronber, 16 years ago

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

File size: 4.3 KB
RevLine 
[1432]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;
[2032]30using HeuristicLab.Tracing;
[1432]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; }
[1440]44      set {
[1726]45        if (base.Engine != null) RemoveItemEvents();
[1440]46        base.Engine = value;
[1726]47        AddItemEvents();
[1440]48        SetDataBinding();
49      }
[1432]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;
[1726]66      base.executeButton.Click += new EventHandler(executeButton_Click);
[2018]67      base.abortButton.Click += new EventHandler(abortButton_Click);
[1432]68    }
[1440]69
[2018]70    void abortButton_Click(object sender, EventArgs e) {
[2032]71      snapshotButton.Enabled = false;
[2018]72    }
73
[1726]74    void executeButton_Click(object sender, EventArgs e) {
[2018]75      abortButton.Enabled = true;
[2032]76      snapshotButton.Enabled = true;
[1726]77    }
78
[1440]79    private void SetDataBinding() {
80      urlTextBox.DataBindings.Add("Text", HiveEngine, "HiveServerUrl");
81    }
[1726]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) {
[2032]96      if (InvokeRequired) {
97        Invoke((EventHandler)Engine_Initialized, sender, e);
98      } else {
99        abortButton.Enabled = false;
100        snapshotButton.Enabled = false;
101      }
[1726]102    }
103
104    void Engine_Finished(object sender, EventArgs e) {
[2032]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;
[2018]125      abortButton.Enabled = false;
[2032]126      snapshotButton.Enabled = false;
127      Logger.Debug("HiveEngineEditor: RunWorkerAsync");
128      worker.RunWorkerAsync();
[1726]129    }
[1432]130  }
131}
Note: See TracBrowser for help on using the repository browser.