[2] | 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 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
| 24 | using System.ComponentModel;
|
---|
| 25 | using System.Data;
|
---|
| 26 | using System.Drawing;
|
---|
| 27 | using System.Linq;
|
---|
| 28 | using System.Text;
|
---|
| 29 | using System.Windows.Forms;
|
---|
| 30 | using System.ServiceModel;
|
---|
| 31 | using HeuristicLab.Core;
|
---|
| 32 | using System.Xml;
|
---|
| 33 | using System.Threading;
|
---|
| 34 | using System.IO;
|
---|
[32] | 35 | using System.Net;
|
---|
[402] | 36 | using System.Diagnostics;
|
---|
[2] | 37 |
|
---|
| 38 | namespace HeuristicLab.Grid {
|
---|
[2518] | 39 |
|
---|
| 40 |
|
---|
[244] | 41 | public partial class ClientForm : Form {
|
---|
[2518] | 42 |
|
---|
| 43 | private List<ClientController> clientControllers;
|
---|
| 44 |
|
---|
[440] | 45 | public ClientForm() {
|
---|
[2] | 46 | InitializeComponent();
|
---|
[2518] | 47 | clientControllers = new List<ClientController>();
|
---|
[2523] | 48 | lock (clientControllers) {
|
---|
| 49 | nClientsControl.Value = Environment.ProcessorCount;
|
---|
| 50 | clientControllerBindingSource.DataSource = clientControllers;
|
---|
| 51 | UpdateControl();
|
---|
| 52 | }
|
---|
[2] | 53 | }
|
---|
| 54 |
|
---|
| 55 | private void startButton_Click(object sender, EventArgs e) {
|
---|
[2523] | 56 | lock (clientControllers) {
|
---|
| 57 | foreach (var client in clientControllers) {
|
---|
| 58 | client.Client.Start(addressTextBox.Text);
|
---|
| 59 | }
|
---|
| 60 | UpdateControl();
|
---|
[2518] | 61 | }
|
---|
[440] | 62 | }
|
---|
[402] | 63 |
|
---|
[440] | 64 | private void stopButton_Click(object sender, EventArgs e) {
|
---|
[2523] | 65 | lock (clientControllers) {
|
---|
| 66 | foreach (var client in clientControllers) {
|
---|
| 67 | client.Client.Stop();
|
---|
| 68 | }
|
---|
| 69 | UpdateControl();
|
---|
[2518] | 70 | }
|
---|
[440] | 71 | }
|
---|
| 72 |
|
---|
| 73 | private void UpdateControl() {
|
---|
[2523] | 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;
|
---|
[2518] | 90 | }
|
---|
[2523] | 91 | clientControllerBindingSource.ResetBindings(false);
|
---|
[2] | 92 | }
|
---|
| 93 | }
|
---|
| 94 |
|
---|
[440] | 95 | private void timer_Tick(object sender, EventArgs e) {
|
---|
| 96 | UpdateControl();
|
---|
[228] | 97 | }
|
---|
[2518] | 98 |
|
---|
| 99 | private void nClientsControl_ValueChanged(object sender, EventArgs e) {
|
---|
[2523] | 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 | }
|
---|
[2518] | 112 | }
|
---|
[2523] | 113 | clientControllerBindingSource.ResetBindings(false);
|
---|
[2518] | 114 | }
|
---|
[2] | 115 | }
|
---|
| 116 | }
|
---|