Index: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/ConfigManager.cs
===================================================================
--- branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/ConfigManager.cs	(revision 5105)
+++ branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/ConfigManager.cs	(revision 5105)
@@ -0,0 +1,131 @@
+﻿#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2010 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 HeuristicLab.Services.Hive.Common;
+using HeuristicLab.Clients.Hive.Slave;
+using HeuristicLab.Services.Hive.Common.DataTransfer;
+using HeuristicLab.Clients.Hive.Slave.Properties;
+
+
+namespace HeuristicLab.Clients.Hive.Salve {
+  /// <summary>
+  /// accesses the Server and sends his data (uuid, uptimes, hardware config) 
+  /// </summary>
+  public class ConfigManager {
+    private static ConfigManager instance = null;
+    public static ConfigManager Instance {
+      get {
+        if (instance == null) {
+          instance = new ConfigManager();
+        }
+        return instance;
+      }
+    }
+
+    public Core Core { get; set; }
+    private HeuristicLab.Services.Hive.Common.DataTransfer.Slave hardwareInfo;
+
+    /// <summary>
+    /// Constructor for the singleton, must recover Guid, Calendar, ...
+    /// </summary>
+    private ConfigManager() {
+      hardwareInfo = new HeuristicLab.Services.Hive.Common.DataTransfer.Slave();
+
+      if (Settings.Default.Guid == Guid.Empty) {
+        hardwareInfo.Id = Guid.NewGuid();
+        Settings.Default.Guid = hardwareInfo.Id;
+        Settings.Default.Save();
+      } else
+        hardwareInfo.Id = Settings.Default.Guid;
+
+      hardwareInfo.Cores = Environment.ProcessorCount;
+      hardwareInfo.Memory = 1024;
+      hardwareInfo.Name = Environment.MachineName;
+    }
+
+    /// <summary>
+    /// Get all the Information about the client
+    /// </summary>
+    /// <returns>the ClientInfo object</returns>
+    public HeuristicLab.Services.Hive.Common.DataTransfer.Slave GetClientInfo() {
+      //TODO: how to display connectedsince in gui?
+      //hardwareInfo.Login = WcfService.Instance.ConnectedSince;
+      return hardwareInfo;
+    }
+
+    /// <summary>
+    /// collects and returns information that get displayed by the Client Console
+    /// </summary>
+    /// <returns></returns>
+    public StatusCommons GetStatusForClientConsole() {
+      //Todo: Locking
+      StatusCommons st = new StatusCommons();
+      st.ClientGuid = hardwareInfo.Id;
+
+      st.Status = WcfService.Instance.ConnState;
+      st.ConnectedSince = WcfService.Instance.ConnectedSince;
+
+      st.TotalCores = hardwareInfo.Cores.HasValue ? hardwareInfo.Cores.Value : 0;
+      st.FreeCores = hardwareInfo.Cores.HasValue ? hardwareInfo.Cores.Value - GetUsedCores() : 0;
+
+      st.JobsAborted = SlaveStatusInfo.JobsAborted;
+      st.JobsDone = SlaveStatusInfo.JobsProcessed;
+      st.JobsFetched = SlaveStatusInfo.JobsFetched;
+
+      Dictionary<Guid, Executor> engines = Core.ExecutionEngines;
+      st.Jobs = new List<JobStatus>();
+
+      lock (engines) {
+        foreach (KeyValuePair<Guid, Executor> kvp in engines) {
+          Executor e = kvp.Value;
+          st.Jobs.Add(new JobStatus { JobId = e.JobId, ExecutionTime = e.ExecutionTime, Since = e.CreationTime });
+        }
+      }
+      return st;
+    }
+
+    public Dictionary<Guid, TimeSpan> GetExecutionTimeOfAllJobs() {
+      Dictionary<Guid, TimeSpan> prog = new Dictionary<Guid, TimeSpan>();
+      Dictionary<Guid, Executor> engines = Core.ExecutionEngines;
+      lock (engines) {
+        foreach (KeyValuePair<Guid, Executor> kvp in engines) {
+          Executor e = kvp.Value;
+          prog[e.JobId] = e.ExecutionTime;
+        }
+      }
+      return prog;
+    }
+
+    public int GetUsedCores() {
+      Dictionary<Guid, Executor> engines = Core.ExecutionEngines;
+      Dictionary<Guid, Job> jobs = Core.Jobs;
+      int usedCores = 0;
+      lock (engines) {
+        foreach (KeyValuePair<Guid, Job> kvp in jobs)
+          usedCores += kvp.Value.CoresNeeded;
+      }
+      return usedCores;
+    }
+
+  }
+}
Index: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/Core.cs
===================================================================
--- branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/Core.cs	(revision 5105)
+++ branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/Core.cs	(revision 5105)
@@ -0,0 +1,347 @@
+﻿#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2010 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.IO;
+using System.Threading;
+using HeuristicLab.Common;
+using HeuristicLab.Core;
+using HeuristicLab.Services.Hive.Common.DataTransfer;
+using HeuristicLab.Services.Hive.Common;
+using HeuristicLab.Clients.Hive.Slave;
+
+
+namespace HeuristicLab.Clients.Hive.Salve {
+  /// <summary>
+  /// The core component of the Hive Client
+  /// </summary>
+  public class Core : MarshalByRefObject {
+    public static bool abortRequested { get; set; }
+
+    public static ILog Log { get; set; }
+
+    private Dictionary<Guid, Executor> engines = new Dictionary<Guid, Executor>();
+    private Dictionary<Guid, AppDomain> appDomains = new Dictionary<Guid, AppDomain>();
+    private Dictionary<Guid, Job> jobs = new Dictionary<Guid, Job>();
+
+    private WcfService wcfService;
+    private HeartbeatManager heartbeatManager;
+
+    private bool currentlyFetching;
+    private bool CurrentlyFetching {
+      get {
+        return currentlyFetching;
+      }
+      set {
+        currentlyFetching = value;
+        Logger.Debug("Set CurrentlyFetching to " + currentlyFetching);
+      }
+    }
+
+    public Dictionary<Guid, Executor> ExecutionEngines {
+      get { return engines; }
+    }
+
+    internal Dictionary<Guid, Job> Jobs {    
+      get { return jobs; }
+    }
+
+    /// <summary>
+    /// Main Method for the client
+    /// </summary>
+    public void Start() {
+      abortRequested = false;
+      Logger.Info("Hive Slave started");
+      //TODO: implement slave console server
+      //SlaveConsoleServer server = new SlaveConsoleServer();
+      //server.Start();
+
+      ConfigManager manager = ConfigManager.Instance;
+      manager.Core = this;
+
+      wcfService = WcfService.Instance;
+      RegisterServiceEvents();
+
+      StartHeartbeats(); // Start heartbeats thread
+      DispatchMessageQueue(); // dispatch messages until abortRequested
+
+      DeRegisterServiceEvents();
+      
+      //server.Close();
+      Logger.Info("Program shutdown");
+    }
+
+    private void StartHeartbeats() {
+      //Initialize the heartbeat
+      heartbeatManager = new HeartbeatManager { Interval = new TimeSpan(0, 0, 10) };
+      heartbeatManager.StartHeartbeat();
+    }
+
+    private void DispatchMessageQueue() {
+      MessageQueue queue = MessageQueue.GetInstance();
+      while (!abortRequested) {
+        MessageContainer container = queue.GetMessage();
+        DetermineAction(container);
+      }
+    }
+
+    private void RegisterServiceEvents() {
+      //TODO
+    }
+
+    private void DeRegisterServiceEvents() {
+      //TODO
+    }
+
+    /// <summary>
+    /// Reads and analyzes the Messages from the MessageQueue and starts corresponding actions
+    /// </summary>
+    /// <param name="container">The Container, containing the message</param>
+    private void DetermineAction(MessageContainer container) {
+      Logger.Info("Message: " + container.Message.ToString() + " for job: " + container.JobId);
+      switch (container.Message) {
+        //Server requests to abort a job
+        case MessageContainer.MessageType.AbortJob:
+          if (engines.ContainsKey(container.JobId))
+            try {
+              engines[container.JobId].Abort();
+            }
+            catch (AppDomainUnloadedException) {
+              // appdomain already unloaded. Finishing job probably ongoing
+            }
+          else
+            Logger.Error("AbortJob: Engine doesn't exist");
+          break;
+                        
+        //Pull a Job from the Server
+        case MessageContainer.MessageType.AquireJob:          
+          if (!CurrentlyFetching) {
+            //TODO: handle in own thread!!
+            Job myJob = wcfService.AquireJob();
+            JobData jobData = wcfService.GetJobData(myJob.Id);
+            wcfService_GetJobCompleted(myJob, jobData);            
+            CurrentlyFetching = true;
+          } else
+            Logger.Info("Currently fetching, won't fetch this time!");
+          break;
+
+        //A Job has finished and can be sent back to the server
+        case MessageContainer.MessageType.JobStopped:
+          SendFinishedJob(container.JobId);
+          break;
+
+        case MessageContainer.MessageType.JobFailed:
+          SendFinishedJob(container.JobId);
+          break;        
+              
+        //Hard shutdown of the client
+        case MessageContainer.MessageType.ShutdownSlave:
+          ShutdownCore();
+          break;
+      }
+    }
+
+    public void ShutdownCore() {
+      Logger.Info("Shutdown Signal received");
+      
+      Logger.Debug("Stopping heartbeat");
+      heartbeatManager.StopHeartBeat();
+      abortRequested = true;     
+      Logger.Debug("Logging out");
+
+      lock (engines) {
+        Logger.Debug("engines locked");
+        foreach (KeyValuePair<Guid, AppDomain> kvp in appDomains) {
+          Logger.Debug("Shutting down Appdomain for " + kvp.Key);
+          appDomains[kvp.Key].UnhandledException -= new UnhandledExceptionEventHandler(appDomain_UnhandledException);
+          AppDomain.Unload(kvp.Value);
+        }
+      }
+     
+      WcfService.Instance.Disconnect();    
+    }
+
+    //TODO: make synchronized
+    //TODO: start own thread?
+    //only called when waiting for child jobs?
+    public void PauseJob(JobData data ) {
+      if(!Jobs.ContainsKey(data.JobId)) {
+        //TODO: error handling 
+      }
+      Job job = Jobs[data.JobId];
+      job.JobState = JobState.WaitingForChildJobs;
+
+      wcfService.UpdateJob(job, data);      
+      KillAppDomain(data.JobId);      
+    }
+            
+    
+    /// <summary>
+    /// serializes the finished job and submits it to the server. If, at the time, a network connection is unavailable, the Job gets stored on the disk. 
+    /// once the connection gets reestablished, the job gets submitted
+    /// </summary>
+    /// <param name="jobId"></param>
+    public void SendFinishedJob(object jobId) {
+      try {
+        Guid jId = (Guid)jobId;
+        Logger.Info("Getting the finished job with id: " + jId);
+        if (!engines.ContainsKey(jId)) {
+          Logger.Info("Engine doesn't exist");
+          return;
+        }  
+        if (!jobs.ContainsKey(jId)) {
+          Logger.Info("Job doesn't exist");
+          return;
+        }
+        Job cJob = jobs[jId];
+
+        JobData sJob = engines[jId].GetFinishedJob();
+        cJob.Exception = engines[jId].CurrentException;
+        cJob.ExecutionTime = engines[jId].ExecutionTime;
+        
+        try {
+          Logger.Info("Sending the finished job with id: " + jId);
+          wcfService.UpdateJob(cJob, sJob);
+          SlaveStatusInfo.JobsProcessed++;          
+        }
+        catch (Exception e) {
+          Logger.Info("Transmitting to server failed. Storing the finished job with id: " + jId + " to hdd (" + e.ToString() + ")");          
+        }
+        finally {
+          KillAppDomain(jId); // kill app-domain in every case
+          heartbeatManager.AwakeHeartBeatThread();
+        }
+      }
+      catch (Exception e) {
+        OnExceptionOccured(e);
+      }
+    }
+  
+    /// <summary>
+    /// A new Job from the wcfService has been received and will be started within a AppDomain.
+    /// </summary>
+    /// <param name="sender"></param>
+    /// <param name="e"></param>
+    void wcfService_GetJobCompleted(Job myJob, JobData jobData) {      
+        Logger.Info("Received new job with id " + myJob.Id);
+        String pluginDir = Path.Combine(PluginCache.Instance.PluginTempBaseDir, myJob.Id.ToString());
+        bool pluginsPrepared = false;
+
+        try {       
+          PluginCache.Instance.PreparePlugins(myJob, jobData);
+          Logger.Debug("Plugins fetched for job " + myJob.Id);
+          pluginsPrepared = true;
+        }
+        catch (Exception exception) {
+          Logger.Error(string.Format("Copying plugins for job {0} failed: {1}", myJob.Id, exception));
+        }
+
+        if (pluginsPrepared) {
+          try {
+            AppDomain appDomain = HeuristicLab.PluginInfrastructure.Sandboxing.SandboxManager.CreateAndInitSandbox(myJob.Id.ToString(), pluginDir, Path.Combine(pluginDir, PluginCache.ConfigFileName));
+            appDomain.UnhandledException += new UnhandledExceptionEventHandler(appDomain_UnhandledException);
+            lock (engines) {
+              if (!jobs.ContainsKey(myJob.Id)) {
+                jobs.Add(myJob.Id, myJob);
+                appDomains.Add(myJob.Id, appDomain);
+                Logger.Debug("Creating AppDomain");
+                Executor engine = (Executor)appDomain.CreateInstanceAndUnwrap(typeof(Executor).Assembly.GetName().Name, typeof(Executor).FullName);
+                Logger.Debug("Created AppDomain");
+                engine.JobId = myJob.Id;
+                engine.core = this;
+                Logger.Debug("Starting Engine for job " + myJob.Id);
+                engines.Add(myJob.Id, engine);
+                engine.Start(jobData.Data);
+                SlaveStatusInfo.JobsFetched++;
+                Logger.Info("Increment FetchedJobs to:" + SlaveStatusInfo.JobsFetched);
+              }
+            }
+            heartbeatManager.AwakeHeartBeatThread();
+          }
+          catch (Exception exception) {
+            Logger.Error("Creating the Appdomain and loading the job failed for job " + myJob.Id);
+            Logger.Error("Error thrown is: ", exception);
+            CurrentlyFetching = false;
+            KillAppDomain(myJob.Id);
+          }
+        }      
+      CurrentlyFetching = false;
+    }
+  
+    public event EventHandler<EventArgs<Exception>> ExceptionOccured;
+    private void OnExceptionOccured(Exception e) {
+      Logger.Error("Error: " + e.ToString());
+      var handler = ExceptionOccured;
+      if (handler != null) handler(this, new EventArgs<Exception>(e));
+    }
+
+    void appDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) {
+      Logger.Error("Exception in AppDomain: " + e.ExceptionObject.ToString());
+      KillAppDomain(new Guid(e.ExceptionObject.ToString()));
+    }
+
+    /// <summary>
+    /// Kill a appdomain with a specific id.
+    /// </summary>
+    /// <param name="id">the GUID of the job</param>
+    public void KillAppDomain(Guid id) {
+      Logger.Debug("Shutting down Appdomain for Job " + id);
+      lock (engines) {
+        try {
+          if (engines.ContainsKey(id))
+            engines[id].Dispose();
+          if (appDomains.ContainsKey(id)) {
+            appDomains[id].UnhandledException -= new UnhandledExceptionEventHandler(appDomain_UnhandledException);
+
+            int repeat = 5;
+            while (repeat > 0) {
+              try {
+                AppDomain.Unload(appDomains[id]);
+                repeat = 0;
+              }
+              catch (CannotUnloadAppDomainException) {
+                Logger.Error("Could not unload AppDomain, will try again in 1 sec.");
+                Thread.Sleep(1000);
+                repeat--;
+                if (repeat == 0) {
+                  throw; // rethrow and let app crash
+                }
+              }
+            }
+            appDomains.Remove(id);
+          }
+
+          engines.Remove(id);
+          jobs.Remove(id);
+          PluginCache.Instance.DeletePluginsForJob(id);
+          GC.Collect();
+        }
+        catch (Exception ex) {
+          Logger.Error("Exception when unloading the appdomain: ", ex);
+        }
+      }
+      GC.Collect();
+    } 
+  }   
+
+
+}
Index: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/Executor.cs
===================================================================
--- branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/Executor.cs	(revision 5105)
+++ branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/Executor.cs	(revision 5105)
@@ -0,0 +1,207 @@
+﻿#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2010 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.Linq;
+using HeuristicLab.Common;
+using HeuristicLab.Core;
+using HeuristicLab.Services.Hive.Common;
+using HeuristicLab.Hive;
+using HeuristicLab.Services.Hive.Common.DataTransfer;
+using System.Collections.Generic;
+using HeuristicLab.Clients.Hive.Slave;
+using HeuristicLab.PluginInfrastructure;
+
+                                             
+namespace HeuristicLab.Clients.Hive.Salve {
+  public class Executor : MarshalByRefObject, IDisposable {
+    public Guid JobId { get; set; }
+    public IJob Job { get; set; }
+    public MessageContainer.MessageType CurrentMessage { get; set; }
+    public Core core { get; set; }    
+        
+    private Exception currentException;
+    public String CurrentException {
+      get {
+        if (currentException != null) {
+          return currentException.ToString();
+        } else {
+          return string.Empty;
+        }
+      }
+    }
+    
+    public ExecutionState ExecutionState {
+      get {
+        return Job != null ? Job.ExecutionState : HeuristicLab.Core.ExecutionState.Stopped;
+      }
+    }
+
+    public TimeSpan ExecutionTime {
+      get {
+        return Job != null ? Job.ExecutionTime : new TimeSpan(0, 0, 0);
+      }
+    }
+
+    public DateTime CreationTime { get; set; }
+
+    /// <param name="serializedJob"></param>
+    /// <param name="collectChildJobs">if true, all child-jobs are downloaded and the job will be resumed.</param>
+    public void Start(byte[] serializedJob) {
+      try {
+        CreationTime = DateTime.Now;
+        Job = PersistenceUtil.Deserialize<IJob>(serializedJob);
+
+        RegisterJobEvents();
+
+        if (Job.CollectChildJobs) {          
+          IEnumerable<JobData> childjobs = WcfService.Instance.GetChildJobs(JobId);
+          Job.Resume(childjobs.Select(j => PersistenceUtil.Deserialize<IJob>(j.Data)));
+        } else {
+          Job.Prepare();
+          Job.Start();
+        }
+      }
+      catch (Exception e) {
+        this.currentException = e;        
+      }
+    }
+
+    public void StartOnlyJob() {
+      try {
+        Job.Start();
+      }
+      catch (Exception e) {
+        this.currentException = e;        
+      }
+    }
+
+    public void Abort() {
+      CurrentMessage = MessageContainer.MessageType.AbortJob;
+      if ((ExecutionState == ExecutionState.Started) || (ExecutionState == ExecutionState.Paused)) {
+        Job.Stop();
+      } else {
+        Job_JobStopped(this, EventArgs.Empty);
+      }
+    }
+
+    private void RegisterJobEvents() {
+      //TODO: warum gibt es jobStopped und jobfailed nicht mehr? 
+      Job.JobStopped += new EventHandler(Job_JobStopped);
+      Job.JobFailed += new EventHandler(Job_JobFailed);
+      Job.NewChildJob += new EventHandler<EventArgs<IJob>>(Job_NewChildJob);
+      Job.WaitForChildJobs += new EventHandler(Job_WaitForChildJobs);
+      Job.DeleteChildJobs += new EventHandler(Job_DeleteChildJobs);
+    }
+
+    private void DeregisterJobEvents() {
+      Job.JobStopped -= new EventHandler(Job_JobStopped);
+      Job.JobFailed -= new EventHandler(Job_JobFailed);
+      Job.NewChildJob -= new EventHandler<EventArgs<IJob>>(Job_NewChildJob);
+      Job.WaitForChildJobs -= new EventHandler(Job_WaitForChildJobs);
+      Job.DeleteChildJobs -= new EventHandler(Job_DeleteChildJobs);
+    }
+
+    private List<Guid> FindPluginsNeeded(IJob obj) {
+      List<Guid> guids = new List<Guid>();
+      foreach(IPluginDescription desc in PluginUtil.GetDeclaringPlugins(obj)) {        
+      }
+      throw new NotImplementedException("FindPluginsNeeded for Job_NewChildJob");
+
+      return guids;
+    }
+
+    private void Job_NewChildJob(object sender, EventArgs<IJob> e) {
+      JobData childJobData = new JobData();
+      childJobData.Data = PersistenceUtil.Serialize(e.Value);
+
+      Job childJob = new Job();
+      childJob.JobState = JobState.Offline;
+      childJob.CoresNeeded = 1;
+      childJob.MemoryNeeded = 0;
+      childJob.PluginsNeededIds = FindPluginsNeeded(e.Value);
+
+      //TODO: is return value needed?
+      WcfService.Instance.AddChildJob(this.JobId, childJob, childJobData);
+    }
+
+    private void Job_WaitForChildJobs(object sender, EventArgs e) {
+      // Pause the job and send it back to the hive. The server will awake it when all child-jobs are finished
+      this.Job.CollectChildJobs = true;
+      
+      JobData jdata = new JobData();
+      jdata.Data = PersistenceUtil.Serialize(Job);
+      jdata.JobId = this.JobId;
+      
+      core.PauseJob(jdata);
+    }
+
+    private void Job_DeleteChildJobs(object sender, EventArgs e) {
+      WcfService.Instance.DeleteChildJobs(JobId);
+    }
+
+    private void Job_JobFailed(object sender, EventArgs e) {
+      //TODO: get exception to client
+      HeuristicLab.Common.EventArgs<Exception> ex = (HeuristicLab.Common.EventArgs<Exception>)e;
+      currentException = ex.Value;
+      core.SendFinishedJob(JobId);
+    }
+
+    private void Job_JobStopped(object sender, EventArgs e) {
+     if (CurrentMessage == MessageContainer.MessageType.AbortJob) {
+       core.KillAppDomain(JobId);
+      } else {
+        core.SendFinishedJob(JobId);
+      }
+    }
+
+    public JobData GetFinishedJob() {
+      if (Job == null) {
+        throw new InvalidStateException("Job is null"); 
+      }              
+
+      if (Job.ExecutionState == HeuristicLab.Core.ExecutionState.Started) {
+        try { Job.Stop(); }
+        catch { }
+      }
+
+      if (Job.ExecutionState == HeuristicLab.Core.ExecutionState.Started) {
+        throw new InvalidStateException("Job is still running"); 
+      } else {
+        JobData jdata = new JobData();
+        jdata.Data = PersistenceUtil.Serialize(Job);
+        jdata.JobId = JobId;
+        return jdata;
+      }
+    }   
+   
+    public Executor() {
+      CurrentMessage = MessageContainer.MessageType.NoMessage;
+    }
+
+    public void Dispose() {
+      if (Job != null)
+        DeregisterJobEvents();
+      //Queue = null;
+      Job = null;
+    }
+  }
+}
Index: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/HeartbeatManager.cs
===================================================================
--- branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/HeartbeatManager.cs	(revision 5105)
+++ branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/HeartbeatManager.cs	(revision 5105)
@@ -0,0 +1,142 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2010 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.Diagnostics;
+using System.Threading;
+using HeuristicLab.Common;
+using HeuristicLab.Clients.Hive.Salve;
+using HeuristicLab.Services.Hive.Common.DataTransfer;
+using HeuristicLab.Services.Hive.Common;
+using System.Collections.Generic;
+
+namespace HeuristicLab.Clients.Hive.Salve {
+  /// <summary>
+  /// Heartbeat class. It sends every x ms a heartbeat to the server and receives a Message
+  /// </summary>
+  public class HeartbeatManager {
+    private static object locker = new object();
+    public TimeSpan Interval { get; set; }
+    private Thread heartBeatThread;
+    private AutoResetEvent waitHandle;
+
+    public HeartbeatManager() {
+      Interval = new TimeSpan(0, 0, 10);
+    }
+
+    public HeartbeatManager(TimeSpan interval) {
+      Interval = interval;
+    }
+
+    private WcfService wcfService;
+
+    private bool abortThreadPending;
+
+    ReaderWriterLockSlim heartBeatThreadIsSleepingLock = new ReaderWriterLockSlim();
+    
+    /// <summary>
+    /// Starts the Heartbeat signal.
+    /// </summary>
+    public void StartHeartbeat() {
+      this.waitHandle = new AutoResetEvent(true);
+      wcfService = WcfService.Instance;     
+      abortThreadPending = false;
+      heartBeatThread = new Thread(RunHeartBeatThread);
+      heartBeatThread.Start();
+    }
+
+    /// <summary>
+    /// Stop the heartbeat
+    /// </summary>
+    public void StopHeartBeat() {
+      abortThreadPending = true;
+      waitHandle.Set();
+      heartBeatThread.Join();
+    }
+    
+    /// <summary>
+    /// use this method to singalize there is work to do (to avoid the waiting period if its clear that actions are required)
+    /// </summary>
+    public void AwakeHeartBeatThread() {
+      waitHandle.Set();
+    }
+
+    private void RunHeartBeatThread() {
+      while (!abortThreadPending) {
+        try {
+          lock (locker) {
+            if (wcfService.ConnState != NetworkEnum.WcfConnState.Connected) {
+              wcfService.Connect(ConfigManager.Instance.GetClientInfo()); // Login happens automatically upon successfull connection
+            }
+            if(wcfService.ConnState == NetworkEnum.WcfConnState.Connected) {
+              HeuristicLab.Services.Hive.Common.DataTransfer.Slave info = ConfigManager.Instance.GetClientInfo();
+
+              Heartbeat heartBeatData = new Heartbeat
+              {
+                SlaveId = info.Id,
+                FreeCores = info.Cores.HasValue ? info.Cores.Value - ConfigManager.Instance.GetUsedCores() : 0,
+                FreeMemory = GetFreeMemory(),
+                JobProgress = ConfigManager.Instance.GetExecutionTimeOfAllJobs()                
+              };
+                              
+              Logger.Debug("Sending Heartbeat: " + heartBeatData);
+              List<MessageContainer> msgs =  wcfService.SendHeartbeat(heartBeatData);
+              
+              if (msgs == null) {
+                Logger.Debug("Error getting response from Heartbeat");
+                OnExceptionOccured(new Exception("Error getting response from Heartbeat"));
+              }
+
+              Logger.Debug("Heartbeat Response received: ");
+              msgs.ForEach(mc => Logger.Debug(mc.Message.ToString()));
+              msgs.ForEach(mc => MessageQueue.GetInstance().AddMessage(mc));      
+            }
+          } // lock
+        }
+        catch (Exception e) {
+          Logger.Error("Heartbeat Thread failed badly: " + e.Message);
+          OnExceptionOccured(e);
+        }
+        waitHandle.WaitOne(this.Interval);
+      } // while
+      waitHandle.Close();
+      abortThreadPending = false;
+      Logger.Debug("Heartbeat thread stopped");
+    }
+         
+
+    #region Eventhandler
+    public event EventHandler<EventArgs<Exception>> ExceptionOccured;
+    private void OnExceptionOccured(Exception e) {
+      var handler = ExceptionOccured;
+      if (handler != null) handler(this, new EventArgs<Exception>(e));
+    }
+    #endregion
+
+    #region Helpers
+    private int GetFreeMemory() {
+      PerformanceCounter counter = new PerformanceCounter("Memory", "Available Bytes", true);
+      int mb = (int)(counter.NextValue() / 1024 / 1024);
+      return mb;
+    }
+    #endregion
+  }
+}
Index: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/HeuristicLab.Clients.Hive.Slave-3.4.csproj
===================================================================
--- branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/HeuristicLab.Clients.Hive.Slave-3.4.csproj	(revision 5104)
+++ branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/HeuristicLab.Clients.Hive.Slave-3.4.csproj	(revision 5105)
@@ -55,4 +55,6 @@
     <Reference Include="System" />
     <Reference Include="System.Core" />
+    <Reference Include="System.Runtime.Serialization" />
+    <Reference Include="System.ServiceModel" />
     <Reference Include="System.Xml.Linq" />
     <Reference Include="System.Data.DataSetExtensions" />
@@ -61,9 +63,34 @@
   </ItemGroup>
   <ItemGroup>
-    <Compile Include="SlaveDummy.cs" />
+    <Compile Include="ConfigManager.cs" />
+    <Compile Include="Core.cs" />
+    <Compile Include="Executor.cs" />
+    <Compile Include="HeartbeatManager.cs" />
+    <Compile Include="InvalidStateException.cs" />
+    <Compile Include="JobStatus.cs" />
+    <Compile Include="Logger.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="MessageQueue.cs" />
+    <Compile Include="NetworkEnum.cs" />
+    <Compile Include="PluginCache.cs" />
+    <Compile Include="PluginUtil.cs" />
+    <Compile Include="Properties\Settings.Designer.cs">
+      <AutoGen>True</AutoGen>
+      <DesignTimeSharedInput>True</DesignTimeSharedInput>
+      <DependentUpon>Settings.settings</DependentUpon>
+    </Compile>
+    <Compile Include="SlaveStatusInfo.cs" />
+    <Compile Include="StatusCommons.cs" />
+    <Compile Include="WcfService.cs" />
+    <None Include="app.config" />
     <None Include="HeuristicLabClientsHiveSlavePlugin.cs.frame" />
     <Compile Include="HeuristicLabClientsHiveSlavePlugin.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <None Include="Properties\AssemblyInfo.cs.frame" />
+    <None Include="Properties\Settings.settings">
+      <Generator>PublicSettingsSingleFileGenerator</Generator>
+      <LastGenOutput>Settings.Designer.cs</LastGenOutput>
+    </None>
   </ItemGroup>
   <ItemGroup>
@@ -74,4 +101,8 @@
       <Project>{B5EF1E5A-9F3D-40B9-B4B0-30AADF2E2CEB}</Project>
       <Name>HeuristicLab.Clients.Hive-3.4</Name>
+    </ProjectReference>
+    <ProjectReference Include="..\..\HeuristicLab.Hive\3.4\HeuristicLab.Hive-3.4.csproj">
+      <Project>{F98A1740-9AC9-4D36-A582-6A2D0D06978D}</Project>
+      <Name>HeuristicLab.Hive-3.4</Name>
     </ProjectReference>
     <ProjectReference Include="..\..\HeuristicLab.Services.Hive.Common\3.4\HeuristicLab.Services.Hive.Common-3.4.csproj">
Index: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/InvalidStateException.cs
===================================================================
--- branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/InvalidStateException.cs	(revision 5105)
+++ branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/InvalidStateException.cs	(revision 5105)
@@ -0,0 +1,35 @@
+﻿#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2010 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;
+
+namespace HeuristicLab.Clients.Hive.Salve {
+  [global::System.Serializable]
+  public class InvalidStateException : Exception {
+    public InvalidStateException() { }
+    public InvalidStateException(string message) : base(message) { }
+    public InvalidStateException(string message, Exception inner) : base(message, inner) { }
+    protected InvalidStateException(
+    System.Runtime.Serialization.SerializationInfo info,
+    System.Runtime.Serialization.StreamingContext context)
+      : base(info, context) { }
+  }
+}
Index: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/JobStatus.cs
===================================================================
--- branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/JobStatus.cs	(revision 5105)
+++ branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/JobStatus.cs	(revision 5105)
@@ -0,0 +1,44 @@
+﻿#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2010 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.Runtime.Serialization;
+
+namespace HeuristicLab.Clients.Hive.Salve {
+  [DataContract]
+  public class JobStatus {
+    /// <summary>
+    /// Id of the Job
+    /// </summary>
+    [DataMember]
+    public Guid JobId { get; set; }
+    /// <summary>
+    /// When has the calculation of the Job begun?
+    /// </summary>
+    [DataMember]
+    public DateTime Since { get; set; }
+    /// <summary>
+    /// Current progress
+    /// </summary>
+    [DataMember]
+    public TimeSpan ExecutionTime { get; set; }
+  }
+}
Index: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/Logger.cs
===================================================================
--- branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/Logger.cs	(revision 5105)
+++ branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/Logger.cs	(revision 5105)
@@ -0,0 +1,46 @@
+﻿using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using HeuristicLab.Core;
+
+namespace HeuristicLab.Clients.Hive.Salve {
+  /// <summary>
+  /// Dummy implementation for a logger until a better solution is found;
+  /// to be removed in the future
+  /// TODO: send messages to gui
+  /// </summary>
+  internal static class Logger {   
+    private static object locker = new object(); 
+
+    public static void Debug(object message) {
+      lock (locker) {
+        Console.WriteLine(message.ToString());
+      }
+    }
+
+    public static void Info(object message) {
+      lock (locker) {
+        Console.WriteLine(message.ToString());
+      }
+    }
+
+    public static void Warn(object message) {
+      lock (locker) {
+        Console.WriteLine(message.ToString());
+      }
+    }
+
+    public static void Error(object message) {
+      lock (locker) {
+        Console.WriteLine(message.ToString());
+      }
+    }
+
+    public static void Error(object message, Exception e) {
+      lock (locker) {
+        Console.WriteLine(message.ToString() + " \n Exception is :" + e.ToString());
+      }
+    }   
+  }
+}
Index: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/MessageQueue.cs
===================================================================
--- branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/MessageQueue.cs	(revision 5105)
+++ branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/MessageQueue.cs	(revision 5105)
@@ -0,0 +1,104 @@
+﻿#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2010 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.Threading;
+using HeuristicLab.Services.Hive.Common;
+
+namespace HeuristicLab.Clients.Hive.Salve {
+
+  /// <summary>
+  /// Queue for the communication between threads and AppDomains. The Queue is threadsafe and uses a semaphore
+  /// </summary>
+  public class MessageQueue : MarshalByRefObject {
+
+    private static MessageQueue instance = null;
+    
+    private Queue<MessageContainer> queue = null;
+    private Semaphore semaphore = null;                 
+
+    /// <summary>
+    /// Returns the Instance of the MessageQueue. If the instance is null, it will be created.
+    /// This is a Implementation of the Singleton pattern
+    /// </summary>
+    /// <returns>the MessageQueue Instance</returns>
+    public static MessageQueue GetInstance() {
+      if (instance == null) {
+        instance = new MessageQueue();
+      }
+      return instance;
+    }
+
+    /// <summary>
+    /// Sets Lease time to infinite
+    /// </summary>
+    /// <returns>nothing</returns>
+    public override object InitializeLifetimeService() {
+      return null;
+    }
+
+    /// <summary>
+    /// Creates a new MessageQueue Object.
+    /// A new Queue and a Semaphore is created. The Semaphore is set to a max size of 5000.
+    /// </summary>
+    private MessageQueue() {
+      queue = new Queue<MessageContainer>();
+      semaphore = new Semaphore(0, 5000);
+    }
+
+    /// <summary>
+    /// Returns the oldest MessageContainer Object from the Queue. 
+    /// </summary>
+    /// <returns>the oldest MessageContainer Object</returns>
+    public MessageContainer GetMessage() {
+      semaphore.WaitOne();
+      lock (this) {
+        if (queue.Count > 0) {
+          return queue.Dequeue();
+        }
+      }
+      return null;
+    }
+
+    /// <summary>
+    /// Adds a MessageContainer Object to the Queue 
+    /// </summary>
+    /// <param name="messageContainer">the MessageContainer</param>
+    public void AddMessage(MessageContainer messageContainer) {
+      lock (this) {
+        queue.Enqueue(messageContainer);
+        semaphore.Release();
+      }
+    }
+
+    /// <summary>
+    /// Adds a message to the Queue. The MessageContainer Object is built in the Method
+    /// </summary>
+    /// <param name="message">the Message</param>
+    public void AddMessage(MessageContainer.MessageType message) {
+      lock (this) {
+        queue.Enqueue(new MessageContainer(message));
+        semaphore.Release();
+      }
+    }
+  }
+}
Index: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/NetworkEnum.cs
===================================================================
--- branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/NetworkEnum.cs	(revision 5105)
+++ branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/NetworkEnum.cs	(revision 5105)
@@ -0,0 +1,27 @@
+﻿#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2010 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
+
+
+namespace HeuristicLab.Clients.Hive.Salve {
+  public class NetworkEnum {
+    public enum WcfConnState { Connected, Disconnected, Failed }  
+  }
+}
Index: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/PluginCache.cs
===================================================================
--- branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/PluginCache.cs	(revision 5105)
+++ branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/PluginCache.cs	(revision 5105)
@@ -0,0 +1,218 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2010 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.IO;
+using System.Linq;
+using System.Runtime.CompilerServices;
+using HeuristicLab.Services.Hive.Common.ServiceContracts;
+using HeuristicLab.Services.Hive.Common.DataTransfer;
+using HeuristicLab.PluginInfrastructure;
+using HeuristicLab.PluginInfrastructure.Manager;
+using System.Threading;
+using System.Reflection;
+using HeuristicLab.Clients.Hive.Salve;
+
+namespace HeuristicLab.Clients.Hive.Slave {
+  public class PluginCache {
+    private static object locker = new object();
+    public const string ConfigFileName = "Sandbox.config";
+
+    private static PluginCache instance = null;
+
+    public string PluginCacheDir { get; set; }
+    public string PluginTempBaseDir { get; set; }
+
+    private List<PluginDescription> cachedPlugins = new List<PluginDescription>();
+
+    private PluginManager pm;
+
+    public static PluginCache Instance {
+      get {
+        if (instance == null)
+          instance = new PluginCache();
+        return instance;
+      }
+    }
+
+    public string ConfigFilePath {
+      get {
+        return Path.Combine(PluginCacheDir, ConfigFileName);
+      }
+    }
+
+    public PluginCache() {
+      PluginCacheDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "PluginCache");
+      PluginTempBaseDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "PluginTemp");
+
+      this.pm = new PluginManager(PluginCacheDir);
+      DoUpdateRun();
+    }
+
+    private void DoUpdateRun() {
+      if (!Directory.Exists(PluginCacheDir)) {
+        Directory.CreateDirectory(PluginCacheDir);
+      }
+      pm.DiscoverAndCheckPlugins();
+      cachedPlugins = new List<PluginDescription>(pm.Plugins);
+    }
+
+    [MethodImpl(MethodImplOptions.Synchronized)]
+    public void CopyPluginsForJob(List<Plugin> requests, Guid jobId) {
+      lock (locker) {
+        String targetDir = Path.Combine(PluginTempBaseDir, jobId.ToString());
+
+        if (Directory.Exists(targetDir)) {
+          Directory.Delete(targetDir, true);
+        }
+
+        DirectoryInfo di = Directory.CreateDirectory(targetDir);
+
+        foreach (Plugin requestedPlugin in requests) {
+          PluginDescription pd = cachedPlugins.Where(cp =>
+            cp.Name == requestedPlugin.Name &&
+            cp.Version.Major == requestedPlugin.Version.Major &&
+            cp.Version.Minor == requestedPlugin.Version.Minor).SingleOrDefault();
+          if (pd != null) {
+            foreach (IPluginFile ipf in pd.Files) {
+              File.Copy(ipf.Name, Path.Combine(targetDir, Path.GetFileName(ipf.Name)));
+            }
+          }
+        }
+
+        // copy config file
+        File.Copy(ConfigFilePath, Path.Combine(targetDir, ConfigFileName));
+
+        // copy files from PluginInfrastructure, which are not declared
+        string baseDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
+        CopyFile(baseDir, targetDir, "HeuristicLab.PluginInfrastructure-3.3.dll");
+        CopyFile(baseDir, targetDir, "ICSharpCode.SharpZipLib.dll");
+        CopyFile(baseDir, targetDir, "ICSharpCode.SharpZipLib License.txt");
+
+        // copy slave plugins, otherwise its not possible to register the UnhandledException handler to the appdomain
+        CopyFile(baseDir, targetDir, "HeuristicLab.Clients.Hive.Slave-3.4.dll");
+        CopyFile(baseDir, targetDir, "HeuristicLab.Clients.Hive-3.4.dll");
+        CopyFile(baseDir, targetDir, "HeuristicLab.Services.Hive.Common-3.4.dll");
+        CopyFile(baseDir, targetDir, "HeuristicLab.Hive-3.4.dll");
+
+        //TODO: remove, just needed for unit tests
+        CopyFile(baseDir, targetDir, "HeuristicLab.Clients.Hive.Slave.Tests-3.4.dll");
+      }
+    }
+
+    private void CopyFile(string baseDir, string targetDir, string fileName) {
+      if (!File.Exists(Path.Combine(targetDir, fileName))) File.Copy(Path.Combine(baseDir, fileName), Path.Combine(targetDir, fileName));
+    }
+
+    [MethodImpl(MethodImplOptions.Synchronized)]
+    internal void PreparePlugins(Job myJob, JobData jobData) {
+      lock (locker) {
+        Logger.Debug("Fetching plugins for job");
+
+        IEnumerable<Plugin> pluginDescriptions = WcfService.Instance.GetPlugins();
+        List<Plugin> requiredPlugins = new List<Plugin>();
+        foreach (Guid pluginId in myJob.PluginsNeededIds) {
+          Plugin pl = pluginDescriptions.FirstOrDefault(p => p.Id == pluginId);
+          if (pl != null)
+            requiredPlugins.Add(pl);
+        }
+
+        List<Plugin> localPlugins = new List<Plugin>();
+        List<Plugin> missingPlugins = new List<Plugin>();
+        List<Guid> missingGuids = new List<Guid>();
+        bool found = false;
+
+        foreach (Plugin info in requiredPlugins) {
+          //we MAY run in problems here - if there is a plugin twice in requests, there may be added two different versions of the plugin
+          foreach (PluginDescription cachedPlugin in cachedPlugins) {
+            if (info.Name == cachedPlugin.Name && info.Version == cachedPlugin.Version) {
+              localPlugins.Add(new Plugin() { Id = new Guid(), Name = info.Name, Version = info.Version });
+              found = true;
+
+              break;
+            }
+          }
+          if (!found) {
+            Logger.Debug("Plugin NOT found " + info.Name + ", " + info.Version);
+            missingPlugins.Add(info);
+            missingGuids.Add(info.Id);
+          }
+          found = false;
+        }
+
+        Logger.Debug("First run - Update the plugins in the cache");
+        localPlugins.AddRange(missingPlugins);
+
+        IEnumerable<PluginData> updateablePlugins = WcfService.Instance.GetPluginDatas(missingGuids);
+
+        foreach (PluginData updateablePlugin in updateablePlugins) {
+          Plugin pluginDescription = pluginDescriptions.Where(desc => desc.Id == updateablePlugin.PluginId).SingleOrDefault();
+          if (pluginDescription != null) {
+
+            PluginDescription pd = cachedPlugins.Where(cachedPlugin =>
+                cachedPlugin.Name == pluginDescription.Name &&
+                cachedPlugin.Version.Major == pluginDescription.Version.Major &&
+                cachedPlugin.Version.Minor == pluginDescription.Version.Major).SingleOrDefault();
+
+            if (pd != null) {
+              foreach (IPluginFile ipf in pd.Files) {
+                Logger.Debug(string.Format("deleting {0}", Path.GetFileName(ipf.Name)));
+                File.Delete(ipf.Name);
+              }
+            }
+            File.WriteAllBytes(Path.Combine(PluginCacheDir, Path.GetFileName(pluginDescription.Name)), updateablePlugin.Data);
+          }
+          //TODO: error handling on pluginDescription, should be found
+        }
+
+        PluginData configFile = WcfService.Instance.GetConfigurationFile();
+        File.WriteAllBytes(ConfigFilePath, configFile.Data);
+
+        DoUpdateRun();
+        CopyPluginsForJob(requiredPlugins, myJob.Id);
+      }
+    }
+
+    internal void DeletePluginsForJob(Guid id) {
+      try {
+        Logger.Debug("unloading...");
+        int tries = 5;
+        while (tries > 0) {
+          try {
+            Directory.Delete(Path.Combine(PluginTempBaseDir, id.ToString()), true);
+            tries = 0;
+          }
+          catch {
+            Thread.Sleep(1000);
+            tries--;
+            if (tries == 0) throw;
+          }
+        }
+      }
+      catch (Exception ex) {
+        Logger.Debug("failed while unloading " + id + " with exception " + ex);
+      }
+    }
+
+
+  }
+}
Index: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/PluginUtil.cs
===================================================================
--- branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/PluginUtil.cs	(revision 5105)
+++ branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/PluginUtil.cs	(revision 5105)
@@ -0,0 +1,157 @@
+﻿#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2010 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.Reflection;
+using HeuristicLab.PluginInfrastructure;
+using System.Linq;
+using HeuristicLab.Common;
+
+namespace HeuristicLab.Clients.Hive.Slave {
+  public static class PluginUtil {
+    #region Required Plugin Search
+
+    /// <summary>
+    /// Returns a list of plugins in which the type itself and all members 
+    /// of the type are declared. Objectgraph is searched recursively.
+    /// </summary>
+    public static IEnumerable<IPluginDescription> GetDeclaringPlugins(IDeepCloneable obj) {
+      object clone = obj.Clone();
+      HashSet<Type> types = new HashSet<Type>();
+      HashSet<object> objects = new HashSet<object>();
+      string namespaceStart = "HeuristicLab.";
+      FindTypesInObject(clone, objects, types, namespaceStart, 10);
+      return GetDeclaringPlugins(types, namespaceStart);
+    }
+
+    /// <summary>
+    /// Returns the plugins (including dependencies) in which the given types are declared
+    /// </summary>
+    public static IEnumerable<IPluginDescription> GetDeclaringPlugins(IEnumerable<Type> types, string namespaceStart) {
+      HashSet<IPluginDescription> plugins = new HashSet<IPluginDescription>();
+      var hlTypes = types.Where(x => x.Namespace != null && x.Namespace.StartsWith(namespaceStart));
+      foreach (Type t in hlTypes) {
+        FindDeclaringPlugins(ApplicationManager.Manager.GetDeclaringPlugin(t), plugins);
+      }
+      return plugins;
+    }
+
+    /// <summary>
+    /// Finds the dependencies of the given plugin and adds it to the plugins hashset.
+    /// Also searches the dependencies recursively.
+    /// </summary>
+    public static void FindDeclaringPlugins(IPluginDescription plugin, HashSet<IPluginDescription> plugins) {
+      if (!plugins.Contains(plugin)) {
+        plugins.Add(plugin);
+        foreach (IPluginDescription dependency in plugin.Dependencies) {
+          FindDeclaringPlugins(dependency, plugins);
+        }
+      }
+    }
+
+    /// <summary>
+    /// Recursively finds all types used in type which are in a namespace which starts with namespaceStart
+    /// Be aware that search is not performed on attributes
+    /// </summary>
+    /// <param name="type">the type to be searched</param>
+    /// <param name="foundTypes">found types will be stored there, needed in order to avoid duplicates</param>
+    public static void FindTypes(Type type, HashSet<Type> foundTypes, string namespaceStart, int nonNamespaceSearchDepth) {
+      if (type.Namespace != null && type.Namespace.StartsWith(namespaceStart)) {
+        nonNamespaceSearchDepth = 10;
+      } else {
+        nonNamespaceSearchDepth--;
+      }
+
+      if (!foundTypes.Contains(type) && nonNamespaceSearchDepth > 0) {
+        foundTypes.Add(type);
+
+        if (type.IsGenericType) {
+          foreach (Type t in type.GetGenericArguments()) {
+            FindTypes(t, foundTypes, namespaceStart, nonNamespaceSearchDepth);
+          }
+        }
+
+        // constructors
+        foreach (ConstructorInfo info in type.GetConstructors()) {
+          foreach (ParameterInfo paramInfo in info.GetParameters()) {
+            FindTypes(paramInfo.ParameterType, foundTypes, namespaceStart, nonNamespaceSearchDepth);
+          }
+        }
+
+        // interfaces
+        foreach (Type t in type.GetInterfaces()) {
+          FindTypes(t, foundTypes, namespaceStart, nonNamespaceSearchDepth);
+        }
+
+        // events
+        foreach (EventInfo info in type.GetEvents()) {
+          FindTypes(info.EventHandlerType, foundTypes, namespaceStart, nonNamespaceSearchDepth);
+          FindTypes(info.DeclaringType, foundTypes, namespaceStart, nonNamespaceSearchDepth);
+        }
+
+        // methods
+        foreach (MethodInfo info in type.GetMethods()) {
+          foreach (ParameterInfo paramInfo in info.GetParameters()) {
+            FindTypes(paramInfo.ParameterType, foundTypes, namespaceStart, nonNamespaceSearchDepth);
+          }
+          FindTypes(info.ReturnType, foundTypes, namespaceStart, nonNamespaceSearchDepth);
+        }
+
+        // base type
+        if (type.BaseType != null) {
+          FindTypes(type.BaseType, foundTypes, namespaceStart, nonNamespaceSearchDepth);
+        }
+      }
+    }
+
+    public static void FindTypesInObject(object obj, HashSet<object> visitedObjects, HashSet<Type> types, string namespaceStart, int nonNamespaceSearchDepth) {
+      Type type = obj.GetType();
+      FindTypes(type, types, namespaceStart, nonNamespaceSearchDepth);
+
+      if (type.Namespace != null && type.Namespace.StartsWith(namespaceStart)) {
+        nonNamespaceSearchDepth = 10;
+      } else {
+        nonNamespaceSearchDepth--;
+      }
+
+      if (!visitedObjects.Contains(obj) && nonNamespaceSearchDepth > 0) {
+        visitedObjects.Add(obj);
+
+        // fields
+        foreach (FieldInfo info in GetAllFields(type)) {
+          var value = info.GetValue(obj);
+          if (value == null) {
+            FindTypes(info.FieldType, types, namespaceStart, nonNamespaceSearchDepth);
+          } else {
+            FindTypesInObject(value, visitedObjects, types, namespaceStart, nonNamespaceSearchDepth);
+          }
+        }
+      }
+    }
+
+    public static IEnumerable<FieldInfo> GetAllFields(Type t) {
+      BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.FlattenHierarchy;
+      return t.GetFields(flags);
+    }
+    #endregion
+  }
+}
Index: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/Properties/Settings.Designer.cs
===================================================================
--- branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/Properties/Settings.Designer.cs	(revision 5105)
+++ branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/Properties/Settings.Designer.cs	(revision 5105)
@@ -0,0 +1,38 @@
+﻿//------------------------------------------------------------------------------
+// <auto-generated>
+//     This code was generated by a tool.
+//     Runtime Version:4.0.30319.1
+//
+//     Changes to this file may cause incorrect behavior and will be lost if
+//     the code is regenerated.
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+namespace HeuristicLab.Clients.Hive.Slave.Properties {
+    
+    
+    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")]
+    public sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
+        
+        private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
+        
+        public static Settings Default {
+            get {
+                return defaultInstance;
+            }
+        }
+        
+        [global::System.Configuration.UserScopedSettingAttribute()]
+        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+        [global::System.Configuration.DefaultSettingValueAttribute("00000000-0000-0000-0000-000000000000")]
+        public global::System.Guid Guid {
+            get {
+                return ((global::System.Guid)(this["Guid"]));
+            }
+            set {
+                this["Guid"] = value;
+            }
+        }
+    }
+}
Index: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/Properties/Settings.settings
===================================================================
--- branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/Properties/Settings.settings	(revision 5105)
+++ branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/Properties/Settings.settings	(revision 5105)
@@ -0,0 +1,9 @@
+﻿<?xml version='1.0' encoding='utf-8'?>
+<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="HeuristicLab.Clients.Hive.Slave.Properties" GeneratedClassName="Settings">
+  <Profiles />
+  <Settings>
+    <Setting Name="Guid" Type="System.Guid" Scope="User">
+      <Value Profile="(Default)">00000000-0000-0000-0000-000000000000</Value>
+    </Setting>
+  </Settings>
+</SettingsFile>
Index: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/SlaveDummy.cs
===================================================================
--- branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/SlaveDummy.cs	(revision 5104)
+++ 	(revision )
@@ -1,17 +1,0 @@
-﻿using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-namespace HeuristicLab.Clients.Hive.Slave {
-  public class SlaveDummy {
-
-    public void SayHello() {
-      using (var service = ServiceLocator.Instance.GetService()) {
-        var job = service.Obj.GetJob(Guid.NewGuid());
-
-        service.Obj.Hello(Guid.NewGuid(), "blubb", 4, 1024);
-      }
-    }
-  }
-}
Index: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/SlaveStatusInfo.cs
===================================================================
--- branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/SlaveStatusInfo.cs	(revision 5105)
+++ branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/SlaveStatusInfo.cs	(revision 5105)
@@ -0,0 +1,31 @@
+﻿#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2010 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;
+
+namespace HeuristicLab.Clients.Hive.Slave {
+  public class SlaveStatusInfo {
+    static public int JobsProcessed { get; set; }
+    static public int JobsAborted { get; set; }
+    static public int JobsFetched { get; set; }
+    static public DateTime LoginTime { get; set; }            
+  }
+}
Index: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/StatusCommons.cs
===================================================================
--- branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/StatusCommons.cs	(revision 5105)
+++ branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/StatusCommons.cs	(revision 5105)
@@ -0,0 +1,51 @@
+﻿#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2010 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.Runtime.Serialization;
+
+namespace HeuristicLab.Clients.Hive.Salve {
+  /// <summary>
+  /// Various Status Information for the ClientConsole
+  /// </summary>
+  [DataContract]
+  public class StatusCommons {    
+    [DataMember]
+    public Guid ClientGuid { get; set; }
+    [DataMember]
+    public NetworkEnum.WcfConnState Status { get; set; }
+    [DataMember]    
+    public DateTime ConnectedSince { get; set; }
+    [DataMember]
+    public int TotalCores { get; set; }
+    [DataMember]
+    public int FreeCores { get; set; }
+    [DataMember]
+    public int JobsFetched { get; set; }
+    [DataMember]
+    public int JobsDone { get; set; }
+    [DataMember]
+    public int JobsAborted { get; set; }
+    [DataMember]
+    public List<JobStatus> Jobs { get; set; }   
+  }
+}
Index: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/WcfService.cs
===================================================================
--- branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/WcfService.cs	(revision 5105)
+++ branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/WcfService.cs	(revision 5105)
@@ -0,0 +1,257 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2010 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 HeuristicLab.Common;
+using HeuristicLab.Clients.Common;
+using HeuristicLab.Services.Hive.Common.ServiceContracts;
+using HeuristicLab.Services.Hive.Common.DataTransfer;
+using HeuristicLab.Services.Hive.Common;
+using HeuristicLab.Clients.Hive.Slave.Properties;
+
+namespace HeuristicLab.Clients.Hive.Salve {
+
+  /// <summary>
+  /// WcfService class is implemented as a Singleton and works as a communication Layer with the Server
+  /// </summary>
+  public class WcfService : MarshalByRefObject {
+    private static WcfService instance;
+    /// <summary>
+    /// Getter for the Instance of the WcfService
+    /// </summary>
+    /// <returns>the Instance of the WcfService class</returns>
+    public static WcfService Instance {
+      get {
+        if (instance == null) {
+          Logger.Debug("New WcfService Instance created");
+          instance = new WcfService();
+        }
+        return instance;
+      }
+    }
+
+    public DateTime ConnectedSince { get; private set; }
+    public NetworkEnum.WcfConnState ConnState { get; private set; }
+
+    public event EventHandler Connected;
+    public void OnConnected() {
+      var handler = Connected;
+      if (handler != null) handler(this, EventArgs.Empty);
+    }
+
+    /// <summary>
+    /// Constructor
+    /// </summary>
+    private WcfService() {
+      ConnState = NetworkEnum.WcfConnState.Disconnected;
+    }
+
+    /// <summary>
+    /// Connects with the Server, registers the events and fires the Connected (and quiet possibly the ConnectionRestored) Event.
+    /// </summary>
+    public void Connect(HeuristicLab.Services.Hive.Common.DataTransfer.Slave slaveInfo) {
+      using (Disposable<IHiveService> service = ServiceLocator.Instance.GetService()) {
+        try {
+          Logger.Debug("Starting the Connection Process");
+          ConnState = NetworkEnum.WcfConnState.Connected;
+          ConnectedSince = DateTime.Now;
+          service.Obj.Hello(Settings.Default.Guid, slaveInfo.Name, slaveInfo.Cores.Value, slaveInfo.Memory.Value);
+          OnConnected();
+        }
+        catch (Exception ex) {
+          HandleNetworkError(ex);
+        }
+      }
+    }
+
+    /// <summary>
+    /// Disconnects the Slave from the Server
+    /// </summary>
+    public void Disconnect() {
+      using (Disposable<IHiveService> service = ServiceLocator.Instance.GetService()) {
+        try {
+          service.Obj.GoodBye();
+          ConnState = NetworkEnum.WcfConnState.Disconnected;
+        }
+        catch (Exception ex) {
+          HandleNetworkError(ex);
+        }
+      }
+    }
+
+    /// <summary>
+    /// Network communication Error Handler - Every network error gets logged and the connection switches to faulted state
+    /// </summary>
+    /// <param name="e">The Exception</param>
+    private void HandleNetworkError(Exception e) {
+      ConnState = NetworkEnum.WcfConnState.Failed;
+      Logger.Error("Network exception occurred: " + e);
+      OnExceptionOccured(e);
+    }
+
+    /// <summary>
+    /// Aquire a Job from the Server, return the Job
+    /// </summary>
+    public Job AquireJob() {
+      using (Disposable<IHiveService> service = ServiceLocator.Instance.GetService()) {
+        try {
+          Job job = service.Obj.AquireJob(Settings.Default.Guid);
+          return job;
+        }
+        catch (Exception ex) {
+          HandleNetworkError(ex);
+          return null;
+        }
+      }
+    }
+
+    public JobData GetJobData(Guid jobId) {
+      using (Disposable<IHiveService> service = ServiceLocator.Instance.GetService()) {
+        try {
+          JobData jobData = service.Obj.GetJobData(jobId);
+          return jobData;
+        }
+        catch (Exception ex) {
+          HandleNetworkError(ex);
+          return null;
+        }
+      }
+    }
+
+    /// <summary>
+    /// used on pause or if job finished to upload the job results
+    /// </summary>
+    /// <param name="job"></param>
+    /// <param name="jobData"></param>    
+    public void UpdateJob(Job job, JobData jobData) {
+      using (Disposable<IHiveService> service = ServiceLocator.Instance.GetService()) {
+        try {
+          service.Obj.UpdateJob(job, jobData);
+        }
+        catch (Exception ex) {
+          HandleNetworkError(ex);
+        }
+      }
+    }
+
+    public List<MessageContainer> SendHeartbeat(Heartbeat heartbeat) {
+      using (Disposable<IHiveService> service = ServiceLocator.Instance.GetService()) {
+        try {
+          List<MessageContainer> msg = service.Obj.Heartbeat(heartbeat);
+          return msg;
+        }
+        catch (Exception ex) {
+          HandleNetworkError(ex);
+          return null;
+        }
+      }
+    }
+
+    public IEnumerable<PluginData> GetPluginDatas(List<Guid> pluginIds) {
+      using (Disposable<IHiveService> service = ServiceLocator.Instance.GetService()) {
+        try {
+          IEnumerable<PluginData> msg = service.Obj.GetPluginDatas(pluginIds);
+          return msg;
+        }
+        catch (Exception ex) {
+          HandleNetworkError(ex);
+          return null;
+        }
+      }
+    }
+
+    public IEnumerable<Plugin> GetPlugins() {
+      using (Disposable<IHiveService> service = ServiceLocator.Instance.GetService()) {
+        try {
+          IEnumerable<Plugin> msg = service.Obj.GetPlugins();
+          return msg;
+        }
+        catch (Exception ex) {
+          HandleNetworkError(ex);
+          return null;
+        }
+      }
+    }
+
+    public Guid AddChildJob(Guid parentJobId, Job job, JobData jobData) {
+      using (Disposable<IHiveService> service = ServiceLocator.Instance.GetService()) {
+        try {
+          Guid msg = service.Obj.AddChildJob(parentJobId, job, jobData);
+          return msg;
+        }
+        catch (Exception ex) {
+          HandleNetworkError(ex);
+          return new Guid();
+        }
+      }
+    }
+
+    public IEnumerable<JobData> GetChildJobs(Guid? parentJobId) {
+      using (Disposable<IHiveService> service = ServiceLocator.Instance.GetService()) {
+        try {
+          IEnumerable<LightweightJob> msg = service.Obj.GetLightweightChildJobs(parentJobId, false, false);
+
+          List<JobData> jobs = new List<JobData>();
+          foreach (LightweightJob ljob in msg)
+            jobs.Add(service.Obj.GetJobData(ljob.Id));
+
+          return jobs;
+        }
+        catch (Exception ex) {
+          HandleNetworkError(ex);
+          return null;
+        }
+      }
+    }
+
+    public void DeleteChildJobs(Guid jobId) {
+      using (Disposable<IHiveService> service = ServiceLocator.Instance.GetService()) {
+        try {
+          service.Obj.DeleteChildJobs(jobId);
+        }
+        catch (Exception ex) {
+          HandleNetworkError(ex);
+        }
+      }
+    }
+
+    public PluginData GetConfigurationFile() {
+      using (Disposable<IHiveService> service = ServiceLocator.Instance.GetService()) {
+        try {
+          PluginData msg = service.Obj.GetConfigurationFile();
+          return msg;
+        }
+        catch (Exception ex) {
+          HandleNetworkError(ex);
+          return null;
+        }
+      }
+    }
+
+    public event EventHandler<EventArgs<Exception>> ExceptionOccured;
+    private void OnExceptionOccured(Exception e) {
+      Logger.Error("Error: " + e.ToString());
+      var handler = ExceptionOccured;
+      if (handler != null) handler(this, new EventArgs<Exception>(e));
+    }
+  }
+}
Index: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/app.config
===================================================================
--- branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/app.config	(revision 5105)
+++ branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/app.config	(revision 5105)
@@ -0,0 +1,15 @@
+﻿<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+    <configSections>
+        <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
+            <section name="HeuristicLab.Clients.Hive.Slave.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
+        </sectionGroup>
+    </configSections>
+    <userSettings>
+        <HeuristicLab.Clients.Hive.Slave.Properties.Settings>
+            <setting name="Guid" serializeAs="String">
+                <value>00000000-0000-0000-0000-000000000000</value>
+            </setting>
+        </HeuristicLab.Clients.Hive.Slave.Properties.Settings>
+    </userSettings>
+</configuration>
