#region License Information
/* HeuristicLab
* Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.ServiceModel;
using HeuristicLab.Core;
using System.Xml;
using System.Threading;
using System.IO;
using System.Net;
using System.Diagnostics;
namespace HeuristicLab.Grid {
public partial class ClientForm : Form {
private List clientControllers;
public ClientForm() {
InitializeComponent();
clientControllers = new List();
lock (clientControllers) {
nClientsControl.Value = Environment.ProcessorCount;
clientControllerBindingSource.DataSource = clientControllers;
UpdateControl();
}
}
private void startButton_Click(object sender, EventArgs e) {
lock (clientControllers) {
foreach (var client in clientControllers) {
client.Client.Start(addressTextBox.Text);
}
UpdateControl();
}
}
private void stopButton_Click(object sender, EventArgs e) {
lock (clientControllers) {
foreach (var client in clientControllers) {
client.Client.Stop();
}
UpdateControl();
}
}
private void UpdateControl() {
lock (clientControllers) {
foreach (var client in clientControllers) {
if (client.Client.Waiting) {
startButton.Enabled = false;
stopButton.Enabled = true;
client.Status = "Waiting for engine";
} else if (client.Client.Executing) {
startButton.Enabled = false;
stopButton.Enabled = true;
client.Status = "Executing engine";
} else if (client.Client.Stopped) {
startButton.Enabled = true;
stopButton.Enabled = false;
client.Status = "Stopped";
}
client.Message = client.Client.StatusMessage;
}
clientControllerBindingSource.ResetBindings(false);
}
}
private void timer_Tick(object sender, EventArgs e) {
UpdateControl();
}
private void nClientsControl_ValueChanged(object sender, EventArgs e) {
lock (clientControllers) {
if (nClientsControl.Value < 0)
nClientsControl.Value = 0;
while (clientControllers.Count < nClientsControl.Value) {
clientControllers.Add(new ClientController() { Client = new GridClient() });
}
while (clientControllerBindingSource.Count > nClientsControl.Value) {
GridClient client = clientControllers.Last().Client;
if (!client.Stopped)
client.Stop();
clientControllers.RemoveAt(clientControllerBindingSource.Count - 1);
}
}
clientControllerBindingSource.ResetBindings(false);
}
}
}