Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 3274 was 2523, checked in by epitzer, 15 years ago

Update data binding after collection changed (#805)

File size: 3.7 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      lock (clientControllers) {
49        nClientsControl.Value = Environment.ProcessorCount;
50        clientControllerBindingSource.DataSource = clientControllers;
51        UpdateControl();
52      }
53    }
54
55    private void startButton_Click(object sender, EventArgs e) {
56      lock (clientControllers) {
57        foreach (var client in clientControllers) {
58          client.Client.Start(addressTextBox.Text);
59        }
60        UpdateControl();
61      }
62    }
63
64    private void stopButton_Click(object sender, EventArgs e) {
65      lock (clientControllers) {
66        foreach (var client in clientControllers) {
67          client.Client.Stop();
68        }
69        UpdateControl();
70      }
71    }
72
73    private void UpdateControl() {
74      lock (clientControllers) {
75        foreach (var client in clientControllers) {
76          if (client.Client.Waiting) {
77            startButton.Enabled = false;
78            stopButton.Enabled = true;
79            client.Status = "Waiting for engine";
80          } else if (client.Client.Executing) {
81            startButton.Enabled = false;
82            stopButton.Enabled = true;
83            client.Status = "Executing engine";
84          } else if (client.Client.Stopped) {
85            startButton.Enabled = true;
86            stopButton.Enabled = false;
87            client.Status = "Stopped";
88          }
89          client.Message = client.Client.StatusMessage;
90        }
91        clientControllerBindingSource.ResetBindings(false);
92      }
93    }
94
95    private void timer_Tick(object sender, EventArgs e) {
96      UpdateControl();
97    }
98
99    private void nClientsControl_ValueChanged(object sender, EventArgs e) {
100      lock (clientControllers) {
101        if (nClientsControl.Value < 0)
102          nClientsControl.Value = 0;
103        while (clientControllers.Count < nClientsControl.Value) {
104          clientControllers.Add(new ClientController() { Client = new GridClient() });
105        }
106        while (clientControllerBindingSource.Count > nClientsControl.Value) {
107          GridClient client = clientControllers.Last().Client;
108          if (!client.Stopped)
109            client.Stop();
110          clientControllers.RemoveAt(clientControllerBindingSource.Count - 1);
111        }
112      }
113      clientControllerBindingSource.ResetBindings(false);
114    }
115  }
116}
Note: See TracBrowser for help on using the repository browser.