Index: branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Services.Hive.Web/Hive-3.3/Status.aspx.cs
===================================================================
--- branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Services.Hive.Web/Hive-3.3/Status.aspx.cs	(revision 12031)
+++ branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Services.Hive.Web/Hive-3.3/Status.aspx.cs	(revision 12247)
@@ -23,11 +23,6 @@
 using System.Collections.Generic;
 using System.Linq;
-using System.Web;
-using System.Web.UI;
 using System.Web.UI.WebControls;
-using HeuristicLab.Services.Hive.DataAccess;
 using HeuristicLab.Services.Hive;
-using HeuristicLab.Services.Hive.DataTransfer;
-using System.Text;
 using System.Web.UI.DataVisualization.Charting;
 using DA = HeuristicLab.Services.Hive.DataAccess;
@@ -37,38 +32,40 @@
   protected void Page_Load(object sender, EventArgs e) {
     var dao = ServiceLocator.Instance.HiveDao;
+    var optDao = ServiceLocator.Instance.OptimizedHiveDao;
     var transactionManager = ServiceLocator.Instance.TransactionManager;
     var resourceName = Request.QueryString["resource"];
-    IEnumerable<Guid> resourceIds = new List<Guid>();
-    IEnumerable<DT.Slave> onlineSlaves = new List<DT.Slave>();
+    List<Guid> resourceIds = new List<Guid>();
+    List<DT.Slave> onlineSlaves = new List<DT.Slave>();
     int currentlyJobsWaiting = 0;
-    Dictionary<Guid, int> calculatingTasksByUser = new Dictionary<Guid,int>();
+    Dictionary<Guid, int> calculatingTasksByUser = new Dictionary<Guid, int>();
     Dictionary<Guid, int> waitingTasksByUser = new Dictionary<Guid, int>();
     List<DT.Resource> groups = new List<DT.Resource>();
 
     transactionManager.UseTransaction(() => {
-       groups = dao.GetResources(x => x.ResourceType == "GROUP").ToList();
-    }, false, false);    
+      groups = dao.GetResources(x => x.ResourceType == "GROUP").ToList();
+    }, false, false);
 
     if (!string.IsNullOrEmpty(resourceName)) {
-        transactionManager.UseTransaction(() =>
-        {
-            var resId = dao.GetResources(x => x.Name == resourceName).Single().Id;
-            resourceIds = dao.GetChildResources(resId).Select(x => x.Id).Union(new List<Guid> { resId });
-            calculatingTasksByUser = dao.GetCalculatingTasksByUserForResources(resourceIds.ToList());
-            waitingTasksByUser = dao.GetWaitingTasksByUserForResources(resourceIds.ToList());
-        }, false, false);        
+      transactionManager.UseTransaction(() => {
+        var resId = dao.GetResources(x => x.Name == resourceName).Single().Id;
+        resourceIds = dao.GetChildResources(resId).Select(x => x.Id).Union(new List<Guid> { resId }).ToList();
+        calculatingTasksByUser = dao.GetCalculatingTasksByUserForResources(resourceIds);
+        waitingTasksByUser = dao.GetWaitingTasksByUserForResources(resourceIds);
+      }, false, false);
     } else {
-        transactionManager.UseTransaction(() =>
-        {
-             resourceIds = dao.GetResources(x => true).Select(y => y.Id);
-             calculatingTasksByUser = dao.GetCalculatingTasksByUser();
-             waitingTasksByUser = dao.GetWaitingTasksByUser();            
-        }, false, false);
-    }   
+      transactionManager.UseTransaction(() => {
+        resourceIds = optDao.GetAllResourceIds().ToList();
+        calculatingTasksByUser = optDao.GetCalculatingTasksByUser();
+        waitingTasksByUser = optDao.GetWaitingTasksByUser();
+      }, false, false);
+    }
 
-    transactionManager.UseTransaction(() =>
-    {                     
-        onlineSlaves = dao.GetSlaves(x => (x.SlaveState == DA.SlaveState.Calculating || x.SlaveState == DA.SlaveState.Idle) && resourceIds.Contains(x.ResourceId));
-        currentlyJobsWaiting = dao.GetLightweightTasks(x => x.State == DA.TaskState.Waiting).Count();            
+    transactionManager.UseTransaction(() => {
+      if (string.IsNullOrEmpty(resourceName)) {
+        onlineSlaves = dao.GetSlaves(x => x.SlaveState == DA.SlaveState.Calculating || x.SlaveState == DA.SlaveState.Idle).ToList();
+      } else {
+        onlineSlaves = dao.GetSlaves(x => (x.SlaveState == DA.SlaveState.Calculating || x.SlaveState == DA.SlaveState.Idle) && resourceIds.Contains(x.ResourceId)).ToList();
+      }
+      currentlyJobsWaiting = optDao.GetNumberOfWaitingTasks();
     }, false, false);
 
@@ -76,5 +73,5 @@
     int currentlyAvailableCores = onlineSlaves.Where(s => s.Cores.HasValue && s.IsAllowedToCalculate).Sum(s => s.Cores.Value);
     int currentlyUsedCores = overallCurrentlyAvailableCores - onlineSlaves.Where(s => s.FreeCores.HasValue).Sum(s => s.FreeCores.Value);
-    
+
     this.overallAvailableCoresLabel.Text = overallCurrentlyAvailableCores.ToString();
     this.availableCoresLabel.Text = currentlyAvailableCores.ToString();
@@ -86,22 +83,21 @@
     groupsLabel.Text += string.Join(", ", groups.Select(x => string.Format("<a href=\"?resource={0}\">{0}</a>", x.Name)));
 
-    overallCpuUtilizationLabel.Text = (onlineSlaves.Count() > 0 ? Math.Round(onlineSlaves.Average(s => s.CpuUtilization), 2).ToString() : "0.0") + " %";
-    cpuUtilizationLabel.Text = (onlineSlaves.Count() > 0 && onlineSlaves.Where(x => x.IsAllowedToCalculate).Count() > 0 ? Math.Round(onlineSlaves.Where(x => x.IsAllowedToCalculate).Average(s => s.CpuUtilization), 2).ToString() : "0.0") + " %";
+    overallCpuUtilizationLabel.Text = (onlineSlaves.Any() ? Math.Round(onlineSlaves.Average(s => s.CpuUtilization), 2).ToString() : "0.0") + " %";
+    cpuUtilizationLabel.Text = (onlineSlaves.Any() && onlineSlaves.Any(x => x.IsAllowedToCalculate) ? Math.Round(onlineSlaves.Where(x => x.IsAllowedToCalculate).Average(s => s.CpuUtilization), 2).ToString() : "0.0") + " %";
 
-    DT.Statistics[] stats = new DT.Statistics[0];    
-    transactionManager.UseTransaction(() =>
-    {   
-        if (daysDropDownList.SelectedValue == "All") {
-          stats = dao.GetStatistics(x => true).OrderBy(x => x.TimeStamp).ToArray();
-        } else {
-          stats = dao.GetStatistics(x => x.Timestamp >= DateTime.Now.Subtract(TimeSpan.FromDays(int.Parse(daysDropDownList.SelectedValue)))).OrderBy(x => x.TimeStamp).ToArray();
-        }
+    DT.Statistics[] stats = new DT.Statistics[0];
+    transactionManager.UseTransaction(() => {
+      if (daysDropDownList.SelectedValue == "All") {
+        stats = dao.GetStatistics(x => true).OrderBy(x => x.TimeStamp).ToArray();
+      } else {
+        stats = dao.GetStatistics(x => x.Timestamp >= DateTime.Now.Subtract(TimeSpan.FromDays(int.Parse(daysDropDownList.SelectedValue)))).OrderBy(x => x.TimeStamp).ToArray();
+      }
     }, false, false);
-    
+
     for (int i = 0; i < stats.Length; i++) {
       var s = stats[i];
-      var slaveStats = s.SlaveStatistics.Where(x => resourceIds.Contains(x.SlaveId));
+      var slaveStats = s.SlaveStatistics.Where(x => resourceIds.Contains(x.SlaveId)).ToArray();
 
-      var averageCpuUtilization = slaveStats.Count() > 0 ? slaveStats.Average(x => x.CpuUtilization) : 0.0;
+      var averageCpuUtilization = slaveStats.Any() ? slaveStats.Average(x => x.CpuUtilization) : 0.0;
       cpuUtilizationChart.Series[0].Points.Add(new DataPoint(s.TimeStamp.ToOADate(), averageCpuUtilization));
 
@@ -118,6 +114,6 @@
     }
 
-    GenerateTasksByUserTable(waitingTasksByUser, waitingTasksByUserTable);  
-    GenerateTasksByUserTable(calculatingTasksByUser, calculatingTasksByUserTable);  
+    GenerateTasksByUserTable(waitingTasksByUser, waitingTasksByUserTable);
+    GenerateTasksByUserTable(calculatingTasksByUser, calculatingTasksByUserTable);
   }
 
@@ -134,6 +130,6 @@
       table.Rows.Add(curRow);
     }
-    if (tasksByUser.Count() > 0) {
-      TableRow sumRow = new TableRow();        
+    if (tasksByUser.Any()) {
+      TableRow sumRow = new TableRow();
       TableCell sumCell = new TableCell();
       sumCell.BorderWidth = Unit.Pixel(3);
@@ -143,4 +139,4 @@
       table.Rows.Add(sumRow);
     }
-  }  
+  }
 }
