- Timestamp:
- 07/25/12 14:12:47 (12 years ago)
- Location:
- branches/OaaS
- Files:
-
- 2 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OaaS/HeuristicLab.Services.Hive.DataAccess/3.3/Settings.Designer.cs
r8266 r8326 52 52 } 53 53 } 54 55 [global::System.Configuration.ApplicationScopedSettingAttribute()] 56 [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 57 [global::System.Configuration.DefaultSettingValueAttribute("HeuristicLab.Services.Hive.DataAccess.Settings.HeuristicLab_Hive_LinqConnectionSt" + 58 "ring")] 59 public string HiveConnectionStringName { 60 get { 61 return ((string)(this["HiveConnectionStringName"])); 62 } 63 } 54 64 } 55 65 } -
branches/OaaS/HeuristicLab.Services.Hive.DataAccess/3.3/Settings.settings
r8266 r8326 17 17 <Value Profile="(Default)">HL.Hive</Value> 18 18 </Setting> 19 <Setting Name="HiveConnectionStringName" Type="System.String" Scope="Application"> 20 <Value Profile="(Default)">HeuristicLab.Services.Hive.DataAccess.Settings.HeuristicLab_Hive_LinqConnectionString</Value> 21 </Setting> 19 22 </Settings> 20 23 </SettingsFile> -
branches/OaaS/HeuristicLab.Services.Hive.DataAccess/3.3/TransactionManager.cs
r8270 r8326 28 28 int n = 10; 29 29 while (n > 0) { 30 //TransactionScope transaction = CreateTransaction(serializable, longRunning);30 TransactionScope transaction = CreateTransaction(serializable, longRunning); 31 31 try { 32 32 call(); 33 //transaction.Complete();33 transaction.Complete(); 34 34 n = 0; 35 35 } … … 40 40 } 41 41 finally { 42 //transaction.Dispose();42 transaction.Dispose(); 43 43 } 44 44 } … … 48 48 int n = 10; 49 49 while (n > 0) { 50 //TransactionScope transaction = CreateTransaction(serializable, longRunning);50 TransactionScope transaction = CreateTransaction(serializable, longRunning); 51 51 try { 52 52 T result = call(); 53 //transaction.Complete();53 transaction.Complete(); 54 54 n = 0; 55 55 return result; … … 61 61 } 62 62 finally { 63 //transaction.Dispose();63 transaction.Dispose(); 64 64 } 65 65 } -
branches/OaaS/HeuristicLab.Services.Hive.DataAccess/3.3/app.config
r6983 r8326 8 8 <connectionStrings> 9 9 <add name="HeuristicLab.Services.Hive.DataAccess.Settings.HeuristicLab_Hive_LinqConnectionString" 10 connectionString="Data Source=localhost;Initial Catalog=HeuristicLab.Hive-3.3;Integrated Security=True;"10 connectionString="Data Source=localhost;Initial Catalog=HeuristicLab.Hive-3.3;Integrated Security=True;" 11 11 providerName="System.Data.SqlClient" /> 12 12 </connectionStrings> … … 19 19 <value>HL.Hive</value> 20 20 </setting> 21 <setting name="HiveConnectionStringName" serializeAs="String"> 22 <value>HeuristicLab.Services.Hive.DataAccess.Settings.HeuristicLab_Hive_LinqConnectionString</value> 23 </setting> 21 24 </HeuristicLab.Services.Hive.DataAccess.Settings> 22 25 </applicationSettings> -
branches/OaaS/HeuristicLab.Services.Hive.WebRole/Web.config
r8235 r8326 23 23 <add name="HeuristicLab.Authentication" connectionString="Server=tcp:pok6rtjc5c.database.windows.net,1433;Database=HeuristicLab.Authentication;User ID=cloudia@pok6rtjc5c;Password=d1fFntitafvX;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;"/> 24 24 <!-- <add name="HeuristicLab.Services.Hive.DataAccess.Settings.HeuristicLab_Hive_LinqConnectionString" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=HeuristicLab.Hive-3.3;Integrated Security=True;" providerName="System.Data.SqlClient" /> --> 25 <add name="HeuristicLab.Services.Hive.DataAccess.Settings.HeuristicLab_Hive_LinqConnectionString" connectionString="Server=tcp:pok6rtjc5c.database.windows.net,1433;Database=HeuristicLab.Hive-3.3;User ID=cloudia@pok6rtjc5c;Password=d1fFntitafvX;Trusted_Connection=False;Encrypt=True;Connection Timeout=30; " providerName="System.Data.SqlClient" />25 <add name="HeuristicLab.Services.Hive.DataAccess.Settings.HeuristicLab_Hive_LinqConnectionString" connectionString="Server=tcp:pok6rtjc5c.database.windows.net,1433;Database=HeuristicLab.Hive-3.3;User ID=cloudia@pok6rtjc5c;Password=d1fFntitafvX;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;Enlist=false;" providerName="System.Data.SqlClient" /> 26 26 </connectionStrings> 27 27 <!-- To collect diagnostic traces, uncomment the section below or merge with existing system.diagnostics section. -
branches/OaaS/HeuristicLab.Services.Hive/3.3/HeuristicLab.Services.Hive-3.3.csproj
r8067 r8326 97 97 </Reference> 98 98 <Reference Include="System" /> 99 <Reference Include="System.configuration" /> 99 100 <Reference Include="System.Core" /> 100 101 <Reference Include="System.Data.Linq" /> … … 112 113 </ItemGroup> 113 114 <ItemGroup> 115 <Compile Include="ConnectionProvider.cs" /> 114 116 <Compile Include="Convert.cs" /> 115 117 <Compile Include="DataTransfer\Command.cs" /> … … 138 140 <Compile Include="HiveDao.cs" /> 139 141 <Compile Include="HiveJanitor.cs" /> 142 <Compile Include="Interfaces\IConnectionProvider.cs" /> 140 143 <Compile Include="Interfaces\IHiveDao.cs" /> 141 144 <Compile Include="Settings.cs" /> -
branches/OaaS/HeuristicLab.Services.Hive/3.3/HiveDao.cs
r7916 r8326 25 25 using System.Linq.Expressions; 26 26 using DT = HeuristicLab.Services.Hive.DataTransfer; 27 using System.ServiceModel; 28 using HeuristicLab.Services.Hive.Interfaces; 29 using System.Data.Common; 27 30 28 31 namespace HeuristicLab.Services.Hive.DataAccess { 29 32 public class HiveDao : IHiveDao { 30 public static HiveDataContext CreateContext(bool longRunning = false) { 31 var context = new HiveDataContext(Settings.Default.HeuristicLab_Hive_LinqConnectionString); 33 34 public HiveDataContext CreateContext(bool longRunning = false) { 35 //var context = new HiveDataContext(Settings.Default.HeuristicLab_Hive_LinqConnectionString); 36 var context = new HiveDataContext(provider.GetOpenConnection(Settings.Default.HiveConnectionStringName)); 32 37 if (longRunning) context.CommandTimeout = (int)Settings.Default.LongRunningDatabaseCommandTimeout.TotalSeconds; 33 38 return context; 34 39 } 35 40 36 public HiveDao() { } 41 private IConnectionProvider provider; 42 43 public HiveDao(IConnectionProvider provider) { this.provider = provider; } 44 45 private delegate T ExecuteWithContextDelegate<T>(HiveDataContext context); 46 private delegate void ExecuteWithContextDelegate(HiveDataContext context); 47 48 private void ExecuteWithContext(ExecuteWithContextDelegate call) { 49 DbConnection con = null; 50 try { 51 using (var db = CreateContext()) { 52 con = db.Connection; 53 call(db); 54 } 55 } 56 finally { 57 provider.ReleaseConnection(con); 58 } 59 } 60 61 private T ExecuteWithContext<T>(ExecuteWithContextDelegate<T> call) { 62 DbConnection con = null; 63 try { 64 using (var db = CreateContext()) { 65 con = db.Connection; 66 T result = call(db); 67 return result; 68 } 69 } 70 finally { 71 provider.ReleaseConnection(con); 72 } 73 } 37 74 38 75 #region Task Methods 39 76 public DT.Task GetTask(Guid id) { 40 using (var db = CreateContext()){77 return ExecuteWithContext<DT.Task>((db) => { 41 78 return DT.Convert.ToDto(db.Tasks.SingleOrDefault(x => x.TaskId == id)); 42 } 79 }); 43 80 } 44 81 45 82 public IEnumerable<DT.Task> GetTasks(Expression<Func<Task, bool>> predicate) { 46 using (var db = CreateContext()){83 return ExecuteWithContext<IEnumerable<DT.Task>>((db) => { 47 84 return db.Tasks.Where(predicate).Select(x => DT.Convert.ToDto(x)).ToArray(); 48 } 85 }); 49 86 } 50 87 51 88 public Guid AddTask(DT.Task dto) { 52 using (var db = CreateContext()){89 return ExecuteWithContext<Guid>((db) => { 53 90 var entity = DT.Convert.ToEntity(dto); 54 91 db.Tasks.InsertOnSubmit(entity); … … 59 96 db.SubmitChanges(); 60 97 return entity.TaskId; 61 } 98 }); 62 99 } 63 100 64 101 public void UpdateTask(DT.Task dto) { 65 using (var db = CreateContext()){102 ExecuteWithContext((db) => { 66 103 var entity = db.Tasks.FirstOrDefault(x => x.TaskId == dto.Id); 67 104 if (entity == null) db.Tasks.InsertOnSubmit(DT.Convert.ToEntity(dto)); … … 73 110 } 74 111 db.SubmitChanges(); 75 } 112 }); 76 113 } 77 114 78 115 public void DeleteTask(Guid id) { 79 using (var db = CreateContext()){116 ExecuteWithContext((db) => { 80 117 var entity = db.Tasks.FirstOrDefault(x => x.TaskId == id); 81 118 if (entity != null) db.Tasks.DeleteOnSubmit(entity); 82 119 db.SubmitChanges(); // taskData and child tasks are deleted by db-trigger 83 } 120 }); 84 121 } 85 122 … … 92 129 /// <returns></returns> 93 130 public IEnumerable<DT.Task> GetParentTasks(IEnumerable<Guid> resourceIds, int count, bool finished) { 94 using (var db = CreateContext()){131 return ExecuteWithContext<IEnumerable<DT.Task>>((db) => { 95 132 var query = from ar in db.AssignedResources 96 133 where resourceIds.Contains(ar.ResourceId) … … 109 146 select DT.Convert.ToDto(ar.Task); 110 147 return count == 0 ? query.ToArray() : query.Take(count).ToArray(); 111 } 148 }); 112 149 } 113 150 114 151 public IEnumerable<DT.Task> GetWaitingTasks(DT.Slave slave, int count) { 115 using (var db = CreateContext()){152 return ExecuteWithContext<IEnumerable<DT.Task>>((db) => { 116 153 var resourceIds = GetParentResources(slave.Id).Select(r => r.Id); 117 154 //Originally we checked here if there are parent tasks which should be calculated (with GetParentTasks(resourceIds, count, false);). … … 129 166 var waitingTasks = (count == 0 ? query : query.Take(count)).ToArray(); 130 167 return waitingTasks; 131 } 168 }); 132 169 } 133 170 134 171 public DT.Task UpdateTaskState(Guid taskId, TaskState taskState, Guid? slaveId, Guid? userId, string exception) { 135 using (var db = CreateContext()){172 return ExecuteWithContext<DT.Task>((db) => { 136 173 var job = db.Tasks.SingleOrDefault(x => x.TaskId == taskId); 137 174 job.State = taskState; … … 147 184 job = db.Tasks.SingleOrDefault(x => x.TaskId == taskId); 148 185 return DT.Convert.ToDto(job); 149 } 186 }); 150 187 } 151 188 #endregion … … 153 190 #region TaskData Methods 154 191 public DT.TaskData GetTaskData(Guid id) { 155 using (var db = CreateContext(true)){192 return ExecuteWithContext<DT.TaskData>((db) => { 156 193 return DT.Convert.ToDto(db.TaskDatas.SingleOrDefault(x => x.TaskId == id)); 157 } 194 }); 158 195 } 159 196 160 197 public IEnumerable<DT.TaskData> GetTaskDatas(Expression<Func<TaskData, bool>> predicate) { 161 using (var db = CreateContext(true)){198 return ExecuteWithContext<IEnumerable<DT.TaskData>>((db) => { 162 199 return db.TaskDatas.Where(predicate).Select(x => DT.Convert.ToDto(x)).ToArray(); 163 } 200 }); 164 201 } 165 202 166 203 public Guid AddTaskData(DT.TaskData dto) { 167 using (var db = CreateContext(true)){204 return ExecuteWithContext<Guid>((db) => { 168 205 var entity = DT.Convert.ToEntity(dto); 169 206 db.TaskDatas.InsertOnSubmit(entity); 170 207 db.SubmitChanges(); 171 208 return entity.TaskId; 172 } 209 }); 173 210 } 174 211 175 212 public void UpdateTaskData(DT.TaskData dto) { 176 using (var db = CreateContext(true)){213 ExecuteWithContext((db) => { 177 214 var entity = db.TaskDatas.FirstOrDefault(x => x.TaskId == dto.TaskId); 178 215 if (entity == null) db.TaskDatas.InsertOnSubmit(DT.Convert.ToEntity(dto)); 179 216 else DT.Convert.ToEntity(dto, entity); 180 217 db.SubmitChanges(); 181 } 218 }); 182 219 } 183 220 184 221 public void DeleteTaskData(Guid id) { 185 using (var db = CreateContext()){222 ExecuteWithContext((db) => { 186 223 var entity = db.TaskDatas.FirstOrDefault(x => x.TaskId == id); // check if all the byte[] is loaded into memory here. otherwise work around to delete without loading it 187 224 if (entity != null) db.TaskDatas.DeleteOnSubmit(entity); 188 225 db.SubmitChanges(); 189 } 226 }); 190 227 } 191 228 #endregion … … 193 230 #region StateLog Methods 194 231 public DT.StateLog GetStateLog(Guid id) { 195 using (var db = CreateContext()){232 return ExecuteWithContext<DT.StateLog>((db) => { 196 233 return DT.Convert.ToDto(db.StateLogs.SingleOrDefault(x => x.StateLogId == id)); 197 } 234 }); 198 235 } 199 236 200 237 public IEnumerable<DT.StateLog> GetStateLogs(Expression<Func<StateLog, bool>> predicate) { 201 using (var db = CreateContext()){238 return ExecuteWithContext<IEnumerable<DT.StateLog>>((db) => { 202 239 return db.StateLogs.Where(predicate).Select(x => DT.Convert.ToDto(x)).ToArray(); 203 } 240 }); 204 241 } 205 242 206 243 public Guid AddStateLog(DT.StateLog dto) { 207 using (var db = CreateContext()){244 return ExecuteWithContext<Guid>((db) => { 208 245 var entity = DT.Convert.ToEntity(dto); 209 246 db.StateLogs.InsertOnSubmit(entity); 210 247 db.SubmitChanges(); 211 248 return entity.StateLogId; 212 } 249 }); 213 250 } 214 251 215 252 public void UpdateStateLog(DT.StateLog dto) { 216 using (var db = CreateContext()){253 ExecuteWithContext((db) => { 217 254 var entity = db.StateLogs.FirstOrDefault(x => x.StateLogId == dto.Id); 218 255 if (entity == null) db.StateLogs.InsertOnSubmit(DT.Convert.ToEntity(dto)); 219 256 else DT.Convert.ToEntity(dto, entity); 220 257 db.SubmitChanges(); 221 } 258 }); 222 259 } 223 260 224 261 public void DeleteStateLog(Guid id) { 225 using (var db = CreateContext()){262 ExecuteWithContext((db) => { 226 263 var entity = db.StateLogs.FirstOrDefault(x => x.StateLogId == id); 227 264 if (entity != null) db.StateLogs.DeleteOnSubmit(entity); 228 265 db.SubmitChanges(); 229 } 266 }); 230 267 } 231 268 #endregion … … 233 270 #region Job Methods 234 271 public DT.Job GetJob(Guid id) { 235 using (var db = CreateContext()){272 return ExecuteWithContext<DT.Job>((db) => { 236 273 return AddStatsToJob(db, DT.Convert.ToDto(db.Jobs.SingleOrDefault(x => x.JobId == id))); 237 } 274 }); 238 275 } 239 276 … … 250 287 251 288 public IEnumerable<DT.Job> GetJobs(Expression<Func<Job, bool>> predicate) { 252 using (var db = CreateContext()){289 return ExecuteWithContext<IEnumerable<DT.Job>>((db) => { 253 290 return db.Jobs.Where(predicate).Select(x => AddStatsToJob(db, DT.Convert.ToDto(x))).ToArray(); 254 } 291 }); 255 292 } 256 293 257 294 public Guid AddJob(DT.Job dto) { 258 using (var db = CreateContext()){295 return ExecuteWithContext<Guid>((db) => { 259 296 var entity = DT.Convert.ToEntity(dto); 260 297 db.Jobs.InsertOnSubmit(entity); 261 298 db.SubmitChanges(); 262 299 return entity.JobId; 263 } 300 }); 264 301 } 265 302 266 303 public void UpdateJob(DT.Job dto) { 267 using (var db = CreateContext()){304 ExecuteWithContext((db) => { 268 305 var entity = db.Jobs.FirstOrDefault(x => x.JobId == dto.Id); 269 306 if (entity == null) db.Jobs.InsertOnSubmit(DT.Convert.ToEntity(dto)); 270 307 else DT.Convert.ToEntity(dto, entity); 271 308 db.SubmitChanges(); 272 } 309 }); 273 310 } 274 311 275 312 public void DeleteJob(Guid id) { 276 using (var db = CreateContext()){313 ExecuteWithContext((db) => { 277 314 var entity = db.Jobs.FirstOrDefault(x => x.JobId == id); 278 315 if (entity != null) db.Jobs.DeleteOnSubmit(entity); 279 316 db.SubmitChanges(); 280 } 317 }); 281 318 } 282 319 #endregion … … 284 321 #region JobPermission Methods 285 322 public DT.JobPermission GetJobPermission(Guid jobId, Guid grantedUserId) { 286 using (var db = CreateContext()){323 return ExecuteWithContext<DT.JobPermission>((db) => { 287 324 return DT.Convert.ToDto(db.JobPermissions.SingleOrDefault(x => x.JobId == jobId && x.GrantedUserId == grantedUserId)); 288 } 325 }); 289 326 } 290 327 291 328 public IEnumerable<DT.JobPermission> GetJobPermissions(Expression<Func<JobPermission, bool>> predicate) { 292 using (var db = CreateContext()){329 return ExecuteWithContext<IEnumerable<DT.JobPermission>>((db) => { 293 330 return db.JobPermissions.Where(predicate).Select(x => DT.Convert.ToDto(x)).ToArray(); 294 } 331 }); 295 332 } 296 333 297 334 public void AddJobPermission(DT.JobPermission dto) { 298 using (var db = CreateContext()){335 ExecuteWithContext((db) => { 299 336 var entity = DT.Convert.ToEntity(dto); 300 337 db.JobPermissions.InsertOnSubmit(entity); 301 338 db.SubmitChanges(); 302 } 339 }); 303 340 } 304 341 305 342 public void UpdateJobPermission(DT.JobPermission dto) { 306 using (var db = CreateContext()){343 ExecuteWithContext((db) => { 307 344 var entity = db.JobPermissions.FirstOrDefault(x => x.JobId == dto.JobId && x.GrantedUserId == dto.GrantedUserId); 308 345 if (entity == null) db.JobPermissions.InsertOnSubmit(DT.Convert.ToEntity(dto)); 309 346 else DT.Convert.ToEntity(dto, entity); 310 347 db.SubmitChanges(); 311 } 348 }); 312 349 } 313 350 314 351 public void DeleteJobPermission(Guid jobId, Guid grantedUserId) { 315 using (var db = CreateContext()){352 ExecuteWithContext((db) => { 316 353 var entity = db.JobPermissions.FirstOrDefault(x => x.JobId == jobId && x.GrantedUserId == grantedUserId); 317 354 if (entity != null) db.JobPermissions.DeleteOnSubmit(entity); 318 355 db.SubmitChanges(); 319 } 356 }); 320 357 } 321 358 … … 324 361 /// </summary> 325 362 public void SetJobPermission(Guid jobId, Guid grantedByUserId, Guid grantedUserId, Permission permission) { 326 using (var db = CreateContext()){363 ExecuteWithContext((db) => { 327 364 JobPermission jobPermission = db.JobPermissions.SingleOrDefault(x => x.JobId == jobId && x.GrantedUserId == grantedUserId); 328 365 if (jobPermission != null) { … … 330 367 // not allowed, delete 331 368 db.JobPermissions.DeleteOnSubmit(jobPermission); 332 } else { 369 } 370 else { 333 371 // update 334 372 jobPermission.Permission = permission; 335 373 jobPermission.GrantedByUserId = grantedByUserId; // update grantedByUserId, always the last "granter" is stored 336 374 } 337 } else { 375 } 376 else { 338 377 // insert 339 378 if (permission != Permission.NotAllowed) { … … 343 382 } 344 383 db.SubmitChanges(); 345 } 384 }); 346 385 } 347 386 #endregion … … 349 388 #region Plugin Methods 350 389 public DT.Plugin GetPlugin(Guid id) { 351 using (var db = CreateContext()){390 return ExecuteWithContext<DT.Plugin>((db) => { 352 391 return DT.Convert.ToDto(db.Plugins.SingleOrDefault(x => x.PluginId == id)); 353 } 392 }); 354 393 } 355 394 356 395 public IEnumerable<DT.Plugin> GetPlugins(Expression<Func<Plugin, bool>> predicate) { 357 using (var db = CreateContext()){396 return ExecuteWithContext<IEnumerable<DT.Plugin>>((db) => { 358 397 return db.Plugins.Where(predicate).Select(x => DT.Convert.ToDto(x)).ToArray(); 359 } 398 }); 360 399 } 361 400 362 401 public Guid AddPlugin(DT.Plugin dto) { 363 using (var db = CreateContext()){402 return ExecuteWithContext<Guid>((db) => { 364 403 var entity = DT.Convert.ToEntity(dto); 365 404 db.Plugins.InsertOnSubmit(entity); 366 405 db.SubmitChanges(); 367 406 return entity.PluginId; 368 } 407 }); 369 408 } 370 409 371 410 public void UpdatePlugin(DT.Plugin dto) { 372 using (var db = CreateContext()){411 ExecuteWithContext((db) => { 373 412 var entity = db.Plugins.FirstOrDefault(x => x.PluginId == dto.Id); 374 413 if (entity == null) db.Plugins.InsertOnSubmit(DT.Convert.ToEntity(dto)); 375 414 else DT.Convert.ToEntity(dto, entity); 376 415 db.SubmitChanges(); 377 } 416 }); 378 417 } 379 418 380 419 public void DeletePlugin(Guid id) { 381 using (var db = CreateContext()){420 ExecuteWithContext((db) => { 382 421 var entity = db.Plugins.FirstOrDefault(x => x.PluginId == id); 383 422 if (entity != null) db.Plugins.DeleteOnSubmit(entity); 384 423 db.SubmitChanges(); 385 } 424 }); 386 425 } 387 426 #endregion … … 389 428 #region PluginData Methods 390 429 public DT.PluginData GetPluginData(Guid id) { 391 using (var db = CreateContext()){430 return ExecuteWithContext<DT.PluginData>((db) => { 392 431 return DT.Convert.ToDto(db.PluginDatas.SingleOrDefault(x => x.PluginDataId == id)); 393 } 432 }); 394 433 } 395 434 396 435 public IEnumerable<DT.PluginData> GetPluginDatas(Expression<Func<PluginData, bool>> predicate) { 397 using (var db = CreateContext()){436 return ExecuteWithContext <IEnumerable<DT.PluginData>>((db) => { 398 437 return db.PluginDatas.Where(predicate).Select(x => DT.Convert.ToDto(x)).ToArray(); 399 } 438 }); 400 439 } 401 440 402 441 public Guid AddPluginData(DT.PluginData dto) { 403 using (var db = CreateContext()){442 return ExecuteWithContext<Guid>((db) => { 404 443 var entity = DT.Convert.ToEntity(dto); 405 444 db.PluginDatas.InsertOnSubmit(entity); 406 445 db.SubmitChanges(); 407 446 return entity.PluginDataId; 408 } 447 }); 409 448 } 410 449 411 450 public void UpdatePluginData(DT.PluginData dto) { 412 using (var db = CreateContext()){451 ExecuteWithContext((db) => { 413 452 var entity = db.PluginDatas.FirstOrDefault(x => x.PluginId == dto.PluginId); 414 453 if (entity == null) db.PluginDatas.InsertOnSubmit(DT.Convert.ToEntity(dto)); 415 454 else DT.Convert.ToEntity(dto, entity); 416 455 db.SubmitChanges(); 417 } 456 }); 418 457 } 419 458 420 459 public void DeletePluginData(Guid id) { 421 using (var db = CreateContext()){460 ExecuteWithContext((db) => { 422 461 var entity = db.PluginDatas.FirstOrDefault(x => x.PluginDataId == id); 423 462 if (entity != null) db.PluginDatas.DeleteOnSubmit(entity); 424 463 db.SubmitChanges(); 425 } 464 }); 426 465 } 427 466 #endregion … … 429 468 #region Slave Methods 430 469 public DT.Slave GetSlave(Guid id) { 431 using (var db = CreateContext()){470 return ExecuteWithContext<DT.Slave>((db) => { 432 471 return DT.Convert.ToDto(db.Resources.OfType<Slave>().SingleOrDefault(x => x.ResourceId == id)); 433 } 472 }); 434 473 } 435 474 436 475 public IEnumerable<DT.Slave> GetSlaves(Expression<Func<Slave, bool>> predicate) { 437 using (var db = CreateContext()){476 return ExecuteWithContext<IEnumerable<DT.Slave>>((db) => { 438 477 return db.Resources.OfType<Slave>().Where(predicate).Select(x => DT.Convert.ToDto(x)).ToArray(); 439 } 478 }); 440 479 } 441 480 442 481 public Guid AddSlave(DT.Slave dto) { 443 using (var db = CreateContext()){482 return ExecuteWithContext<Guid>((db) => { 444 483 var entity = DT.Convert.ToEntity(dto); 445 484 db.Resources.InsertOnSubmit(entity); 446 485 db.SubmitChanges(); 447 486 return entity.ResourceId; 448 } 487 }); 449 488 } 450 489 451 490 public void UpdateSlave(DT.Slave dto) { 452 using (var db = CreateContext()){491 ExecuteWithContext((db) => { 453 492 var entity = db.Resources.OfType<Slave>().FirstOrDefault(x => x.ResourceId == dto.Id); 454 493 if (entity == null) db.Resources.InsertOnSubmit(DT.Convert.ToEntity(dto)); 455 494 else DT.Convert.ToEntity(dto, entity); 456 495 db.SubmitChanges(); 457 } 496 }); 458 497 } 459 498 460 499 public void DeleteSlave(Guid id) { 461 using (var db = CreateContext()){500 ExecuteWithContext((db) => { 462 501 var entity = db.Resources.OfType<Slave>().FirstOrDefault(x => x.ResourceId == id); 463 502 if (entity != null) db.Resources.DeleteOnSubmit(entity); 464 503 db.SubmitChanges(); 465 } 504 }); 466 505 } 467 506 #endregion … … 469 508 #region SlaveGroup Methods 470 509 public DT.SlaveGroup GetSlaveGroup(Guid id) { 471 using (var db = CreateContext()){510 return ExecuteWithContext<DT.SlaveGroup>((db) => { 472 511 return DT.Convert.ToDto(db.Resources.OfType<SlaveGroup>().SingleOrDefault(x => x.ResourceId == id)); 473 } 512 }); 474 513 } 475 514 476 515 public IEnumerable<DT.SlaveGroup> GetSlaveGroups(Expression<Func<SlaveGroup, bool>> predicate) { 477 using (var db = CreateContext()){516 return ExecuteWithContext<IEnumerable<DT.SlaveGroup>>((db) => { 478 517 return db.Resources.OfType<SlaveGroup>().Where(predicate).Select(x => DT.Convert.ToDto(x)).ToArray(); 479 } 518 }); 480 519 } 481 520 482 521 public Guid AddSlaveGroup(DT.SlaveGroup dto) { 483 using (var db = CreateContext()){522 return ExecuteWithContext<Guid>((db) => { 484 523 if (dto.Id == Guid.Empty) 485 524 dto.Id = Guid.NewGuid(); … … 488 527 db.SubmitChanges(); 489 528 return entity.ResourceId; 490 } 529 }); 491 530 } 492 531 493 532 public void UpdateSlaveGroup(DT.SlaveGroup dto) { 494 using (var db = CreateContext()){533 ExecuteWithContext((db) => { 495 534 var entity = db.Resources.OfType<SlaveGroup>().FirstOrDefault(x => x.ResourceId == dto.Id); 496 535 if (entity == null) db.Resources.InsertOnSubmit(DT.Convert.ToEntity(dto)); 497 536 else DT.Convert.ToEntity(dto, entity); 498 537 db.SubmitChanges(); 499 } 538 }); 500 539 } 501 540 502 541 public void DeleteSlaveGroup(Guid id) { 503 using (var db = CreateContext()){542 ExecuteWithContext((db) => { 504 543 var entity = db.Resources.OfType<SlaveGroup>().FirstOrDefault(x => x.ResourceId == id); 505 544 if (entity != null) { … … 510 549 } 511 550 db.SubmitChanges(); 512 } 551 }); 513 552 } 514 553 #endregion … … 516 555 #region Resource Methods 517 556 public DT.Resource GetResource(Guid id) { 518 using (var db = CreateContext()){557 return ExecuteWithContext<DT.Resource>((db) => { 519 558 return DT.Convert.ToDto(db.Resources.SingleOrDefault(x => x.ResourceId == id)); 520 } 559 }); 521 560 } 522 561 523 562 public IEnumerable<DT.Resource> GetResources(Expression<Func<Resource, bool>> predicate) { 524 using (var db = CreateContext()){563 return ExecuteWithContext<IEnumerable<DT.Resource>>((db) => { 525 564 return db.Resources.Where(predicate).Select(x => DT.Convert.ToDto(x)).ToArray(); 526 } 565 }); 527 566 } 528 567 529 568 public Guid AddResource(DT.Resource dto) { 530 using (var db = CreateContext()){569 return ExecuteWithContext<Guid>((db) => { 531 570 var entity = DT.Convert.ToEntity(dto); 532 571 db.Resources.InsertOnSubmit(entity); 533 572 db.SubmitChanges(); 534 573 return entity.ResourceId; 535 } 574 }); 536 575 } 537 576 538 577 public void UpdateResource(DT.Resource dto) { 539 using (var db = CreateContext()){578 ExecuteWithContext((db) => { 540 579 var entity = db.Resources.FirstOrDefault(x => x.ResourceId == dto.Id); 541 580 if (entity == null) db.Resources.InsertOnSubmit(DT.Convert.ToEntity(dto)); 542 581 else DT.Convert.ToEntity(dto, entity); 543 582 db.SubmitChanges(); 544 } 583 }); 545 584 } 546 585 547 586 public void DeleteResource(Guid id) { 548 using (var db = CreateContext()){587 ExecuteWithContext((db) => { 549 588 var entity = db.Resources.FirstOrDefault(x => x.ResourceId == id); 550 589 if (entity != null) db.Resources.DeleteOnSubmit(entity); 551 590 db.SubmitChanges(); 552 } 591 }); 553 592 } 554 593 555 594 public void AssignJobToResource(Guid jobId, Guid resourceId) { 556 using (var db = CreateContext()){595 ExecuteWithContext((db) => { 557 596 var job = db.Tasks.Where(x => x.TaskId == jobId).Single(); 558 597 job.AssignedResources.Add(new AssignedResource() { TaskId = jobId, ResourceId = resourceId }); 559 598 db.SubmitChanges(); 560 } 599 }); 561 600 } 562 601 563 602 public IEnumerable<DT.Resource> GetAssignedResources(Guid jobId) { 564 using (var db = CreateContext()){603 return ExecuteWithContext <IEnumerable<DT.Resource>>((db) => { 565 604 var job = db.Tasks.Where(x => x.TaskId == jobId).Single(); 566 605 return job.AssignedResources.Select(x => DT.Convert.ToDto(x.Resource)).ToArray(); 567 } 606 }); 568 607 } 569 608 … … 572 611 /// </summary> 573 612 public IEnumerable<DT.Resource> GetParentResources(Guid resourceId) { 574 using (var db = CreateContext()){613 return ExecuteWithContext<IEnumerable<DT.Resource>>((db) => { 575 614 var resources = new List<Resource>(); 576 615 CollectParentResources(resources, db.Resources.Where(r => r.ResourceId == resourceId).Single()); 577 616 return resources.Select(r => DT.Convert.ToDto(r)).ToArray(); 578 } 617 }); 579 618 } 580 619 … … 589 628 /// </summary> 590 629 public IEnumerable<DT.Resource> GetChildResources(Guid resourceId) { 591 using (var db = CreateContext()){630 return ExecuteWithContext<IEnumerable<DT.Resource>>((db) => { 592 631 var childs = new List<DT.Resource>(); 593 632 foreach (var child in db.Resources.Where(x => x.ParentResourceId == resourceId)) { … … 596 635 } 597 636 return childs; 598 } 637 }); 599 638 } 600 639 601 640 public IEnumerable<DT.Task> GetJobsByResourceId(Guid resourceId) { 602 using (var db = CreateContext()){641 return ExecuteWithContext<IEnumerable<DT.Task>>((db) => { 603 642 var resources = GetChildResources(resourceId).Select(x => x.Id).ToList(); 604 643 resources.Add(resourceId); … … 609 648 resources.Contains(j.StateLogs.OrderByDescending(x => x.DateTime).First().SlaveId.Value)); 610 649 return jobs.Select(j => DT.Convert.ToDto(j)).ToArray(); 611 } 650 }); 612 651 } 613 652 #endregion … … 615 654 #region ResourcePermission Methods 616 655 public DT.ResourcePermission GetResourcePermission(Guid resourceId, Guid grantedUserId) { 617 using (var db = CreateContext()){656 return ExecuteWithContext <DT.ResourcePermission> ((db) => { 618 657 return DT.Convert.ToDto(db.ResourcePermissions.SingleOrDefault(x => x.ResourceId == resourceId && x.GrantedUserId == grantedUserId)); 619 } 658 }); 620 659 } 621 660 622 661 public IEnumerable<DT.ResourcePermission> GetResourcePermissions(Expression<Func<ResourcePermission, bool>> predicate) { 623 using (var db = CreateContext()){662 return ExecuteWithContext<IEnumerable<DT.ResourcePermission>>((db) => { 624 663 return db.ResourcePermissions.Where(predicate).Select(x => DT.Convert.ToDto(x)).ToArray(); 625 } 664 }); 626 665 } 627 666 628 667 public void AddResourcePermission(DT.ResourcePermission dto) { 629 using (var db = CreateContext()){668 ExecuteWithContext((db) => { 630 669 var entity = db.ResourcePermissions.SingleOrDefault(x => x.ResourceId == dto.ResourceId && x.GrantedUserId == dto.GrantedUserId); 631 670 if (entity == null) { db.ResourcePermissions.InsertOnSubmit(DT.Convert.ToEntity(dto)); db.SubmitChanges(); } 632 } 671 }); 633 672 } 634 673 635 674 public void UpdateResourcePermission(DT.ResourcePermission dto) { 636 using (var db = CreateContext()){675 ExecuteWithContext((db) => { 637 676 var entity = db.ResourcePermissions.FirstOrDefault(x => x.ResourceId == dto.ResourceId && x.GrantedUserId == dto.GrantedUserId); 638 677 if (entity == null) db.ResourcePermissions.InsertOnSubmit(DT.Convert.ToEntity(dto)); 639 678 else DT.Convert.ToEntity(dto, entity); 640 679 db.SubmitChanges(); 641 } 680 }); 642 681 } 643 682 644 683 public void DeleteResourcePermission(Guid resourceId, Guid grantedUserId) { 645 using (var db = CreateContext()){684 ExecuteWithContext((db) => { 646 685 var entity = db.ResourcePermissions.FirstOrDefault(x => x.ResourceId == resourceId && x.GrantedUserId == grantedUserId); 647 686 if (entity != null) db.ResourcePermissions.DeleteOnSubmit(entity); 648 687 db.SubmitChanges(); 649 } 688 }); 650 689 } 651 690 #endregion … … 653 692 #region Authorization Methods 654 693 public Permission GetPermissionForTask(Guid taskId, Guid userId) { 655 using (var db = CreateContext()){694 return ExecuteWithContext<Permission>((db) => { 656 695 return GetPermissionForJob(GetJobForTask(taskId), userId); 657 } 696 }); 658 697 } 659 698 660 699 public Permission GetPermissionForJob(Guid jobId, Guid userId) { 661 using (var db = CreateContext()){700 return ExecuteWithContext<Permission>((db) => { 662 701 Job job = db.Jobs.SingleOrDefault(x => x.JobId == jobId); 663 702 if (job == null) return Permission.NotAllowed; … … 665 704 JobPermission permission = db.JobPermissions.SingleOrDefault(p => p.JobId == jobId && p.GrantedUserId == userId); 666 705 return permission != null ? permission.Permission : Permission.NotAllowed; 667 } 706 }); 668 707 } 669 708 670 709 public Guid GetJobForTask(Guid taskId) { 671 using (var db = CreateContext()){710 return ExecuteWithContext<Guid>((db) => { 672 711 return db.Tasks.Single(j => j.TaskId == taskId).JobId; 673 } 712 }); 674 713 } 675 714 #endregion … … 677 716 #region Lifecycle Methods 678 717 public DateTime GetLastCleanup() { 679 using (var db = CreateContext()){718 return ExecuteWithContext<DateTime>((db) => { 680 719 var entity = db.Lifecycles.SingleOrDefault(); 681 720 return entity != null ? entity.LastCleanup : DateTime.MinValue; 682 } 721 }); 683 722 } 684 723 685 724 public void SetLastCleanup(DateTime datetime) { 686 using (var db = CreateContext()){725 ExecuteWithContext((db) => { 687 726 var entity = db.Lifecycles.SingleOrDefault(); 688 727 if (entity != null) { 689 728 entity.LastCleanup = datetime; 690 } else { 729 } 730 else { 691 731 entity = new Lifecycle(); 692 732 entity.LifecycleId = 0; // always only one entry with ID:0 … … 695 735 } 696 736 db.SubmitChanges(); 697 } 737 }); 698 738 } 699 739 #endregion … … 701 741 #region Downtime Methods 702 742 public DT.Downtime GetDowntime(Guid id) { 703 using (var db = CreateContext()){743 return ExecuteWithContext<DT.Downtime>((db) => { 704 744 return DT.Convert.ToDto(db.Downtimes.SingleOrDefault(x => x.DowntimeId == id)); 705 } 745 }); 706 746 } 707 747 708 748 public IEnumerable<DT.Downtime> GetDowntimes(Expression<Func<Downtime, bool>> predicate) { 709 using (var db = CreateContext()){749 return ExecuteWithContext<IEnumerable<DT.Downtime>>((db) => { 710 750 return db.Downtimes.Where(predicate).Select(x => DT.Convert.ToDto(x)).ToArray(); 711 } 751 }); 712 752 } 713 753 714 754 public Guid AddDowntime(DT.Downtime dto) { 715 using (var db = CreateContext()){755 return ExecuteWithContext<Guid>((db) => { 716 756 var entity = DT.Convert.ToEntity(dto); 717 757 db.Downtimes.InsertOnSubmit(entity); 718 758 db.SubmitChanges(); 719 759 return entity.DowntimeId; 720 } 760 }); 721 761 } 722 762 723 763 public void UpdateDowntime(DT.Downtime dto) { 724 using (var db = CreateContext()){764 ExecuteWithContext((db) => { 725 765 var entity = db.Downtimes.FirstOrDefault(x => x.DowntimeId == dto.Id); 726 766 if (entity == null) db.Downtimes.InsertOnSubmit(DT.Convert.ToEntity(dto)); 727 767 else DT.Convert.ToEntity(dto, entity); 728 768 db.SubmitChanges(); 729 } 769 }); 730 770 } 731 771 732 772 public void DeleteDowntime(Guid id) { 733 using (var db = CreateContext()){773 ExecuteWithContext((db) => { 734 774 var entity = db.Downtimes.FirstOrDefault(x => x.DowntimeId == id); 735 775 if (entity != null) db.Downtimes.DeleteOnSubmit(entity); 736 776 db.SubmitChanges(); 737 } 777 }); 738 778 } 739 779 #endregion … … 741 781 #region Statistics Methods 742 782 public DT.Statistics GetStatistic(Guid id) { 743 using (var db = CreateContext()){783 return ExecuteWithContext<DT.Statistics>((db) => { 744 784 return DT.Convert.ToDto(db.Statistics.SingleOrDefault(x => x.StatisticsId == id)); 745 } 785 }); 746 786 } 747 787 748 788 public IEnumerable<DT.Statistics> GetStatistics(Expression<Func<Statistics, bool>> predicate) { 749 using (var db = CreateContext()){789 return ExecuteWithContext<IEnumerable<DT.Statistics>>((db) => { 750 790 return db.Statistics.Where(predicate).Select(x => DT.Convert.ToDto(x)).ToArray(); 751 } 791 }); 752 792 } 753 793 754 794 public Guid AddStatistics(DT.Statistics dto) { 755 using (var db = CreateContext()){795 return ExecuteWithContext<Guid>((db) => { 756 796 var entity = DT.Convert.ToEntity(dto); 757 797 db.Statistics.InsertOnSubmit(entity); … … 769 809 db.SubmitChanges(); 770 810 return entity.StatisticsId; 771 } 811 }); 772 812 } 773 813 774 814 public void DeleteStatistics(Guid id) { 775 using (var db = CreateContext()){815 ExecuteWithContext((db) => { 776 816 var entity = db.Statistics.FirstOrDefault(x => x.StatisticsId == id); 777 817 if (entity != null) db.Statistics.DeleteOnSubmit(entity); 778 818 db.SubmitChanges(); 779 } 819 }); 780 820 } 781 821 782 822 public List<DT.UserStatistics> GetUserStatistics() { 783 using (var db = CreateContext()){823 return ExecuteWithContext<List<DT.UserStatistics>>((db) => { 784 824 var userStats = new Dictionary<Guid, DT.UserStatistics>(); 785 825 … … 853 893 854 894 return userStats.Values.ToList(); 855 } 895 }); 856 896 } 857 897 #endregion -
branches/OaaS/HeuristicLab.Services.Hive/3.3/HiveService.cs
r8266 r8326 28 28 using DA = HeuristicLab.Services.Hive.DataAccess; 29 29 using DT = HeuristicLab.Services.Hive.DataTransfer; 30 using System.Transactions; 30 31 31 32 … … 63 64 public Guid AddTask(Task task, TaskData taskData, IEnumerable<Guid> resourceIds) { 64 65 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 66 Guid currentUserId = userManager.CurrentUserId; 65 67 return trans.UseTransaction(() => { 66 68 task.Id = dao.AddTask(task); … … 71 73 } 72 74 dao.AddTaskData(taskData); 73 dao.UpdateTaskState(task.Id, DA.TaskState.Waiting, null, userManager.CurrentUserId, null);75 dao.UpdateTaskState(task.Id, DA.TaskState.Waiting, null, currentUserId, null); 74 76 return taskData.TaskId; 75 77 }, false, true); … … 181 183 182 184 public Task UpdateTaskState(Guid taskId, TaskState taskState, Guid? slaveId, Guid? userId, string exception) { 183 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client, HiveRoles.Slave); 184 author.AuthorizeForTask(taskId, Permission.Full); 185 using (var ts = new TransactionScope(TransactionScopeOption.Suppress)) { 186 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client, HiveRoles.Slave); 187 author.AuthorizeForTask(taskId, Permission.Full); 188 } 185 189 return trans.UseTransaction(() => { 186 190 Task task = dao.UpdateTaskState(taskId, DataTransfer.Convert.ToEntity(taskState), slaveId, userId, exception); … … 245 249 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client, HiveRoles.Slave); 246 250 author.AuthorizeForTask(taskId, Permission.Full); 247 trans.UseTransaction(() => { 248 Task task = dao.UpdateTaskState(taskId, DA.TaskState.Waiting, null, userManager.CurrentUserId, string.Empty); 251 Guid currentUserId = userManager.CurrentUserId; 252 trans.UseTransaction(() => { 253 Task task = dao.UpdateTaskState(taskId, DA.TaskState.Waiting, null, currentUserId, string.Empty); 249 254 task.Command = null; 250 255 dao.UpdateTask(task); … … 320 325 public void GrantPermission(Guid jobId, Guid grantedUserId, Permission permission) { 321 326 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 327 Guid currentUserId = userManager.CurrentUserId; 322 328 trans.UseTransaction(() => { 323 329 Job job = dao.GetJob(jobId); 324 330 if (job == null) throw new FaultException<FaultReason>(new FaultReason("Could not find task with id " + jobId)); 325 Permission perm = DT.Convert.ToDto(dao.GetPermissionForJob(job.Id, userManager.CurrentUserId));331 Permission perm = DT.Convert.ToDto(dao.GetPermissionForJob(job.Id, currentUserId)); 326 332 if (perm != Permission.Full) throw new FaultException<FaultReason>(new FaultReason("Not allowed to grant permissions for this experiment")); 327 dao.SetJobPermission(jobId, userManager.CurrentUserId, grantedUserId, DT.Convert.ToEntity(permission));333 dao.SetJobPermission(jobId, currentUserId, grantedUserId, DT.Convert.ToEntity(permission)); 328 334 }); 329 335 } … … 331 337 public void RevokePermission(Guid jobId, Guid grantedUserId) { 332 338 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 339 Guid currentUserId = userManager.CurrentUserId; 333 340 trans.UseTransaction(() => { 334 341 Job job = dao.GetJob(jobId); 335 342 if (job == null) throw new FaultException<FaultReason>(new FaultReason("Could not find task with id " + jobId)); 336 DA.Permission perm = dao.GetPermissionForJob(job.Id, userManager.CurrentUserId);343 DA.Permission perm = dao.GetPermissionForJob(job.Id, currentUserId); 337 344 if (perm != DA.Permission.Full) throw new FaultException<FaultReason>(new FaultReason("Not allowed to grant permissions for this experiment")); 338 dao.SetJobPermission(jobId, userManager.CurrentUserId, grantedUserId, DA.Permission.NotAllowed);345 dao.SetJobPermission(jobId, currentUserId, grantedUserId, DA.Permission.NotAllowed); 339 346 }); 340 347 } … … 342 349 public IEnumerable<JobPermission> GetJobPermissions(Guid jobId) { 343 350 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 344 return trans.UseTransaction(() => { 345 DA.Permission currentUserPermission = dao.GetPermissionForJob(jobId, userManager.CurrentUserId); 351 Guid currentUserId = userManager.CurrentUserId; 352 return trans.UseTransaction(() => { 353 DA.Permission currentUserPermission = dao.GetPermissionForJob(jobId, currentUserId); 346 354 if (currentUserPermission != DA.Permission.Full) throw new FaultException<FaultReason>(new FaultReason("Not allowed to list permissions for this experiment")); 347 355 return dao.GetJobPermissions(x => x.JobId == jobId); … … 421 429 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 422 430 return trans.UseTransaction(() => { 423 plugin.UserId = userManager.CurrentUserId; 431 using (var ts = new TransactionScope(TransactionScopeOption.Suppress)) { 432 plugin.UserId = userManager.CurrentUserId; 433 } 424 434 plugin.DateCreated = DateTime.Now; 425 435 … … 476 486 public void GrantResourcePermissions(Guid resourceId, Guid[] grantedUserIds) { 477 487 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 488 Guid currentUserId = userManager.CurrentUserId; 478 489 trans.UseTransaction(() => { 479 490 Resource resource = dao.GetResource(resourceId); 480 491 if (resource == null) throw new FaultException<FaultReason>(new FaultReason("Could not find resource with id " + resourceId)); 481 if (resource.OwnerUserId != userManager.CurrentUserId && !authen.IsInRole(HiveRoles.Administrator)) throw new FaultException<FaultReason>(new FaultReason("Not allowed to grant permission for this resource"));492 if (resource.OwnerUserId != currentUserId && !authen.IsInRole(HiveRoles.Administrator)) throw new FaultException<FaultReason>(new FaultReason("Not allowed to grant permission for this resource")); 482 493 foreach (Guid id in grantedUserIds) 483 dao.AddResourcePermission(new ResourcePermission { ResourceId = resourceId, GrantedByUserId = userManager.CurrentUserId, GrantedUserId = id });494 dao.AddResourcePermission(new ResourcePermission { ResourceId = resourceId, GrantedByUserId = currentUserId, GrantedUserId = id }); 484 495 }); 485 496 } … … 487 498 public void RevokeResourcePermissions(Guid resourceId, Guid[] grantedUserIds) { 488 499 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 500 Guid currentUserId = userManager.CurrentUserId; 489 501 trans.UseTransaction(() => { 490 502 Resource resource = dao.GetResource(resourceId); 491 503 if (resource == null) throw new FaultException<FaultReason>(new FaultReason("Could not find resource with id " + resourceId)); 492 if (resource.OwnerUserId != userManager.CurrentUserId && !authen.IsInRole(HiveRoles.Administrator)) throw new FaultException<FaultReason>(new FaultReason("Not allowed to revoke permission for this resource"));504 if (resource.OwnerUserId != currentUserId && !authen.IsInRole(HiveRoles.Administrator)) throw new FaultException<FaultReason>(new FaultReason("Not allowed to revoke permission for this resource")); 493 505 foreach (Guid id in grantedUserIds) 494 506 dao.DeleteResourcePermission(resourceId, id); -
branches/OaaS/HeuristicLab.Services.Hive/3.3/ServiceLocator.cs
r8051 r8326 21 21 22 22 using HeuristicLab.Services.Hive.DataAccess; 23 using HeuristicLab.Services.Hive.Interfaces; 23 24 24 25 namespace HeuristicLab.Services.Hive { … … 34 35 } 35 36 37 private IConnectionProvider connProvider; 38 public IConnectionProvider ConnectionProvider { 39 get { 40 if (connProvider == null) connProvider = new ConnectionProvider(); 41 return connProvider; 42 } 43 } 44 36 45 private IHiveDao hiveDao; 37 46 public IHiveDao HiveDao { 38 47 get { 39 if (hiveDao == null) hiveDao = new HiveDao( );48 if (hiveDao == null) hiveDao = new HiveDao(ConnectionProvider); 40 49 return hiveDao; 41 50 }
Note: See TracChangeset
for help on using the changeset viewer.