Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Grid/3.2/ClientForm.cs @ 2518

Last change on this file since 2518 was 2518, checked in by epitzer, 14 years ago

Use DataGrid to monitor several grid client instances inside a single grid application. (#805)

File size: 3.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.Data;
26using System.Drawing;
27using System.Linq;
28using System.Text;
29using System.Windows.Forms;
30using System.ServiceModel;
31using HeuristicLab.Core;
32using System.Xml;
33using System.Threading;
34using System.IO;
35using System.Net;
36using System.Diagnostics;
37
38namespace HeuristicLab.Grid {
39
40
41  public partial class ClientForm : Form {
42
43    private List<ClientController> clientControllers;
44
45    public ClientForm() {
46      InitializeComponent();
47      clientControllers = new List<ClientController>();
48      nClientsControl.Value = Environment.ProcessorCount;
49      clientControllerBindingSource.DataSource = clientControllers;
50      UpdateControl();
51    }
52
53    private void startButton_Click(object sender, EventArgs e) {
54      foreach (var client in clientControllers) {
55        client.Client.Start(addressTextBox.Text);
56      }
57      UpdateControl();
58    }
59
60    private void stopButton_Click(object sender, EventArgs e) {
61      foreach (var client in clientControllers) {
62        client.Client.Stop();
63      }
64      UpdateControl();
65    }
66
67    private void UpdateControl() {
68      foreach (var client in clientControllers) {
69        if (client.Client.Waiting) {
70          startButton.Enabled = false;
71          stopButton.Enabled = true;
72          client.Status = "Waiting for engine";
73        } else if (client.Client.Executing) {
74          startButton.Enabled = false;
75          stopButton.Enabled = true;
76          client.Status = "Executing engine";
77        } else if (client.Client.Stopped) {
78          startButton.Enabled = true;
79          stopButton.Enabled = false;
80          client.Status = "Stopped";
81        }
82        client.Message = client.Client.StatusMessage;
83      }
84      clientGrid.Invalidate();
85    }
86
87    private void timer_Tick(object sender, EventArgs e) {
88      UpdateControl();
89    }
90
91    private void nClientsControl_ValueChanged(object sender, EventArgs e) {
92      if (nClientsControl.Value < 0)
93        nClientsControl.Value = 0;
94      while (clientControllers.Count < nClientsControl.Value)
95        clientControllers.Add(new ClientController() { Client = new GridClient() });
96      while (clientControllers.Count > nClientsControl.Value) {
97        try {
98          clientControllers[clientControllers.Count - 1].Client.Stop();
99          clientControllers.RemoveAt(clientControllers.Count - 1);
100        } catch { }
101      }
102      clientGrid.Invalidate();
103    }
104  }
105}
Note: See TracBrowser for help on using the repository browser.