Index: branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Calendar/3.3/Properties/AssemblyInfo.cs
===================================================================
--- branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Calendar/3.3/Properties/AssemblyInfo.cs	(revision 4331)
+++ branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Calendar/3.3/Properties/AssemblyInfo.cs	(revision 4333)
@@ -58,3 +58,3 @@
 // [assembly: AssemblyVersion("1.0.*")]
 [assembly: AssemblyVersion("3.3.0.0")]
-[assembly: AssemblyFileVersion("3.3.0.4316")]
+[assembly: AssemblyFileVersion("3.3.0.4320")]
Index: branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Contracts/3.3/BusinessObjects/JobDto.cs
===================================================================
--- branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Contracts/3.3/BusinessObjects/JobDto.cs	(revision 4331)
+++ branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Contracts/3.3/BusinessObjects/JobDto.cs	(revision 4333)
@@ -41,5 +41,5 @@
     [Storable]
     [DataMember]
-    public Guid UserId { get; set; }
+    public string UserId { get; set; }
     [Storable]
     [DataMember]
Index: branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Experiment.Views/3.3/HiveExperimentView.cs
===================================================================
--- branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Experiment.Views/3.3/HiveExperimentView.cs	(revision 4331)
+++ branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Experiment.Views/3.3/HiveExperimentView.cs	(revision 4333)
@@ -122,5 +122,5 @@
         Invoke(new EventHandler(Content_ExecutionStateChanged), sender, e);
       else
-        startButton.Enabled = pauseButton.Enabled = stopButton.Enabled = resetButton.Enabled = false;
+        SetEnabledStateOfExecutableButtons();
     }
     private void Content_Prepared(object sender, EventArgs e) {
Index: branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Experiment/3.3/HiveExperiment.cs
===================================================================
--- branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Experiment/3.3/HiveExperiment.cs	(revision 4331)
+++ branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Experiment/3.3/HiveExperiment.cs	(revision 4333)
@@ -67,4 +67,6 @@
     private Semaphore fetchJobSemaphore = new Semaphore(2, 2);
 
+    private static object pendingOptimizerMappingsLocker = new object();
+
     private bool stopResultsPollingPending = false;
 
@@ -197,10 +199,11 @@
       clone.pendingOptimizersByJobId = new Dictionary<Guid, IOptimizer>();
 
-      foreach (var pair in this.pendingOptimizersByJobId)
-        clone.pendingOptimizersByJobId[pair.Key] = (IOptimizer)cloner.Clone(pair.Value);
-
-      foreach (var pair in this.parentOptimizersByPendingOptimizer)
-        clone.parentOptimizersByPendingOptimizer[(IOptimizer)cloner.Clone(pair.Key)] = (IOptimizer)cloner.Clone(pair.Value);
-
+      lock (pendingOptimizerMappingsLocker) {
+        foreach (var pair in this.pendingOptimizersByJobId)
+          clone.pendingOptimizersByJobId[pair.Key] = (IOptimizer)cloner.Clone(pair.Value);
+
+        foreach (var pair in this.parentOptimizersByPendingOptimizer)
+          clone.parentOptimizersByPendingOptimizer[(IOptimizer)cloner.Clone(pair.Key)] = (IOptimizer)cloner.Clone(pair.Value);
+      }
       clone.log = (ILog)cloner.Clone(log);
       clone.stopPending = this.stopPending;
@@ -243,8 +246,8 @@
       if (experiment != null) {
         StopResultPolling();
-        lock (pendingOptimizersByJobId) {
+        lock (pendingOptimizerMappingsLocker) {
           pendingOptimizersByJobId.Clear();
-        }
-        parentOptimizersByPendingOptimizer.Clear();
+          parentOptimizersByPendingOptimizer.Clear();
+        }
         lock (jobItems) {
           jobItems.Clear();
@@ -275,21 +278,20 @@
 
           IEnumerable<string> groups = ResourceGroups;
-
-          foreach (IOptimizer optimizer in parentOptimizersByPendingOptimizer.Keys) {
-            SerializedJob serializedJob = CreateSerializedJob(optimizer);
-            ResponseObject<JobDto> response = clientFacade.AddJobWithGroupStrings(serializedJob, groups);
-            lock (pendingOptimizersByJobId) {
+          lock (pendingOptimizerMappingsLocker) {
+            foreach (IOptimizer optimizer in parentOptimizersByPendingOptimizer.Keys) {
+              SerializedJob serializedJob = CreateSerializedJob(optimizer);
+              ResponseObject<JobDto> response = clientFacade.AddJobWithGroupStrings(serializedJob, groups);
               pendingOptimizersByJobId.Add(response.Obj.Id, optimizer);
+
+              JobItem jobItem = new JobItem() {
+                JobDto = response.Obj,
+                LatestSnapshot = null,
+                Optimizer = optimizer
+              };
+              lock (jobItems) {
+                jobItems.Add(jobItem);
+              }
+              LogMessage(jobItem.JobDto.Id, "Job sent to Hive");
             }
-
-            JobItem jobItem = new JobItem() {
-              JobDto = response.Obj,
-              LatestSnapshot = null,
-              Optimizer = optimizer
-            };
-            lock (jobItems) {
-              jobItems.Add(jobItem);
-            }
-            LogMessage(jobItem.JobDto.Id, "Job sent to Hive");
           }
         }
@@ -396,5 +398,5 @@
 
     private bool NoMorePendingOptimizers() {
-      lock (pendingOptimizersByJobId) {
+      lock (pendingOptimizerMappingsLocker) {
         return pendingOptimizersByJobId.Count == 0;
       }
@@ -408,6 +410,6 @@
     /// <param name="jobId"></param>
     private void DisposeOptimizerMappings(Guid jobId) {
-      lock (pendingOptimizersByJobId) {
-        LogMessage(jobId, "Disposing Optimizer Mappings");
+      LogMessage(jobId, "Disposing Optimizer Mappings");
+      lock (pendingOptimizerMappingsLocker) {
         parentOptimizersByPendingOptimizer.Remove(pendingOptimizersByJobId[jobId]);
         pendingOptimizersByJobId.Remove(jobId);
@@ -436,16 +438,23 @@
     private void JobItem_JobStateChanged(object sender, EventArgs e) {
       JobItem jobItem = (JobItem)sender;
+
       Thread t = new Thread(() => {
-        if (jobItem.State == JobState.Finished) {
-          FetchAndUpdateJob(jobItem.JobDto.Id);
-          DisposeOptimizerMappings(jobItem.JobDto.Id);
-        } else if (jobItem.State == JobState.Failed) {
-          DisposeOptimizerMappings(jobItem.JobDto.Id);
-        }
-
-        if (NoMorePendingOptimizers()) {
-          StopResultPolling();
-          this.ExecutionState = Core.ExecutionState.Stopped;
-          OnStopped();
+        try {
+          if (jobItem.State == JobState.Finished) {
+            FetchAndUpdateJob(jobItem.JobDto.Id);
+            DisposeOptimizerMappings(jobItem.JobDto.Id);
+          } else if (jobItem.State == JobState.Failed) {
+            DisposeOptimizerMappings(jobItem.JobDto.Id);
+          }
+
+          if (NoMorePendingOptimizers()) {
+            StopResultPolling();
+            this.ExecutionState = Core.ExecutionState.Stopped;
+            OnStopped();
+          }
+        }
+        catch (Exception ex) {
+          Logger.Error("JobItem_JobStateChanged failed badly: " + ex.Message);
+          LogMessage("JobItem_JobStateChanged failed badly: " + ex.Message);
         }
       });
@@ -457,20 +466,35 @@
     /// </summary>
     private void FetchAndUpdateJob(Guid jobId) {
+      bool tryagain = false;
       LogMessage(jobId, "FetchAndUpdateJob started");
-      IClientFacade clientFacade = CreateStreamedClientFacade();
-      IOptimizer originalOptimizer;
-      lock (pendingOptimizersByJobId) {
-        originalOptimizer = pendingOptimizersByJobId[jobId];
-      }
-
-      fetchJobSemaphore.WaitOne();
-      ResponseObject<SerializedJob> jobResponse = clientFacade.GetLastSerializedResult(jobId, false, false);
-      ServiceLocator.DisposeClientFacade(clientFacade);
-      IJob restoredObject = XmlParser.Deserialize<IJob>(new MemoryStream(jobResponse.Obj.SerializedJobData));
-      IOptimizer restoredOptimizer = ((OptimizerJob)restoredObject).Optimizer;
-
-      ReplaceOptimizer(parentOptimizersByPendingOptimizer[originalOptimizer], originalOptimizer, restoredOptimizer);
-      fetchJobSemaphore.Release();
-      LogMessage(jobId, "FetchAndUpdateJob ended");
+      if (fetchJobSemaphore.WaitOne(new TimeSpan(0, 2, 0))) {
+        IClientFacade clientFacade = null;
+        try {
+          clientFacade = CreateStreamedClientFacade();
+          IOptimizer originalOptimizer;
+          originalOptimizer = pendingOptimizersByJobId[jobId];
+
+          ResponseObject<SerializedJob> jobResponse = clientFacade.GetLastSerializedResult(jobId, false, false);
+          IJob restoredObject = XmlParser.Deserialize<IJob>(new MemoryStream(jobResponse.Obj.SerializedJobData));
+          IOptimizer restoredOptimizer = ((OptimizerJob)restoredObject).Optimizer;
+          ReplaceOptimizer(parentOptimizersByPendingOptimizer[originalOptimizer], originalOptimizer, restoredOptimizer);
+          LogMessage(jobId, "FetchAndUpdateJob ended");
+        }
+        catch (Exception e) {
+          LogMessage(jobId, "FetchAndUpdateJob failed: " + e.Message + ". Will try again!");
+          tryagain = true;
+        }
+        finally {
+          ServiceLocator.DisposeClientFacade(clientFacade);
+          fetchJobSemaphore.Release();
+        }
+      } else {
+        LogMessage(jobId, "FetchAndUpdateJob timed out. Will try again!");
+        tryagain = true;
+      }
+
+      if (tryagain) {
+        FetchAndUpdateJob(jobId);
+      }
     }
 
@@ -509,6 +533,5 @@
         PluginsNeeded = pluginsNeeded,
         State = JobState.Offline,
-        MemoryNeeded = 0,
-        UserId = Guid.Empty // [chn] set real userid here!
+        MemoryNeeded = 0
       };
 
@@ -537,5 +560,7 @@
     public void StopResultPolling() {
       this.stopResultsPollingPending = true;
-      resultPollingThread.Interrupt();
+      if (resultPollingThread != null && resultPollingThread.ThreadState == System.Threading.ThreadState.WaitSleepJoin) {
+        resultPollingThread.Interrupt();
+      }
       this.stopResultsPollingPending = false;
     }
@@ -581,4 +606,8 @@
           // thread has been interuppted
         }
+        catch (Exception e) {
+          LogMessage("Result Polling Thread failed badly: " + e.Message);
+          Logger.Error("Result Polling Thread failed badly: " + e.Message);
+        }
         finally {
           this.IsPollingResults = false;
@@ -598,6 +627,8 @@
     public void RequestSnapshot(Guid jobId) {
       Thread t = new Thread(() => {
-        IClientFacade clientFacade = CreateStreamedClientFacade();
+        IClientFacade clientFacade = null;
         try {
+          clientFacade = CreateStreamedClientFacade();
+
           ResponseObject<SerializedJob> response;
           int retryCount = 0;
@@ -633,4 +664,8 @@
           }
         }
+        catch (Exception e) {
+          LogMessage("RequestSnapshot Thread failed badly: " + e.Message);
+          Logger.Error("RequestSnapshot Thread failed badly: " + e.Message);
+        }
         finally {
           ServiceLocator.DisposeClientFacade(clientFacade);
@@ -885,5 +920,6 @@
           clientFacade = ServiceLocator.CreateClientFacade(Settings.Default.HiveServerIp);
 
-        } catch (EndpointNotFoundException exception) {
+        }
+        catch (EndpointNotFoundException exception) {
           LogMessage("Could not connect to Server: " + exception.Message + ". Will try again in " + (resultPollingIntervalMs / 1000) + " sec.");
           Thread.Sleep(resultPollingIntervalMs);
@@ -899,5 +935,6 @@
           //clientFacade = ServiceLocator.CreateStreamedClientFacade(string.Format("http://{0}:{1}/{2}", Settings.Default.HiveServerIp, Settings.Default.HiveServerPort, WcfSettings.ClientStreamedServiceName));
           clientFacade = ServiceLocator.CreateStreamedClientFacade(Settings.Default.HiveServerIp);
-        } catch (EndpointNotFoundException exception) {
+        }
+        catch (EndpointNotFoundException exception) {
           LogMessage("Could not connect to Server: " + exception.Message + ". Will try again in " + (resultPollingIntervalMs / 1000) + " sec.");
           Thread.Sleep(resultPollingIntervalMs);
Index: branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Experiment/3.3/app.config
===================================================================
--- branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Experiment/3.3/app.config	(revision 4331)
+++ branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Experiment/3.3/app.config	(revision 4333)
@@ -32,6 +32,6 @@
             openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
             transactionFlow="false" transferMode="Streamed" transactionProtocol="OleTransactions"
-            hostNameComparisonMode="StrongWildcard" listenBacklog="10"
-            maxBufferPoolSize="104857600" maxBufferSize="104857600" maxConnections="10"
+            hostNameComparisonMode="StrongWildcard" listenBacklog="100"
+            maxBufferPoolSize="104857600" maxBufferSize="104857600" maxConnections="100"
             maxReceivedMessageSize="104857600">
           <readerQuotas maxDepth="32" maxStringContentLength="104857600" maxArrayLength="104857600"
@@ -47,6 +47,6 @@
             openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
             transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
-            hostNameComparisonMode="StrongWildcard" listenBacklog="10"
-            maxBufferPoolSize="524288" maxBufferSize="65536" maxConnections="10"
+            hostNameComparisonMode="StrongWildcard" listenBacklog="100"
+            maxBufferPoolSize="524288" maxBufferSize="65536" maxConnections="100"
             maxReceivedMessageSize="65536">
           <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
Index: branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.Core/3.3/Authorization/AuthorizationManager.cs
===================================================================
--- branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.Core/3.3/Authorization/AuthorizationManager.cs	(revision 4333)
+++ branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.Core/3.3/Authorization/AuthorizationManager.cs	(revision 4333)
@@ -0,0 +1,34 @@
+﻿using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Security.Principal;
+using System.ServiceModel;
+using System.Threading;
+using System.Security;
+using HeuristicLab.Hive.Server.DataAccess;
+using HeuristicLab.Hive.Server.Core.InternalInterfaces;
+
+namespace HeuristicLab.Hive.Server.Core.Authorization {
+  public class AuthorizationManager : IAuthorizationManager {
+    private IContextFactory contextFactory = ServiceLocator.GetContextFactory();
+
+    public void AuthorizeForJobs(params Guid[] jobId) {
+      if (!(Identity.IsAuthenticated && IsAuthorizedForJobs(jobId))) {
+        throw new SecurityException();
+      }
+    }
+
+    public string UserId {
+      get { return Identity.Name; }
+    }
+    
+    private bool IsAuthorizedForJobs(params Guid[] jobIds) {
+      return DaoLocator.JobDao.IsUserAuthorizedForJobs(Identity.Name, jobIds);
+    }
+
+    private IIdentity Identity {
+      get { return ServiceSecurityContext.Current.PrimaryIdentity; }
+    }
+  }
+}
Index: branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.Core/3.3/Facades/ClientFacade.cs
===================================================================
--- branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.Core/3.3/Facades/ClientFacade.cs	(revision 4331)
+++ branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.Core/3.3/Facades/ClientFacade.cs	(revision 4333)
@@ -62,4 +62,5 @@
     public Response RequestSnapshot(Guid jobId) {
       using (contextFactory.GetContext()) {
+        ServiceLocator.GetAuthorizationManager().AuthorizeForJobs(jobId);
         return jobManager.RequestSnapshot(jobId);
       }
@@ -70,4 +71,5 @@
     public ResponseObject<SerializedJob> GetLastSerializedResult(Guid jobId, bool requested, bool snapshot) {
       using (contextFactory.GetContext(false)) {
+        ServiceLocator.GetAuthorizationManager().AuthorizeForJobs(jobId);
         return jobManager.GetLastSerializedResult(jobId, requested, snapshot);
       }
@@ -78,4 +80,5 @@
     public ResponseObject<JobDto> GetJobById(Guid jobId) {
       using (contextFactory.GetContext(false)) {
+        ServiceLocator.GetAuthorizationManager().AuthorizeForJobs(jobId);
         return jobManager.GetJobById(jobId);
       }
@@ -86,4 +89,5 @@
     public Response AbortJob(Guid jobId) {
       using (contextFactory.GetContext()) {
+        ServiceLocator.GetAuthorizationManager().AuthorizeForJobs(jobId);
         return jobManager.AbortJob(jobId);
       }
@@ -94,4 +98,5 @@
     public ResponseObject<JobResultList> GetJobResults(IEnumerable<Guid> jobIds) {
       using (contextFactory.GetContext(false)) {
+        ServiceLocator.GetAuthorizationManager().AuthorizeForJobs(jobIds.ToArray());
         return jobManager.GetJobResults(jobIds);
       }
Index: branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.Core/3.3/Facades/ServerConsoleFacade.cs
===================================================================
--- branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.Core/3.3/Facades/ServerConsoleFacade.cs	(revision 4331)
+++ branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.Core/3.3/Facades/ServerConsoleFacade.cs	(revision 4333)
@@ -33,12 +33,4 @@
 using System.Security.Permissions;
 
-      //IIdentity id = ServiceSecurityContext.Current.PrimaryIdentity;
-      //if (!Thread.CurrentPrincipal.IsInRole("Administrator")) {
-
-      //} else {
-      //  // access denied
-      //  throw new SecurityException();
-      //}
-
 namespace HeuristicLab.Hive.Server.Core {
   public class ServerConsoleFacade : IServerConsoleFacade {
Index: branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.Core/3.3/Facades/SlaveFacade.cs
===================================================================
--- branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.Core/3.3/Facades/SlaveFacade.cs	(revision 4331)
+++ branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.Core/3.3/Facades/SlaveFacade.cs	(revision 4333)
@@ -77,4 +77,5 @@
     public ResponseResultReceived StoreFinishedJobResult(Guid slaveId, Guid jobId, byte[] result, double percentage, string exception) {
       using (contextFactory.GetContext()) {
+        ServiceLocator.GetAuthorizationManager().AuthorizeForJobs(jobId);
         return slaveCommunicator.StoreFinishedJobResult(slaveId, jobId, result, percentage, exception);
       }
@@ -93,5 +94,6 @@
     public Response IsJobStillNeeded(Guid jobId) {
       using (contextFactory.GetContext()) {
-        return slaveCommunicator.IsJobStillNeeded(jobId); 
+        ServiceLocator.GetAuthorizationManager().AuthorizeForJobs(jobId);
+        return slaveCommunicator.IsJobStillNeeded(jobId);
       }
     }
@@ -100,5 +102,5 @@
     [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)]
     public ResponseList<CachedHivePluginInfoDto> GetPlugins(List<HivePluginInfoDto> pluginList) {
-      return slaveCommunicator.GetPlugins(pluginList);      
+      return slaveCommunicator.GetPlugins(pluginList);
     }
 
@@ -107,5 +109,6 @@
     public ResponseResultReceived ProcessSnapshot(Guid slaveId, Guid jobId, byte[] result, double percentage, string exception) {
       using (contextFactory.GetContext()) {
-        return slaveCommunicator.ProcessSnapshot(slaveId, jobId, result, percentage, exception); 
+        ServiceLocator.GetAuthorizationManager().AuthorizeForJobs(jobId);
+        return slaveCommunicator.ProcessSnapshot(slaveId, jobId, result, percentage, exception);
       }
     }
@@ -115,5 +118,5 @@
     public ResponseCalendar GetCalendar(Guid slaveId) {
       using (contextFactory.GetContext()) {
-        return slaveCommunicator.GetCalendar(slaveId); 
+        return slaveCommunicator.GetCalendar(slaveId);
       }
     }
@@ -121,5 +124,5 @@
     [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
     [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)]
-    public Response SetCalendarStatus(Guid slaveId, CalendarState state) { 
+    public Response SetCalendarStatus(Guid slaveId, CalendarState state) {
       using (contextFactory.GetContext()) {
         return slaveCommunicator.SetCalendarStatus(slaveId, state);
@@ -137,8 +140,6 @@
     public Stream GetStreamedJob(Guid slaveId) {
       using (contextFactory.GetContext(false)) {
+        ResponseObject<JobDto> job = null;
         MultiStream stream = new MultiStream();
-
-        ResponseObject<JobDto> job = null;
-
         job = ServiceLocator.GetSlaveCommunicator().GetJob(slaveId);
 
@@ -183,5 +184,5 @@
     public ResponseResultReceived ProcessSnapshotStreamed(Stream stream) {
       using (contextFactory.GetContext()) {
-        return ((IInternalSlaveCommunicator)slaveCommunicator).ProcessJobResult(stream, false);  
+        return ((IInternalSlaveCommunicator)slaveCommunicator).ProcessJobResult(stream, false);
       }
     }
Index: branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.Core/3.3/HeuristicLab.Hive.Server.Core-3.3.csproj
===================================================================
--- branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.Core/3.3/HeuristicLab.Hive.Server.Core-3.3.csproj	(revision 4331)
+++ branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.Core/3.3/HeuristicLab.Hive.Server.Core-3.3.csproj	(revision 4333)
@@ -114,4 +114,5 @@
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="Authorization\AuthorizationManager.cs" />
     <Compile Include="CreateHiveDatabaseApplication.cs" />
     <Compile Include="SlaveCommunicator.cs" />
@@ -122,5 +123,5 @@
     <Compile Include="Facades\ClientFacade.cs" />
     <Compile Include="HeuristicLabHiveServerCorePlugin.cs" />
-    <Compile Include="InternalInterfaces\IHivePermissionManager.cs" />
+    <Compile Include="InternalInterfaces\IAuthorizationManager.cs" />
     <Compile Include="InternalInterfaces\IInternalSlaveCommunicator.cs" />
     <Compile Include="InternalInterfaces\IInternalJobManager.cs" />
@@ -158,7 +159,5 @@
     </ProjectReference>
   </ItemGroup>
-  <ItemGroup>
-    <Folder Include="Authorization\" />
-  </ItemGroup>
+  <ItemGroup />
   <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
   <ProjectExtensions>
Index: branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.Core/3.3/InternalInterfaces/IAuthorizationManager.cs
===================================================================
--- branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.Core/3.3/InternalInterfaces/IAuthorizationManager.cs	(revision 4333)
+++ branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.Core/3.3/InternalInterfaces/IAuthorizationManager.cs	(revision 4333)
@@ -0,0 +1,15 @@
+﻿using System;
+using System.Collections.Generic;
+namespace HeuristicLab.Hive.Server.Core.InternalInterfaces {
+  public interface IAuthorizationManager {
+
+    string UserId { get; }
+
+    /// <summary>
+    /// Checks if the user is allowed to access all the jobs.
+    /// throws an exception if one of those jobs is inaccessible
+    /// </summary>
+    /// <exception cref="SecurityException">thrown when access denied</exception>
+    void AuthorizeForJobs(params Guid[] jobId);
+  }
+}
Index: branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.Core/3.3/InternalInterfaces/IInternalSlaveCommunicator.cs
===================================================================
--- branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.Core/3.3/InternalInterfaces/IInternalSlaveCommunicator.cs	(revision 4331)
+++ branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.Core/3.3/InternalInterfaces/IInternalSlaveCommunicator.cs	(revision 4333)
@@ -31,7 +31,5 @@
 namespace HeuristicLab.Hive.Server.Core.InternalInterfaces {
   interface IInternalSlaveCommunicator {
-    ResponseResultReceived ProcessJobResult(
-      Stream stream,
-      bool finished);
+    ResponseResultReceived ProcessJobResult(Stream stream, bool finished);
   }
 }
Index: branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.Core/3.3/JobManager.cs
===================================================================
--- branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.Core/3.3/JobManager.cs	(revision 4331)
+++ branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.Core/3.3/JobManager.cs	(revision 4333)
@@ -167,4 +167,5 @@
 
         job.JobInfo.DateCreated = DateTime.Now;
+        job.JobInfo.UserId = ServiceLocator.GetAuthorizationManager().UserId;
         DaoLocator.JobDao.InsertWithAttachedJob(job);
         DaoLocator.PluginInfoDao.InsertPluginDependenciesForJob(job.JobInfo);
Index: branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.Core/3.3/ServiceLocator.cs
===================================================================
--- branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.Core/3.3/ServiceLocator.cs	(revision 4331)
+++ branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.Core/3.3/ServiceLocator.cs	(revision 4333)
@@ -42,13 +42,9 @@
 
     private static ILifecycleManager lifecycleManager = null;
-
-    private static ISessionFactory sessionFactory = null;
-
+    
     private static IScheduler scheduler = null;
 
-    //private static IPermissionManager permManager = null;
-
-    private static IHivePermissionManager hivePermManager = null;
-
+    private static IAuthorizationManager authorizationManager = null;
+    
     private static IContextFactory contextFactory = null;
 
@@ -118,23 +114,10 @@
     /// </summary>
     /// <returns></returns>
-    //[MethodImpl(MethodImplOptions.Synchronized)]
-    //public static IPermissionManager GetPermissionManager() {
-    //  if (permManager == null)
-    //    permManager = ApplicationManager.Manager.GetInstances<IPermissionManager>().First();
-    //  return permManager;
-
-    //}
-
-    ///// <summary>
-    ///// Gets the permission manager
-    ///// </summary>
-    ///// <returns></returns>
-    //[MethodImpl(MethodImplOptions.Synchronized)]
-    //public static IHivePermissionManager GetHivePermissionManager() {
-    //  if (hivePermManager == null)
-    //    hivePermManager = ApplicationManager.Manager.GetInstances<IHivePermissionManager>().First();
-    //  return hivePermManager;
-
-    //}
+    [MethodImpl(MethodImplOptions.Synchronized)]
+    public static IAuthorizationManager GetAuthorizationManager() {
+      if (authorizationManager == null)
+        authorizationManager = ApplicationManager.Manager.GetInstances<IAuthorizationManager>().First();
+      return authorizationManager;
+    }
 
     /// <summary>
Index: branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.Core/3.3/SlaveCommunicator.cs
===================================================================
--- branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.Core/3.3/SlaveCommunicator.cs	(revision 4331)
+++ branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.Core/3.3/SlaveCommunicator.cs	(revision 4333)
@@ -247,8 +247,8 @@
     /// check if there is work for the slave and send the slave a response if he should pull a job
     /// </summary>
-    /// <param name="hbData"></param>
+    /// <param name="heartbeatData"></param>
     /// <returns></returns>
-    public ResponseHeartBeat ProcessHeartBeat(HeartBeatData hbData) {
-      Logger.Debug("BEGIN Processing Heartbeat for Slave " + hbData.SlaveId);
+    public ResponseHeartBeat ProcessHeartBeat(HeartBeatData heartbeatData) {
+      Logger.Debug("BEGIN Processing Heartbeat for Slave " + heartbeatData.SlaveId);
 
       ResponseHeartBeat response = new ResponseHeartBeat();
@@ -256,10 +256,10 @@
 
       Logger.Debug("BEGIN Started Slave Fetching");
-      SlaveDto slave = DaoLocator.SlaveDao.FindById(hbData.SlaveId);
+      SlaveDto slave = DaoLocator.SlaveDao.FindById(heartbeatData.SlaveId);
       Logger.Debug("END Finished Slave Fetching");
 
-      slave.NrOfFreeCores = hbData.FreeCores;
-      slave.FreeMemory = hbData.FreeMemory;
-      slave.IsAllowedToCalculate = hbData.IsAllowedToCalculate;
+      slave.NrOfFreeCores = heartbeatData.FreeCores;
+      slave.FreeMemory = heartbeatData.FreeMemory;
+      slave.IsAllowedToCalculate = heartbeatData.IsAllowedToCalculate;
 
       // check if the slave is logged in
@@ -275,13 +275,13 @@
       heartbeatLock.EnterWriteLock();
       Logger.Debug("END Locked for Heartbeats");
-      if (lastHeartbeats.ContainsKey(hbData.SlaveId)) {
-        lastHeartbeats[hbData.SlaveId] = DateTime.Now;
+      if (lastHeartbeats.ContainsKey(heartbeatData.SlaveId)) {
+        lastHeartbeats[heartbeatData.SlaveId] = DateTime.Now;
       } else {
-        lastHeartbeats.Add(hbData.SlaveId, DateTime.Now);
+        lastHeartbeats.Add(heartbeatData.SlaveId, DateTime.Now);
       }
       heartbeatLock.ExitWriteLock();
 
       Logger.Debug("BEGIN Processing Heartbeat Jobs");
-      ProcessJobProcess(hbData, response);
+      ProcessJobProcess(heartbeatData, response);
       Logger.Debug("END Processed Heartbeat Jobs");
 
@@ -296,5 +296,5 @@
       // if true, ask scheduler for a new job for this slave
       Logger.Debug(" BEGIN Looking for Slave Jobs");
-      if (slave.IsAllowedToCalculate && hbData.FreeCores > 0 && scheduler.ExistsJobForSlave(hbData)) {
+      if (slave.IsAllowedToCalculate && heartbeatData.FreeCores > 0 && scheduler.ExistsJobForSlave(heartbeatData)) {
         response.ActionRequest.Add(new MessageContainer(MessageContainer.MessageType.FetchJob));
       } else {
@@ -306,5 +306,5 @@
 
       //tx.Commit();
-      Logger.Debug(" END Processed Heartbeat for Slave " + hbData.SlaveId);
+      Logger.Debug(" END Processed Heartbeat for Slave " + heartbeatData.SlaveId);
       return response;
     }
@@ -341,7 +341,4 @@
       if (hbData.JobProgress != null && hbData.JobProgress.Count > 0) {
         if (jobsOfSlave == null || jobsOfSlave.Count == 0) {
-          //response.Success = false;
-          //response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_JOB_IS_NOT_BEEING_CALCULATED;
-
           foreach (Guid jobId in hbData.JobProgress.Keys) {
             response.ActionRequest.Add(new MessageContainer(MessageContainer.MessageType.AbortJob, jobId));
@@ -354,8 +351,12 @@
         foreach (KeyValuePair<Guid, double> jobProgress in hbData.JobProgress) {
           JobDto curJob = DaoLocator.JobDao.FindById(jobProgress.Key);
+          if (curJob == null) {
+            response.StatusMessage = ResponseStatus.ProcessJobResult_JobDoesNotExist;
+            response.ActionRequest.Add(new MessageContainer(MessageContainer.MessageType.AbortJob, jobProgress.Key));
+            Logger.Error("Job does not exist in DB: " + jobProgress.Key);
+            return;
+          }
           curJob.Slave = DaoLocator.SlaveDao.GetSlaveForJob(curJob.Id);
           if (curJob.Slave == null || curJob.Slave.Id != hbData.SlaveId) {
-            //response.Success = false;
-            //response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_JOB_IS_NOT_BEEING_CALCULATED;
             response.ActionRequest.Add(new MessageContainer(MessageContainer.MessageType.AbortJob, curJob.Id));
             Logger.Error("There is no job calculated by this user " + hbData.SlaveId + " Job: " + curJob);
Index: branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.Core/3.3/app.config
===================================================================
--- branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.Core/3.3/app.config	(revision 4331)
+++ branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.Core/3.3/app.config	(revision 4333)
@@ -1,4 +1,21 @@
 <?xml version="1.0" encoding="utf-8" ?>
 <configuration>
+  <system.diagnostics>
+    <sources>
+      <source name="Warnings" switchValue="Warning, ActivityTracing">
+        <listeners>
+          <add type="System.Diagnostics.DefaultTraceListener" name="Default">
+            <filter type="" />
+          </add>
+        </listeners>
+      </source>
+    </sources>
+    <sharedListeners>
+      <add type="System.Diagnostics.EventLogTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
+        name="EventLogTracer" traceOutputOptions="LogicalOperationStack, DateTime, Timestamp, ProcessId, ThreadId, Callstack">
+        <filter type="" />
+      </add>
+    </sharedListeners>
+  </system.diagnostics>
   <connectionStrings>
     <add name="HeuristicLab.Authentication"
@@ -26,12 +43,18 @@
 
   <system.serviceModel>
-    
+
+    <diagnostics>
+      <messageLogging logEntireMessage="true" logMalformedMessages="true"
+        logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true"
+        maxMessagesToLog="3000" />
+    </diagnostics>
     <bindings>
       <netTcpBinding>
         <binding name="TcpStreamedBinding" sendTimeout="00:10:00" transferMode="Streamed"
-          maxBufferPoolSize="104857600" maxBufferSize="104857600" maxReceivedMessageSize="104857600">
+          maxBufferPoolSize="104857600" maxBufferSize="104857600"
+          maxReceivedMessageSize="104857600" maxConnections="100" listenBacklog="100">
           <readerQuotas maxStringContentLength="104857600" maxArrayLength="104857600" />
           <security mode="TransportWithMessageCredential">
-            <transport clientCredentialType="Certificate" />
+            <transport clientCredentialType="Certificate"/>
             <message clientCredentialType="UserName" />
           </security>
@@ -39,6 +62,7 @@
       </netTcpBinding>
       <wsHttpBinding>
-        <binding name="HttpBinding">
+        <binding name="HiveServerHttpBinding">
           <security mode="Message">
+            <transport/>
             <message clientCredentialType="UserName" />
           </security>
@@ -60,4 +84,5 @@
           <serviceSecurityAudit auditLogLocation="Application" suppressAuditFailure="false"
             messageAuthenticationAuditLevel="SuccessOrFailure" />
+          <serviceThrottling maxConcurrentCalls="100"/>
         </behavior>
       </serviceBehaviors>
@@ -65,7 +90,7 @@
     <services>
       <service behaviorConfiguration="ServiceBehaviour" name="HeuristicLab.Hive.Server.Core.SlaveFacade">
-        <endpoint address="" binding="wsHttpBinding" bindingConfiguration="HttpBinding"
+        <endpoint address="" binding="wsHttpBinding" bindingConfiguration="HiveServerHttpBinding"
           name="SlaveHttpEndpoint" contract="HeuristicLab.Hive.Contracts.Interfaces.ISlaveFacade" />
-        <endpoint address="mex" binding="mexHttpBinding" name="SlaveMexEndpoint"
+        <endpoint address="mex" binding="mexHttpBinding" name="SlaveMexEndpoint" bindingConfiguration=""
           contract="HeuristicLab.Hive.Contracts.Interfaces.ISlaveFacade" />
         <endpoint binding="netTcpBinding" bindingConfiguration="TcpStreamedBinding"
@@ -81,5 +106,5 @@
       </service>
       <service behaviorConfiguration="ServiceBehaviour" name="HeuristicLab.Hive.Server.Core.ServerConsoleFacade">
-        <endpoint address="" binding="wsHttpBinding" bindingConfiguration="HttpBinding"
+        <endpoint address="" binding="wsHttpBinding" bindingConfiguration="HiveServerHttpBinding"
           name="ServerConsoleHttpEndpoint" contract="HeuristicLab.Hive.Contracts.Interfaces.IServerConsoleFacade" />
         <endpoint address="mex" binding="mexHttpBinding" name="ServerConsoleMexEndpoint"
@@ -96,5 +121,5 @@
         <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
           name="ClientTcpMexEndpoint" contract="IMetadataExchange" />
-        <endpoint binding="wsHttpBinding" bindingConfiguration="HttpBinding"
+        <endpoint binding="wsHttpBinding" bindingConfiguration="HiveServerHttpBinding"
           name="ClientHttpEndpoint" contract="HeuristicLab.Hive.Contracts.Interfaces.IClientFacade" />
         <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration=""
@@ -108,6 +133,6 @@
       </service>
     </services>
-    
+
   </system.serviceModel>
-  
+
 </configuration>
Index: branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.DataAccess/3.3/IJobDao.cs
===================================================================
--- branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.DataAccess/3.3/IJobDao.cs	(revision 4331)
+++ branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.DataAccess/3.3/IJobDao.cs	(revision 4333)
@@ -20,4 +20,5 @@
 
     IEnumerable<JobDto> FindFittingJobsForSlave(JobState state, int freeCores, int freeMemory, Guid slaveGuid);
+
     Stream GetSerializedJobStream(Guid jobId);
 
@@ -27,4 +28,6 @@
 
     IEnumerable<JobDto> FindJobsById(IEnumerable<Guid> jobIds);
+
+    bool IsUserAuthorizedForJobs(string userId, params Guid[] jobIds);
   }
 }
Index: branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.LINQDataAccess/3.3/HeuristicLab.Hive.Server.LINQDataAccess-3.3.csproj
===================================================================
--- branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.LINQDataAccess/3.3/HeuristicLab.Hive.Server.LINQDataAccess-3.3.csproj	(revision 4331)
+++ branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.LINQDataAccess/3.3/HeuristicLab.Hive.Server.LINQDataAccess-3.3.csproj	(revision 4333)
@@ -128,4 +128,5 @@
     <None Include="HeuristicLab.snk" />
     <None Include="Properties\AssemblyInfo.frame" />
+    <None Include="Scripts\UpdateContext.bat" />
   </ItemGroup>
   <ItemGroup>
@@ -156,4 +157,6 @@
       <SubType>Designer</SubType>
     </Content>
+    <Content Include="Scripts\cleanHiveDatabase.sql" />
+    <Content Include="Scripts\prepareHiveDatabase.sql" />
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Index: branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.LINQDataAccess/3.3/HiveDataContext.cs
===================================================================
--- branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.LINQDataAccess/3.3/HiveDataContext.cs	(revision 4331)
+++ branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.LINQDataAccess/3.3/HiveDataContext.cs	(revision 4333)
@@ -1979,5 +1979,5 @@
 		private System.Nullable<System.Guid> _ProjectId;
 		
-		private System.Nullable<System.Guid> _UserId;
+		private string _UserId;
 		
 		private int _CoresNeeded;
@@ -2025,5 +2025,5 @@
     partial void OnProjectIdChanging(System.Nullable<System.Guid> value);
     partial void OnProjectIdChanged();
-    partial void OnUserIdChanging(System.Nullable<System.Guid> value);
+    partial void OnUserIdChanging(string value);
     partial void OnUserIdChanged();
     partial void OnCoresNeededChanging(int value);
@@ -2296,6 +2296,6 @@
 		}
 		
-		[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_UserId", DbType="UniqueIdentifier")]
-		public System.Nullable<System.Guid> UserId
+		[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_UserId", DbType="VarChar(MAX)")]
+		public string UserId
 		{
 			get
Index: branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.LINQDataAccess/3.3/HiveDataContext.xml
===================================================================
--- branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.LINQDataAccess/3.3/HiveDataContext.xml	(revision 4331)
+++ branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.LINQDataAccess/3.3/HiveDataContext.xml	(revision 4333)
@@ -107,5 +107,5 @@
       <Column Name="Priority" Member="Priority" DbType="Int NOT NULL" Type="System.Int32"/>
       <Column Name="ProjectId" Member="ProjectId" DbType="UniqueIdentifier" Type="System.Guid" CanBeNull="true"/>
-      <Column Name="UserId" Member="UserId" DbType="UniqueIdentifier" Type="System.Guid" CanBeNull="true"/>
+      <Column Name="UserId" Member="UserId" DbType="VarChar(MAX)" Type="System.String" CanBeNull="true"/>
       <Column Name="CoresNeeded" Member="CoresNeeded" DbType="Int NOT NULL" Type="System.Int32"/>
       <Column Name="MemoryNeeded" Member="MemoryNeeded" DbType="Int NOT NULL" Type="System.Int32"/>
Index: branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.LINQDataAccess/3.3/JobDao.cs
===================================================================
--- branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.LINQDataAccess/3.3/JobDao.cs	(revision 4331)
+++ branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.LINQDataAccess/3.3/JobDao.cs	(revision 4333)
@@ -150,6 +150,12 @@
                                 where jobIds.Contains(job.JobId)
                                 select EntityToDto(job, null);
-
       return jobs.ToList();
+    }
+
+    public bool IsUserAuthorizedForJobs(string userId, params Guid[] jobIds) {
+      var jobs = from job in Context.Jobs
+                 where jobIds.Contains(job.JobId)
+                 select job;
+      return jobs.All(job => job.UserId == userId);
     }
     #endregion
@@ -174,4 +180,5 @@
       target.Priority = source.Priority;
       target.JobState = Enum.GetName(typeof(JobState), source.State);
+      target.UserId = source.UserId;
       return target;
     }
@@ -185,9 +192,4 @@
         target = new JobDto();
 
-      //target.ParentJob = null;
-      //target.PluginsNeeded = null;
-      //target.Slave = null;
-      //target.Project = null;
-
       target.CoresNeeded = source.CoresNeeded;
       target.MemoryNeeded = source.MemoryNeeded;
@@ -197,5 +199,5 @@
       target.DateFinished = source.DateFinished;
       target.Id = source.JobId;
-
+      
       target.Exception = source.Exception;
       target.Percentage = source.Percentage;
@@ -203,4 +205,5 @@
       target.Priority = source.Priority;
       target.State = (JobState)Enum.Parse(typeof(JobState), source.JobState, true);
+      target.UserId = source.UserId;
       return target;
     }
Index: branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.LINQDataAccess/3.3/Scripts/UpdateContext.bat
===================================================================
--- branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.LINQDataAccess/3.3/Scripts/UpdateContext.bat	(revision 4333)
+++ branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.LINQDataAccess/3.3/Scripts/UpdateContext.bat	(revision 4333)
@@ -0,0 +1,1 @@
+sqlmetal /namespace:HeuristicLab.Hive.Server.LINQDataAccess /code:../HiveDataContext.cs /language:csharp ../HiveDataContext.xml
Index: branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.LINQDataAccess/3.3/Scripts/cleanHiveDatabase.sql
===================================================================
--- branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.LINQDataAccess/3.3/Scripts/cleanHiveDatabase.sql	(revision 4333)
+++ branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.LINQDataAccess/3.3/Scripts/cleanHiveDatabase.sql	(revision 4333)
@@ -0,0 +1,9 @@
+DELETE FROM [HeuristicLab.Hive].[dbo].AssignedResources
+DELETE FROM [HeuristicLab.Hive].[dbo].RequiredPlugins
+DELETE FROM [HeuristicLab.Hive].[dbo].PluginInfo
+DELETE FROM [HeuristicLab.Hive].[dbo].UptimeStatistics
+DELETE FROM [HeuristicLab.Hive].[dbo].UptimeCalendar
+DELETE FROM [HeuristicLab.Hive].[dbo].SlaveConfig
+DELETE FROM [HeuristicLab.Hive].[dbo].SlaveGroup_Resource
+DELETE FROM [HeuristicLab.Hive].[dbo].[Resource]
+DELETE FROM [HeuristicLab.Hive].[dbo].Job
Index: branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.LINQDataAccess/3.3/Scripts/prepareHiveDatabase.sql
===================================================================
--- branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.LINQDataAccess/3.3/Scripts/prepareHiveDatabase.sql	(revision 4333)
+++ branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.LINQDataAccess/3.3/Scripts/prepareHiveDatabase.sql	(revision 4333)
@@ -0,0 +1,61 @@
+/* this script is supposed to be executed after the plain DB is generated by the linq-to-sql schema */
+
+/*
+use these DROP commands if you want to run this query a second time on the same db */
+/*
+ALTER TABLE dbo.AssignedResources ALTER COLUMN AssignedRessourcesId DROP ROWGUIDCOL;
+ALTER TABLE dbo.Job ALTER COLUMN JobId DROP ROWGUIDCOL;
+ALTER TABLE dbo.SlaveConfig ALTER COLUMN SlaveConfigId DROP ROWGUIDCOL;
+ALTER TABLE dbo.SlaveGroup_Resource ALTER COLUMN SlaveGroup_RessourceId DROP ROWGUIDCOL;
+ALTER TABLE dbo.PluginInfo ALTER COLUMN PluginId DROP ROWGUIDCOL;
+ALTER TABLE dbo.Project ALTER COLUMN ProjectId DROP ROWGUIDCOL;
+ALTER TABLE dbo.RequiredPlugins ALTER COLUMN RequiredPluginId DROP ROWGUIDCOL;
+ALTER TABLE dbo.Resource ALTER COLUMN ResourceId DROP ROWGUIDCOL;
+ALTER TABLE dbo.UptimeCalendar ALTER COLUMN UptimeCalendarId DROP ROWGUIDCOL;
+ALTER TABLE dbo.UptimeStatistics ALTER COLUMN UptimeStatisticsId DROP ROWGUIDCOL;
+
+ALTER TABLE dbo.AssignedResources DROP CONSTRAINT [DF_AssignedResources_AssignedRessourcesId];
+ALTER TABLE dbo.Job DROP CONSTRAINT [DF_Job_JobId];
+ALTER TABLE dbo.SlaveConfig DROP CONSTRAINT [DF_SlaveConfig_SlaveConfigId];
+ALTER TABLE dbo.SlaveGroup_Resource DROP CONSTRAINT [DF_SlaveGroup_ResourceSlaveGroup_RessourceId];
+ALTER TABLE dbo.PluginInfo DROP CONSTRAINT [DF_PluginInfo_PluginId];
+ALTER TABLE dbo.Project DROP CONSTRAINT [DF_Project_ProjectId];
+ALTER TABLE dbo.RequiredPlugins DROP CONSTRAINT [DF_RequiredPlugins_RequiredPluginId];
+ALTER TABLE dbo.Resource DROP CONSTRAINT [DF_Resource_ResourceId];
+ALTER TABLE dbo.UptimeCalendar DROP CONSTRAINT [DF_UptimeCalendar_UptimeCalendarId];
+ALTER TABLE dbo.UptimeStatistics DROP CONSTRAINT [DF_UptimeStatistics_UptimeStatisticsId];
+*/
+
+
+ALTER TABLE dbo.AssignedResources ALTER COLUMN AssignedRessourcesId ADD ROWGUIDCOL;
+ALTER TABLE dbo.AssignedResources WITH NOCHECK ADD CONSTRAINT [DF_AssignedResources_AssignedRessourcesId] DEFAULT (newid()) FOR AssignedRessourcesId;
+
+ALTER TABLE dbo.Job ALTER COLUMN JobId ADD ROWGUIDCOL;
+ALTER TABLE dbo.Job WITH NOCHECK ADD CONSTRAINT [DF_Job_JobId] DEFAULT (newid()) FOR JobId;
+
+ALTER TABLE dbo.SlaveConfig ALTER COLUMN SlaveConfigId ADD ROWGUIDCOL;
+ALTER TABLE dbo.SlaveConfig WITH NOCHECK ADD CONSTRAINT [DF_SlaveConfig_SlaveConfigId] DEFAULT (newid()) FOR SlaveConfigId;
+
+ALTER TABLE dbo.SlaveGroup_Resource ALTER COLUMN SlaveGroup_RessourceId ADD ROWGUIDCOL;
+ALTER TABLE dbo.SlaveGroup_Resource WITH NOCHECK ADD CONSTRAINT [DF_SlaveGroup_Resource_SlaveGroup_RessourceId] DEFAULT (newid()) FOR SlaveGroup_RessourceId;
+
+ALTER TABLE dbo.PluginInfo ALTER COLUMN PluginId ADD ROWGUIDCOL;
+ALTER TABLE dbo.PluginInfo WITH NOCHECK ADD CONSTRAINT [DF_PluginInfo_PluginId] DEFAULT (newid()) FOR PluginId;
+
+ALTER TABLE dbo.Project ALTER COLUMN ProjectId ADD ROWGUIDCOL;
+ALTER TABLE dbo.Project WITH NOCHECK ADD CONSTRAINT [DF_Project_ProjectId] DEFAULT (newid()) FOR ProjectId;
+
+ALTER TABLE dbo.RequiredPlugins ALTER COLUMN RequiredPluginId ADD ROWGUIDCOL;
+ALTER TABLE dbo.RequiredPlugins WITH NOCHECK ADD CONSTRAINT [DF_RequiredPlugins_RequiredPluginId] DEFAULT (newid()) FOR RequiredPluginId;
+
+ALTER TABLE dbo.Resource ALTER COLUMN ResourceId ADD ROWGUIDCOL;
+ALTER TABLE dbo.Resource WITH NOCHECK ADD CONSTRAINT [DF_Resource_ResourceId] DEFAULT (newid()) FOR ResourceId;
+
+ALTER TABLE dbo.UptimeCalendar ALTER COLUMN UptimeCalendarId ADD ROWGUIDCOL;
+ALTER TABLE dbo.UptimeCalendar WITH NOCHECK ADD CONSTRAINT [DF_UptimeCalendar_UptimeCalendarId] DEFAULT (newid()) FOR UptimeCalendarId;
+
+ALTER TABLE dbo.UptimeStatistics ALTER COLUMN UptimeStatisticsId ADD ROWGUIDCOL;
+ALTER TABLE dbo.UptimeStatistics WITH NOCHECK ADD CONSTRAINT [DF_UptimeStatistics_UptimeStatisticsId] DEFAULT (newid()) FOR UptimeStatisticsId;
+
+/* create indices */
+CREATE INDEX Index_RequiredPlugins_JobId ON RequiredPlugins(JobId);
Index: branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server/3.3/HeuristicLabHiveServerApplication.cs
===================================================================
--- branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server/3.3/HeuristicLabHiveServerApplication.cs	(revision 4331)
+++ branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server/3.3/HeuristicLabHiveServerApplication.cs	(revision 4333)
@@ -35,5 +35,4 @@
   [Application("Hive Server", "Server application for the distributed hive engine.", false)]
   public class HeuristicLabHiveServerApplication : ApplicationBase {
-    //private Dictionary<string, Uri> baseAddrDict = new Dictionary<string, Uri>();
     private IDictionary<string, ServiceHost> serviceHosts = new Dictionary<string, ServiceHost>();
     ILifecycleManager lifecycleManager = null;
Index: branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Slave.Communication/3.3/WcfService.cs
===================================================================
--- branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Slave.Communication/3.3/WcfService.cs	(revision 4331)
+++ branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Slave.Communication/3.3/WcfService.cs	(revision 4333)
@@ -103,5 +103,5 @@
         proxy.Open();
         Logger.Debug("Opened the Connection");
-
+        
         ConnState = NetworkEnum.WcfConnState.Connected;
         ConnectedSince = DateTime.Now;
Index: branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Slave.Communication/3.3/app.config
===================================================================
--- branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Slave.Communication/3.3/app.config	(revision 4331)
+++ branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Slave.Communication/3.3/app.config	(revision 4333)
@@ -23,6 +23,6 @@
           openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
           transactionFlow="false" transferMode="Streamed" transactionProtocol="OleTransactions"
-          hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="104857600"
-          maxBufferSize="104857600" maxConnections="10" maxReceivedMessageSize="104857600">
+          hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="104857600"
+          maxBufferSize="104857600" maxConnections="100" listenBacklog="100" maxReceivedMessageSize="104857600">
           <readerQuotas maxDepth="32" maxStringContentLength="104857600" maxArrayLength="104857600"
             maxBytesPerRead="4096" maxNameTableCharCount="16384" />
@@ -37,6 +37,6 @@
           receiveTimeout="00:10:00" sendTimeout="00:01:00" transactionFlow="false"
           transferMode="Buffered" transactionProtocol="OleTransactions"
-          hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="524288"
-          maxBufferSize="65536" maxConnections="10" maxReceivedMessageSize="65536">
+          hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288"
+          maxBufferSize="65536" maxConnections="100" listenBacklog="100" maxReceivedMessageSize="65536">
           <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
             maxBytesPerRead="4096" maxNameTableCharCount="16384" />
Index: branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Slave.Console/3.3/app.config
===================================================================
--- branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Slave.Console/3.3/app.config	(revision 4331)
+++ branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Slave.Console/3.3/app.config	(revision 4333)
@@ -19,6 +19,6 @@
           openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
           transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
-          hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="524288"
-          maxBufferSize="65536" maxConnections="10" maxReceivedMessageSize="65536">
+          hostNameComparisonMode="StrongWildcard" listenBacklog="100" maxBufferPoolSize="524288"
+          maxBufferSize="65536" maxConnections="100" maxReceivedMessageSize="65536">
           <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
             maxBytesPerRead="4096" maxNameTableCharCount="16384" />
Index: branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Slave.Core/3.3/ConfigurationManager/ConfigManager.cs
===================================================================
--- branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Slave.Core/3.3/ConfigurationManager/ConfigManager.cs	(revision 4331)
+++ branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Slave.Core/3.3/ConfigurationManager/ConfigManager.cs	(revision 4333)
@@ -114,5 +114,5 @@
       st.JobsFetched = SlaveStatusInfo.JobsFetched;
 
-      Dictionary<Guid, Executor> engines = Core.GetExecutionEngines();
+      Dictionary<Guid, Executor> engines = Core.ExecutionEngines;
       st.Jobs = new List<JobStatus>();
 
@@ -128,5 +128,5 @@
     public Dictionary<Guid, double> GetProgressOfAllJobs() {
       Dictionary<Guid, double> prog = new Dictionary<Guid, double>();
-      Dictionary<Guid, Executor> engines = Core.GetExecutionEngines();
+      Dictionary<Guid, Executor> engines = Core.ExecutionEngines;
       lock (engines) {
         foreach (KeyValuePair<Guid, Executor> kvp in engines) {
@@ -140,6 +140,6 @@
 
     public int GetUsedCores() {
-      Dictionary<Guid, Executor> engines = Core.GetExecutionEngines();
-      Dictionary<Guid, JobDto> jobs = Core.GetJobs();
+      Dictionary<Guid, Executor> engines = Core.ExecutionEngines;
+      Dictionary<Guid, JobDto> jobs = Core.Jobs;
       int usedCores = 0;
       lock (engines) {
Index: branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Slave.Core/3.3/Core.cs
===================================================================
--- branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Slave.Core/3.3/Core.cs	(revision 4331)
+++ branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Slave.Core/3.3/Core.cs	(revision 4333)
@@ -44,12 +44,12 @@
     public static bool abortRequested { get; set; }
 
-    private bool _currentlyFetching;
+    private bool currentlyFetching;
     private bool CurrentlyFetching {
       get {
-        return _currentlyFetching;
+        return currentlyFetching;
       }
       set {
-        _currentlyFetching = value;
-        Logger.Debug("Set CurrentlyFetching to " + _currentlyFetching);
+        currentlyFetching = value;
+        Logger.Debug("Set CurrentlyFetching to " + currentlyFetching);
       }
     }
@@ -69,11 +69,43 @@
       Logger.Info("Hive Slave started");
       SlaveConsoleServer server = new SlaveConsoleServer();
-      server.StartClientConsoleServer();
+      server.Start();
       
       ConfigManager manager = ConfigManager.Instance;
       manager.Core = this;
 
-      //Register all Wcf Service references
       wcfService = WcfService.Instance;
+      RegisterServiceEvents();
+
+      RecoverSettings(); // recover server IP from the settings framework
+      StartHeartbeats(); // Start heartbeats thread
+      DispatchMessageQueue(); // dispatch messages until abortRequested
+
+      DeRegisterServiceEvents();
+      server.Close();
+      Logger.Info("Program shutdown");
+    }
+
+    private void RecoverSettings() {
+      ConnectionContainer cc = ConfigManager.Instance.GetServerIP();
+      if (cc.IPAdress != String.Empty) {
+        wcfService.SetIP(cc.IPAdress);
+      }
+    }
+
+    private void StartHeartbeats() {
+      //Initialize the heartbeat
+      beat = new HeartbeatManager { Interval = new TimeSpan(0, 0, 10) };
+      beat.StartHeartbeat();
+    }
+
+    private void DispatchMessageQueue() {
+      MessageQueue queue = MessageQueue.GetInstance();
+      while (!abortRequested) {
+        MessageContainer container = queue.GetMessage();
+        DetermineAction(container);
+      }
+    }
+
+    private void RegisterServiceEvents() {
       wcfService.GetJobCompleted += new EventHandler<GetJobCompletedEventArgs>(wcfService_GetJobCompleted);
       wcfService.GetFinishedJobResultCompleted += new EventHandler<StoreFinishedJobResultCompletedEventArgs>(wcfService_StoreFinishedJobResultCompleted);
@@ -82,24 +114,13 @@
       wcfService.ServerChanged += new EventHandler(wcfService_ServerChanged);
       wcfService.Connected += new EventHandler(wcfService_Connected);
-
-      //Recover Server IP and Port from the Settings Framework
-      ConnectionContainer cc = ConfigManager.Instance.GetServerIP();
-      if (cc.IPAdress != String.Empty)
-        wcfService.SetIP(cc.IPAdress);
-
-      //Initialize the heartbeat
-      beat = new HeartbeatManager { Interval = new TimeSpan(0, 0, 10) };
-      beat.StartHeartbeat();
-
-      MessageQueue queue = MessageQueue.GetInstance();
-
-      //Main processing loop     
-      //Todo: own thread for message handling
-      //Rly?!
-      while (!abortRequested) {
-        MessageContainer container = queue.GetMessage();
-        DetermineAction(container);
-      }
-      Logger.Info("Program shutdown");
+    }
+
+    private void DeRegisterServiceEvents() {
+      wcfService.GetJobCompleted -= new EventHandler<GetJobCompletedEventArgs>(wcfService_GetJobCompleted);
+      wcfService.GetFinishedJobResultCompleted -= new EventHandler<StoreFinishedJobResultCompletedEventArgs>(wcfService_StoreFinishedJobResultCompleted);
+      wcfService.ProcessSnapshotCompleted -= new EventHandler<ProcessSnapshotCompletedEventArgs>(wcfService_ProcessSnapshotCompleted);
+      wcfService.ConnectionRestored -= new EventHandler(wcfService_ConnectionRestored);
+      wcfService.ServerChanged -= new EventHandler(wcfService_ServerChanged);
+      wcfService.Connected -= new EventHandler(wcfService_Connected);
     }
 
@@ -433,14 +454,14 @@
     #endregion
 
-    public Dictionary<Guid, Executor> GetExecutionEngines() {
-      return engines;
+    public Dictionary<Guid, Executor> ExecutionEngines {
+      get { return engines; }
+    }
+
+    internal Dictionary<Guid, JobDto> Jobs {
+      get { return jobs; }
     }
 
     void appDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) {
       Logger.Error("Exception in AppDomain: " + e.ExceptionObject.ToString());
-    }
-
-    internal Dictionary<Guid, JobDto> GetJobs() {
-      return jobs;
     }
 
Index: branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Slave.Core/3.3/SlaveConsoleService/SlaveConsoleServer.cs
===================================================================
--- branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Slave.Core/3.3/SlaveConsoleService/SlaveConsoleServer.cs	(revision 4331)
+++ branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Slave.Core/3.3/SlaveConsoleService/SlaveConsoleServer.cs	(revision 4333)
@@ -11,8 +11,13 @@
 namespace HeuristicLab.Hive.Slave.Core.SlaveConsoleService {
   public class SlaveConsoleServer {
-    public ServiceHost StartClientConsoleServer() {
-      ServiceHost host = new ServiceHost(ApplicationManager.Manager.GetTypes(typeof(ISlaveConsoleCommunicator)).First());
+    ServiceHost host = null;
+
+    public void Start() {
+      host = new ServiceHost(ApplicationManager.Manager.GetTypes(typeof(ISlaveConsoleCommunicator)).First());
       host.Open();
-      return host;
+    }
+
+    public void Close() {
+      host.Close();
     }
   }
Index: branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Slave.Core/3.3/app.config
===================================================================
--- branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Slave.Core/3.3/app.config	(revision 4331)
+++ branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Slave.Core/3.3/app.config	(revision 4333)
@@ -26,9 +26,7 @@
     <bindings>
       <netTcpBinding>
-        <binding name="SlaveConsoleTcpBinding">
+        <binding name="SlaveConsoleTcpBinding" listenBacklog="100" maxConnections="100">
           <security mode="None">
-            <transport>
-              <extendedProtectionPolicy policyEnforcement="Never" />
-            </transport>
+            <transport/>
           </security>
         </binding>
@@ -41,5 +39,5 @@
           name="SlaveConsoleTcpEndpoint" contract="HeuristicLab.Hive.Slave.Core.SlaveConsoleService.Interfaces.ISlaveConsoleCommunicator" />
         <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
-          name="SlaveConsoleTcpMexBinding" contract="IMetadataExchange" />
+          name="SlaveConsoleTcpMexEndpoint" contract="IMetadataExchange" />
         <host>
           <baseAddresses>
Index: branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive/3.3/HeuristicLab.Hive-3.3.dll.config
===================================================================
--- branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive/3.3/HeuristicLab.Hive-3.3.dll.config	(revision 4331)
+++ branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive/3.3/HeuristicLab.Hive-3.3.dll.config	(revision 4333)
@@ -10,4 +10,3 @@
     <gcServer enabled="true"/>
   </runtime>
-
 </configuration>
Index: branches/3.3-HiveMigration/tools/cleanHiveDatabase.sql
===================================================================
--- branches/3.3-HiveMigration/tools/cleanHiveDatabase.sql	(revision 4331)
+++ 	(revision )
@@ -1,9 +1,0 @@
-DELETE FROM [HeuristicLab.Hive].[dbo].AssignedResources
-DELETE FROM [HeuristicLab.Hive].[dbo].RequiredPlugins
-DELETE FROM [HeuristicLab.Hive].[dbo].PluginInfo
-DELETE FROM [HeuristicLab.Hive].[dbo].UptimeStatistics
-DELETE FROM [HeuristicLab.Hive].[dbo].UptimeCalendar
-DELETE FROM [HeuristicLab.Hive].[dbo].SlaveConfig
-DELETE FROM [HeuristicLab.Hive].[dbo].SlaveGroup_Resource
-DELETE FROM [HeuristicLab.Hive].[dbo].[Resource]
-DELETE FROM [HeuristicLab.Hive].[dbo].Job
Index: branches/3.3-HiveMigration/tools/prepareHiveDatabase.sql
===================================================================
--- branches/3.3-HiveMigration/tools/prepareHiveDatabase.sql	(revision 4331)
+++ 	(revision )
@@ -1,61 +1,0 @@
-/* this script is supposed to be executed after the plain DB is generated by the linq-to-sql schema */
-
-/*
-use these DROP commands if you want to run this query a second time on the same db */
-/*
-ALTER TABLE dbo.AssignedResources ALTER COLUMN AssignedRessourcesId DROP ROWGUIDCOL;
-ALTER TABLE dbo.Job ALTER COLUMN JobId DROP ROWGUIDCOL;
-ALTER TABLE dbo.SlaveConfig ALTER COLUMN SlaveConfigId DROP ROWGUIDCOL;
-ALTER TABLE dbo.SlaveGroup_Resource ALTER COLUMN SlaveGroup_RessourceId DROP ROWGUIDCOL;
-ALTER TABLE dbo.PluginInfo ALTER COLUMN PluginId DROP ROWGUIDCOL;
-ALTER TABLE dbo.Project ALTER COLUMN ProjectId DROP ROWGUIDCOL;
-ALTER TABLE dbo.RequiredPlugins ALTER COLUMN RequiredPluginId DROP ROWGUIDCOL;
-ALTER TABLE dbo.Resource ALTER COLUMN ResourceId DROP ROWGUIDCOL;
-ALTER TABLE dbo.UptimeCalendar ALTER COLUMN UptimeCalendarId DROP ROWGUIDCOL;
-ALTER TABLE dbo.UptimeStatistics ALTER COLUMN UptimeStatisticsId DROP ROWGUIDCOL;
-
-ALTER TABLE dbo.AssignedResources DROP CONSTRAINT [DF_AssignedResources_AssignedRessourcesId];
-ALTER TABLE dbo.Job DROP CONSTRAINT [DF_Job_JobId];
-ALTER TABLE dbo.SlaveConfig DROP CONSTRAINT [DF_SlaveConfig_SlaveConfigId];
-ALTER TABLE dbo.SlaveGroup_Resource DROP CONSTRAINT [DF_SlaveGroup_ResourceSlaveGroup_RessourceId];
-ALTER TABLE dbo.PluginInfo DROP CONSTRAINT [DF_PluginInfo_PluginId];
-ALTER TABLE dbo.Project DROP CONSTRAINT [DF_Project_ProjectId];
-ALTER TABLE dbo.RequiredPlugins DROP CONSTRAINT [DF_RequiredPlugins_RequiredPluginId];
-ALTER TABLE dbo.Resource DROP CONSTRAINT [DF_Resource_ResourceId];
-ALTER TABLE dbo.UptimeCalendar DROP CONSTRAINT [DF_UptimeCalendar_UptimeCalendarId];
-ALTER TABLE dbo.UptimeStatistics DROP CONSTRAINT [DF_UptimeStatistics_UptimeStatisticsId];
-*/
-
-
-ALTER TABLE dbo.AssignedResources ALTER COLUMN AssignedRessourcesId ADD ROWGUIDCOL;
-ALTER TABLE dbo.AssignedResources WITH NOCHECK ADD CONSTRAINT [DF_AssignedResources_AssignedRessourcesId] DEFAULT (newid()) FOR AssignedRessourcesId;
-
-ALTER TABLE dbo.Job ALTER COLUMN JobId ADD ROWGUIDCOL;
-ALTER TABLE dbo.Job WITH NOCHECK ADD CONSTRAINT [DF_Job_JobId] DEFAULT (newid()) FOR JobId;
-
-ALTER TABLE dbo.SlaveConfig ALTER COLUMN SlaveConfigId ADD ROWGUIDCOL;
-ALTER TABLE dbo.SlaveConfig WITH NOCHECK ADD CONSTRAINT [DF_SlaveConfig_SlaveConfigId] DEFAULT (newid()) FOR SlaveConfigId;
-
-ALTER TABLE dbo.SlaveGroup_Resource ALTER COLUMN SlaveGroup_RessourceId ADD ROWGUIDCOL;
-ALTER TABLE dbo.SlaveGroup_Resource WITH NOCHECK ADD CONSTRAINT [DF_SlaveGroup_Resource_SlaveGroup_RessourceId] DEFAULT (newid()) FOR SlaveGroup_RessourceId;
-
-ALTER TABLE dbo.PluginInfo ALTER COLUMN PluginId ADD ROWGUIDCOL;
-ALTER TABLE dbo.PluginInfo WITH NOCHECK ADD CONSTRAINT [DF_PluginInfo_PluginId] DEFAULT (newid()) FOR PluginId;
-
-ALTER TABLE dbo.Project ALTER COLUMN ProjectId ADD ROWGUIDCOL;
-ALTER TABLE dbo.Project WITH NOCHECK ADD CONSTRAINT [DF_Project_ProjectId] DEFAULT (newid()) FOR ProjectId;
-
-ALTER TABLE dbo.RequiredPlugins ALTER COLUMN RequiredPluginId ADD ROWGUIDCOL;
-ALTER TABLE dbo.RequiredPlugins WITH NOCHECK ADD CONSTRAINT [DF_RequiredPlugins_RequiredPluginId] DEFAULT (newid()) FOR RequiredPluginId;
-
-ALTER TABLE dbo.Resource ALTER COLUMN ResourceId ADD ROWGUIDCOL;
-ALTER TABLE dbo.Resource WITH NOCHECK ADD CONSTRAINT [DF_Resource_ResourceId] DEFAULT (newid()) FOR ResourceId;
-
-ALTER TABLE dbo.UptimeCalendar ALTER COLUMN UptimeCalendarId ADD ROWGUIDCOL;
-ALTER TABLE dbo.UptimeCalendar WITH NOCHECK ADD CONSTRAINT [DF_UptimeCalendar_UptimeCalendarId] DEFAULT (newid()) FOR UptimeCalendarId;
-
-ALTER TABLE dbo.UptimeStatistics ALTER COLUMN UptimeStatisticsId ADD ROWGUIDCOL;
-ALTER TABLE dbo.UptimeStatistics WITH NOCHECK ADD CONSTRAINT [DF_UptimeStatistics_UptimeStatisticsId] DEFAULT (newid()) FOR UptimeStatisticsId;
-
-/* create indices */
-CREATE INDEX Index_RequiredPlugins_JobId ON RequiredPlugins(JobId);
