Index: trunk/sources/HeuristicLab.CEDMA.Operators/HeuristicLab.CEDMA.Operators.csproj
===================================================================
--- trunk/sources/HeuristicLab.CEDMA.Operators/HeuristicLab.CEDMA.Operators.csproj	(revision 537)
+++ trunk/sources/HeuristicLab.CEDMA.Operators/HeuristicLab.CEDMA.Operators.csproj	(revision 538)
@@ -4,5 +4,5 @@
     <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
     <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
-    <ProductVersion>9.0.21022</ProductVersion>
+    <ProductVersion>9.0.30729</ProductVersion>
     <SchemaVersion>2.0</SchemaVersion>
     <ProjectGuid>{6BC692D4-8843-4945-ACE4-5B41ED55476A}</ProjectGuid>
@@ -54,4 +54,9 @@
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="OntologyExtractor.cs" />
+    <Compile Include="ResultsExtractor.cs" />
+    <Compile Include="MakeStatement.cs" />
+    <Compile Include="InjectedVariableExtractor.cs" />
+    <Compile Include="SplitScopeToItemsResultWriter.cs" />
     <Compile Include="ItemMailer.cs" />
     <Compile Include="ScopeResultWriter.cs" />
@@ -64,4 +69,8 @@
   </ItemGroup>
   <ItemGroup>
+    <ProjectReference Include="..\HeuristicLab.CEDMA.Core\HeuristicLab.CEDMA.Core.csproj">
+      <Project>{C27DDF6C-84DF-45EF-B82F-57A28DD51166}</Project>
+      <Name>HeuristicLab.CEDMA.Core</Name>
+    </ProjectReference>
     <ProjectReference Include="..\HeuristicLab.CEDMA.DB.Interfaces\HeuristicLab.CEDMA.DB.Interfaces.csproj">
       <Project>{4F9BB789-D561-436B-B226-2BF44B7D0804}</Project>
@@ -75,4 +84,8 @@
       <Project>{F473D9AF-3F09-4296-9F28-3C65118DAFFA}</Project>
       <Name>HeuristicLab.Data</Name>
+    </ProjectReference>
+    <ProjectReference Include="..\HeuristicLab.Operators\HeuristicLab.Operators.csproj">
+      <Project>{A9983BA2-B3B2-475E-8E2C-62050B71D1C5}</Project>
+      <Name>HeuristicLab.Operators</Name>
     </ProjectReference>
     <ProjectReference Include="..\HeuristicLab.PluginInfrastructure\HeuristicLab.PluginInfrastructure.csproj">
Index: trunk/sources/HeuristicLab.CEDMA.Operators/InjectedVariableExtractor.cs
===================================================================
--- trunk/sources/HeuristicLab.CEDMA.Operators/InjectedVariableExtractor.cs	(revision 538)
+++ trunk/sources/HeuristicLab.CEDMA.Operators/InjectedVariableExtractor.cs	(revision 538)
@@ -0,0 +1,93 @@
+#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.Core;
+using HeuristicLab.Operators;
+
+namespace HeuristicLab.CEDMA.Operators {
+  public class InjectedVariableExtractor : OperatorBase {
+    public override string Description {
+      get { return "TASK."; }
+    }
+
+    public InjectedVariableExtractor()
+      : base() {
+      AddVariableInfo(new VariableInfo("AgentId", "Id of the agent to extract injected variables from.", typeof(IntData), VariableKind.In));
+      AddVariableInfo(new VariableInfo("CedmaServerUri", "Uri of the CEDMA server", typeof(StringData), VariableKind.In));
+      AddVariableInfo(new VariableInfo("VariableName", "Name of the injected variable that should be extracted", typeof(StringData), VariableKind.In));
+    }
+
+    public override IOperation Apply(IScope scope) {
+      string serverUrl = GetVariableValue<StringData>("CedmaServerUri", scope, true).Data;
+      long agentId = GetVariableValue<IntData>("AgentId", scope, true).Data;
+      string variableName = GetVariableValue<StringData>("VariableName", scope, 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));
+        IOperatorGraph opGraph = (IOperatorGraph)PersistenceManager.RestoreFromGZip(database.GetAgentRawData(agentId));        
+        OperatorLinkPatcher.LinkDatabase(opGraph, database);
+        IVariable var = FindInjectedVariable(database, variableName, opGraph);
+        if(var != null) {
+          scope.AddVariable(var);
+        }
+      }
+      return null;
+    }
+
+    private IVariable FindInjectedVariable(IDatabase database, string variableName, IOperatorGraph opGraph) {
+      foreach(IOperator op in opGraph.Operators) {
+        IVariable var = FindInjectedVariable(database, variableName, op);
+        if(var != null) return var;
+      }
+      return null;
+    }
+
+    private IVariable FindInjectedVariable(IDatabase database, string variableName, IOperator op) {
+      IVariable var = op.GetVariable(variableName);
+      if(var != null) return var;
+      else if(op is CombinedOperator) {
+        var = FindInjectedVariable(database, variableName, ((CombinedOperator)op).OperatorGraph);
+      } else if(op is OperatorLink) {
+        OperatorLink link = op as OperatorLink;
+        OperatorEntry targetEntry = database.GetOperator(link.Id);
+        IOperator target = (IOperator)PersistenceManager.RestoreFromGZip(targetEntry.RawData);
+        OperatorLinkPatcher.LinkDatabase(target, database);
+        link.Operator = target;
+
+        var = FindInjectedVariable(database, variableName, link.Operator);
+      }
+      return var;
+    }
+  }
+}
Index: trunk/sources/HeuristicLab.CEDMA.Operators/MakeStatement.cs
===================================================================
--- trunk/sources/HeuristicLab.CEDMA.Operators/MakeStatement.cs	(revision 538)
+++ trunk/sources/HeuristicLab.CEDMA.Operators/MakeStatement.cs	(revision 538)
@@ -0,0 +1,101 @@
+#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.Core;
+using HeuristicLab.Operators;
+
+namespace HeuristicLab.CEDMA.Operators {
+  public class MakeStatement : OperatorBase {
+    public override string Description {
+      get { return "TASK."; }
+    }
+
+    public MakeStatement()
+      : base() {
+      AddVariableInfo(new VariableInfo("AgentId", "Id of the agent to extract injected variables from.", typeof(IntData), VariableKind.In));
+      AddVariableInfo(new VariableInfo("CedmaServerUri", "Uri of the CEDMA server", typeof(StringData), VariableKind.In));
+      AddVariableInfo(new VariableInfo("Subject", "", typeof(IItem), VariableKind.In));
+      AddVariableInfo(new VariableInfo("Predicate", "", typeof(IItem), VariableKind.In));
+      AddVariableInfo(new VariableInfo("Property", "", typeof(IItem), VariableKind.In));
+    }
+
+    public override IOperation Apply(IScope scope) {
+      string serverUrl = GetVariableValue<StringData>("CedmaServerUri", scope, true).Data;
+      long agentId = GetVariableValue<IntData>("AgentId", scope, true).Data;
+      IItem subject = GetVariableValue<IItem>("Subject", scope, true);
+      IItem predicate = GetVariableValue<IItem>("Predicate", scope, true);
+      IItem property = GetVariableValue<IItem>("Property", scope, true);
+
+      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));
+        ItemEntry subjectEntry = new ItemEntry();
+        subjectEntry.Guid = subject.Guid;
+        subjectEntry.RawData = PersistenceManager.SaveToGZip(subject);
+        ItemEntry predicateEntry = new ItemEntry();
+        predicateEntry.Guid = predicate.Guid;
+        predicateEntry.RawData = PersistenceManager.SaveToGZip(predicate);
+        ItemEntry propertyEntry = new ItemEntry();
+        propertyEntry.Guid = property.Guid;
+        propertyEntry.RawData = PersistenceManager.SaveToGZip(property);
+        database.LinkItems(subjectEntry, predicateEntry, propertyEntry);
+      }
+      return null;
+    }
+
+    private IVariable FindInjectedVariable(IDatabase database, string variableName, IOperatorGraph opGraph) {
+      foreach(IOperator op in opGraph.Operators) {
+        IVariable var = FindInjectedVariable(database, variableName, op);
+        if(var != null) return var;
+      }
+      return null;
+    }
+
+    private IVariable FindInjectedVariable(IDatabase database, string variableName, IOperator op) {
+      IVariable var = op.GetVariable(variableName);
+      if(var != null) return var;
+      else if(op is CombinedOperator) {
+        var = FindInjectedVariable(database, variableName, ((CombinedOperator)op).OperatorGraph);
+      } else if(op is OperatorLink) {
+        OperatorLink link = op as OperatorLink;
+        OperatorEntry targetEntry = database.GetOperator(link.Id);
+        IOperator target = (IOperator)PersistenceManager.RestoreFromGZip(targetEntry.RawData);
+        OperatorLinkPatcher.LinkDatabase(target, database);
+        link.Operator = target;
+
+        var = FindInjectedVariable(database, variableName, link.Operator);
+      }
+      return var;
+    }
+  }
+}
Index: trunk/sources/HeuristicLab.CEDMA.Operators/OntologyExtractor.cs
===================================================================
--- trunk/sources/HeuristicLab.CEDMA.Operators/OntologyExtractor.cs	(revision 538)
+++ trunk/sources/HeuristicLab.CEDMA.Operators/OntologyExtractor.cs	(revision 538)
@@ -0,0 +1,62 @@
+#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.Core;
+using HeuristicLab.Operators;
+
+namespace HeuristicLab.CEDMA.Operators {
+  public class OntologyExtractor : OperatorBase {
+    public override string Description {
+      get { return "TASK."; }
+    }
+
+    public OntologyExtractor()
+      : base() {
+      AddVariableInfo(new VariableInfo("CedmaServerUri", "Uri of the CEDMA server", typeof(StringData), VariableKind.In));
+    }
+
+    public override IOperation Apply(IScope scope) {
+      string serverUrl = GetVariableValue<StringData>("CedmaServerUri", scope, 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));
+        foreach(ItemEntry entry in database.GetOntologyItems()) {
+          StringData item = (StringData)PersistenceManager.RestoreFromGZip(entry.RawData);
+          scope.AddVariable(new Variable(item.Data, item));
+        }
+      }
+      return null;
+    }
+  }
+}
Index: trunk/sources/HeuristicLab.CEDMA.Operators/ResultsExtractor.cs
===================================================================
--- trunk/sources/HeuristicLab.CEDMA.Operators/ResultsExtractor.cs	(revision 538)
+++ trunk/sources/HeuristicLab.CEDMA.Operators/ResultsExtractor.cs	(revision 538)
@@ -0,0 +1,71 @@
+#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.Core;
+using HeuristicLab.Operators;
+
+namespace HeuristicLab.CEDMA.Operators {
+  public class ResultsExtractor : OperatorBase {
+    public override string Description {
+      get { return "TASK."; }
+    }
+
+    public ResultsExtractor()
+      : base() {
+      AddVariableInfo(new VariableInfo("AgentId", "Id of the agent to extract injected variables from.", typeof(IntData), VariableKind.In));
+      AddVariableInfo(new VariableInfo("CedmaServerUri", "Uri of the CEDMA server", typeof(StringData), VariableKind.In));
+    }
+
+    public override IOperation Apply(IScope scope) {
+      string serverUrl = GetVariableValue<StringData>("CedmaServerUri", scope, true).Data;
+      long agentId = GetVariableValue<IntData>("AgentId", scope, 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));
+        ExtractResults(database, scope, database.GetResults(agentId));
+      }
+      return null;
+    }
+
+    private void ExtractResults(IDatabase database, IScope scope, ICollection<ResultEntry> results) {
+      foreach(ResultEntry result in results) {
+        IItem item = (IItem)PersistenceManager.RestoreFromGZip(database.GetResultRawData(result.Id));
+        Scope resultScope = new Scope();
+        resultScope.AddVariable(new Variable(result.Summary, item));
+        ExtractResults(database, resultScope, database.GetSubResults(result.Id));
+        scope.AddSubScope(resultScope);
+      }
+    }
+  }
+}
Index: trunk/sources/HeuristicLab.CEDMA.Operators/SplitScopeToItemsResultWriter.cs
===================================================================
--- trunk/sources/HeuristicLab.CEDMA.Operators/SplitScopeToItemsResultWriter.cs	(revision 538)
+++ trunk/sources/HeuristicLab.CEDMA.Operators/SplitScopeToItemsResultWriter.cs	(revision 538)
@@ -0,0 +1,91 @@
+#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;
+
+namespace HeuristicLab.CEDMA.Operators {
+  public class SplitScopeToItemsResultWriter : OperatorBase {
+    public override string Description {
+      get { return "TASK."; }
+    }
+
+    public SplitScopeToItemsResultWriter()
+      : base() {
+      AddVariableInfo(new VariableInfo("AgentId", "Id of the agent whose results should be transformed.", typeof(IntData), VariableKind.In));
+      AddVariableInfo(new VariableInfo("CedmaServerUri", "Uri of the CEDMA server", typeof(StringData), VariableKind.In));
+    }
+
+    public override IOperation Apply(IScope scope) {
+      string serverUrl = GetVariableValue<StringData>("CedmaServerUri", scope, true).Data;
+      long agentId = GetVariableValue<IntData>("AgentId", scope, 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));
+        TransformResults(database, agentId);
+      }
+      return null;
+    }
+
+    private void TransformResults(IDatabase database, long agentId) {
+      TransformResults(database, database.GetResults(agentId));
+      foreach(AgentEntry subAgent in database.GetSubAgents(agentId)) {
+        TransformResults(database, subAgent.Id);
+      }
+    }
+
+    private void TransformResults(IDatabase database, ICollection<ResultEntry> results) {
+      foreach(ResultEntry entry in results) {
+        byte[] rawData = database.GetResultRawData(entry.Id);
+        object resultItem = PersistenceManager.RestoreFromGZip(rawData);
+        if(resultItem is IScope) {
+          IScope resultScope = resultItem as IScope;
+          IVariable funTreeVariable = resultScope.GetVariable("FunctionTree");
+          if(funTreeVariable != null) {
+            long newResultId = 0;
+            if(entry.AgentId.HasValue) {
+              newResultId = database.InsertResult(entry.AgentId.Value, funTreeVariable.Name, resultScope.Name, PersistenceManager.SaveToGZip(funTreeVariable.Value));
+            } else if(entry.ParentResultId.HasValue) {
+              newResultId = database.InsertSubResult(entry.ParentResultId.Value, funTreeVariable.Name, resultScope.Name, PersistenceManager.SaveToGZip(funTreeVariable.Value));
+            }
+            foreach(IVariable var in resultScope.Variables) {
+              if(var != funTreeVariable) {
+                database.InsertSubResult(newResultId, var.Name, "", PersistenceManager.SaveToGZip(var.Value));
+              }
+            }
+          }
+        }
+        TransformResults(database, database.GetSubResults(entry.Id));
+      }
+    }
+  }
+}
