Index: /trunk/sources/HeuristicLab.CEDMA.Core/Agent.cs
===================================================================
--- /trunk/sources/HeuristicLab.CEDMA.Core/Agent.cs	(revision 392)
+++ /trunk/sources/HeuristicLab.CEDMA.Core/Agent.cs	(revision 393)
@@ -65,7 +65,14 @@
     public ICollection<IAgent> SubAgents {
       get {
-        List<IAgent> runs = new List<IAgent>();
-        // TASK
-        return runs;
+        List<IAgent> agents = new List<IAgent>();
+        foreach(AgentEntry entry in Database.GetSubAgents(Id)) {
+          Agent newAgent = (Agent)DbPersistenceManager.Restore(entry.RawData);
+          newAgent.Database = Database;
+          newAgent.Id = entry.Id;
+          newAgent.Name = entry.Name;
+          newAgent.Status = entry.Status;
+          agents.Add(newAgent);
+        }
+        return agents;
       }
     }
@@ -74,5 +81,7 @@
       get {
         List<IResult> results = new List<IResult>();
-        // TASK
+        foreach(ResultEntry entry in Database.GetResults(Id)) {
+          Result result = (Result)DbPersistenceManager.Restore(entry.RawData);
+        }
         return results;
       }
@@ -92,4 +101,7 @@
     #endregion
 
+    public override IView CreateView() {
+      return new AgentView(this);
+    }
   }
 }
Index: /trunk/sources/HeuristicLab.CEDMA.Core/AgentListView.cs
===================================================================
--- /trunk/sources/HeuristicLab.CEDMA.Core/AgentListView.cs	(revision 392)
+++ /trunk/sources/HeuristicLab.CEDMA.Core/AgentListView.cs	(revision 393)
@@ -64,4 +64,5 @@
           node.Text = agent.Name;
           node.Tag = agent;
+          node.Nodes.Add("dummy");
           agentTreeView.Nodes.Add(node);
         }
@@ -77,4 +78,20 @@
 
     private void agentTreeView_BeforeExpand(object sender, TreeViewCancelEventArgs e) {
+      e.Node.Nodes.Clear();
+      IAgent agent = (IAgent)e.Node.Tag;
+      foreach(IAgent subAgent in agent.SubAgents) {
+        TreeNode node = new TreeNode();
+        node.Text = subAgent.Name;
+        node.Tag = subAgent;
+        node.Nodes.Add("dummy");
+        e.Node.Nodes.Add(node);
+      }
+      foreach(IResult result in agent.Results) {
+        TreeNode node = new TreeNode();
+        node.Text = result.Summary;
+        node.Tag = result;
+        node.Nodes.Add("dummy");
+        e.Node.Nodes.Add(node);
+      }
     }
 
@@ -85,6 +102,6 @@
       detailsGroupBox.Enabled = false;
       if(agentTreeView.SelectedNode != null) {
-        IAgent agent = (IAgent)agentTreeView.SelectedNode.Tag;
-        Control control = (Control)new AgentView(agent);
+        IViewable viewable = (IViewable)agentTreeView.SelectedNode.Tag;
+        Control control = (Control)viewable.CreateView();
         detailsGroupBox.Controls.Add(control);
         control.Dock = DockStyle.Fill;
Index: /trunk/sources/HeuristicLab.CEDMA.Core/ConsoleEditor.cs
===================================================================
--- /trunk/sources/HeuristicLab.CEDMA.Core/ConsoleEditor.cs	(revision 392)
+++ /trunk/sources/HeuristicLab.CEDMA.Core/ConsoleEditor.cs	(revision 393)
@@ -38,4 +38,6 @@
     private Label projectLabel;
     private Button newButton;
+    private Timer refreshTimer;
+    private System.ComponentModel.IContainer components;
     private Console console;
 
@@ -46,4 +48,5 @@
 
     private void InitializeComponent() {
+      this.components = new System.ComponentModel.Container();
       this.uriTextBox = new System.Windows.Forms.TextBox();
       this.uriLabel = new System.Windows.Forms.Label();
@@ -54,4 +57,5 @@
       this.projectLabel = new System.Windows.Forms.Label();
       this.newButton = new System.Windows.Forms.Button();
+      this.refreshTimer = new System.Windows.Forms.Timer(this.components);
       this.tabControl.SuspendLayout();
       this.SuspendLayout();
@@ -135,4 +139,9 @@
       this.newButton.UseVisualStyleBackColor = true;
       // 
+      // refreshTimer
+      // 
+      this.refreshTimer.Interval = 3000;
+      this.refreshTimer.Tick += new System.EventHandler(this.refreshTimer_Tick);
+      // 
       // ConsoleEditor
       // 
@@ -161,4 +170,5 @@
         agentsPage.Controls.Add((Control)console.AgentList.CreateView());
         agentsPage.Controls[0].Dock = DockStyle.Fill;
+        refreshTimer.Enabled = true;
       } catch(CommunicationException ex) {
         // TASK create helper class for error reporting
@@ -166,4 +176,10 @@
       }
     }
+
+    private void refreshTimer_Tick(object sender, EventArgs e) {
+      refreshTimer.Stop();
+      UpdateControls();
+      refreshTimer.Enabled = true;
+    }
   }
 }
Index: /trunk/sources/HeuristicLab.CEDMA.Core/ConsoleEditor.resx
===================================================================
--- /trunk/sources/HeuristicLab.CEDMA.Core/ConsoleEditor.resx	(revision 392)
+++ /trunk/sources/HeuristicLab.CEDMA.Core/ConsoleEditor.resx	(revision 393)
@@ -118,3 +118,6 @@
     <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
   </resheader>
+  <metadata name="refreshTimer.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>17, 17</value>
+  </metadata>
 </root>
Index: /trunk/sources/HeuristicLab.CEDMA.Core/HeuristicLab.CEDMA.Core.csproj
===================================================================
--- /trunk/sources/HeuristicLab.CEDMA.Core/HeuristicLab.CEDMA.Core.csproj	(revision 392)
+++ /trunk/sources/HeuristicLab.CEDMA.Core/HeuristicLab.CEDMA.Core.csproj	(revision 393)
@@ -62,4 +62,5 @@
       <SubType>UserControl</SubType>
     </Compile>
+    <Compile Include="Result.cs" />
     <Compile Include="IResult.cs" />
     <Compile Include="DbPersistenceManager.cs" />
Index: /trunk/sources/HeuristicLab.CEDMA.Core/IAgent.cs
===================================================================
--- /trunk/sources/HeuristicLab.CEDMA.Core/IAgent.cs	(revision 392)
+++ /trunk/sources/HeuristicLab.CEDMA.Core/IAgent.cs	(revision 393)
@@ -28,5 +28,5 @@
 
 namespace HeuristicLab.CEDMA.Core {
-  public interface IAgent : IDatabaseItem {
+  public interface IAgent : IDatabaseItem, IViewable {
     string Name { get; }
     ProcessStatus Status { get; }
@@ -35,5 +35,5 @@
     ICollection<IResult> Results { get; }
     bool Terminated { get; }
-    
+    void Save();
     void Start();
   }
Index: /trunk/sources/HeuristicLab.CEDMA.Core/IDatabaseItem.cs
===================================================================
--- /trunk/sources/HeuristicLab.CEDMA.Core/IDatabaseItem.cs	(revision 392)
+++ /trunk/sources/HeuristicLab.CEDMA.Core/IDatabaseItem.cs	(revision 393)
@@ -31,5 +31,4 @@
     IDatabase Database { get; set; }
     long Id { get; set; }
-    void Save();
   }
 }
Index: /trunk/sources/HeuristicLab.CEDMA.Core/IResult.cs
===================================================================
--- /trunk/sources/HeuristicLab.CEDMA.Core/IResult.cs	(revision 392)
+++ /trunk/sources/HeuristicLab.CEDMA.Core/IResult.cs	(revision 393)
@@ -28,5 +28,5 @@
 
 namespace HeuristicLab.CEDMA.Core {
-  public interface IResult : IDatabaseItem {
+  public interface IResult : IDatabaseItem, IViewable {
     string Summary { get; }
     string Description { get; }
Index: /trunk/sources/HeuristicLab.CEDMA.Core/Result.cs
===================================================================
--- /trunk/sources/HeuristicLab.CEDMA.Core/Result.cs	(revision 393)
+++ /trunk/sources/HeuristicLab.CEDMA.Core/Result.cs	(revision 393)
@@ -0,0 +1,76 @@
+﻿#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 System.Xml;
+using HeuristicLab.CEDMA.DB.Interfaces;
+
+namespace HeuristicLab.CEDMA.Core {
+  public class Result : ItemBase, IResult {
+    public IDatabase Database { get; set; }
+    public long Id { get; set; }
+    public string Summary { get; set; }
+    public string Description { get; set; }
+    public IItem result;
+    public Result()
+      : base() {
+    }
+
+    public Result(IDatabase database, long id)
+      : this() {
+      Database = database;
+      Id = id;
+    }
+
+
+    public ICollection<IResult> SubResults {
+      get {
+        List<IResult> results = new List<IResult>();
+        foreach(ResultEntry entry in Database.GetSubResults(Id)) {
+          Result result = (Result)DbPersistenceManager.Restore(entry.RawData);
+        }
+        return results;
+      }
+    } 
+
+    #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("Result", result, document, persistedObjects));
+      return node;
+    }
+
+    public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
+      base.Populate(node, restoredObjects);
+      result = (IItem)PersistenceManager.Restore(node.SelectSingleNode("Result"), restoredObjects);
+    }
+    #endregion
+
+    // TASK: create class ResultView
+    //public override IView CreateView() {
+    //  return new ResultView(this);
+    //}
+  }
+}
Index: /trunk/sources/HeuristicLab.CEDMA.DB/Database.cs
===================================================================
--- /trunk/sources/HeuristicLab.CEDMA.DB/Database.cs	(revision 392)
+++ /trunk/sources/HeuristicLab.CEDMA.DB/Database.cs	(revision 393)
@@ -298,5 +298,4 @@
           statusParameter.Value = status.ToString();
           c.Parameters.Add(statusParameter);
-
           SQLiteDataReader r = c.ExecuteReader();
           while(r.Read()) {
@@ -330,5 +329,5 @@
                 agent.Id = r.GetInt32(0);
                 agent.ParentAgentId = r.IsDBNull(1) ? null : new Nullable<long>(r.GetInt32(1));
-                agent.Name = r.GetString(2);
+                agent.Name = r.IsDBNull(2)?"-":r.GetString(2);
                 agent.Status = (ProcessStatus)Enum.Parse(typeof(ProcessStatus), r.GetString(3));
                 agent.ControllerAgent = r.GetBoolean(4);
@@ -353,4 +352,9 @@
           using(DbCommand c = cnn.CreateCommand()) {
             c.CommandText = "Select id, name, status, controllerAgent, rawdata from Agent where ParentAgentId=@ParentAgentId";
+            DbParameter parentParameter = c.CreateParameter();
+            parentParameter.ParameterName = "@ParentAgentId";
+            parentParameter.Value = parentAgentId;
+            c.Parameters.Add(parentParameter);
+
             using(DbDataReader r = c.ExecuteReader()) {
               while(r.Read()) {
@@ -358,5 +362,5 @@
                 agent.ParentAgentId = parentAgentId;
                 agent.Id = r.GetInt32(0);
-                agent.Name = r.GetString(1);
+                agent.Name = r.IsDBNull(1)?"-":r.GetString(1);
                 agent.Status = (ProcessStatus)Enum.Parse(typeof(ProcessStatus), r.GetString(2));
                 agent.ControllerAgent = r.GetBoolean(3);
Index: /trunk/sources/HeuristicLab.CEDMA.Operators/OnGridProcessor.cs
===================================================================
--- /trunk/sources/HeuristicLab.CEDMA.Operators/OnGridProcessor.cs	(revision 392)
+++ /trunk/sources/HeuristicLab.CEDMA.Operators/OnGridProcessor.cs	(revision 393)
@@ -40,5 +40,5 @@
       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));
+      AddVariableInfo(new VariableInfo("CedmaServerUri", "Uri of the CEDMA server", typeof(StringData), VariableKind.In));
     }
 
@@ -46,6 +46,12 @@
       
       IOperatorGraph operatorGraph = scope.GetVariableValue<IOperatorGraph>("OperatorGraph", false);
-      string serverUrl = scope.GetVariableValue<StringData>("ServerUrl", true).Data;
+      string serverUrl = scope.GetVariableValue<StringData>("CedmaServerUri", true).Data;
       long agentId = scope.GetVariableValue<IntData>("AgentId", true).Data;
+
+      Agent agent = new Agent();
+      foreach(IOperator op in operatorGraph.Operators) {
+        agent.OperatorGraph.AddOperator(op);
+      }
+      agent.OperatorGraph.InitialOperator = operatorGraph.InitialOperator;
 
       NetTcpBinding binding = new NetTcpBinding();
@@ -56,5 +62,5 @@
       using(ChannelFactory<IDatabase> factory = new ChannelFactory<IDatabase>(binding)) {
         IDatabase database = factory.CreateChannel(new EndpointAddress(serverUrl));
-        long id = database.InsertAgent(agentId, null, false, DbPersistenceManager.Save(operatorGraph));
+        long id = database.InsertAgent(agentId, null, false, DbPersistenceManager.Save(agent));
         database.UpdateAgent(id, ProcessStatus.Waiting);
       }
Index: /trunk/sources/HeuristicLab.CEDMA.Server/AgentScheduler.cs
===================================================================
--- /trunk/sources/HeuristicLab.CEDMA.Server/AgentScheduler.cs	(revision 392)
+++ /trunk/sources/HeuristicLab.CEDMA.Server/AgentScheduler.cs	(revision 393)
@@ -29,4 +29,5 @@
 using System.Threading;
 using HeuristicLab.CEDMA.Core;
+using HeuristicLab.Data;
 
 namespace HeuristicLab.CEDMA.Server {
@@ -35,7 +36,9 @@
     private List<IEngine> engines;
     private Dictionary<IEngine, AgentEntry> agent;
+    private string serverUri;
 
-    public AgentScheduler(Database database) {
+    public AgentScheduler(Database database, string serverUri) {
       this.database = database;
+      this.serverUri = serverUri;
       engines = new List<IEngine>();
       agent = new Dictionary<IEngine, AgentEntry>();
@@ -74,4 +77,8 @@
         engine.Reset();
 
+        // initialize CEDMA variables for the execution of the agent
+        engine.GlobalScope.AddVariable(new Variable("AgentId", new IntData((int)a.Id)));
+        engine.GlobalScope.AddVariable(new Variable("CedmaServerUri", new StringData(serverUri)));
+
         agent[engine] = a;
         engines.Add(engine);
Index: /trunk/sources/HeuristicLab.CEDMA.Server/HeuristicLab.CEDMA.Server.csproj
===================================================================
--- /trunk/sources/HeuristicLab.CEDMA.Server/HeuristicLab.CEDMA.Server.csproj	(revision 392)
+++ /trunk/sources/HeuristicLab.CEDMA.Server/HeuristicLab.CEDMA.Server.csproj	(revision 393)
@@ -89,4 +89,8 @@
       <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">
       <Project>{545CE756-98D8-423B-AC2E-6E7D70926E5C}</Project>
Index: /trunk/sources/HeuristicLab.CEDMA.Server/RunScheduler.cs
===================================================================
--- /trunk/sources/HeuristicLab.CEDMA.Server/RunScheduler.cs	(revision 392)
+++ /trunk/sources/HeuristicLab.CEDMA.Server/RunScheduler.cs	(revision 393)
@@ -31,4 +31,5 @@
 using HeuristicLab.Grid;
 using System.Diagnostics;
+using HeuristicLab.Data;
 
 namespace HeuristicLab.CEDMA.Server {
@@ -39,4 +40,5 @@
       public AtomicOperation Operation;
     }
+    private string serverUri;
     private Database database;
     private JobManager jobManager;
@@ -47,7 +49,8 @@
     private AutoResetEvent runningJobs = new AutoResetEvent(false);
 
-    public RunScheduler(Database database, JobManager jobManager) {
+    public RunScheduler(Database database, JobManager jobManager, string serverUri) {
       this.database = database;
       this.jobManager = jobManager;
+      this.serverUri = serverUri;
       jobQueue = new Queue<Job>();
       Thread resultsGatheringThread = new Thread(GatherResults);
@@ -66,6 +69,11 @@
       }
       foreach(AgentEntry entry in agents) {
-        IOperatorGraph opGraph = (IOperatorGraph)DbPersistenceManager.Restore(entry.RawData);
-        AtomicOperation op = new AtomicOperation(opGraph.InitialOperator, new Scope());
+        Agent agent = (Agent)DbPersistenceManager.Restore(entry.RawData);
+        IOperatorGraph opGraph = agent.OperatorGraph;
+        Scope scope = new Scope();
+        // initialize CEDMA variables for the execution of the agent
+        scope.AddVariable(new Variable("AgentId", new IntData((int)entry.Id)));
+        scope.AddVariable(new Variable("CedmaServerUri", new StringData(serverUri)));
+        AtomicOperation op = new AtomicOperation(opGraph.InitialOperator, scope);
         WaitHandle wHandle;
         lock(remoteCommLock) {
Index: /trunk/sources/HeuristicLab.CEDMA.Server/ServerForm.cs
===================================================================
--- /trunk/sources/HeuristicLab.CEDMA.Server/ServerForm.cs	(revision 392)
+++ /trunk/sources/HeuristicLab.CEDMA.Server/ServerForm.cs	(revision 393)
@@ -55,5 +55,5 @@
 
     private void InitAgentScheduler() {
-      AgentScheduler scheduler = new AgentScheduler(database);
+      AgentScheduler scheduler = new AgentScheduler(database, addressTextBox.Text);
       Thread agentSchedulerThread = new Thread(scheduler.Run);
       agentSchedulerThread.Start();
@@ -63,5 +63,5 @@
       JobManager jobManager = new JobManager(gridAddress.Text);
       jobManager.Reset();
-      RunScheduler scheduler = new RunScheduler(database, jobManager);
+      RunScheduler scheduler = new RunScheduler(database, jobManager, addressTextBox.Text);
       Thread runSchedulerThread = new Thread(scheduler.Run);
       runSchedulerThread.Start();
