Index: /branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/Dispatcher.cs
===================================================================
--- /branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/Dispatcher.cs	(revision 1044)
+++ /branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/Dispatcher.cs	(revision 1044)
@@ -0,0 +1,92 @@
+#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 System.Windows.Forms;
+using HeuristicLab.PluginInfrastructure;
+using System.Net;
+using System.ServiceModel;
+using HeuristicLab.CEDMA.DB.Interfaces;
+using HeuristicLab.CEDMA.DB;
+using System.ServiceModel.Description;
+using System.Linq;
+using HeuristicLab.CEDMA.Core;
+
+namespace HeuristicLab.CEDMA.Server {
+  public class Dispatcher {
+    private List<string> dispatchQueue;
+    public IList<string> DispatchQueue {
+      get { return dispatchQueue.AsReadOnly(); }
+    }
+
+    private IStore store;
+
+    public Dispatcher(IStore store) {
+      this.store = store;
+      this.dispatchQueue = new List<string>();
+    }
+
+    private void FillDispatchQueue() {
+      Dictionary<Entity, Dictionary<int, int>> numberOfModelsOfTargetVariableOfDataSet = new Dictionary<Entity, Dictionary<int, int>>();
+      IList<Statement> datasetStatements = store.Select(new Statement(Ontology.AnyEntity, Ontology.PredicateInstanceOf, Ontology.TypeDataSet));
+      foreach (Statement datasetStatement in datasetStatements) {
+        numberOfModelsOfTargetVariableOfDataSet.Add(datasetStatement.Subject, new Dictionary<int, int>());
+        IList<Statement> modelStatements = store.Select(new Statement(datasetStatement.Subject, Ontology.PredicateHasModel, Ontology.AnyEntity));
+        foreach (Statement modelStatement in modelStatements) {
+          IList<Statement> modelAttributeStatements = store.Select(new Statement((Entity)modelStatement.Property, Ontology.PredicateModelAttribute, Ontology.AnyEntity));
+          foreach (Statement modelAttrStatement in modelAttributeStatements) {
+            var targetVariableStatements = store.Select(new Statement((Entity)modelAttrStatement.Property, Ontology.PredicateModelAttributeName, Ontology.AnyEntity))
+               .Where(t => (string)((Literal)t.Property).Value == "TargetVariable")
+               .SelectMany(t => store.Select(new Statement((Entity)modelAttrStatement.Property, Ontology.PredicateModelAttributeValue, Ontology.AnyEntity)))
+               .GroupBy(t => (int)((Literal)t.Property).Value);
+            foreach (var targetVariable in targetVariableStatements) {
+              numberOfModelsOfTargetVariableOfDataSet[datasetStatement.Subject].Add(targetVariable.Key, targetVariable.Count());
+            }
+          }
+        }
+      }
+      foreach(KeyValuePair<Entity, Dictionary<int, int>> dataSetEntry in numberOfModelsOfTargetVariableOfDataSet) {
+        DataSet dataSet = new DataSet(store, dataSetEntry.Key);
+        foreach(int targetVariable in dataSet.Problem.AllowedTargetVariables)
+          if (!dataSetEntry.Value.ContainsKey(targetVariable) || dataSetEntry.Value[targetVariable] < 10) {
+            QueueJob(dataSet.Name + " - target variable: " + targetVariable);
+          }
+      }
+    }
+
+    private void QueueJob(string job) {
+      dispatchQueue.Add(job);
+    }
+
+    private string GetNextJob() {
+      if (dispatchQueue.Count == 0) FillDispatchQueue();
+      string next = dispatchQueue[0];
+      dispatchQueue.RemoveAt(0);
+      return next;
+    }
+
+    internal void Start() {
+      FillDispatchQueue();
+    }
+  }
+}
Index: /branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/HeuristicLab.CEDMA.Server.csproj
===================================================================
--- /branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/HeuristicLab.CEDMA.Server.csproj	(revision 1043)
+++ /branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/HeuristicLab.CEDMA.Server.csproj	(revision 1044)
@@ -75,4 +75,6 @@
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="Dispatcher.cs" />
+    <Compile Include="Server.cs" />
     <Compile Include="ServerApplication.cs" />
     <Compile Include="HeuristicLabCedmaServerPlugin.cs" />
Index: /branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/Server.cs
===================================================================
--- /branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/Server.cs	(revision 1044)
+++ /branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/Server.cs	(revision 1044)
@@ -0,0 +1,83 @@
+#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 System.Windows.Forms;
+using HeuristicLab.PluginInfrastructure;
+using System.Net;
+using System.ServiceModel;
+using HeuristicLab.CEDMA.DB.Interfaces;
+using HeuristicLab.CEDMA.DB;
+using System.ServiceModel.Description;
+
+namespace HeuristicLab.CEDMA.Server {
+  public class Server {
+    private ServiceHost host;
+    private IStore store;
+
+    private string gridServiceUrl;
+
+    public string GridServiceUrl {
+      get { return gridServiceUrl; }
+      set { gridServiceUrl = value; }
+    }
+
+    private string cedmaServiceUrl;
+
+    public string CedmaServiceUrl {
+      get { return cedmaServiceUrl; }
+      set { cedmaServiceUrl = value; }
+    }
+
+    public Server(IStore store) {
+      // 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) {
+        cedmaServiceUrl = "net.tcp://" + Dns.GetHostAddresses(Dns.GetHostName())[2] + ":8002/CEDMA/World";
+      } else {
+        cedmaServiceUrl = "net.tcp://" + Dns.GetHostAddresses(Dns.GetHostName())[0] + ":8002/CEDMA/World";
+      }
+      this.store = store;
+    }
+
+    public void Start() {
+      host = new ServiceHost(store, new Uri(cedmaServiceUrl));
+      ServiceThrottlingBehavior throttlingBehavior = new ServiceThrottlingBehavior();
+      throttlingBehavior.MaxConcurrentSessions = 20;
+      host.Description.Behaviors.Add(throttlingBehavior);
+      try {
+        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;
+
+        host.AddServiceEndpoint(typeof(IStore), binding, cedmaServiceUrl);
+        host.Open();
+      }
+      catch (CommunicationException ex) {
+        MessageBox.Show("An exception occurred: " + ex.Message);
+        host.Abort();
+      }
+    }
+  }
+}
Index: /branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/ServerForm.cs
===================================================================
--- /branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/ServerForm.cs	(revision 1043)
+++ /branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/ServerForm.cs	(revision 1044)
@@ -42,53 +42,27 @@
 namespace HeuristicLab.CEDMA.Server {
   public partial class ServerForm : Form {
-    private ServiceHost host;
+    private Server server;
     private Store store;
+    private Dispatcher dispatcher;
+
     private static readonly string rdfFile = AppDomain.CurrentDomain.BaseDirectory + "rdf_store.db3";
     private static readonly string rdfConnectionString = "sqlite:rdf:Data Source=\"" + rdfFile + "\"";
+    
     public ServerForm() {
       InitializeComponent();
-      // 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] + ":8002/CEDMA/World";
-      } else {
-        addressTextBox.Text = "net.tcp://" + Dns.GetHostAddresses(Dns.GetHostName())[0] + ":8002/CEDMA/World";
-      }
+      store = new Store(rdfConnectionString);
+      server = new Server(store);
+      server.Start();
+      addressTextBox.Text = server.CedmaServiceUrl;
+      dispatcher = new Dispatcher(store);
+      dispatcher.Start();
     }
 
-    private void InitRunScheduler() {
-      JobManager jobManager = new JobManager(gridAddress.Text);
-      jobManager.Reset();
+    private void refreshTimer_Tick(object sender, EventArgs e) {
+      listBox.DataSource = dispatcher.DispatchQueue;
     }
 
-    private void InitRdfStore() {
-      store = new Store(rdfConnectionString);
-    }
-
-    private void Start() {
-      InitRdfStore();
-      InitRunScheduler();
-
-      host = new ServiceHost(store, new Uri(addressTextBox.Text));
-      ServiceThrottlingBehavior throttlingBehavior = new ServiceThrottlingBehavior();
-      throttlingBehavior.MaxConcurrentSessions = 20;
-      host.Description.Behaviors.Add(throttlingBehavior);
-      try {
-        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;
-
-        host.AddServiceEndpoint(typeof(IStore), binding, addressTextBox.Text);
-        host.Open();
-      } catch(CommunicationException ex) {
-        MessageBox.Show("An exception occurred: " + ex.Message);
-        host.Abort();
-      }
-    }
-
-    private void startButton_Click(object sender, EventArgs e) {
-      Start();
-      startButton.Enabled = false;
+    private void connectButton_Click(object sender, EventArgs e) {
+      // new GridExecutor(dispatcher)
     }
   }
Index: /branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/ServerForm.designer.cs
===================================================================
--- /branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/ServerForm.designer.cs	(revision 1043)
+++ /branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/ServerForm.designer.cs	(revision 1044)
@@ -45,9 +45,12 @@
     /// </summary>
     private void InitializeComponent() {
+      this.components = new System.ComponentModel.Container();
       this.addressTextBox = new System.Windows.Forms.TextBox();
       this.externalAddressLabel = new System.Windows.Forms.Label();
       this.gridAddressLabel = new System.Windows.Forms.Label();
       this.gridAddress = new System.Windows.Forms.TextBox();
-      this.startButton = new System.Windows.Forms.Button();
+      this.connectButton = new System.Windows.Forms.Button();
+      this.listBox = new System.Windows.Forms.ListBox();
+      this.refreshTimer = new System.Windows.Forms.Timer(this.components);
       this.SuspendLayout();
       // 
@@ -82,16 +85,33 @@
       this.gridAddress.Location = new System.Drawing.Point(106, 32);
       this.gridAddress.Name = "gridAddress";
-      this.gridAddress.Size = new System.Drawing.Size(229, 20);
+      this.gridAddress.Size = new System.Drawing.Size(160, 20);
       this.gridAddress.TabIndex = 8;
       // 
-      // startButton
+      // connectButton
       // 
-      this.startButton.Location = new System.Drawing.Point(15, 84);
-      this.startButton.Name = "startButton";
-      this.startButton.Size = new System.Drawing.Size(75, 23);
-      this.startButton.TabIndex = 10;
-      this.startButton.Text = "Start";
-      this.startButton.UseVisualStyleBackColor = true;
-      this.startButton.Click += new System.EventHandler(this.startButton_Click);
+      this.connectButton.Location = new System.Drawing.Point(272, 30);
+      this.connectButton.Name = "connectButton";
+      this.connectButton.Size = new System.Drawing.Size(75, 23);
+      this.connectButton.TabIndex = 10;
+      this.connectButton.Text = "Connect";
+      this.connectButton.UseVisualStyleBackColor = true;
+      this.connectButton.Click += new System.EventHandler(this.connectButton_Click);
+      // 
+      // listBox
+      // 
+      this.listBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
+                  | System.Windows.Forms.AnchorStyles.Left)
+                  | System.Windows.Forms.AnchorStyles.Right)));
+      this.listBox.FormattingEnabled = true;
+      this.listBox.Location = new System.Drawing.Point(12, 58);
+      this.listBox.Name = "listBox";
+      this.listBox.Size = new System.Drawing.Size(350, 277);
+      this.listBox.TabIndex = 11;
+      // 
+      // refreshTimer
+      // 
+      this.refreshTimer.Enabled = true;
+      this.refreshTimer.Interval = 1000;
+      this.refreshTimer.Tick += new System.EventHandler(this.refreshTimer_Tick);
       // 
       // ServerForm
@@ -99,6 +119,7 @@
       this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
       this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
-      this.ClientSize = new System.Drawing.Size(347, 119);
-      this.Controls.Add(this.startButton);
+      this.ClientSize = new System.Drawing.Size(374, 342);
+      this.Controls.Add(this.listBox);
+      this.Controls.Add(this.connectButton);
       this.Controls.Add(this.gridAddressLabel);
       this.Controls.Add(this.gridAddress);
@@ -118,5 +139,7 @@
     private System.Windows.Forms.Label gridAddressLabel;
     private System.Windows.Forms.TextBox gridAddress;
-    private System.Windows.Forms.Button startButton;
+    private System.Windows.Forms.Button connectButton;
+    private System.Windows.Forms.ListBox listBox;
+    private System.Windows.Forms.Timer refreshTimer;
   }
 }
Index: /branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/ServerForm.resx
===================================================================
--- /branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/ServerForm.resx	(revision 1043)
+++ /branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/ServerForm.resx	(revision 1044)
@@ -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>
