Index: /trunk/sources/HeuristicLab.CEDMA.Console/Agent.cs
===================================================================
--- /trunk/sources/HeuristicLab.CEDMA.Console/Agent.cs	(revision 374)
+++ /trunk/sources/HeuristicLab.CEDMA.Console/Agent.cs	(revision 375)
@@ -33,5 +33,5 @@
     public long Id { get; set; }
     public string Name { get; set; }
-    public AgentStatus Status { get; set; }
+    public ProcessStatus Status { get; set; }
     private OperatorGraph operatorGraph;
 
@@ -51,10 +51,11 @@
 
     public void Save() {
-      AgentEntry entry = new AgentEntry(Id, Name, Status, DbPersistenceManager.Save(this));
-      Database.Update(entry);
+      Database.UpdateAgent(Id, Name);
+      Database.UpdateAgent(Id, Status);
+      Database.UpdateAgent(Id, DbPersistenceManager.Save(this));
     }
 
     public void Activate() {
-      Status = AgentStatus.Waiting;
+      Status = ProcessStatus.Waiting;
       Save();
     }
Index: /trunk/sources/HeuristicLab.CEDMA.Console/AgentList.cs
===================================================================
--- /trunk/sources/HeuristicLab.CEDMA.Console/AgentList.cs	(revision 374)
+++ /trunk/sources/HeuristicLab.CEDMA.Console/AgentList.cs	(revision 375)
@@ -46,5 +46,5 @@
     private void ReloadList() {
       agentList.Clear();
-      foreach(AgentEntry a in database.GetAgentEntries()) {
+      foreach(AgentEntry a in database.GetAgents()) {
         Agent newAgent = (Agent)DbPersistenceManager.Restore(a.RawData);
         newAgent.Database = database;
@@ -63,8 +63,10 @@
 
     public void CreateAgent() {
-      long id = database.CreateAgent();
-      Agent agent = new Agent(database, id);
+      Agent agent = new Agent();
       agent.Name = DateTime.Now.ToString();
-      agent.Save();
+      agent.Status = ProcessStatus.Unkown;
+      agent.Database = database;
+      long id = database.InsertAgent(agent.Name, DbPersistenceManager.Save(agent));
+      agent.Id = id;
       agentList.Add(agent);
     }
Index: /trunk/sources/HeuristicLab.CEDMA.Console/AgentView.cs
===================================================================
--- /trunk/sources/HeuristicLab.CEDMA.Console/AgentView.cs	(revision 374)
+++ /trunk/sources/HeuristicLab.CEDMA.Console/AgentView.cs	(revision 375)
@@ -58,5 +58,5 @@
         }
 
-        if(Agent.Status == AgentStatus.Unkown) activateButton.Enabled = true;
+        if(Agent.Status == ProcessStatus.Unkown) activateButton.Enabled = true;
         else activateButton.Enabled = false;
       }
Index: /trunk/sources/HeuristicLab.CEDMA.Console/DbPersistenceManager.cs
===================================================================
--- /trunk/sources/HeuristicLab.CEDMA.Console/DbPersistenceManager.cs	(revision 374)
+++ /trunk/sources/HeuristicLab.CEDMA.Console/DbPersistenceManager.cs	(revision 375)
@@ -29,10 +29,10 @@
 
 namespace HeuristicLab.CEDMA.Console {
-  internal static class DbPersistenceManager {
-    internal static IStorable Restore(byte[] serializedStorable) {
+  public static class DbPersistenceManager {
+    public static IStorable Restore(byte[] serializedStorable) {
       GZipStream stream = new GZipStream(new MemoryStream(serializedStorable), CompressionMode.Decompress);
       return PersistenceManager.Load(stream);
     }
-    internal static byte[] Save(IStorable storable) {
+    public static byte[] Save(IStorable storable) {
       MemoryStream memStream = new MemoryStream();
       GZipStream stream = new GZipStream(memStream, CompressionMode.Compress, true);
Index: /trunk/sources/HeuristicLab.CEDMA.Console/IAgent.cs
===================================================================
--- /trunk/sources/HeuristicLab.CEDMA.Console/IAgent.cs	(revision 374)
+++ /trunk/sources/HeuristicLab.CEDMA.Console/IAgent.cs	(revision 375)
@@ -30,5 +30,5 @@
   public interface IAgent : IDatabaseItem {
     string Name { get; }
-    AgentStatus Status { get; }
+    ProcessStatus Status { get; }
     IOperatorGraph OperatorGraph { get; }
     void Save();
Index: /trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/AgentEntry.cs
===================================================================
--- /trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/AgentEntry.cs	(revision 374)
+++ /trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/AgentEntry.cs	(revision 375)
@@ -35,14 +35,7 @@
     public string Name { get; set; }
     [DataMember]
-    public AgentStatus Status { get; set; }
+    public ProcessStatus Status { get; set; }
     [DataMember]
     public byte[] RawData { get; set; }
-
-    public AgentEntry(long id, string name, AgentStatus status, byte[] rawData) {
-      Id = id;
-      Name = name;
-      Status = status;
-      RawData = rawData;
-    }
   }
 }
Index: unk/sources/HeuristicLab.CEDMA.DB.Interfaces/AgentStatus.cs
===================================================================
--- /trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/AgentStatus.cs	(revision 374)
+++ 	(revision )
@@ -1,29 +1,0 @@
-﻿#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;
-
-namespace HeuristicLab.CEDMA.DB.Interfaces {
-  public enum AgentStatus { Unkown, Active, Finished, Error, Waiting}
-}
Index: /trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/HeuristicLab.CEDMA.DB.Interfaces.csproj
===================================================================
--- /trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/HeuristicLab.CEDMA.DB.Interfaces.csproj	(revision 374)
+++ /trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/HeuristicLab.CEDMA.DB.Interfaces.csproj	(revision 375)
@@ -59,5 +59,6 @@
   <ItemGroup>
     <Compile Include="AgentEntry.cs" />
-    <Compile Include="AgentStatus.cs" />
+    <Compile Include="ProcessStatus.cs" />
+    <Compile Include="RunEntry.cs" />
     <Compile Include="ResultEntry.cs" />
     <Compile Include="HeuristicLabCedmaDbInterfacesPlugin.cs" />
Index: /trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/IDatabase.cs
===================================================================
--- /trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/IDatabase.cs	(revision 374)
+++ /trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/IDatabase.cs	(revision 375)
@@ -31,14 +31,47 @@
   public interface IDatabase {
     [OperationContract]
-    ICollection<AgentEntry> GetAgentEntries();
+    long InsertAgent(string name, byte[] rawData);
+
+    [OperationContract(Name = "UpdateAgentName")]
+    void UpdateAgent(long id, string name);
+
+    [OperationContract(Name = "UpdateAgentStatus")]
+    void UpdateAgent(long id, ProcessStatus status);
+
+    [OperationContract(Name = "UpdateAgentData")]
+    void UpdateAgent(long id, byte[] rawData);
 
     [OperationContract]
-    long CreateAgent();
+    long InsertRun(long agentId, byte[] rawData);
 
-    [OperationContract(Name="UpdateAgent")]
-    void Update(AgentEntry entry);
+    [OperationContract]
+    void UpdateRunStart(long runId, DateTime CreationTime);
 
-    [OperationContract(Name ="UpdateResult")]
-    void Update(ResultEntry result);
+    [OperationContract]
+    void UpdateRunFinished(long runId, DateTime CreationTime);
+
+    [OperationContract]
+    void UpdateRunStatus(long runId, ProcessStatus status);
+
+    [OperationContract]
+    long InsertResult(long runId, byte[] rawData);
+
+    [OperationContract]
+    long InsertSubResult(long resultId, byte[] rawData);
+
+
+    // should be replaced by more powerful querying interface (LINQ provider?)
+    [OperationContract]
+    ICollection<AgentEntry> GetAgents();
+
+    [OperationContract]
+    ICollection<RunEntry> GetRuns();
+
+    [OperationContract]
+    ICollection<ResultEntry> GetResults(long runId);
+
+    [OperationContract]
+    ICollection<ResultEntry> GetSubResults(long resultId);
+
   }
 }
Index: /trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/ProcessStatus.cs
===================================================================
--- /trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/ProcessStatus.cs	(revision 375)
+++ /trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/ProcessStatus.cs	(revision 375)
@@ -0,0 +1,29 @@
+﻿#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;
+
+namespace HeuristicLab.CEDMA.DB.Interfaces {
+  public enum ProcessStatus { Unkown, Active, Finished, Error, Waiting}
+}
Index: /trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/ResultEntry.cs
===================================================================
--- /trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/ResultEntry.cs	(revision 374)
+++ /trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/ResultEntry.cs	(revision 375)
@@ -31,20 +31,13 @@
   public class ResultEntry {
     [DataMember]
-    private long id;
+    public long Id { get; set; }
     [DataMember]
-    private byte[] rawData;
-
-    public ResultEntry(long id, byte[] rawData) {
-      this.id = id;
-      this.rawData = rawData;
-    }
-
-    public long Id {
-      get { return id; }
-    }
-
-    public byte[] RawData {
-      get { return rawData; }
-    }
+    public long RunId { get; set; }
+    [DataMember]
+    public long ResultId { get; set; }
+    [DataMember]
+    public DateTime CreationTime { get; set; }
+    [DataMember]
+    public byte[] RawData { get; set; }
   }
 }
Index: /trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/RunEntry.cs
===================================================================
--- /trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/RunEntry.cs	(revision 375)
+++ /trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/RunEntry.cs	(revision 375)
@@ -0,0 +1,47 @@
+﻿#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.Interfaces;
+using System.Runtime.Serialization;
+
+namespace HeuristicLab.CEDMA.DB.Interfaces {
+  [DataContract]
+  public class RunEntry {
+    [DataMember]
+    public long Id { get; set; }
+    [DataMember]
+    public long AgentId { get; set; }
+    [DataMember]
+    public DateTime CreationTime { get; set; }
+    [DataMember]
+    public DateTime? StartTime { get; set; }
+    [DataMember]
+    public DateTime? FinishedTime { get; set; }
+    [DataMember]
+    public ProcessStatus Status { get; set; }
+    [DataMember]
+    public byte[] RawData { get; set; }
+  }
+}
Index: /trunk/sources/HeuristicLab.CEDMA.DB/Database.cs
===================================================================
--- /trunk/sources/HeuristicLab.CEDMA.DB/Database.cs	(revision 374)
+++ /trunk/sources/HeuristicLab.CEDMA.DB/Database.cs	(revision 375)
@@ -32,105 +32,455 @@
 
 namespace HeuristicLab.CEDMA.DB {
-  [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Single, UseSynchronizationContext = true)]
+  [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple, UseSynchronizationContext = false)]
   public class Database : IDatabase {
     private string connectionString;
+    private object bigLock = new object();
     public Database(string connectionString) {
       this.connectionString = connectionString;
     }
 
+    #region create empty database
     public void CreateNew() {
-      using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
-        cnn.ConnectionString = connectionString;
-        cnn.Open();
-
-        SQLiteCommand cAgent = cnn.CreateCommand();
-        cAgent.CommandText = "CREATE TABLE Agent (ID integer primary key autoincrement, ProjectId integer, Name text, Status text default 'Unknown', RawData Blob)";
-        SQLiteCommand cProject = cnn.CreateCommand();
-        cProject.CommandText = "CREATE TABLE Project (ID integer primary key autoincrement, Name text, Description text, CreationDate DateTime)";
-        SQLiteCommand cResult = cnn.CreateCommand();
-        cResult.CommandText = "CREATE TABLE Result (ID integer primary key autoincrement, AgentId integer, ParentResultId integer, CreationDate DateTime, RawData Blob)";
-        cAgent.ExecuteNonQuery();
-        cProject.ExecuteNonQuery();
-        cResult.ExecuteNonQuery();
-      }
-    }
-
-    public long CreateAgent() {
-      using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
-        cnn.Open();
-        SQLiteCommand c = cnn.CreateCommand();
-        c.CommandText = "Insert into Agent (Name) values (@Name); select last_insert_rowid()";
-        DbParameter nameParam = c.CreateParameter();
-        nameParam.ParameterName = "@Name";
-        nameParam.Value = DateTime.Now.ToString();
-        c.Parameters.Add(nameParam);
-        long id = (long)c.ExecuteScalar();
-        return id;
-      }
-    }
-
-    public ICollection<AgentEntry> GetAgentEntries() {
-      List<AgentEntry> agents = new List<AgentEntry>();
-      using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
-        cnn.Open();
-        SQLiteCommand c = cnn.CreateCommand();
-        c.CommandText = "Select id, name, status, rawdata from Agent";
-        SQLiteDataReader r = c.ExecuteReader();
-        while(r.Read()) {
-          AgentEntry agent = new AgentEntry(r.GetInt32(0), r.GetString(1), (AgentStatus)Enum.Parse(typeof(AgentStatus), r.GetString(2)), (byte[])r.GetValue(3));
-          agents.Add(agent);
-        }
-      }
-      return agents;
-    }
-
-    public ICollection<AgentEntry> GetAgentEntries(AgentStatus status) {
-      List<AgentEntry> agents = new List<AgentEntry>();
-      using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
-        cnn.Open();
-        SQLiteCommand c = cnn.CreateCommand();
-        c.CommandText = "Select id, name, status, rawdata from Agent where Status=@Status";
-        DbParameter statusParameter = c.CreateParameter();
-        statusParameter.ParameterName = "@Status";
-        statusParameter.Value = (int)status;
-        c.Parameters.Add(statusParameter);
-
-        SQLiteDataReader r = c.ExecuteReader();
-        while(r.Read()) {
-          AgentEntry agent = new AgentEntry(r.GetInt32(0), r.GetString(1), (AgentStatus)Enum.Parse(typeof(AgentStatus), r.GetString(2)), (byte[])r.GetValue(3));
-          agents.Add(agent);
-        }
-      }
-      return agents;
-    }
-
-    public void Update(AgentEntry entry) {
-      using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
-        cnn.Open();
-        SQLiteCommand c = cnn.CreateCommand();
-        c.CommandText = "Update Agent set Name=@Name, Status=@Status, RawData=@RawData where id=@Id";
-        DbParameter nameParam = c.CreateParameter();
-        DbParameter statusParam = c.CreateParameter();
-        DbParameter rawDataParam = c.CreateParameter();
-        DbParameter idParam = c.CreateParameter();
-        nameParam.ParameterName = "@Name";
-        nameParam.Value = entry.Name;
-        statusParam.ParameterName = "@Status";
-        statusParam.Value = entry.Status;
-        rawDataParam.ParameterName = "@RawData";
-        rawDataParam.Value = entry.RawData;
-        idParam.ParameterName = "@Id";
-        idParam.Value = entry.Id;
-        c.Parameters.Add(nameParam);
-        c.Parameters.Add(statusParam);
-        c.Parameters.Add(rawDataParam);
-        c.Parameters.Add(idParam);
-        c.ExecuteNonQuery();
-      }
-    }
-
-    public void Update(ResultEntry result) {
+      lock(bigLock) {
+        using(DbConnection cnn = new SQLiteConnection(connectionString)) {
+          cnn.Open();
+          using(DbTransaction t = cnn.BeginTransaction()) {
+            using(DbCommand cmd = cnn.CreateCommand()) {
+              cmd.CommandText = "CREATE TABLE Project (ID integer primary key autoincrement, Name text, Description text, CreationTime DateTime)";
+              cmd.Transaction = t;
+              cmd.ExecuteNonQuery();
+            }
+            using(DbCommand cmd = cnn.CreateCommand()) {
+              cmd.CommandText = "CREATE TABLE Agent (ID integer primary key autoincrement, ProjectId integer, Name text, Status text default 'Unknown', RawData Blob)";
+              cmd.Transaction = t;
+              cmd.ExecuteNonQuery();
+            }
+            using(DbCommand cmd = cnn.CreateCommand()) {
+              cmd.CommandText = "CREATE TABLE Run (ID integer primary key autoincrement, AgentId integer, CreationTime DateTime, StartTime DateTime, FinishedTime DateTime, Status text default 'Unknown', RawData Blob)";
+              cmd.Transaction = t;
+              cmd.ExecuteNonQuery();
+            }
+            using(DbCommand cmd = cnn.CreateCommand()) {
+              cmd.CommandText = "CREATE TABLE Result (ID integer primary key autoincrement, RunId integer, ResultId integer, CreationTime DateTime, RawData Blob)";
+              cmd.Transaction = t;
+              cmd.ExecuteNonQuery();
+            }
+            t.Commit();
+          }
+        }
+      }
+    }
+    #endregion
+
+    #region insert agent/run/result/sub-result
+    public long InsertAgent(string name, byte[] rawData) {
+      lock(bigLock) {
+        using(DbConnection cnn = new SQLiteConnection(connectionString)) {
+          cnn.Open();
+          long id;
+          using(DbTransaction t = cnn.BeginTransaction()) {
+            using(DbCommand c = cnn.CreateCommand()) {
+              c.Transaction = t;
+              c.CommandText = "Insert into Agent (Name, RawData) values (@Name, @RawData); select last_insert_rowid()";
+              DbParameter nameParam = c.CreateParameter();
+              nameParam.ParameterName = "@Name";
+              nameParam.Value = name;
+              c.Parameters.Add(nameParam);
+              DbParameter dataParam = c.CreateParameter();
+              dataParam.ParameterName = "@RawData";
+              dataParam.Value = rawData;
+              c.Parameters.Add(dataParam);
+              id = (long)c.ExecuteScalar();
+            }
+            t.Commit();
+            return id;
+          }
+        }
+      }
+    }
+
+    public long InsertRun(long agentId, byte[] rawData) {
+      lock(bigLock) {
+        using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
+          cnn.Open();
+          long id;
+          using(DbTransaction t = cnn.BeginTransaction()) {
+            using(DbCommand c = cnn.CreateCommand()) {
+              c.Transaction = t;
+              c.CommandText = "Insert into Run (AgentId, CreationTime, RawData) values (@AgentId, @CreationTime, @RawData); select last_insert_rowid()";
+              DbParameter agentIdParam = c.CreateParameter();
+              agentIdParam.ParameterName = "@AgentId";
+              agentIdParam.Value = agentId;
+              c.Parameters.Add(agentIdParam);
+              DbParameter creationParam = c.CreateParameter();
+              creationParam.ParameterName = "@CreationTime";
+              DateTime now = DateTime.Now;
+              creationParam.Value = now;
+              c.Parameters.Add(creationParam);
+              DbParameter rawDataParam = c.CreateParameter();
+              rawDataParam.ParameterName = "@RawData";
+              rawDataParam.Value = rawData;
+              c.Parameters.Add(rawDataParam);
+              id = (long)c.ExecuteScalar();
+            }
+            t.Commit();
+            return id;
+          }
+        }
+      }
+    }
+
+    public long InsertResult(long runId, byte[] rawData) {
+      lock(bigLock) {
+        using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
+          cnn.Open();
+          long id;
+          using(DbTransaction t = cnn.BeginTransaction()) {
+            using(DbCommand c = cnn.CreateCommand()) {
+              c.Transaction = t;
+              c.CommandText = "Insert into Result (RunId, CreationTime, RawData) values (@RunId, @CreationTime, @RawData); select last_insert_rowid()";
+              DbParameter runIdParam = c.CreateParameter();
+              runIdParam.ParameterName = "@RunId";
+              runIdParam.Value = runId;
+              c.Parameters.Add(runIdParam);
+              DbParameter creationParam = c.CreateParameter();
+              creationParam.ParameterName = "@CreationTime";
+              DateTime now = DateTime.Now;
+              creationParam.Value = now;
+              c.Parameters.Add(creationParam);
+              DbParameter rawDataParam = c.CreateParameter();
+              rawDataParam.ParameterName = "@RawData";
+              rawDataParam.Value = rawData;
+              c.Parameters.Add(rawDataParam);
+              id = (long)c.ExecuteScalar();
+            }
+            t.Commit();
+            return id;
+          }
+        }
+      }
+    }
+
+    public long InsertSubResult(long resultId, byte[] rawData) {
+      lock(bigLock) {
+
+        using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
+          cnn.Open();
+          long id;
+          using(DbTransaction t = cnn.BeginTransaction()) {
+            using(DbCommand c = cnn.CreateCommand()) {
+              c.Transaction = t;
+              c.CommandText = "Insert into Result (ResultId, CreationTime, RawData) values (@ResultId, @CreationTime, @RawData); select last_insert_rowid()";
+              DbParameter resultIdParam = c.CreateParameter();
+              resultIdParam.ParameterName = "@ResultId";
+              resultIdParam.Value = resultId;
+              c.Parameters.Add(resultIdParam);
+              DbParameter creationParam = c.CreateParameter();
+              creationParam.ParameterName = "@CreationTime";
+              DateTime now = DateTime.Now;
+              creationParam.Value = now;
+              c.Parameters.Add(creationParam);
+              DbParameter rawDataParam = c.CreateParameter();
+              rawDataParam.ParameterName = "@RawData";
+              rawDataParam.Value = rawData;
+              c.Parameters.Add(rawDataParam);
+              id = (long)c.ExecuteScalar();
+            }
+            t.Commit();
+            return id;
+          }
+        }
+      }
+    }
+    #endregion
+
+    #region update agent/run
+    public void UpdateAgent(long id, string name) {
+      lock(bigLock) {
+        using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
+          cnn.Open();
+          using(SQLiteTransaction t = cnn.BeginTransaction()) {
+            using(SQLiteCommand c = cnn.CreateCommand()) {
+              c.Transaction = t;
+              c.CommandText = "Update Agent set Name=@Name where id=@Id";
+              DbParameter nameParam = c.CreateParameter();
+              DbParameter idParam = c.CreateParameter();
+              nameParam.ParameterName = "@Name";
+              nameParam.Value = name;
+              idParam.ParameterName = "@Id";
+              idParam.Value = id;
+              c.Parameters.Add(nameParam);
+              c.Parameters.Add(idParam);
+              c.ExecuteNonQuery();
+            }
+            t.Commit();
+          }
+        }
+      }
+    }
+
+    public void UpdateAgent(long id, ProcessStatus status) {
+      lock(bigLock) {
+        using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
+          cnn.Open();
+          using(SQLiteTransaction t = cnn.BeginTransaction()) {
+            using(SQLiteCommand c = cnn.CreateCommand()) {
+              c.Transaction = t;
+              c.CommandText = "Update Agent set Status=@Status where id=@Id";
+              DbParameter statusParam = c.CreateParameter();
+              DbParameter idParam = c.CreateParameter();
+              statusParam.ParameterName = "@Status";
+              statusParam.Value = status;
+              idParam.ParameterName = "@Id";
+              idParam.Value = id;
+              c.Parameters.Add(statusParam);
+              c.Parameters.Add(idParam);
+              c.ExecuteNonQuery();
+            }
+            t.Commit();
+          }
+        }
+      }
+    }
+
+    public void UpdateAgent(long id, byte[] rawData) {
+      lock(bigLock) {
+        using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
+          cnn.Open();
+          using(SQLiteTransaction t = cnn.BeginTransaction()) {
+            using(SQLiteCommand c = cnn.CreateCommand()) {
+              c.Transaction = t;
+              c.CommandText = "Update Agent set RawData=@RawData where id=@Id";
+              DbParameter rawDataParam = c.CreateParameter();
+              DbParameter idParam = c.CreateParameter();
+              rawDataParam.ParameterName = "@RawData";
+              rawDataParam.Value = rawData;
+              idParam.ParameterName = "@Id";
+              idParam.Value = id;
+              c.Parameters.Add(rawDataParam);
+              c.Parameters.Add(idParam);
+              c.ExecuteNonQuery();
+            }
+            t.Commit();
+          }
+        }
+      }
+    }
+
+    public void UpdateRunStart(long runId, DateTime startTime) {
+      lock(bigLock) {
+        using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
+          cnn.Open();
+          using(SQLiteTransaction t = cnn.BeginTransaction()) {
+            using(SQLiteCommand c = cnn.CreateCommand()) {
+              c.Transaction = t;
+              c.CommandText = "Update Run set StartTime=@StartTime where id=@Id";
+              DbParameter startTimeParam = c.CreateParameter();
+              DbParameter idParam = c.CreateParameter();
+              startTimeParam.ParameterName = "@StartTime";
+              startTimeParam.Value = startTime;
+              idParam.ParameterName = "@Id";
+              idParam.Value = runId;
+              c.Parameters.Add(startTimeParam);
+              c.Parameters.Add(idParam);
+              c.ExecuteNonQuery();
+            }
+            t.Commit();
+          }
+        }
+      }
+    }
+
+    public void UpdateRunFinished(long runId, DateTime finishedTime) {
+      lock(bigLock) {
+        using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
+          cnn.Open();
+          using(SQLiteTransaction t = cnn.BeginTransaction()) {
+            using(SQLiteCommand c = cnn.CreateCommand()) {
+              c.Transaction = t;
+              c.CommandText = "Update Run set FinishedTime=@FinishedTime where id=@Id";
+              DbParameter finishedTimeParam = c.CreateParameter();
+              DbParameter idParam = c.CreateParameter();
+              finishedTimeParam.ParameterName = "@FinishedTime";
+              finishedTimeParam.Value = finishedTime;
+              idParam.ParameterName = "@Id";
+              idParam.Value = runId;
+              c.Parameters.Add(finishedTimeParam);
+              c.Parameters.Add(idParam);
+              c.ExecuteNonQuery();
+            }
+            t.Commit();
+          }
+        }
+      }
+    }
+
+    public void UpdateRunStatus(long runId, ProcessStatus status) {
+      lock(bigLock) {
+        using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
+          cnn.Open();
+          using(SQLiteTransaction t = cnn.BeginTransaction()) {
+            using(SQLiteCommand c = cnn.CreateCommand()) {
+              c.Transaction = t;
+              c.CommandText = "Update Run set Status=@Status where id=@Id";
+              DbParameter statusParam = c.CreateParameter();
+              DbParameter idParam = c.CreateParameter();
+              statusParam.ParameterName = "@Status";
+              statusParam.Value = status;
+              idParam.ParameterName = "@Id";
+              idParam.Value = runId;
+              c.Parameters.Add(statusParam);
+              c.Parameters.Add(idParam);
+              c.ExecuteNonQuery();
+            }
+            t.Commit();
+          }
+        }
+      }
+    }
+
+
+
+    #endregion
+
+
+    #region get agent/run/result/sub-result
+
+    public ICollection<AgentEntry> GetAgents(ProcessStatus status) {
+      lock(bigLock) {
+        List<AgentEntry> agents = new List<AgentEntry>();
+        using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
+          cnn.Open();
+          SQLiteCommand c = cnn.CreateCommand();
+          c.CommandText = "Select id, name, status, rawdata from Agent where Status=@Status";
+          DbParameter statusParameter = c.CreateParameter();
+          statusParameter.ParameterName = "@Status";
+          statusParameter.Value = status;
+          c.Parameters.Add(statusParameter);
+
+          SQLiteDataReader r = c.ExecuteReader();
+          while(r.Read()) {
+            AgentEntry agent = new AgentEntry();
+            agent.Id = r.GetInt32(0);
+            agent.Name = r.GetString(1);
+            agent.Status = (ProcessStatus)Enum.Parse(typeof(ProcessStatus), r.GetString(2));
+            agent.RawData = (byte[])r.GetValue(3);
+            agents.Add(agent);
+          }
+        }
+        return agents;
+      }
+    }
+
+    public ICollection<AgentEntry> GetAgents() {
+      lock(bigLock) {
+        List<AgentEntry> agents = new List<AgentEntry>();
+        using(DbConnection cnn = new SQLiteConnection(connectionString)) {
+          cnn.Open();
+          using(DbCommand c = cnn.CreateCommand()) {
+            c.CommandText = "Select id, name, status, rawdata from Agent";
+            using(DbDataReader r = c.ExecuteReader()) {
+              while(r.Read()) {
+                AgentEntry agent = new AgentEntry();
+                agent.Id = r.GetInt32(0);
+                agent.Name = r.GetString(1);
+                agent.Status = (ProcessStatus)Enum.Parse(typeof(ProcessStatus), r.GetString(2));
+                agent.RawData = (byte[])r.GetValue(3);
+                agents.Add(agent);
+              }
+            }
+          }
+        }
+        return agents;
+      }
+    }
+
+    //(ID integer primary key autoincrement, AgentId integer, CreationTime DateTime, StartTime DateTime, FinishedTime DateTime, Status text default 'Unknown', RawData Blob)";
+
+    public ICollection<RunEntry> GetRuns() {
+      lock(bigLock) {
+        List<RunEntry> runs = new List<RunEntry>();
+        using(DbConnection cnn = new SQLiteConnection(connectionString)) {
+          cnn.Open();
+          using(DbCommand c = cnn.CreateCommand()) {
+            c.CommandText = "Select Id, AgentId, CreationTime, StartTime, FinishedTime, Status, Rawdata from Run";
+            using(DbDataReader r = c.ExecuteReader()) {
+              while(r.Read()) {
+                RunEntry run = new RunEntry();
+                run.Id = r.GetInt32(0);
+                run.AgentId = r.GetInt32(1);
+                run.CreationTime = r.GetDateTime(2);
+                run.StartTime = r.GetDateTime(3);
+                run.FinishedTime = r.GetDateTime(4);
+                run.Status = (ProcessStatus)Enum.Parse(typeof(ProcessStatus), r.GetString(5));
+                run.RawData = (byte[])r.GetValue(6);
+                runs.Add(run);
+              }
+            }
+          }
+        }
+        return runs;
+      }
+    }
+
+    public ICollection<RunEntry> GetRuns(ProcessStatus status) {
+      lock(bigLock) {
+        List<RunEntry> runs = new List<RunEntry>();
+        using(DbConnection cnn = new SQLiteConnection(connectionString)) {
+          cnn.Open();
+          using(DbCommand c = cnn.CreateCommand()) {
+            c.CommandText = "Select Id, AgentId, CreationTime, StartTime, FinishedTime, Status, Rawdata from Run where Status=@Status";
+            DbParameter statusParameter = c.CreateParameter();
+            statusParameter.ParameterName = "@Status";
+            statusParameter.Value = status;
+            c.Parameters.Add(statusParameter);
+
+            using(DbDataReader r = c.ExecuteReader()) {
+              while(r.Read()) {
+                RunEntry run = new RunEntry();
+                run.Id = r.GetInt32(0);
+                run.AgentId = r.GetInt32(1);
+                run.CreationTime = r.GetDateTime(2);
+                run.StartTime = r.IsDBNull(3)? null : new Nullable<DateTime>(r.GetDateTime(3));
+                run.FinishedTime = r.IsDBNull(4) ? null:new Nullable<DateTime>(r.GetDateTime(4));
+                run.Status = (ProcessStatus)Enum.Parse(typeof(ProcessStatus), r.GetString(5));
+                run.RawData = (byte[])r.GetValue(6);
+                runs.Add(run);
+              }
+            }
+          }
+        }
+        return runs;
+      }
+    }
+
+    // (ID integer primary key autoincrement, RunId integer, ResultId integer, CreationTime DateTime, RawData Blob)";
+    public ICollection<ResultEntry> GetResults(long runId) {
+      lock(bigLock) {
+        List<ResultEntry> results = new List<ResultEntry>();
+        using(DbConnection cnn = new SQLiteConnection(connectionString)) {
+          cnn.Open();
+          using(DbCommand c = cnn.CreateCommand()) {
+            c.CommandText = "Select Id, RunId, CreationTime, Rawdata from Result";
+            using(DbDataReader r = c.ExecuteReader()) {
+              while(r.Read()) {
+                ResultEntry result = new ResultEntry();
+                result.Id = r.GetInt32(0);
+                result.RunId = r.GetInt32(1);
+                result.CreationTime = r.GetDateTime(2);
+                result.RawData = (byte[])r.GetValue(3);
+                results.Add(result);
+              }
+            }
+          }
+        }
+        return results;
+      }
+    }
+
+    public ICollection<ResultEntry> GetSubResults(long resultId) {
       throw new NotImplementedException();
     }
+    #endregion
   }
 }
Index: /trunk/sources/HeuristicLab.CEDMA.Operators/HeuristicLab.CEDMA.Operators.csproj
===================================================================
--- /trunk/sources/HeuristicLab.CEDMA.Operators/HeuristicLab.CEDMA.Operators.csproj	(revision 374)
+++ /trunk/sources/HeuristicLab.CEDMA.Operators/HeuristicLab.CEDMA.Operators.csproj	(revision 375)
@@ -42,4 +42,10 @@
       <RequiredTargetFramework>3.5</RequiredTargetFramework>
     </Reference>
+    <Reference Include="System.Runtime.Serialization">
+      <RequiredTargetFramework>3.0</RequiredTargetFramework>
+    </Reference>
+    <Reference Include="System.ServiceModel">
+      <RequiredTargetFramework>3.0</RequiredTargetFramework>
+    </Reference>
     <Reference Include="System.Xml.Linq">
       <RequiredTargetFramework>3.5</RequiredTargetFramework>
@@ -53,8 +59,27 @@
   <ItemGroup>
     <Compile Include="HeuristicLabCedmaOperatorsPlugin.cs" />
+    <Compile Include="OnGridProcessor.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
   </ItemGroup>
   <ItemGroup>
     <None Include="HeuristicLab.snk" />
+  </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\HeuristicLab.CEDMA.Console\HeuristicLab.CEDMA.Console.csproj">
+      <Project>{F8880599-F224-4EC7-9288-5C4A6853E7BE}</Project>
+      <Name>HeuristicLab.CEDMA.Console</Name>
+    </ProjectReference>
+    <ProjectReference Include="..\HeuristicLab.CEDMA.DB.Interfaces\HeuristicLab.CEDMA.DB.Interfaces.csproj">
+      <Project>{4F9BB789-D561-436B-B226-2BF44B7D0804}</Project>
+      <Name>HeuristicLab.CEDMA.DB.Interfaces</Name>
+    </ProjectReference>
+    <ProjectReference Include="..\HeuristicLab.Core\HeuristicLab.Core.csproj">
+      <Project>{F43B59AB-2B8C-4570-BC1E-15592086517C}</Project>
+      <Name>HeuristicLab.Core</Name>
+    </ProjectReference>
+    <ProjectReference Include="..\HeuristicLab.Data\HeuristicLab.Data.csproj">
+      <Project>{F473D9AF-3F09-4296-9F28-3C65118DAFFA}</Project>
+      <Name>HeuristicLab.Data</Name>
+    </ProjectReference>
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Index: /trunk/sources/HeuristicLab.CEDMA.Operators/OnGridProcessor.cs
===================================================================
--- /trunk/sources/HeuristicLab.CEDMA.Operators/OnGridProcessor.cs	(revision 375)
+++ /trunk/sources/HeuristicLab.CEDMA.Operators/OnGridProcessor.cs	(revision 375)
@@ -0,0 +1,63 @@
+#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.Text;
+using HeuristicLab.Core;
+using HeuristicLab.Data;
+using System.Threading;
+using HeuristicLab.CEDMA.DB.Interfaces;
+using System.ServiceModel;
+using HeuristicLab.CEDMA.Console;
+
+namespace HeuristicLab.CEDMA.Operators {
+  public class OnGridProcessor : OperatorBase {
+    public override string Description {
+      get { return "TASK."; }
+    }
+
+    public OnGridProcessor()
+      : base() {
+      AddVariableInfo(new VariableInfo("AgentId", "Id of the agent that the run should be associated to.", typeof(IntData), VariableKind.In));
+      AddVariableInfo(new VariableInfo("OperatorGraph", "The operator graph that should be executed on the grid", typeof(IOperatorGraph), VariableKind.In));
+      AddVariableInfo(new VariableInfo("ServerUrl", "Url of the CEDMA server", typeof(StringData), VariableKind.In));
+    }
+
+    public override IOperation Apply(IScope scope) {
+      IOperatorGraph operatorGraph = scope.GetVariableValue<IOperatorGraph>("OperatorGraph", false);
+      string serverUrl = scope.GetVariableValue<StringData>("ServerUrl", true).Data;
+      long agentId = scope.GetVariableValue<IntData>("AgentId", true).Data;
+
+      NetTcpBinding binding = new NetTcpBinding();
+      binding.MaxReceivedMessageSize = 10000000; // 10Mbytes
+      binding.ReaderQuotas.MaxStringContentLength = 10000000; // also 10M chars
+      binding.ReaderQuotas.MaxArrayLength = 10000000; // also 10M elements;
+      binding.Security.Mode = SecurityMode.None;
+      using(ChannelFactory<IDatabase> factory = new ChannelFactory<IDatabase>(binding)) {
+        IDatabase database = factory.CreateChannel(new EndpointAddress(serverUrl));
+        long id = database.InsertRun(agentId, DbPersistenceManager.Save(operatorGraph));
+        database.UpdateRunStatus(id, ProcessStatus.Waiting);
+      }
+      return null;
+    }
+  }
+}
Index: /trunk/sources/HeuristicLab.CEDMA.Server/AgentScheduler.cs
===================================================================
--- /trunk/sources/HeuristicLab.CEDMA.Server/AgentScheduler.cs	(revision 374)
+++ /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 374)
+++ /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 374)
+++ /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 374)
+++ /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;
   }
 }
Index: /trunk/sources/HeuristicLab.DistributedEngine/HeuristicLab.DistributedEngine.csproj
===================================================================
--- /trunk/sources/HeuristicLab.DistributedEngine/HeuristicLab.DistributedEngine.csproj	(revision 374)
+++ /trunk/sources/HeuristicLab.DistributedEngine/HeuristicLab.DistributedEngine.csproj	(revision 375)
@@ -49,5 +49,4 @@
   </ItemGroup>
   <ItemGroup>
-    <Compile Include="OnGridProcessor.cs" />
     <Compile Include="HeuristicLabDistributedEnginePlugin.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
Index: unk/sources/HeuristicLab.DistributedEngine/OnGridProcessor.cs
===================================================================
--- /trunk/sources/HeuristicLab.DistributedEngine/OnGridProcessor.cs	(revision 374)
+++ 	(revision )
@@ -1,58 +1,0 @@
-#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.Text;
-using HeuristicLab.Core;
-using HeuristicLab.Data;
-using HeuristicLab.Grid;
-using System.Threading;
-
-namespace HeuristicLab.DistributedEngine {
-  public class OnGridProcessor : OperatorBase {
-    public override string Description {
-      get { return "TASK."; }
-    }
-
-    public OnGridProcessor()
-      : base() {
-      AddVariableInfo(new VariableInfo("OperatorGraph", "The operator graph that should be executed on the grid", typeof(IOperatorGraph), VariableKind.In));
-      AddVariableInfo(new VariableInfo("GridServerUrl", "Url of the grid server", typeof(StringData), VariableKind.In));
-    }
-
-    public override IOperation Apply(IScope scope) {
-      IOperatorGraph operatorGraph = scope.GetVariableValue<IOperatorGraph>("OperatorGraph", false);
-      string gridServerUrl = scope.GetVariableValue<StringData>("GridServerUrl", true).Data;
-      JobManager jobManager = new JobManager(gridServerUrl);
-      jobManager.Reset();
-      Scope globalScope = new Scope();
-      AtomicOperation operation = new AtomicOperation(operatorGraph.InitialOperator, globalScope);
-      WaitHandle w = jobManager.BeginExecuteOperation(globalScope, operation);
-      
-      ThreadPool.QueueUserWorkItem(delegate(object status) {
-        w.WaitOne();
-        jobManager.EndExecuteOperation(operation);
-      });
-      return null;
-    }
-  }
-}
