Index: trunk/sources/HeuristicLab.CEDMA.Console/Agent.cs
===================================================================
--- trunk/sources/HeuristicLab.CEDMA.Console/Agent.cs	(revision 371)
+++ trunk/sources/HeuristicLab.CEDMA.Console/Agent.cs	(revision 372)
@@ -1,3 +1,24 @@
-﻿using System;
+﻿#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;
@@ -5,13 +26,13 @@
 using HeuristicLab.Core;
 using System.Xml;
+using HeuristicLab.CEDMA.DB.Interfaces;
 
 namespace HeuristicLab.CEDMA.Console {
   public class Agent : ItemBase, IAgent {
-    private string name;
+    public IDatabase Database { get; set; }
+    public long Id { get; set; }
+    public string Name { get; set; }
+    public AgentStatus Status { get; set; }
     private OperatorGraph operatorGraph;
-    public string Name {
-      get { return name; }
-      set { name = value; }
-    }
 
     public IOperatorGraph OperatorGraph {
@@ -19,7 +40,37 @@
     }
 
-    public Agent() : base() {
+    public Agent()
+      : base() {
       operatorGraph = new OperatorGraph();
     }
+
+    public Agent(IDatabase database, long id) : this() {
+      Database = database;
+      Id = id;
+    }
+
+    public void Save() {
+      AgentEntry entry = new AgentEntry(Id, Name, Status, DbPersistenceManager.Save(this));
+      Database.Update(entry);
+    }
+
+    public void Activate() {
+      Status = AgentStatus.Waiting;
+      Save();
+    }
+
+    #region persistence
+    public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
+      XmlNode node = base.GetXmlNode(name, document, persistedObjects);
+      node.AppendChild(PersistenceManager.Persist("OperatorGraph", operatorGraph, document, persistedObjects));
+      return node;
+    }
+
+    public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
+      base.Populate(node, restoredObjects);
+      operatorGraph = (OperatorGraph)PersistenceManager.Restore(node.SelectSingleNode("OperatorGraph"), restoredObjects);
+    }
+    #endregion
+
   }
 }
Index: trunk/sources/HeuristicLab.CEDMA.Console/AgentList.cs
===================================================================
--- trunk/sources/HeuristicLab.CEDMA.Console/AgentList.cs	(revision 371)
+++ trunk/sources/HeuristicLab.CEDMA.Console/AgentList.cs	(revision 372)
@@ -1,3 +1,24 @@
-﻿using System;
+﻿#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;
@@ -6,7 +27,10 @@
 using System.Collections;
 using HeuristicLab.CEDMA.DB.Interfaces;
+using System.Xml;
+using System.Runtime.Serialization;
+using System.IO;
 
 namespace HeuristicLab.CEDMA.Console {
-  public class AgentList: ItemBase, IAgentList {
+  public class AgentList : ItemBase, IAgentList {
     private string serverUri;
     private List<IAgent> agentList;
@@ -22,7 +46,10 @@
     private void ReloadList() {
       agentList.Clear();
-      foreach(HeuristicLab.CEDMA.DB.Interfaces.IAgent a in database.GetAgents()) {
-        Agent newAgent = new Agent();
+      foreach(AgentEntry a in database.GetAgentEntries()) {
+        Agent newAgent = (Agent)DbPersistenceManager.Restore(a.RawData);
+        newAgent.Database = database;
+        newAgent.Id = a.Id;
         newAgent.Name = a.Name;
+        newAgent.Status = a.Status;
         agentList.Add(newAgent);
       }
@@ -34,6 +61,10 @@
       agentList = new List<IAgent>();
     }
-    
-    public void Add(IAgent agent) {
+
+    public void CreateAgent() {
+      long id = database.CreateAgent();
+      Agent agent = new Agent(database, id);
+      agent.Name = DateTime.Now.ToString();
+      agent.Save();
       agentList.Add(agent);
     }
Index: trunk/sources/HeuristicLab.CEDMA.Console/AgentListView.cs
===================================================================
--- trunk/sources/HeuristicLab.CEDMA.Console/AgentListView.cs	(revision 371)
+++ trunk/sources/HeuristicLab.CEDMA.Console/AgentListView.cs	(revision 372)
@@ -94,8 +94,6 @@
     #region Button Events
     private void addButton_Click(object sender, EventArgs e) {
-      Agent agent = new Agent();
-      string name = DateTime.Now.ToString();
-      agent.Name = name;
-      AgentList.Add(agent);
+      AgentList.CreateAgent();
+      UpdateControls();
     }
     #endregion
Index: trunk/sources/HeuristicLab.CEDMA.Console/AgentView.Designer.cs
===================================================================
--- trunk/sources/HeuristicLab.CEDMA.Console/AgentView.Designer.cs	(revision 371)
+++ trunk/sources/HeuristicLab.CEDMA.Console/AgentView.Designer.cs	(revision 372)
@@ -48,5 +48,4 @@
       this.saveButton = new System.Windows.Forms.Button();
       this.activateButton = new System.Windows.Forms.Button();
-      this.stopButton = new System.Windows.Forms.Button();
       this.SuspendLayout();
       // 
@@ -72,4 +71,5 @@
       this.saveButton.Text = "&Save";
       this.saveButton.UseVisualStyleBackColor = true;
+      this.saveButton.Click += new System.EventHandler(this.saveButton_Click);
       // 
       // activateButton
@@ -82,14 +82,5 @@
       this.activateButton.Text = "&Activate";
       this.activateButton.UseVisualStyleBackColor = true;
-      // 
-      // stopButton
-      // 
-      this.stopButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
-      this.stopButton.Location = new System.Drawing.Point(166, 128);
-      this.stopButton.Name = "stopButton";
-      this.stopButton.Size = new System.Drawing.Size(75, 23);
-      this.stopButton.TabIndex = 3;
-      this.stopButton.Text = "S&top";
-      this.stopButton.UseVisualStyleBackColor = true;
+      this.activateButton.Click += new System.EventHandler(this.activateButton_Click);
       // 
       // AgentView
@@ -97,5 +88,4 @@
       this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
       this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
-      this.Controls.Add(this.stopButton);
       this.Controls.Add(this.activateButton);
       this.Controls.Add(this.saveButton);
@@ -112,5 +102,4 @@
     private System.Windows.Forms.Button saveButton;
     private System.Windows.Forms.Button activateButton;
-    private System.Windows.Forms.Button stopButton;
   }
 }
Index: trunk/sources/HeuristicLab.CEDMA.Console/AgentView.cs
===================================================================
--- trunk/sources/HeuristicLab.CEDMA.Console/AgentView.cs	(revision 371)
+++ trunk/sources/HeuristicLab.CEDMA.Console/AgentView.cs	(revision 372)
@@ -28,4 +28,5 @@
 using System.Windows.Forms;
 using HeuristicLab.Core;
+using HeuristicLab.CEDMA.DB.Interfaces;
 
 namespace HeuristicLab.CEDMA.Console {
@@ -56,5 +57,17 @@
           editorGroupBox.Enabled = true;
         }
+
+        if(Agent.Status == AgentStatus.Unkown) activateButton.Enabled = true;
+        else activateButton.Enabled = false;
       }
+    }
+
+    private void saveButton_Click(object sender, EventArgs e) {
+      Agent.Save();
+    }
+
+    private void activateButton_Click(object sender, EventArgs e) {
+      Agent.Activate();
+      activateButton.Enabled = false;
     }
   }
Index: trunk/sources/HeuristicLab.CEDMA.Console/Console.cs
===================================================================
--- trunk/sources/HeuristicLab.CEDMA.Console/Console.cs	(revision 371)
+++ trunk/sources/HeuristicLab.CEDMA.Console/Console.cs	(revision 372)
@@ -1,3 +1,24 @@
-﻿using System;
+﻿#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;
Index: trunk/sources/HeuristicLab.CEDMA.Console/ConsoleEditor.cs
===================================================================
--- trunk/sources/HeuristicLab.CEDMA.Console/ConsoleEditor.cs	(revision 371)
+++ trunk/sources/HeuristicLab.CEDMA.Console/ConsoleEditor.cs	(revision 372)
@@ -1,3 +1,24 @@
-﻿using System;
+﻿#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;
@@ -16,4 +37,7 @@
     private System.Windows.Forms.TabPage resultsPage;
     private Button connectButton;
+    private ComboBox comboBox1;
+    private Label projectLabel;
+    private Button newButton;
     private Console console;
 
@@ -31,4 +55,7 @@
       this.resultsPage = new System.Windows.Forms.TabPage();
       this.connectButton = new System.Windows.Forms.Button();
+      this.comboBox1 = new System.Windows.Forms.ComboBox();
+      this.projectLabel = new System.Windows.Forms.Label();
+      this.newButton = new System.Windows.Forms.Button();
       this.tabControl.SuspendLayout();
       this.SuspendLayout();
@@ -59,8 +86,8 @@
       this.tabControl.Controls.Add(this.resultsPage);
       this.tabControl.Enabled = false;
-      this.tabControl.Location = new System.Drawing.Point(6, 29);
+      this.tabControl.Location = new System.Drawing.Point(6, 56);
       this.tabControl.Name = "tabControl";
       this.tabControl.SelectedIndex = 0;
-      this.tabControl.Size = new System.Drawing.Size(407, 242);
+      this.tabControl.Size = new System.Drawing.Size(506, 407);
       this.tabControl.TabIndex = 2;
       // 
@@ -70,5 +97,5 @@
       this.overviewPage.Name = "overviewPage";
       this.overviewPage.Padding = new System.Windows.Forms.Padding(3);
-      this.overviewPage.Size = new System.Drawing.Size(399, 216);
+      this.overviewPage.Size = new System.Drawing.Size(498, 381);
       this.overviewPage.TabIndex = 0;
       this.overviewPage.Text = "Overview";
@@ -80,5 +107,5 @@
       this.agentsPage.Name = "agentsPage";
       this.agentsPage.Padding = new System.Windows.Forms.Padding(3);
-      this.agentsPage.Size = new System.Drawing.Size(399, 216);
+      this.agentsPage.Size = new System.Drawing.Size(498, 381);
       this.agentsPage.TabIndex = 1;
       this.agentsPage.Text = "Agents";
@@ -90,5 +117,5 @@
       this.resultsPage.Name = "resultsPage";
       this.resultsPage.Padding = new System.Windows.Forms.Padding(3);
-      this.resultsPage.Size = new System.Drawing.Size(399, 216);
+      this.resultsPage.Size = new System.Drawing.Size(498, 381);
       this.resultsPage.TabIndex = 2;
       this.resultsPage.Text = "Results";
@@ -105,7 +132,39 @@
       this.connectButton.Click += new System.EventHandler(this.connectButton_Click);
       // 
+      // comboBox1
+      // 
+      this.comboBox1.Enabled = false;
+      this.comboBox1.FormattingEnabled = true;
+      this.comboBox1.Location = new System.Drawing.Point(91, 29);
+      this.comboBox1.Name = "comboBox1";
+      this.comboBox1.Size = new System.Drawing.Size(121, 21);
+      this.comboBox1.TabIndex = 4;
+      // 
+      // projectLabel
+      // 
+      this.projectLabel.AutoSize = true;
+      this.projectLabel.Enabled = false;
+      this.projectLabel.Location = new System.Drawing.Point(42, 32);
+      this.projectLabel.Name = "projectLabel";
+      this.projectLabel.Size = new System.Drawing.Size(43, 13);
+      this.projectLabel.TabIndex = 5;
+      this.projectLabel.Text = "Project:";
+      // 
+      // newButton
+      // 
+      this.newButton.Enabled = false;
+      this.newButton.Location = new System.Drawing.Point(218, 27);
+      this.newButton.Name = "newButton";
+      this.newButton.Size = new System.Drawing.Size(75, 23);
+      this.newButton.TabIndex = 6;
+      this.newButton.Text = "New...";
+      this.newButton.UseVisualStyleBackColor = true;
+      // 
       // ConsoleEditor
       // 
       this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
+      this.Controls.Add(this.newButton);
+      this.Controls.Add(this.projectLabel);
+      this.Controls.Add(this.comboBox1);
       this.Controls.Add(this.connectButton);
       this.Controls.Add(this.tabControl);
@@ -113,5 +172,5 @@
       this.Controls.Add(this.uriTextBox);
       this.Name = "ConsoleEditor";
-      this.Size = new System.Drawing.Size(416, 274);
+      this.Size = new System.Drawing.Size(515, 466);
       this.tabControl.ResumeLayout(false);
       this.ResumeLayout(false);
@@ -125,5 +184,7 @@
         connectButton.Enabled = false;
         tabControl.Enabled = true;
+        agentsPage.Controls.Clear();
         agentsPage.Controls.Add((Control)console.AgentList.CreateView());
+        agentsPage.Controls[0].Dock = DockStyle.Fill;
       } catch(CommunicationException ex) {
         // TASK create helper class for error reporting
Index: trunk/sources/HeuristicLab.CEDMA.Console/DbPersistenceManager.cs
===================================================================
--- trunk/sources/HeuristicLab.CEDMA.Console/DbPersistenceManager.cs	(revision 372)
+++ trunk/sources/HeuristicLab.CEDMA.Console/DbPersistenceManager.cs	(revision 372)
@@ -0,0 +1,44 @@
+﻿#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 System.IO.Compression;
+using System.IO;
+using HeuristicLab.Core;
+
+namespace HeuristicLab.CEDMA.Console {
+  internal static class DbPersistenceManager {
+    internal static IStorable Restore(byte[] serializedStorable) {
+      GZipStream stream = new GZipStream(new MemoryStream(serializedStorable), CompressionMode.Decompress);
+      return PersistenceManager.Load(stream);
+    }
+    internal static byte[] Save(IStorable storable) {
+      MemoryStream memStream = new MemoryStream();
+      GZipStream stream = new GZipStream(memStream, CompressionMode.Compress, true);
+      PersistenceManager.Save(storable, stream);
+      stream.Close();
+      return memStream.ToArray();
+    }
+  }
+}
Index: trunk/sources/HeuristicLab.CEDMA.Console/HeuristicLab.CEDMA.Console.csproj
===================================================================
--- trunk/sources/HeuristicLab.CEDMA.Console/HeuristicLab.CEDMA.Console.csproj	(revision 371)
+++ trunk/sources/HeuristicLab.CEDMA.Console/HeuristicLab.CEDMA.Console.csproj	(revision 372)
@@ -66,7 +66,9 @@
       <SubType>UserControl</SubType>
     </Compile>
+    <Compile Include="DbPersistenceManager.cs" />
     <Compile Include="HeuristicLabCedmaConsolePlugin.cs" />
     <Compile Include="IAgent.cs" />
     <Compile Include="IAgentList.cs" />
+    <Compile Include="IDatabaseItem.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="AgentListView.cs">
Index: trunk/sources/HeuristicLab.CEDMA.Console/IAgent.cs
===================================================================
--- trunk/sources/HeuristicLab.CEDMA.Console/IAgent.cs	(revision 371)
+++ trunk/sources/HeuristicLab.CEDMA.Console/IAgent.cs	(revision 372)
@@ -1,12 +1,37 @@
-﻿using System;
+﻿#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.Core;
+using HeuristicLab.CEDMA.DB.Interfaces;
 
 namespace HeuristicLab.CEDMA.Console {
-  public interface IAgent : IItem {
+  public interface IAgent : IDatabaseItem {
     string Name { get; }
+    AgentStatus Status { get; }
     IOperatorGraph OperatorGraph { get; }
+    void Save();
+    void Activate();
   }
 }
Index: trunk/sources/HeuristicLab.CEDMA.Console/IAgentList.cs
===================================================================
--- trunk/sources/HeuristicLab.CEDMA.Console/IAgentList.cs	(revision 371)
+++ trunk/sources/HeuristicLab.CEDMA.Console/IAgentList.cs	(revision 372)
@@ -1,3 +1,24 @@
-﻿using System;
+﻿#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;
@@ -7,5 +28,5 @@
 namespace HeuristicLab.CEDMA.Console {
   public interface IAgentList : IItem, IEnumerable<IAgent> {
-    void Add(IAgent agent);
+    void CreateAgent();
   }
 }
Index: trunk/sources/HeuristicLab.CEDMA.Console/IDatabaseItem.cs
===================================================================
--- trunk/sources/HeuristicLab.CEDMA.Console/IDatabaseItem.cs	(revision 372)
+++ trunk/sources/HeuristicLab.CEDMA.Console/IDatabaseItem.cs	(revision 372)
@@ -0,0 +1,35 @@
+﻿#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.Core;
+using HeuristicLab.CEDMA.DB.Interfaces;
+
+namespace HeuristicLab.CEDMA.Console {
+  public interface IDatabaseItem : IItem {
+    IDatabase Database { get; set; }
+    long Id { get; set; }
+    void Save();
+  }
+}
Index: trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/AgentEntry.cs
===================================================================
--- trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/AgentEntry.cs	(revision 372)
+++ trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/AgentEntry.cs	(revision 372)
@@ -0,0 +1,48 @@
+﻿#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 AgentEntry {
+    [DataMember]
+    public long Id { get; set; }
+    [DataMember]
+    public string Name { get; set; }
+    [DataMember]
+    public AgentStatus 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: trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/AgentStatus.cs
===================================================================
--- trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/AgentStatus.cs	(revision 371)
+++ trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/AgentStatus.cs	(revision 372)
@@ -1,3 +1,24 @@
-﻿using System;
+﻿#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;
@@ -5,4 +26,4 @@
 
 namespace HeuristicLab.CEDMA.DB.Interfaces {
-  public enum AgentStatus { Aktive, Finished, Error, Waiting }
+  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 371)
+++ trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/HeuristicLab.CEDMA.DB.Interfaces.csproj	(revision 372)
@@ -42,4 +42,7 @@
       <RequiredTargetFramework>3.5</RequiredTargetFramework>
     </Reference>
+    <Reference Include="System.Runtime.Serialization, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
+      <RequiredTargetFramework>3.0</RequiredTargetFramework>
+    </Reference>
     <Reference Include="System.ServiceModel">
       <RequiredTargetFramework>3.0</RequiredTargetFramework>
@@ -55,7 +58,8 @@
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="AgentEntry.cs" />
     <Compile Include="AgentStatus.cs" />
+    <Compile Include="ResultEntry.cs" />
     <Compile Include="HeuristicLabCedmaDbInterfacesPlugin.cs" />
-    <Compile Include="IAgent.cs" />
     <Compile Include="IDatabase.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
Index: trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/IAgent.cs
===================================================================
--- trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/IAgent.cs	(revision 371)
+++ 	(revision )
@@ -1,13 +1,0 @@
-﻿using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-namespace HeuristicLab.CEDMA.DB.Interfaces {
-  public interface IAgent {
-    string Name { get; }
-    AgentStatus Status { get; }
-    byte[] RawData { get; }
-    void Save();
-  }
-}
Index: trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/IDatabase.cs
===================================================================
--- trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/IDatabase.cs	(revision 371)
+++ trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/IDatabase.cs	(revision 372)
@@ -1,16 +1,44 @@
-﻿using System;
+﻿#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 System.ServiceModel;
+using System.Data;
 
 namespace HeuristicLab.CEDMA.DB.Interfaces {
-  [ServiceContract(Namespace = "http://HeuristicLab.Cedma")]
+  [ServiceContract(Namespace = "http://HeuristicLab.CEDMA.DB")]
   public interface IDatabase {
     [OperationContract]
-    IList<IAgent> GetAgents();
+    ICollection<AgentEntry> GetAgentEntries();
 
     [OperationContract]
-    IAgent CreateAgent();
+    long CreateAgent();
+
+    [OperationContract(Name="UpdateAgent")]
+    void Update(AgentEntry entry);
+
+    [OperationContract(Name ="UpdateResult")]
+    void Update(ResultEntry result);
   }
 }
Index: trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/ResultEntry.cs
===================================================================
--- trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/ResultEntry.cs	(revision 372)
+++ trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/ResultEntry.cs	(revision 372)
@@ -0,0 +1,50 @@
+﻿#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 ResultEntry {
+    [DataMember]
+    private long id;
+    [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; }
+    }
+  }
+}
Index: trunk/sources/HeuristicLab.CEDMA.DB/Database.cs
===================================================================
--- trunk/sources/HeuristicLab.CEDMA.DB/Database.cs	(revision 371)
+++ trunk/sources/HeuristicLab.CEDMA.DB/Database.cs	(revision 372)
@@ -1,3 +1,24 @@
-﻿using System;
+﻿#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;
@@ -6,31 +27,109 @@
 using HeuristicLab.CEDMA.DB.Interfaces;
 using System.ServiceModel;
+using System.Data;
+using System.Data.SQLite;
+using System.Data.Common;
 
 namespace HeuristicLab.CEDMA.DB {
-  [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple, UseSynchronizationContext = false)]
-  public class Database : DataContext, IDatabase {
-    Table<Agent> Agents;
-
-    public Database() : this("c:\\cedma.mdf") { }
-
-    public Database(string connection) : base(connection) { 
+  [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Single, UseSynchronizationContext = true)]
+  public class Database : IDatabase {
+    private string connectionString;
+    public Database(string connectionString) {
+      this.connectionString = connectionString;
     }
 
-    public IList<IAgent> GetAgents() {
-      List<IAgent> result = new List<IAgent>();
-      foreach(Agent a in Agents) {
-        result.Add(a);
+    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();
       }
-      return result;
     }
 
-    public IAgent CreateAgent() {
-      Agent newAgent = new Agent();
-      newAgent.Name = DateTime.Now.ToString();
-      newAgent.Status = AgentStatus.Waiting;
-      newAgent.RawData = null;
-      Agents.InsertOnSubmit(newAgent);
-      this.SubmitChanges();
-      return newAgent;
+    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) {
+      throw new NotImplementedException();
     }
   }
Index: trunk/sources/HeuristicLab.CEDMA.DB/HeuristicLab.CEDMA.DB.csproj
===================================================================
--- trunk/sources/HeuristicLab.CEDMA.DB/HeuristicLab.CEDMA.DB.csproj	(revision 371)
+++ trunk/sources/HeuristicLab.CEDMA.DB/HeuristicLab.CEDMA.DB.csproj	(revision 372)
@@ -15,4 +15,6 @@
     <SignAssembly>true</SignAssembly>
     <AssemblyOriginatorKeyFile>HeuristicLab.snk</AssemblyOriginatorKeyFile>
+    <StartupObject>
+    </StartupObject>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
@@ -62,11 +64,19 @@
   </ItemGroup>
   <ItemGroup>
-    <Compile Include="Agent.cs" />
     <Compile Include="Database.cs" />
     <Compile Include="HeuristicLabCedmaDbPlugin.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="Properties\Settings.Designer.cs">
+      <AutoGen>True</AutoGen>
+      <DesignTimeSharedInput>True</DesignTimeSharedInput>
+      <DependentUpon>Settings.settings</DependentUpon>
+    </Compile>
   </ItemGroup>
   <ItemGroup>
     <None Include="HeuristicLab.snk" />
+    <None Include="Properties\Settings.settings">
+      <Generator>SettingsSingleFileGenerator</Generator>
+      <LastGenOutput>Settings.Designer.cs</LastGenOutput>
+    </None>
   </ItemGroup>
   <ItemGroup>
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 372)
@@ -0,0 +1,90 @@
+﻿#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;
+
+namespace HeuristicLab.CEDMA.Server {
+  public class AgentScheduler {
+    private Database database;
+    private List<IEngine> engines;
+    private Dictionary<IEngine, AgentEntry> agent;
+
+    public AgentScheduler(Database database) {
+      this.database = database;
+      engines = new List<IEngine>();
+      agent = new Dictionary<IEngine, AgentEntry>();
+    }
+
+    public void Run() {
+      while(true) {
+        ClearFinishedEngines();
+        CreateNewEngines();
+        StepAllEngines();
+      }
+    }
+    private void ClearFinishedEngines() {
+      List<IEngine> finishedEngines = new List<IEngine>();
+      foreach(IEngine e in engines) {
+        if(!e.Running) {
+          finishedEngines.Add(e);
+        }
+      }
+      foreach(IEngine e in finishedEngines) {
+        engines.Remove(e);
+        AgentEntry entry = agent[e];
+        entry.Status = AgentStatus.Finished;
+        database.Update(entry);
+      }
+    }
+    private void CreateNewEngines() {
+      ICollection<AgentEntry> agents = database.GetAgentEntries(AgentStatus.Waiting);
+      foreach(AgentEntry a in agents) {
+        SequentialEngine.SequentialEngine engine = new HeuristicLab.SequentialEngine.SequentialEngine();
+        Agent newAgent = (Agent)DbPersistenceManager.Restore(a.RawData);
+        engine.OperatorGraph.Clear();
+        foreach(IOperator op in newAgent.OperatorGraph.Operators) engine.OperatorGraph.AddOperator(op);
+        engine.OperatorGraph.InitialOperator = newAgent.OperatorGraph.InitialOperator;
+        engine.Reset();
+
+        agent[engine] = a;
+        engines.Add(engine);
+        a.Status = AgentStatus.Active;
+        database.Update(a);
+      }
+    }
+    private void StepAllEngines() {
+      for(int steps = 0; steps < 100; steps++) {
+        foreach(IEngine engine in engines) {
+          engine.ExecuteStep();
+        }
+        Thread.Sleep(100); // prevent over-load
+      }
+    }
+  }
+}
Index: trunk/sources/HeuristicLab.CEDMA.Server/DbPersistenceManager.cs
===================================================================
--- trunk/sources/HeuristicLab.CEDMA.Server/DbPersistenceManager.cs	(revision 372)
+++ trunk/sources/HeuristicLab.CEDMA.Server/DbPersistenceManager.cs	(revision 372)
@@ -0,0 +1,44 @@
+﻿#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 System.IO.Compression;
+using System.IO;
+using HeuristicLab.Core;
+
+namespace HeuristicLab.CEDMA.Server  {
+  internal static class DbPersistenceManager {
+    internal static IStorable Restore(byte[] serializedStorable) {
+      GZipStream stream = new GZipStream(new MemoryStream(serializedStorable), CompressionMode.Decompress);
+      return PersistenceManager.Load(stream);
+    }
+    internal static byte[] Save(IStorable storable) {
+      MemoryStream memStream = new MemoryStream();
+      GZipStream stream = new GZipStream(memStream, CompressionMode.Compress, true);
+      PersistenceManager.Save(storable, stream);
+      stream.Close();
+      return memStream.ToArray();
+    }
+  }
+}
Index: trunk/sources/HeuristicLab.CEDMA.Server/HeuristicLab.CEDMA.Server.csproj
===================================================================
--- trunk/sources/HeuristicLab.CEDMA.Server/HeuristicLab.CEDMA.Server.csproj	(revision 371)
+++ trunk/sources/HeuristicLab.CEDMA.Server/HeuristicLab.CEDMA.Server.csproj	(revision 372)
@@ -59,4 +59,6 @@
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="AgentScheduler.cs" />
+    <Compile Include="DbPersistenceManager.cs" />
     <Compile Include="ServerApplication.cs" />
     <Compile Include="HeuristicLabCedmaServerPlugin.cs" />
@@ -70,4 +72,8 @@
   </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>
@@ -78,7 +84,15 @@
       <Name>HeuristicLab.CEDMA.DB</Name>
     </ProjectReference>
+    <ProjectReference Include="..\HeuristicLab.Core\HeuristicLab.Core.csproj">
+      <Project>{F43B59AB-2B8C-4570-BC1E-15592086517C}</Project>
+      <Name>HeuristicLab.Core</Name>
+    </ProjectReference>
     <ProjectReference Include="..\HeuristicLab.PluginInfrastructure\HeuristicLab.PluginInfrastructure.csproj">
       <Project>{94186A6A-5176-4402-AE83-886557B53CCA}</Project>
       <Name>HeuristicLab.PluginInfrastructure</Name>
+    </ProjectReference>
+    <ProjectReference Include="..\HeuristicLab.SequentialEngine\HeuristicLab.SequentialEngine.csproj">
+      <Project>{B4BE8E53-BA06-4237-9A01-24255F880201}</Project>
+      <Name>HeuristicLab.SequentialEngine</Name>
     </ProjectReference>
   </ItemGroup>
Index: trunk/sources/HeuristicLab.CEDMA.Server/ServerForm.cs
===================================================================
--- trunk/sources/HeuristicLab.CEDMA.Server/ServerForm.cs	(revision 371)
+++ trunk/sources/HeuristicLab.CEDMA.Server/ServerForm.cs	(revision 372)
@@ -34,20 +34,41 @@
 using HeuristicLab.CEDMA.DB;
 using HeuristicLab.CEDMA.DB.Interfaces;
+using System.Data.Common;
+using System.Threading;
 
 namespace HeuristicLab.CEDMA.Server {
   public partial class ServerForm : Form {
     private ServiceHost host;
-    private Database database = new Database();
-
+    private Database database;
+    private static readonly string dbFile = AppDomain.CurrentDomain.BaseDirectory + "/test.db3";
+    private static readonly string connectionString = "Data Source=\""+dbFile+"\";Pooling=False";
     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) {
-        addressTextBox.Text = "net.tcp://" + Dns.GetHostAddresses(Dns.GetHostName())[2] + ":8000/CEDMA/World";
+        addressTextBox.Text = "net.tcp://" + Dns.GetHostAddresses(Dns.GetHostName())[2] + ":8002/CEDMA/World";
       } else {
-        addressTextBox.Text = "net.tcp://" + Dns.GetHostAddresses(Dns.GetHostName())[0] + ":8000/CEDMA/World";
+        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 InitDatabase() {
+      DbProviderFactory fact;
+      fact = DbProviderFactories.GetFactory("System.Data.SQLite");
+      if(!System.IO.File.Exists(dbFile)) {
+        database = new Database(connectionString);
+        database.CreateNew();
+      } else {
+        database = new Database(connectionString);
+      }
     }
 
Index: trunk/sources/HeuristicLab.DistributedEngine/HeuristicLab.DistributedEngine.csproj
===================================================================
--- trunk/sources/HeuristicLab.DistributedEngine/HeuristicLab.DistributedEngine.csproj	(revision 371)
+++ trunk/sources/HeuristicLab.DistributedEngine/HeuristicLab.DistributedEngine.csproj	(revision 372)
@@ -49,6 +49,6 @@
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="OnGridProcessor.cs" />
     <Compile Include="HeuristicLabDistributedEnginePlugin.cs" />
-    <Compile Include="JobManager.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="DistributedEngine.cs" />
@@ -64,4 +64,8 @@
       <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>
     <ProjectReference Include="..\HeuristicLab.Grid\HeuristicLab.Grid.csproj">
Index: trunk/sources/HeuristicLab.DistributedEngine/JobManager.cs
===================================================================
--- trunk/sources/HeuristicLab.DistributedEngine/JobManager.cs	(revision 371)
+++ 	(revision )
@@ -1,244 +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;
-using System.ServiceModel;
-using HeuristicLab.Grid;
-using System.Threading;
-using HeuristicLab.Core;
-using System.IO;
-using System.IO.Compression;
-using System.Windows.Forms;
-
-namespace HeuristicLab.DistributedEngine {
-  class JobManager {
-    private IGridServer server;
-    private string address;
-    private Dictionary<Guid, ProcessingEngine> engines = new Dictionary<Guid, ProcessingEngine>();
-    private Dictionary<Guid, ManualResetEvent> waithandles = new Dictionary<Guid, ManualResetEvent>();
-    private Dictionary<AtomicOperation, byte[]> results = new Dictionary<AtomicOperation, byte[]>();
-    private List<IOperation> erroredOperations = new List<IOperation>();
-    private object connectionLock = new object();
-    private object dictionaryLock = new object();
-
-    private const int MAX_RESTARTS = 5;
-    private const int MAX_CONNECTION_RETRIES = 10;
-    private const int RETRY_TIMEOUT_SEC = 60;
-    private const int CHECK_RESULTS_TIMEOUT = 10;
-
-    private ChannelFactory<IGridServer> factory;
-
-    public JobManager(string address) {
-      this.address = address;
-    }
-
-    internal void Reset() {
-      ResetConnection();
-      lock(dictionaryLock) {
-        foreach(WaitHandle wh in waithandles.Values) wh.Close();
-        waithandles.Clear();
-        engines.Clear();
-        results.Clear();
-        erroredOperations.Clear();
-      }
-    }
-
-    private void ResetConnection() {
-      lock(connectionLock) {
-        // open a new channel
-        NetTcpBinding binding = new NetTcpBinding();
-        binding.MaxReceivedMessageSize = 100000000; // 100Mbytes
-        binding.ReaderQuotas.MaxStringContentLength = 100000000; // also 100M chars
-        binding.ReaderQuotas.MaxArrayLength = 100000000; // also 100M elements;
-        binding.Security.Mode = SecurityMode.None;
-
-        factory = new ChannelFactory<IGridServer>(binding);
-        server = factory.CreateChannel(new EndpointAddress(address));
-      }
-    }
-
-    public WaitHandle BeginExecuteOperation(IScope globalScope, AtomicOperation operation) {
-      ProcessingEngine engine = new ProcessingEngine(globalScope, operation);
-      byte[] zippedEngine = ZipEngine(engine);
-      Guid currentEngineGuid = Guid.Empty;
-      bool success = false;
-      int retryCount = 0;
-      do {
-        try {
-          lock(connectionLock) {
-            currentEngineGuid = server.BeginExecuteEngine(zippedEngine);
-          }
-          success = true;
-        } catch(TimeoutException timeoutException) {
-          if(retryCount++ >= MAX_CONNECTION_RETRIES) {
-            throw new ApplicationException("Maximal number of connection attempts reached. There is a problem with the connection to the grid-server.", timeoutException);
-          }
-          Thread.Sleep(TimeSpan.FromSeconds(RETRY_TIMEOUT_SEC));
-        } catch(CommunicationException communicationException) {
-          if(retryCount++ >= MAX_CONNECTION_RETRIES) {
-            throw new ApplicationException("Maximal number of connection attempts reached. There is a problem with the connection to the grid-server.", communicationException);
-          }
-          ResetConnection();
-          Thread.Sleep(TimeSpan.FromSeconds(RETRY_TIMEOUT_SEC));
-        }
-      } while(!success);
-      lock(dictionaryLock) {
-        engines[currentEngineGuid] = engine;
-        waithandles[currentEngineGuid] = new ManualResetEvent(false);
-      }
-      ThreadPool.QueueUserWorkItem(new WaitCallback(TryGetResult), currentEngineGuid);
-      return waithandles[currentEngineGuid];
-    }
-
-    private byte[] ZipEngine(ProcessingEngine engine) {
-      MemoryStream memStream = new MemoryStream();
-      GZipStream stream = new GZipStream(memStream, CompressionMode.Compress, true);
-      PersistenceManager.Save(engine, stream);
-      stream.Close();
-      byte[] zippedEngine = memStream.ToArray();
-      memStream.Close();
-      return zippedEngine;
-    }
-
-    public ProcessingEngine EndExecuteOperation(AtomicOperation operation) {
-      if(erroredOperations.Contains(operation)) {
-        erroredOperations.Remove(operation);
-        throw new ApplicationException("Maximal number of job restarts reached. There is a problem with the connection to the grid-server.");
-      } else {
-        byte[] zippedResult = null;
-        lock(dictionaryLock) {
-          zippedResult = results[operation];
-          results.Remove(operation);
-        }
-        // restore the engine 
-        using(GZipStream stream = new GZipStream(new MemoryStream(zippedResult), CompressionMode.Decompress)) {
-          return (ProcessingEngine)PersistenceManager.Load(stream);
-        }
-      }
-    }
-
-    private void TryGetResult(object state) {
-      Guid engineGuid = (Guid)state;
-      int restartCounter = 0;
-      do {
-        Thread.Sleep(TimeSpan.FromSeconds(CHECK_RESULTS_TIMEOUT));
-        byte[] zippedResult = TryEndExecuteEngine(server, engineGuid);
-        if(zippedResult != null) { // successful
-          lock(dictionaryLock) {
-            // store result
-            results[engines[engineGuid].InitialOperation] = zippedResult;
-            // clean up and signal the wait handle then return
-            engines.Remove(engineGuid);
-            waithandles[engineGuid].Set();
-            waithandles.Remove(engineGuid);
-          }
-          return;
-        } else {
-          // there was a problem -> check the state of the job and restart if necessary
-          JobState jobState = TryGetJobState(server, engineGuid);
-          if(jobState == JobState.Unkown) {
-            TryRestartJob(engineGuid);
-            restartCounter++;
-          }
-        }
-      } while(restartCounter < MAX_RESTARTS);
-      lock(dictionaryLock) {
-        // the job was never finished and restarting didn't help -> stop trying to execute the job and
-        // save the faulted operation in a list to throw an exception when EndExecuteEngine is called.
-        erroredOperations.Add(engines[engineGuid].InitialOperation);
-        // clean up and signal the wait handle
-        engines.Remove(engineGuid);
-        waithandles[engineGuid].Set();
-        waithandles.Remove(engineGuid);
-      }
-    }
-
-    private void TryRestartJob(Guid engineGuid) {
-      // restart job
-      ProcessingEngine engine;
-      lock(dictionaryLock) {
-        engine = engines[engineGuid];
-      }
-      byte[] zippedEngine = ZipEngine(engine);
-      int retries = 0;
-      do {
-        try {
-          lock(connectionLock) {
-            server.BeginExecuteEngine(zippedEngine);
-          }
-          return;
-        } catch(TimeoutException timeoutException) {
-          retries++;
-          Thread.Sleep(TimeSpan.FromSeconds(RETRY_TIMEOUT_SEC));
-        } catch(CommunicationException communicationException) {
-          ResetConnection();
-          retries++;
-          Thread.Sleep(TimeSpan.FromSeconds(RETRY_TIMEOUT_SEC));
-        }
-      } while(retries < MAX_CONNECTION_RETRIES);
-    }
-
-    private byte[] TryEndExecuteEngine(IGridServer server, Guid engineGuid) {
-      int retries = 0;
-      do {
-        try {
-          lock(connectionLock) {
-            byte[] zippedResult = server.TryEndExecuteEngine(engineGuid, 100);
-            return zippedResult;
-          }
-        } catch(TimeoutException timeoutException) {
-          retries++;
-          Thread.Sleep(TimeSpan.FromSeconds(RETRY_TIMEOUT_SEC));
-        } catch(CommunicationException communicationException) {
-          ResetConnection();
-          retries++;
-          Thread.Sleep(TimeSpan.FromSeconds(RETRY_TIMEOUT_SEC));
-        }
-      } while(retries < MAX_CONNECTION_RETRIES);
-      return null;
-    }
-
-    private JobState TryGetJobState(IGridServer server, Guid engineGuid) {
-      // check if the server is still working on the job
-      int retries = 0;
-      do {
-        try {
-          lock(connectionLock) {
-            JobState jobState = server.JobState(engineGuid);
-            return jobState;
-          }
-        } catch(TimeoutException timeoutException) {
-          retries++;
-          Thread.Sleep(TimeSpan.FromSeconds(RETRY_TIMEOUT_SEC));
-        } catch(CommunicationException communicationException) {
-          ResetConnection();
-          retries++;
-          Thread.Sleep(TimeSpan.FromSeconds(RETRY_TIMEOUT_SEC));
-        }
-      } while(retries < MAX_CONNECTION_RETRIES);
-      return JobState.Unkown;
-      
-    }
-  }
-}
Index: trunk/sources/HeuristicLab.DistributedEngine/OnGridProcessor.cs
===================================================================
--- trunk/sources/HeuristicLab.DistributedEngine/OnGridProcessor.cs	(revision 372)
+++ trunk/sources/HeuristicLab.DistributedEngine/OnGridProcessor.cs	(revision 372)
@@ -0,0 +1,58 @@
+#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;
+    }
+  }
+}
Index: trunk/sources/HeuristicLab.Grid/HeuristicLab.Grid.csproj
===================================================================
--- trunk/sources/HeuristicLab.Grid/HeuristicLab.Grid.csproj	(revision 371)
+++ trunk/sources/HeuristicLab.Grid/HeuristicLab.Grid.csproj	(revision 372)
@@ -65,4 +65,5 @@
     <Compile Include="IEngineStore.cs" />
     <Compile Include="IGridServer.cs" />
+    <Compile Include="JobManager.cs" />
     <Compile Include="ProcessingEngine.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
Index: trunk/sources/HeuristicLab.Grid/JobManager.cs
===================================================================
--- trunk/sources/HeuristicLab.Grid/JobManager.cs	(revision 372)
+++ trunk/sources/HeuristicLab.Grid/JobManager.cs	(revision 372)
@@ -0,0 +1,244 @@
+﻿#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 System.ServiceModel;
+using HeuristicLab.Grid;
+using System.Threading;
+using HeuristicLab.Core;
+using System.IO;
+using System.IO.Compression;
+using System.Windows.Forms;
+
+namespace HeuristicLab.Grid {
+  public class JobManager {
+    private IGridServer server;
+    private string address;
+    private Dictionary<Guid, ProcessingEngine> engines = new Dictionary<Guid, ProcessingEngine>();
+    private Dictionary<Guid, ManualResetEvent> waithandles = new Dictionary<Guid, ManualResetEvent>();
+    private Dictionary<AtomicOperation, byte[]> results = new Dictionary<AtomicOperation, byte[]>();
+    private List<IOperation> erroredOperations = new List<IOperation>();
+    private object connectionLock = new object();
+    private object dictionaryLock = new object();
+
+    private const int MAX_RESTARTS = 5;
+    private const int MAX_CONNECTION_RETRIES = 10;
+    private const int RETRY_TIMEOUT_SEC = 60;
+    private const int CHECK_RESULTS_TIMEOUT = 10;
+
+    private ChannelFactory<IGridServer> factory;
+
+    public JobManager(string address) {
+      this.address = address;
+    }
+
+    public void Reset() {
+      ResetConnection();
+      lock(dictionaryLock) {
+        foreach(WaitHandle wh in waithandles.Values) wh.Close();
+        waithandles.Clear();
+        engines.Clear();
+        results.Clear();
+        erroredOperations.Clear();
+      }
+    }
+
+    private void ResetConnection() {
+      lock(connectionLock) {
+        // open a new channel
+        NetTcpBinding binding = new NetTcpBinding();
+        binding.MaxReceivedMessageSize = 100000000; // 100Mbytes
+        binding.ReaderQuotas.MaxStringContentLength = 100000000; // also 100M chars
+        binding.ReaderQuotas.MaxArrayLength = 100000000; // also 100M elements;
+        binding.Security.Mode = SecurityMode.None;
+
+        factory = new ChannelFactory<IGridServer>(binding);
+        server = factory.CreateChannel(new EndpointAddress(address));
+      }
+    }
+
+    public WaitHandle BeginExecuteOperation(IScope globalScope, AtomicOperation operation) {
+      ProcessingEngine engine = new ProcessingEngine(globalScope, operation);
+      byte[] zippedEngine = ZipEngine(engine);
+      Guid currentEngineGuid = Guid.Empty;
+      bool success = false;
+      int retryCount = 0;
+      do {
+        try {
+          lock(connectionLock) {
+            currentEngineGuid = server.BeginExecuteEngine(zippedEngine);
+          }
+          success = true;
+        } catch(TimeoutException timeoutException) {
+          if(retryCount++ >= MAX_CONNECTION_RETRIES) {
+            throw new ApplicationException("Maximal number of connection attempts reached. There is a problem with the connection to the grid-server.", timeoutException);
+          }
+          Thread.Sleep(TimeSpan.FromSeconds(RETRY_TIMEOUT_SEC));
+        } catch(CommunicationException communicationException) {
+          if(retryCount++ >= MAX_CONNECTION_RETRIES) {
+            throw new ApplicationException("Maximal number of connection attempts reached. There is a problem with the connection to the grid-server.", communicationException);
+          }
+          ResetConnection();
+          Thread.Sleep(TimeSpan.FromSeconds(RETRY_TIMEOUT_SEC));
+        }
+      } while(!success);
+      lock(dictionaryLock) {
+        engines[currentEngineGuid] = engine;
+        waithandles[currentEngineGuid] = new ManualResetEvent(false);
+      }
+      ThreadPool.QueueUserWorkItem(new WaitCallback(TryGetResult), currentEngineGuid);
+      return waithandles[currentEngineGuid];
+    }
+
+    private byte[] ZipEngine(ProcessingEngine engine) {
+      MemoryStream memStream = new MemoryStream();
+      GZipStream stream = new GZipStream(memStream, CompressionMode.Compress, true);
+      PersistenceManager.Save(engine, stream);
+      stream.Close();
+      byte[] zippedEngine = memStream.ToArray();
+      memStream.Close();
+      return zippedEngine;
+    }
+
+    public ProcessingEngine EndExecuteOperation(AtomicOperation operation) {
+      if(erroredOperations.Contains(operation)) {
+        erroredOperations.Remove(operation);
+        throw new ApplicationException("Maximal number of job restarts reached. There is a problem with the connection to the grid-server.");
+      } else {
+        byte[] zippedResult = null;
+        lock(dictionaryLock) {
+          zippedResult = results[operation];
+          results.Remove(operation);
+        }
+        // restore the engine 
+        using(GZipStream stream = new GZipStream(new MemoryStream(zippedResult), CompressionMode.Decompress)) {
+          return (ProcessingEngine)PersistenceManager.Load(stream);
+        }
+      }
+    }
+
+    private void TryGetResult(object state) {
+      Guid engineGuid = (Guid)state;
+      int restartCounter = 0;
+      do {
+        Thread.Sleep(TimeSpan.FromSeconds(CHECK_RESULTS_TIMEOUT));
+        byte[] zippedResult = TryEndExecuteEngine(server, engineGuid);
+        if(zippedResult != null) { // successful
+          lock(dictionaryLock) {
+            // store result
+            results[engines[engineGuid].InitialOperation] = zippedResult;
+            // clean up and signal the wait handle then return
+            engines.Remove(engineGuid);
+            waithandles[engineGuid].Set();
+            waithandles.Remove(engineGuid);
+          }
+          return;
+        } else {
+          // there was a problem -> check the state of the job and restart if necessary
+          JobState jobState = TryGetJobState(server, engineGuid);
+          if(jobState == JobState.Unkown) {
+            TryRestartJob(engineGuid);
+            restartCounter++;
+          }
+        }
+      } while(restartCounter < MAX_RESTARTS);
+      lock(dictionaryLock) {
+        // the job was never finished and restarting didn't help -> stop trying to execute the job and
+        // save the faulted operation in a list to throw an exception when EndExecuteEngine is called.
+        erroredOperations.Add(engines[engineGuid].InitialOperation);
+        // clean up and signal the wait handle
+        engines.Remove(engineGuid);
+        waithandles[engineGuid].Set();
+        waithandles.Remove(engineGuid);
+      }
+    }
+
+    private void TryRestartJob(Guid engineGuid) {
+      // restart job
+      ProcessingEngine engine;
+      lock(dictionaryLock) {
+        engine = engines[engineGuid];
+      }
+      byte[] zippedEngine = ZipEngine(engine);
+      int retries = 0;
+      do {
+        try {
+          lock(connectionLock) {
+            server.BeginExecuteEngine(zippedEngine);
+          }
+          return;
+        } catch(TimeoutException timeoutException) {
+          retries++;
+          Thread.Sleep(TimeSpan.FromSeconds(RETRY_TIMEOUT_SEC));
+        } catch(CommunicationException communicationException) {
+          ResetConnection();
+          retries++;
+          Thread.Sleep(TimeSpan.FromSeconds(RETRY_TIMEOUT_SEC));
+        }
+      } while(retries < MAX_CONNECTION_RETRIES);
+    }
+
+    private byte[] TryEndExecuteEngine(IGridServer server, Guid engineGuid) {
+      int retries = 0;
+      do {
+        try {
+          lock(connectionLock) {
+            byte[] zippedResult = server.TryEndExecuteEngine(engineGuid, 100);
+            return zippedResult;
+          }
+        } catch(TimeoutException timeoutException) {
+          retries++;
+          Thread.Sleep(TimeSpan.FromSeconds(RETRY_TIMEOUT_SEC));
+        } catch(CommunicationException communicationException) {
+          ResetConnection();
+          retries++;
+          Thread.Sleep(TimeSpan.FromSeconds(RETRY_TIMEOUT_SEC));
+        }
+      } while(retries < MAX_CONNECTION_RETRIES);
+      return null;
+    }
+
+    private JobState TryGetJobState(IGridServer server, Guid engineGuid) {
+      // check if the server is still working on the job
+      int retries = 0;
+      do {
+        try {
+          lock(connectionLock) {
+            JobState jobState = server.JobState(engineGuid);
+            return jobState;
+          }
+        } catch(TimeoutException timeoutException) {
+          retries++;
+          Thread.Sleep(TimeSpan.FromSeconds(RETRY_TIMEOUT_SEC));
+        } catch(CommunicationException communicationException) {
+          ResetConnection();
+          retries++;
+          Thread.Sleep(TimeSpan.FromSeconds(RETRY_TIMEOUT_SEC));
+        }
+      } while(retries < MAX_CONNECTION_RETRIES);
+      return JobState.Unkown;
+      
+    }
+  }
+}
