Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 3188 was 3018, checked in by kgrading, 15 years ago

added Priority and resource restricted scheduling (#907)

File size: 4.5 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      multiSubmitTextbox.DataBindings.Add("Text", HiveEngine, "MultiSubmitCount");
82      assignedRessourceTextBox.DataBindings.Add("Text", HiveEngine, "RessourceIds");         
83    }
84
85    protected override void RemoveItemEvents() {
86      Engine.Initialized -= new EventHandler(Engine_Initialized);
87      Engine.Finished -= new EventHandler(Engine_Finished);
88      base.RemoveItemEvents();
89    }
90
91    protected override void AddItemEvents() {
92      base.AddItemEvents();
93      Engine.Finished += new EventHandler(Engine_Finished);
94      Engine.Initialized += new EventHandler(Engine_Initialized);
95    }
96
97    void Engine_Initialized(object sender, EventArgs e) {
98      if (InvokeRequired) {
99        Invoke((EventHandler)Engine_Initialized, sender, e);
100      } else {
101        abortButton.Enabled = false;
102        snapshotButton.Enabled = false;
103      }
104    }
105
106    void Engine_Finished(object sender, EventArgs e) {
107      if (InvokeRequired) {
108        Invoke((EventHandler)Engine_Initialized, sender, e);
109      } else {
110        abortButton.Enabled = false;
111        snapshotButton.Enabled = false;
112      }
113    }
114
115    private void snapshotButton_Click(object sender, EventArgs e) {
116      BackgroundWorker worker = new BackgroundWorker();
117      worker.DoWork += (s, args) => {
118        HiveEngine.RequestSnapshot();
119      };
120      worker.RunWorkerCompleted += (s, args) => {
121        Logger.Debug("HiveEngineEditor: RunWorkerCompleted");
122        this.Cursor = Cursors.Default;
123        abortButton.Enabled = true;
124        snapshotButton.Enabled = true;
125      };
126      this.Cursor = Cursors.WaitCursor;
127      abortButton.Enabled = false;
128      snapshotButton.Enabled = false;
129      Logger.Debug("HiveEngineEditor: RunWorkerAsync");
130      worker.RunWorkerAsync();
131    }
132  }
133}
Note: See TracBrowser for help on using the repository browser.