Index: /branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3/HiveDataContext.dbml
===================================================================
--- /branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3/HiveDataContext.dbml	(revision 9556)
+++ /branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3/HiveDataContext.dbml	(revision 9557)
@@ -116,4 +116,5 @@
       <Column Name="Data" Type="System.Byte[]" DbType="VarBinary(MAX)" CanBeNull="false" UpdateCheck="Never" IsDelayLoaded="true" />
       <Column Name="LastUpdate" Type="System.DateTime" DbType="DateTime" CanBeNull="false" />
+      <Column Name="DataSize" Type="System.Int64" DbType="BigInt NOT NULL" IsReadOnly="true" IsDbGenerated="true" CanBeNull="false" />
       <Association Name="Task_TaskData" Member="Task" Storage="_Job" ThisKey="TaskId" OtherKey="TaskId" Type="Task" IsForeignKey="true" />
     </Type>
@@ -212,5 +213,5 @@
   <Table Name="[statistics].DimClient" Member="DimClients">
     <Type Name="DimClient">
-      <Column Name="Id" AutoSync="Never" Type="System.Guid" DbType="UniqueIdentifier NOT NULL" IsPrimaryKey="true" IsDbGenerated="true" CanBeNull="false" />
+      <Column Name="Id" Type="System.Guid" DbType="UniqueIdentifier NOT NULL" IsPrimaryKey="true" IsDbGenerated="true" CanBeNull="false" />
       <Column Name="Name" Type="System.String" DbType="VarChar(MAX) NOT NULL" CanBeNull="false" />
       <Column Name="ResourceId" Type="System.Guid" DbType="UniqueIdentifier NOT NULL" CanBeNull="false" />
@@ -224,5 +225,5 @@
   <Table Name="[statistics].FactTask" Member="FactTasks">
     <Type Name="FactTask">
-      <Column Name="TaskId" Type="System.Guid" DbType="UniqueIdentifier NOT NULL" CanBeNull="false" />
+      <Column Name="TaskId" Type="System.Guid" DbType="UniqueIdentifier NOT NULL" IsPrimaryKey="true" CanBeNull="false" />
       <Column Name="TotalRuntime" Type="System.Double" DbType="Float NOT NULL" CanBeNull="false" />
       <Column Name="TotalWaitingTime" Type="System.Double" DbType="Float NOT NULL" CanBeNull="false" />
@@ -232,6 +233,6 @@
       <Column Name="CoresRequired" Type="System.Int32" DbType="Int NOT NULL" CanBeNull="false" />
       <Column Name="MemoryRequired" Type="System.Int32" DbType="Int NOT NULL" CanBeNull="false" />
-      <Column Name="TaskSize" Type="System.Int32" DbType="Int NOT NULL" CanBeNull="false" />
-      <Column Name="ResultSize" Type="System.Int32" DbType="Int" CanBeNull="true" />
+      <Column Name="TaskSize" Type="System.Int64" DbType="BigInt NOT NULL" CanBeNull="false" />
+      <Column Name="ResultSize" Type="System.Int64" DbType="BigInt" CanBeNull="true" />
       <Column Name="Priority" Type="System.Int32" DbType="Int NOT NULL" CanBeNull="false" />
       <Column Name="LastClientId" Type="System.Guid" DbType="UniqueIdentifier NOT NULL" IsPrimaryKey="true" CanBeNull="false" />
@@ -241,6 +242,6 @@
       <Association Name="DimClient_FactTask" Member="DimClient" ThisKey="LastClientId" OtherKey="Id" Type="DimClient" IsForeignKey="true" />
       <Association Name="DimJob_FactTask" Member="DimJob" ThisKey="JobId" OtherKey="JobId" Type="DimJob" IsForeignKey="true" />
-      <Association Name="DimTime_FactTask" Member="DimTime" ThisKey="EndTime" OtherKey="Time" Type="DimTime" IsForeignKey="true" />
-      <Association Name="DimTime_FactTask1" Member="DimTime1" ThisKey="StartTime" OtherKey="Time" Type="DimTime" IsForeignKey="true" />
+      <Association Name="DimTime_FactTask" Member="DimTimeEnd" Storage="_DimTime" ThisKey="EndTime" OtherKey="Time" Type="DimTime" IsForeignKey="true" />
+      <Association Name="DimTime_FactTask1" Member="DimTimeStart" Storage="_DimTime1" ThisKey="StartTime" OtherKey="Time" Type="DimTime" IsForeignKey="true" />
     </Type>
   </Table>
Index: /branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3/HiveDataContext.dbml.layout
===================================================================
--- /branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3/HiveDataContext.dbml.layout	(revision 9556)
+++ /branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3/HiveDataContext.dbml.layout	(revision 9557)
@@ -76,8 +76,8 @@
       </nodes>
     </associationConnector>
-    <classShape Id="6bc13f26-f9a8-4597-b054-35be34190d12" absoluteBounds="4.125, 1, 2, 1.26050048828125">
+    <classShape Id="6bc13f26-f9a8-4597-b054-35be34190d12" absoluteBounds="4.125, 1, 2, 1.424847819010417">
       <DataClassMoniker Name="/HiveDataContext/TaskData" />
       <nestedChildShapes>
-        <elementListCompartment Id="a068522c-7974-4679-b356-e33c941c465b" absoluteBounds="4.14, 1.46, 1.9700000000000002, 0.70050048828125" name="DataPropertiesCompartment" titleTextColor="Black" itemTextColor="Black" />
+        <elementListCompartment Id="a068522c-7974-4679-b356-e33c941c465b" absoluteBounds="4.14, 1.46, 1.9700000000000002, 0.86484781901041663" name="DataPropertiesCompartment" titleTextColor="Black" itemTextColor="Black" />
       </nestedChildShapes>
     </classShape>
@@ -121,5 +121,5 @@
       </nestedChildShapes>
     </classShape>
-    <associationConnector edgePoints="[(11.25 : 1.44547136382195); (11.0260416666667 : 1.44547136382195); (11.0260416666667 : 0.5625); (2.75 : 0.5625); (2.75 : 1)]" manuallyRouted="true" fixedFrom="Caller" fixedTo="Algorithm">
+    <associationConnector edgePoints="[(11.25 : 1.44547136382195); (11.0260416666667 : 1.44547136382195); (11.0260416666667 : 0.5625); (2.75 : 0.5625); (2.75 : 1)]" manuallyRouted="true" fixedFrom="NotFixed" fixedTo="NotFixed">
       <AssociationMoniker Name="/HiveDataContext/Resource/Resource_StateLog" />
       <nodes>
@@ -179,5 +179,5 @@
       </nodes>
     </associationConnector>
-    <associationConnector edgePoints="[(8.0192961430407 : 3.90397379557292); (8.0192961430407 : 5.04807657877604); (8.875 : 5.04807657877604)]" fixedFrom="Caller" fixedTo="Algorithm">
+    <associationConnector edgePoints="[(8.0192961430407 : 3.90397379557292); (8.0192961430407 : 5.04807657877604); (8.875 : 5.04807657877604)]" fixedFrom="NotFixed" fixedTo="NotFixed">
       <AssociationMoniker Name="/HiveDataContext/Task/Task_AssignedResource" />
       <nodes>
@@ -186,5 +186,5 @@
       </nodes>
     </associationConnector>
-    <associationConnector edgePoints="[(7.20145120722822 : 3.90397379557292); (7.20145120722822 : 5.875)]" fixedFrom="Caller" fixedTo="Algorithm">
+    <associationConnector edgePoints="[(7.20145120722822 : 3.90397379557292); (7.20145120722822 : 5.875)]" fixedFrom="NotFixed" fixedTo="NotFixed">
       <AssociationMoniker Name="/HiveDataContext/Task/Task_RequiredPlugin" />
       <nodes>
@@ -193,5 +193,5 @@
       </nodes>
     </associationConnector>
-    <associationConnector edgePoints="[(7.20923076923077 : 1); (7.20923076923077 : 0.770833333333333); (7.80461538461539 : 0.770833333333333); (7.80461538461539 : 1)]" manuallyRouted="true" fixedFrom="Algorithm" fixedTo="Algorithm">
+    <associationConnector edgePoints="[(7.20923076923077 : 1); (7.20923076923077 : 0.770833333333333); (7.80461538461539 : 0.770833333333333); (7.80461538461539 : 1)]" manuallyRouted="true" fixedFrom="NotFixed" fixedTo="NotFixed">
       <AssociationMoniker Name="/HiveDataContext/Task/Task_Task" />
       <nodes>
@@ -200,5 +200,5 @@
       </nodes>
     </associationConnector>
-    <associationConnector edgePoints="[(6.5 : 1.69314697265625); (6.125 : 1.69314697265625)]" fixedFrom="NotFixed" fixedTo="NotFixed">
+    <associationConnector edgePoints="[(6.5 : 1.71242390950521); (6.125 : 1.71242390950521)]" fixedFrom="NotFixed" fixedTo="NotFixed">
       <AssociationMoniker Name="/HiveDataContext/Task/Task_TaskData" />
       <nodes>
@@ -207,5 +207,5 @@
       </nodes>
     </associationConnector>
-    <associationConnector edgePoints="[(6.5 : 2.50564697265625); (3.75 : 2.50564697265625)]" fixedFrom="NotFixed" fixedTo="NotFixed">
+    <associationConnector edgePoints="[(6.5 : 2.52492390950521); (3.75 : 2.52492390950521)]" fixedFrom="NotFixed" fixedTo="NotFixed">
       <AssociationMoniker Name="/HiveDataContext/Task/Task_StateLog" />
       <nodes>
Index: /branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3/HiveDataContext.designer.cs
===================================================================
--- /branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3/HiveDataContext.designer.cs	(revision 9556)
+++ /branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3/HiveDataContext.designer.cs	(revision 9557)
@@ -2731,4 +2731,6 @@
 		private System.DateTime _LastUpdate;
 		
+		private long _DataSize = default(long);
+		
 		private EntityRef<Task> _Job;
 		
@@ -2812,4 +2814,13 @@
 					this.OnLastUpdateChanged();
 				}
+			}
+		}
+		
+		[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_DataSize", AutoSync=AutoSync.Always, DbType="BigInt NOT NULL", IsDbGenerated=true, UpdateCheck=UpdateCheck.Never)]
+		public long DataSize
+		{
+			get
+			{
+				return this._DataSize;
 			}
 		}
@@ -4648,5 +4659,5 @@
 		}
 		
-		[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Id", DbType="UniqueIdentifier NOT NULL", IsPrimaryKey=true, IsDbGenerated=true)]
+		[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Id", AutoSync=AutoSync.OnInsert, DbType="UniqueIdentifier NOT NULL", IsPrimaryKey=true, IsDbGenerated=true)]
 		public System.Guid Id
 		{
@@ -4861,7 +4872,7 @@
 		private int _MemoryRequired;
 		
-		private int _TaskSize;
-		
-		private System.Nullable<int> _ResultSize;
+		private long _TaskSize;
+		
+		private System.Nullable<long> _ResultSize;
 		
 		private int _Priority;
@@ -4903,7 +4914,7 @@
     partial void OnMemoryRequiredChanging(int value);
     partial void OnMemoryRequiredChanged();
-    partial void OnTaskSizeChanging(int value);
+    partial void OnTaskSizeChanging(long value);
     partial void OnTaskSizeChanged();
-    partial void OnResultSizeChanging(System.Nullable<int> value);
+    partial void OnResultSizeChanging(System.Nullable<long> value);
     partial void OnResultSizeChanged();
     partial void OnPriorityChanging(int value);
@@ -4928,5 +4939,5 @@
 		}
 		
-		[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_TaskId", DbType="UniqueIdentifier NOT NULL")]
+		[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_TaskId", DbType="UniqueIdentifier NOT NULL", IsPrimaryKey=true)]
 		public System.Guid TaskId
 		{
@@ -5088,6 +5099,6 @@
 		}
 		
-		[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_TaskSize", DbType="Int NOT NULL")]
-		public int TaskSize
+		[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_TaskSize", DbType="BigInt NOT NULL")]
+		public long TaskSize
 		{
 			get
@@ -5108,6 +5119,6 @@
 		}
 		
-		[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_ResultSize", DbType="Int")]
-		public System.Nullable<int> ResultSize
+		[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_ResultSize", DbType="BigInt")]
+		public System.Nullable<long> ResultSize
 		{
 			get
@@ -5313,5 +5324,5 @@
 		
 		[global::System.Data.Linq.Mapping.AssociationAttribute(Name="DimTime_FactTask", Storage="_DimTime", ThisKey="EndTime", OtherKey="Time", IsForeignKey=true)]
-		public DimTime DimTime
+		public DimTime DimTimeEnd
 		{
 			get
@@ -5341,5 +5352,5 @@
 						this._EndTime = default(System.DateTime);
 					}
-					this.SendPropertyChanged("DimTime");
+					this.SendPropertyChanged("DimTimeEnd");
 				}
 			}
@@ -5347,5 +5358,5 @@
 		
 		[global::System.Data.Linq.Mapping.AssociationAttribute(Name="DimTime_FactTask1", Storage="_DimTime1", ThisKey="StartTime", OtherKey="Time", IsForeignKey=true)]
-		public DimTime DimTime1
+		public DimTime DimTimeStart
 		{
 			get
@@ -5375,5 +5386,5 @@
 						this._StartTime = default(System.DateTime);
 					}
-					this.SendPropertyChanged("DimTime1");
+					this.SendPropertyChanged("DimTimeStart");
 				}
 			}
@@ -5771,5 +5782,5 @@
 		{
 			this.SendPropertyChanging();
-			entity.DimTime = this;
+			entity.DimTimeEnd = this;
 		}
 		
@@ -5777,5 +5788,5 @@
 		{
 			this.SendPropertyChanging();
-			entity.DimTime = null;
+			entity.DimTimeEnd = null;
 		}
 		
@@ -5783,5 +5794,5 @@
 		{
 			this.SendPropertyChanging();
-			entity.DimTime1 = this;
+			entity.DimTimeStart = this;
 		}
 		
@@ -5789,5 +5800,5 @@
 		{
 			this.SendPropertyChanging();
-			entity.DimTime1 = null;
+			entity.DimTimeStart = null;
 		}
 		
Index: /branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3/SQL Scripts/Initialize Hive Database.sql
===================================================================
--- /branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3/SQL Scripts/Initialize Hive Database.sql	(revision 9556)
+++ /branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3/SQL Scripts/Initialize Hive Database.sql	(revision 9557)
@@ -96,4 +96,5 @@
   [Data] VarBinary(MAX) Filestream NOT NULL,
   [LastUpdate] DateTime NOT NULL,
+  [DataSize]  AS (datalength([Data])),
   CONSTRAINT [PK_dbo.TaskData] PRIMARY KEY ([TaskId])
   )
@@ -260,6 +261,6 @@
     [CoresRequired]      INT              NOT NULL,
     [MemoryRequired]     INT              NOT NULL,
-    [TaskSize]           INT              NOT NULL,
-    [ResultSize]         INT              NULL,
+    [TaskSize]           BIGINT           NOT NULL,
+    [ResultSize]         BIGINT           NULL,
     [Priority]           INT              NOT NULL,
     [LastClientId]       UNIQUEIDENTIFIER NOT NULL,
@@ -267,5 +268,5 @@
     [StartTime]          DATETIME         NOT NULL,
     [EndTime]            DATETIME         NOT NULL,
-    CONSTRAINT [PK_FactTask] PRIMARY KEY CLUSTERED ([LastClientId] ASC, [JobId] ASC, [StartTime] ASC, [EndTime] ASC),
+    CONSTRAINT [PK_FactTask] PRIMARY KEY CLUSTERED ([TaskId] ASC, [LastClientId] ASC, [JobId] ASC, [StartTime] ASC, [EndTime] ASC),
     CONSTRAINT [FK_FactTask_DimClient] FOREIGN KEY ([LastClientId]) REFERENCES [statistics].[DimClient] ([Id]),
     CONSTRAINT [FK_FactTask_DimJob] FOREIGN KEY ([JobId]) REFERENCES [statistics].[DimJob] ([JobId]),
@@ -273,2 +274,5 @@
     CONSTRAINT [FK_FactTask_DimTimeEnd] FOREIGN KEY ([EndTime]) REFERENCES [statistics].[DimTime] ([Time])
 );
+
+INSERT INTO [HeuristicLab.Hive-3.3].[statistics].[DimClient] ([Id] ,[Name] ,[ResourceId])
+VALUES ('00000000-0000-0000-0000-000000000000' ,'NULL' ,'00000000-0000-0000-0000-000000000000')
Index: /branches/HiveStatistics/sources/HeuristicLab.Services.Hive/3.3/HiveStatisticsGenerator.cs
===================================================================
--- /branches/HiveStatistics/sources/HeuristicLab.Services.Hive/3.3/HiveStatisticsGenerator.cs	(revision 9556)
+++ /branches/HiveStatistics/sources/HeuristicLab.Services.Hive/3.3/HiveStatisticsGenerator.cs	(revision 9557)
@@ -14,5 +14,6 @@
     public void GenerateStatistics() {
       using (var db = new HiveDataContext(Settings.Default.HeuristicLab_Hive_LinqConnectionString))
-      using (var transaction = new TransactionScope()) {
+      using (var transaction = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted })) {
+
         var newTime = UpdateDimensionTables(db);
         db.SubmitChanges();
@@ -30,6 +31,6 @@
       var newTime = UpdateTime(db);
       // Update other tables out of sync with time dimension?
+      UpdateUsers(db);
       UpdateJobs(db);
-      UpdateUsers(db);
       UpdateClients(db);
 
@@ -38,5 +39,5 @@
 
     private DimTime UpdateTime(HiveDataContext db) {
-      var lastUpdate =
+      var lastUpdateTime =
         (from t in db.DimTimes
          orderby t.Time descending
@@ -46,5 +47,6 @@
       var now = DateTime.Now;
       DimTime newTime = null;
-      if (lastUpdate == default(DateTime) || lastUpdate + SmallestTimeSpan < now) {
+
+      if (lastUpdateTime == default(DateTime) || lastUpdateTime + SmallestTimeSpan < now) {
         newTime = new DimTime {
           Time = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute - now.Minute % SmallestTimeSpan.Minutes, 0),
@@ -58,4 +60,25 @@
 
       return newTime;
+    }
+
+    private void UpdateUsers(HiveDataContext db) {
+      var newUsers =
+        from u in db.Resources.Where(x => x.OwnerUserId != null).Select(x => x.OwnerUserId.Value).Union(db.Jobs.Select(x => x.OwnerUserId))
+        where !db.DimUsers.Select(x => x.UserId).Contains(u)
+        select u;
+
+      var newDimUsers =
+        from u in newUsers.ToList()
+        select new DimUser {
+          UserId = u,
+          Name = userManager.GetUserById(u).UserName
+        };
+
+      db.DimUsers.InsertAllOnSubmit(newDimUsers);
+
+      // insert NULL-User
+      if (!db.DimUsers.Any(x => x.UserId == Guid.Empty)) {
+        db.DimUsers.InsertOnSubmit(new DimUser { UserId = Guid.Empty, Name = "NULL" });
+      }
     }
 
@@ -76,24 +99,8 @@
 
       db.DimJobs.InsertAllOnSubmit(newDimJobs);
-    }
-
-    private void UpdateUsers(HiveDataContext db) {
-      var newUsers =
-        from u in db.Resources.Where(x => x.OwnerUserId != null).Select(x => x.OwnerUserId.Value).Union(db.Jobs.Select(x => x.OwnerUserId))
-        where !db.DimUsers.Select(x => x.UserId).Contains(u)
-        select u;
-
-      var newDimUsers =
-        from u in newUsers.ToList()
-        select new DimUser {
-          UserId = u,
-          Name = userManager.GetUserById(u).UserName
-        };
-
-      db.DimUsers.InsertAllOnSubmit(newDimUsers);
-
-      // insert NULL-User
-      if (!db.DimUsers.Any(x => x.UserId == Guid.Empty)) {
-        db.DimUsers.InsertOnSubmit(new DimUser { UserId = Guid.Empty, Name = "NULL" });
+
+      // insert NULL-Job
+      if (!db.DimJobs.Any(x => x.JobId == Guid.Empty)) {
+        db.DimJobs.InsertOnSubmit(new DimJob { JobId = Guid.Empty, JobName = "NULL", UserId = Guid.Empty, UserName = "NULL" });
       }
     }
@@ -143,5 +150,5 @@
     private void UpdateFactTables(DimTime newTime, HiveDataContext db) {
       UpdateClientInfoFacts(newTime, db);
-      //UpdateTaskFacts(newTime, db);
+      UpdateTaskFacts(newTime, db);
     }
 
@@ -213,4 +220,42 @@
                : selector(lastFact);
     }
+
+    private void UpdateTaskFacts(DimTime newTime, HiveDataContext db) {
+      var lastFacts =
+        from f in db.FactTasks
+        group f by f.TaskId into grpFacts
+        select grpFacts.OrderByDescending(x => x.EndTime).First();
+
+      var tasksWithLastFact =
+        from t in db.Tasks
+        join lf in lastFacts on t.TaskId equals lf.TaskId into tLfJoin
+        from lWithLf in tLfJoin.DefaultIfEmpty()
+        where !t.IsParentTask
+        select new { Task = t, LastFact = tLfJoin.FirstOrDefault() };
+
+      var tasksWithNewStateLogs =
+        from sl in db.StateLogs
+        join twlf in tasksWithLastFact on sl.TaskId equals twlf.Task.TaskId
+        where twlf.LastFact == null || (sl.DateTime > twlf.LastFact.EndTime && sl.DateTime < newTime.Time)
+        group sl by twlf.Task into factGroup
+        select new { Task = factGroup.Key, StateLogs = factGroup.OrderBy(x => x.DateTime) };
+
+      var tasksWithLastFactsAndStateLogs =
+        from twsl in tasksWithNewStateLogs
+        join twlf in tasksWithLastFact on twsl.Task equals twlf.Task
+        select new { twlf.Task, twlf.LastFact, twsl.StateLogs };
+
+      var newTaskFacts =
+        from t in tasksWithLastFactsAndStateLogs.ToList()
+        select new FactTask {
+          TaskId = t.Task.TaskId,
+          JobId = t.Task.JobId,
+          DimTimeStart = t.LastFact.DimTimeStart,
+          DimTimeEnd = newTime,
+          // ...
+        };
+
+      db.FactTasks.InsertAllOnSubmit(newTaskFacts);
+    }
   }
 }
