Index: trunk/sources/HeuristicLab.CEDMA.Server/AgentScheduler.cs
===================================================================
--- trunk/sources/HeuristicLab.CEDMA.Server/AgentScheduler.cs	(revision 372)
+++ trunk/sources/HeuristicLab.CEDMA.Server/AgentScheduler.cs	(revision 375)
@@ -59,10 +59,10 @@
         engines.Remove(e);
         AgentEntry entry = agent[e];
-        entry.Status = AgentStatus.Finished;
-        database.Update(entry);
+        entry.Status = ProcessStatus.Finished;
+        database.UpdateAgent(entry.Id, entry.Status);
       }
     }
     private void CreateNewEngines() {
-      ICollection<AgentEntry> agents = database.GetAgentEntries(AgentStatus.Waiting);
+      ICollection<AgentEntry> agents = database.GetAgents(ProcessStatus.Waiting);
       foreach(AgentEntry a in agents) {
         SequentialEngine.SequentialEngine engine = new HeuristicLab.SequentialEngine.SequentialEngine();
@@ -75,6 +75,6 @@
         agent[engine] = a;
         engines.Add(engine);
-        a.Status = AgentStatus.Active;
-        database.Update(a);
+        a.Status = ProcessStatus.Active;
+        database.UpdateAgent(a.Id, a.Status);
       }
     }
@@ -84,5 +84,5 @@
           engine.ExecuteStep();
         }
-        Thread.Sleep(100); // prevent over-load
+        Thread.Sleep(100); // prevent overload
       }
     }
Index: trunk/sources/HeuristicLab.CEDMA.Server/HeuristicLab.CEDMA.Server.csproj
===================================================================
--- trunk/sources/HeuristicLab.CEDMA.Server/HeuristicLab.CEDMA.Server.csproj	(revision 372)
+++ trunk/sources/HeuristicLab.CEDMA.Server/HeuristicLab.CEDMA.Server.csproj	(revision 375)
@@ -60,4 +60,5 @@
   <ItemGroup>
     <Compile Include="AgentScheduler.cs" />
+    <Compile Include="RunScheduler.cs" />
     <Compile Include="DbPersistenceManager.cs" />
     <Compile Include="ServerApplication.cs" />
@@ -87,4 +88,8 @@
       <Project>{F43B59AB-2B8C-4570-BC1E-15592086517C}</Project>
       <Name>HeuristicLab.Core</Name>
+    </ProjectReference>
+    <ProjectReference Include="..\HeuristicLab.Grid\HeuristicLab.Grid.csproj">
+      <Project>{545CE756-98D8-423B-AC2E-6E7D70926E5C}</Project>
+      <Name>HeuristicLab.Grid</Name>
     </ProjectReference>
     <ProjectReference Include="..\HeuristicLab.PluginInfrastructure\HeuristicLab.PluginInfrastructure.csproj">
Index: trunk/sources/HeuristicLab.CEDMA.Server/RunScheduler.cs
===================================================================
--- trunk/sources/HeuristicLab.CEDMA.Server/RunScheduler.cs	(revision 375)
+++ trunk/sources/HeuristicLab.CEDMA.Server/RunScheduler.cs	(revision 375)
@@ -0,0 +1,72 @@
+﻿#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 <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using HeuristicLab.CEDMA.DB;
+using HeuristicLab.CEDMA.DB.Interfaces;
+using HeuristicLab.Core;
+using System.Threading;
+using HeuristicLab.CEDMA.Console;
+using HeuristicLab.Grid;
+
+namespace HeuristicLab.CEDMA.Server {
+  public class RunScheduler {
+    private Database database;
+    private JobManager jobManager;
+    private const int RELEASE_INTERVAL = 5;
+    public RunScheduler(Database database, JobManager jobManager) {
+      this.database = database;
+      this.jobManager = jobManager;
+    }
+    public void Run() {
+      while(true) {
+        ReleaseWaitingRuns();
+        Thread.Sleep(TimeSpan.FromSeconds(RELEASE_INTERVAL));
+      }
+    }
+    private void ReleaseWaitingRuns() {
+      ICollection<RunEntry> runs = database.GetRuns(ProcessStatus.Waiting);
+      jobManager.Reset();
+      foreach(RunEntry entry in runs) {
+        IOperatorGraph opGraph = (IOperatorGraph)DbPersistenceManager.Restore(entry.RawData);
+
+        Scope scope = new Scope();
+        AtomicOperation op = new AtomicOperation(opGraph.InitialOperator, scope);
+        WaitHandle wHandle = jobManager.BeginExecuteOperation(scope, op);
+
+        ThreadPool.QueueUserWorkItem(delegate(object state) {
+          wHandle.WaitOne();
+          jobManager.EndExecuteOperation(op);
+          entry.Status = ProcessStatus.Finished;
+          database.UpdateRunStatus(entry.Id, entry.Status);
+          database.UpdateRunFinished(entry.Id, DateTime.Now);
+        });
+
+        entry.Status = ProcessStatus.Active;
+        database.UpdateRunStatus(entry.Id, entry.Status);
+        database.UpdateRunStart(entry.Id, DateTime.Now);
+      }
+    }
+  }
+}
Index: trunk/sources/HeuristicLab.CEDMA.Server/ServerForm.cs
===================================================================
--- trunk/sources/HeuristicLab.CEDMA.Server/ServerForm.cs	(revision 372)
+++ trunk/sources/HeuristicLab.CEDMA.Server/ServerForm.cs	(revision 375)
@@ -36,4 +36,5 @@
 using System.Data.Common;
 using System.Threading;
+using HeuristicLab.Grid;
 
 namespace HeuristicLab.CEDMA.Server {
@@ -45,7 +46,4 @@
     public ServerForm() {
       InitializeComponent();
-      InitDatabase();
-      InitAgentScheduler();
-
       // windows XP returns the external ip on index 0 while windows vista returns the external ip on index 2
       if (System.Environment.OSVersion.Version.Major >= 6) {
@@ -54,9 +52,14 @@
         addressTextBox.Text = "net.tcp://" + Dns.GetHostAddresses(Dns.GetHostName())[0] + ":8002/CEDMA/World";
       }
-      Start();
     }
 
     private void InitAgentScheduler() {
       AgentScheduler scheduler = new AgentScheduler(database);
+      ThreadPool.QueueUserWorkItem(delegate(object status) { scheduler.Run(); });
+    }
+
+    private void InitRunScheduler() {
+      JobManager jobManager = new JobManager(gridAddress.Text);
+      RunScheduler scheduler = new RunScheduler(database, jobManager);
       ThreadPool.QueueUserWorkItem(delegate(object status) { scheduler.Run(); });
     }
@@ -74,4 +77,8 @@
 
     private void Start() {
+      InitDatabase();
+      InitAgentScheduler();
+      InitRunScheduler();
+
       host = new ServiceHost(database, new Uri(addressTextBox.Text));
       ServiceThrottlingBehavior throttlingBehavior = new ServiceThrottlingBehavior();
@@ -95,4 +102,9 @@
     private void statusUpdateTimer_Tick(object sender, EventArgs e) {
     }
+
+    private void startButton_Click(object sender, EventArgs e) {
+      Start();
+      startButton.Enabled = false;
+    }
   }
 }
Index: trunk/sources/HeuristicLab.CEDMA.Server/ServerForm.designer.cs
===================================================================
--- trunk/sources/HeuristicLab.CEDMA.Server/ServerForm.designer.cs	(revision 372)
+++ trunk/sources/HeuristicLab.CEDMA.Server/ServerForm.designer.cs	(revision 375)
@@ -51,4 +51,7 @@
       this.activeAgentsTextBox = new System.Windows.Forms.TextBox();
       this.statusUpdateTimer = new System.Windows.Forms.Timer(this.components);
+      this.gridAddressLabel = new System.Windows.Forms.Label();
+      this.gridAddress = new System.Windows.Forms.TextBox();
+      this.startButton = new System.Windows.Forms.Button();
       this.SuspendLayout();
       // 
@@ -73,5 +76,5 @@
       // 
       this.activeAgentsLabel.AutoSize = true;
-      this.activeAgentsLabel.Location = new System.Drawing.Point(12, 35);
+      this.activeAgentsLabel.Location = new System.Drawing.Point(12, 61);
       this.activeAgentsLabel.Name = "activeAgentsLabel";
       this.activeAgentsLabel.Size = new System.Drawing.Size(75, 13);
@@ -81,5 +84,5 @@
       // activeAgentsTextBox
       // 
-      this.activeAgentsTextBox.Location = new System.Drawing.Point(106, 32);
+      this.activeAgentsTextBox.Location = new System.Drawing.Point(106, 58);
       this.activeAgentsTextBox.Name = "activeAgentsTextBox";
       this.activeAgentsTextBox.ReadOnly = true;
@@ -95,9 +98,38 @@
       this.statusUpdateTimer.Tick += new System.EventHandler(this.statusUpdateTimer_Tick);
       // 
+      // gridAddressLabel
+      // 
+      this.gridAddressLabel.AutoSize = true;
+      this.gridAddressLabel.Location = new System.Drawing.Point(12, 35);
+      this.gridAddressLabel.Name = "gridAddressLabel";
+      this.gridAddressLabel.Size = new System.Drawing.Size(69, 13);
+      this.gridAddressLabel.TabIndex = 9;
+      this.gridAddressLabel.Text = "&Grid address:";
+      // 
+      // gridAddress
+      // 
+      this.gridAddress.Location = new System.Drawing.Point(106, 32);
+      this.gridAddress.Name = "gridAddress";
+      this.gridAddress.Size = new System.Drawing.Size(229, 20);
+      this.gridAddress.TabIndex = 8;
+      // 
+      // startButton
+      // 
+      this.startButton.Location = new System.Drawing.Point(15, 84);
+      this.startButton.Name = "startButton";
+      this.startButton.Size = new System.Drawing.Size(75, 23);
+      this.startButton.TabIndex = 10;
+      this.startButton.Text = "Start";
+      this.startButton.UseVisualStyleBackColor = true;
+      this.startButton.Click += new System.EventHandler(this.startButton_Click);
+      // 
       // ServerForm
       // 
       this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
       this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
-      this.ClientSize = new System.Drawing.Size(347, 62);
+      this.ClientSize = new System.Drawing.Size(347, 119);
+      this.Controls.Add(this.startButton);
+      this.Controls.Add(this.gridAddressLabel);
+      this.Controls.Add(this.gridAddress);
       this.Controls.Add(this.activeAgentsLabel);
       this.Controls.Add(this.activeAgentsTextBox);
@@ -118,4 +150,7 @@
     private System.Windows.Forms.TextBox activeAgentsTextBox;
     private System.Windows.Forms.Timer statusUpdateTimer;
+    private System.Windows.Forms.Label gridAddressLabel;
+    private System.Windows.Forms.TextBox gridAddress;
+    private System.Windows.Forms.Button startButton;
   }
 }
