Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive/3.4/HiveService.cs @ 6347

Last change on this file since 6347 was 6267, checked in by cneumuel, 14 years ago

#1233

  • extended statistics recording:
    • execution times of users are captured
    • execution times and start-to-finish time of finished jobs is captured (to computer hive overhead)
    • data of deleted jobs is automatically captured in DeletedJobStatistics
  • changed ExecutionTime type in database from string to float (milliseconds are stored instead of TimeSpan.ToString())
  • added IsPrivileged field to job to indicate if it should be executed in a privileged sandbox
  • added CpuUtilization field to slave to be able to report cpu utilization
  • added GetJobsByResourceId to retrieve all jobs which are currently beeing calculated in a slave(-group)
  • TransactionManager now allows to use serializable tranactions (used for lifecycle trigger)
File size: 22.3 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.ServiceModel;
5using HeuristicLab.Services.Hive.Common;
6using HeuristicLab.Services.Hive.Common.DataTransfer;
7using HeuristicLab.Services.Hive.Common.ServiceContracts;
8
9namespace HeuristicLab.Services.Hive {
10
11  /// <summary>
12  /// Implementation of the Hive service (interface <see cref="IHiveService"/>).
13  /// We need 'IgnoreExtensionDataObject' Attribute for the slave to work.
14  /// </summary>
15  [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, IgnoreExtensionDataObject = true)]
16  public class HiveService : IHiveService {
17    private DataAccess.IHiveDao dao {
18      get { return ServiceLocator.Instance.HiveDao; }
19    }
20    private HeuristicLab.Services.Hive.DataAccess.TransactionManager trans {
21      get { return ServiceLocator.Instance.TransactionManager; }
22    }
23    private IAuthorizationManager auth {
24      get { return ServiceLocator.Instance.AuthorizationManager; }
25    }
26    private ILifecycleManager lifecycleManager {
27      get { return ServiceLocator.Instance.LifecycleManager; }
28    }
29    private HeartbeatManager heartbeatManager {
30      get { return ServiceLocator.Instance.HeartbeatManager; }
31    }
32
33    #region Job Methods
34    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
35    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
36    public Guid AddJob(Job job, JobData jobData, IEnumerable<Guid> resourceIds) {
37      return trans.UseTransaction(() => {
38        job.Id = dao.AddJob(job);
39        jobData.JobId = job.Id;
40        jobData.LastUpdate = DateTime.Now;
41        if (resourceIds != null) {
42          foreach (Guid slaveGroupId in resourceIds) {
43            dao.AssignJobToResource(job.Id, slaveGroupId);
44          }
45        } else {
46          // todo: use default group
47        }
48        dao.AddJobData(jobData);
49        dao.UpdateJobState(job.Id, JobState.Waiting, null, auth.UserId, null);
50        return jobData.JobId;
51      });
52    }
53
54    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
55    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
56    public Guid AddChildJob(Guid parentJobId, Job job, JobData jobData) {
57      return trans.UseTransaction(() => {
58        job.ParentJobId = parentJobId;
59        return AddJob(job, jobData, dao.GetAssignedResources(parentJobId).Select(x => x.Id));
60      });
61    }
62
63    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
64    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
65    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)]
66    public Job GetJob(Guid jobId) {
67      return dao.GetJob(jobId);
68    }
69
70    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
71    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
72    public IEnumerable<Job> GetJobs() {
73      return dao.GetJobs(x => true);
74    }
75
76    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
77    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
78    public IEnumerable<LightweightJob> GetLightweightJobs(IEnumerable<Guid> jobIds) {
79      return dao.GetJobs(x => jobIds.Contains(x.JobId)).Select(x => new LightweightJob(x)).ToArray();
80    }
81
82    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
83    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
84    public IEnumerable<LightweightJob> GetLightweightChildJobs(Guid? parentJobId, bool recursive, bool includeParent) {
85      return GetChildJobs(parentJobId, recursive, includeParent).Select(x => new LightweightJob(x)).ToArray();
86    }
87
88    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
89    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
90    public IEnumerable<LightweightJob> GetLightweightExperimentJobs(Guid experimentId) {
91      return dao.GetJobs(x => x.HiveExperimentId == experimentId).Select(x => new LightweightJob(x)).ToArray();
92    }
93
94    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
95    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
96    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)]
97    public JobData GetJobData(Guid jobId) {
98      return dao.GetJobData(jobId);
99    }
100
101    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
102    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
103    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)]
104    public void UpdateJob(Job job) {
105      trans.UseTransaction(() => {
106        dao.UpdateJob(job);
107      });
108    }
109
110    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
111    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
112    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)]
113    public void UpdateJobData(Job job, JobData jobData) {
114      trans.UseTransaction(() => {
115        jobData.LastUpdate = DateTime.Now;
116        dao.UpdateJob(job);
117        dao.UpdateJobData(jobData);
118      });
119    }
120
121    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
122    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
123    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)]
124    public void DeleteJob(Guid jobId) {
125      trans.UseTransaction(() => {
126        dao.DeleteJob(jobId);
127      });
128    }
129
130    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
131    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
132    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)]
133    public void DeleteChildJobs(Guid parentJobId) {
134      trans.UseTransaction(() => {
135        var jobs = GetChildJobs(parentJobId, true, false);
136        foreach (var job in jobs) {
137          dao.DeleteJob(job.Id);
138          dao.DeleteJobData(job.Id);
139        };
140      });
141    }
142
143    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
144    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
145    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)]
146    public Job UpdateJobState(Guid jobId, JobState jobState, Guid? slaveId, Guid? userId, string exception) {
147      return trans.UseTransaction(() => {
148        Job job = dao.UpdateJobState(jobId, jobState, slaveId, userId, exception);
149
150        if (job.Command.HasValue && job.Command.Value == Command.Pause && job.State == JobState.Paused) {
151          job.Command = null;
152        } else if (job.Command.HasValue && job.Command.Value == Command.Abort && job.State == JobState.Aborted) {
153          job.Command = null;
154        } else if (job.Command.HasValue && job.Command.Value == Command.Stop && job.State == JobState.Aborted) {
155          job.Command = null;
156        } else if (jobState == JobState.Paused && !job.Command.HasValue) {
157          // job was paused and uploaded by slave without the user-command to pause it -> set waiting
158          job = dao.UpdateJobState(jobId, JobState.Waiting, slaveId, userId, exception);
159        }
160
161        dao.UpdateJob(job);
162        return job;
163      });
164    }
165    #endregion
166
167    #region Job Control Methods
168    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
169    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
170    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)]
171    public void StopJob(Guid jobId) {
172      trans.UseTransaction(() => {
173        var job = dao.GetJob(jobId);
174        if (job.State == JobState.Calculating || job.State == JobState.Transferring) {
175          job.Command = Command.Stop;
176          dao.UpdateJob(job);
177        } else {
178          if (job.State != JobState.Aborted && job.State != JobState.Finished && job.State != JobState.Failed) {
179            job = UpdateJobState(jobId, JobState.Aborted, null, null, string.Empty);
180          }
181        }
182      });
183    }
184
185    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
186    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
187    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)]
188    public void PauseJob(Guid jobId) {
189      trans.UseTransaction(() => {
190        var job = dao.GetJob(jobId);
191        if (job.State == JobState.Calculating || job.State == JobState.Transferring) {
192          job.Command = Command.Pause;
193          dao.UpdateJob(job);
194        } else {
195          job = UpdateJobState(jobId, JobState.Paused, null, null, string.Empty);
196        }
197      });
198    }
199
200    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
201    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
202    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)]
203    public void RestartJob(Guid jobId) {
204      trans.UseTransaction(() => {
205        Job job = dao.UpdateJobState(jobId, JobState.Waiting, null, auth.UserId, string.Empty);
206        job.Command = null;
207        dao.UpdateJob(job);
208      });
209    }
210    #endregion
211
212    #region HiveExperiment Methods
213    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
214    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
215    public HiveExperiment GetHiveExperiment(Guid id) {
216      return dao.GetHiveExperiments(x =>
217             x.HiveExperimentId == id
218          && (x.OwnerUserId == auth.UserId || x.HiveExperimentPermissions.Count(hep => hep.Permission != Permission.NotAllowed && hep.GrantedUserId == auth.UserId) > 0)
219          ).FirstOrDefault();
220    }
221
222    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
223    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
224    public IEnumerable<HiveExperiment> GetHiveExperiments() {
225      return dao.GetHiveExperiments(x => x.OwnerUserId == auth.UserId || x.HiveExperimentPermissions.Count(hep => hep.Permission != Permission.NotAllowed && hep.GrantedUserId == auth.UserId) > 0);
226    }
227
228    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]   
229    public IEnumerable<HiveExperiment> GetAllHiveExperiments() {
230      return dao.GetHiveExperiments(x => true);
231    }
232
233    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
234    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
235    public Guid AddHiveExperiment(HiveExperiment hiveExperimentDto) {
236      return trans.UseTransaction(() => {
237        hiveExperimentDto.OwnerUserId = auth.UserId;
238        hiveExperimentDto.DateCreated = DateTime.Now;
239        return dao.AddHiveExperiment(hiveExperimentDto);
240      });
241    }
242
243    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
244    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
245    public void UpdateHiveExperiment(HiveExperiment hiveExperimentDto) {
246      trans.UseTransaction(() => {
247        dao.UpdateHiveExperiment(hiveExperimentDto);
248      });
249    }
250
251    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
252    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
253    public void DeleteHiveExperiment(Guid hiveExperimentId) {
254      trans.UseTransaction(() => {
255        HiveExperiment he = dao.GetHiveExperiment(hiveExperimentId);
256        dao.DeleteHiveExperiment(hiveExperimentId); // child jobs will be deleted by db-trigger
257      });
258    }
259    #endregion
260
261    #region Login Methods
262    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)]
263    public void Hello(Slave slaveInfo) {
264      trans.UseTransaction(() => {
265        var slave = dao.GetSlave(slaveInfo.Id);
266
267        if (slave == null) {
268          dao.AddSlave(slaveInfo);
269        } else {
270          var dbSlave = dao.GetSlave(slaveInfo.Id);
271
272          dbSlave.Name = slaveInfo.Name;
273          dbSlave.Description = slaveInfo.Description;
274
275          dbSlave.Cores = slaveInfo.Cores;
276          dbSlave.CpuArchitecture = slaveInfo.CpuArchitecture;
277          dbSlave.CpuSpeed = slaveInfo.CpuSpeed;
278          dbSlave.FreeCores = slaveInfo.FreeCores;
279          dbSlave.FreeMemory = slaveInfo.FreeMemory;
280          dbSlave.Memory = slaveInfo.Memory;
281          dbSlave.OperatingSystem = slaveInfo.OperatingSystem;
282
283          dbSlave.LastHeartbeat = DateTime.Now;
284          dbSlave.SlaveState = SlaveState.Idle;
285
286          // don't update those properties:
287          // dbSlave.IsAllowedToCalculate = slaveInfo.IsAllowedToCalculate;
288          // dbSlave.ParentResourceId = slaveInfo.ParentResourceId;
289
290          dao.UpdateSlave(dbSlave);
291        }
292      });
293    }
294
295    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)]
296    public void GoodBye(Guid slaveId) {
297      trans.UseTransaction(() => {
298        var slave = dao.GetSlave(slaveId);
299        if (slave != null) {
300          slave.SlaveState = SlaveState.Offline;
301          dao.UpdateSlave(slave);
302        }
303      });
304    }
305    #endregion
306
307    #region Heartbeat Methods
308    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)]
309    public List<MessageContainer> Heartbeat(Heartbeat heartbeat) {
310      TriggerLifecycle(false);
311      return trans.UseTransaction(() => heartbeatManager.ProcessHeartbeat(heartbeat));
312    }
313    #endregion
314
315    #region Plugin Methods
316    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
317    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
318    public Guid AddPlugin(Plugin plugin, List<PluginData> pluginDatas) {
319      return trans.UseTransaction(() => {
320        plugin.UserId = auth.UserId;
321        plugin.DateCreated = DateTime.Now;
322        if (!plugin.IsLocal) {
323          var existing = dao.GetPlugins(x => x.Name == plugin.Name && x.Version == plugin.Version.ToString() && !x.IsLocal);
324          if (existing.Count() > 0) {
325            // a plugin with the same name and version already exists.
326            throw new FaultException<PluginAlreadyExistsFault>(new PluginAlreadyExistsFault(existing.Single().Id));
327          }
328        }
329        Guid pluginId = dao.AddPlugin(plugin);
330        foreach (PluginData pluginData in pluginDatas) {
331          pluginData.PluginId = pluginId;
332          dao.AddPluginData(pluginData);
333        }
334        return pluginId;
335      });
336    }
337
338    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
339    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
340    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)]
341    public Plugin GetPlugin(Guid pluginId) {
342      return dao.GetPlugin(pluginId);
343    }
344
345    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
346    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
347    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)]
348    public IEnumerable<Plugin> GetPlugins() {
349      return dao.GetPlugins(x => x.IsLocal == false);
350    }
351
352    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
353    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
354    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)]
355    public IEnumerable<PluginData> GetPluginDatas(List<Guid> pluginIds) {
356      List<PluginData> pluginDatas = new List<PluginData>();
357
358      return trans.UseTransaction(() => {
359        foreach (Guid guid in pluginIds) {
360          List<PluginData> pluginData = dao.GetPluginDatas(x => x.PluginId == guid).ToList();
361          if (pluginData != null) {
362            pluginDatas.AddRange(pluginData);
363          } else {
364            //ignore ?
365          }
366        }
367        return pluginDatas;
368      });
369    }
370
371    #endregion
372
373    #region Slave Methods
374    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
375    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
376    public Guid AddSlave(Slave slave) {
377      return trans.UseTransaction(() => dao.AddSlave(slave));
378    }
379
380    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
381    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
382    public Guid AddSlaveGroup(SlaveGroup slaveGroup) {
383      return trans.UseTransaction(() => dao.AddSlaveGroup(slaveGroup));
384    }
385
386    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
387    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
388    public Slave GetSlave(Guid slaveId) {
389      return dao.GetSlave(slaveId);
390    }
391
392    public SlaveGroup GetSlaveGroup(Guid slaveGroupId) {
393      return dao.GetSlaveGroup(slaveGroupId);
394    }
395
396    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
397    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
398    public IEnumerable<Slave> GetSlaves() {
399      return dao.GetSlaves(x => true);
400    }
401
402    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
403    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
404    public IEnumerable<SlaveGroup> GetSlaveGroups() {
405      return dao.GetSlaveGroups(x => true);
406    }
407
408    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
409    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
410    public void UpdateSlave(Slave slave) {
411      trans.UseTransaction(() => {
412        dao.UpdateSlave(slave);
413      });
414    }
415
416    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
417    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
418    public void UpdateSlaveGroup(SlaveGroup slaveGroup) {
419      trans.UseTransaction(() => {
420        dao.UpdateSlaveGroup(slaveGroup);
421      });
422    }
423
424    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
425    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
426    public void DeleteSlave(Guid slaveId) {
427      trans.UseTransaction(() => {
428        dao.DeleteSlave(slaveId);
429      });
430    }
431
432    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
433    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
434    public void DeleteSlaveGroup(Guid slaveGroupId) {
435      trans.UseTransaction(() => {
436        dao.DeleteSlaveGroup(slaveGroupId);
437      });
438    }
439
440    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
441    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
442    public void AddResourceToGroup(Guid slaveGroupId, Guid resourceId) {
443      trans.UseTransaction(() => {
444        var resource = dao.GetResource(resourceId);
445        resource.ParentResourceId = slaveGroupId;
446        dao.UpdateResource(resource);
447      });
448    }
449
450    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
451    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
452    public void RemoveResourceFromGroup(Guid slaveGroupId, Guid resourceId) {
453      trans.UseTransaction(() => {
454        var resource = dao.GetResource(resourceId);
455        resource.ParentResourceId = null;
456        dao.UpdateResource(resource);
457      });
458    }
459
460    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
461    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
462    public Guid GetResourceId(string resourceName) {
463      return trans.UseTransaction(() => {
464        var resource = dao.GetResources(x => x.Name == resourceName).FirstOrDefault();
465        if (resource != null) {
466          return resource.Id;
467        } else {
468          return Guid.Empty;
469        }
470      });
471    }
472
473    public void TriggerLifecycle(bool force) {
474      // use a serializable transaction here to ensure not two threads execute this simultaniously (locking would not work since IIS may use multiple AppDomains)
475      trans.UseTransaction(() => {
476        DateTime lastCleanup = dao.GetLastCleanup();
477        if (force || DateTime.Now - lastCleanup > TimeSpan.FromSeconds(59)) {
478          dao.SetLastCleanup(DateTime.Now);
479          lifecycleManager.Cleanup();
480        }
481      }, true);
482    }
483    #endregion
484
485    #region Helper Methods
486    private IEnumerable<Job> GetChildJobs(Guid? parentJobId, bool recursive, bool includeParent) {
487      var jobs = new List<Job>(dao.GetJobs(x => parentJobId == null ? !x.ParentJobId.HasValue : x.ParentJobId.Value == parentJobId));
488
489      if (recursive) {
490        var childs = new List<Job>();
491        foreach (var job in jobs) {
492          childs.AddRange(GetChildJobs(job.Id, recursive, false));
493        }
494        jobs.AddRange(childs);
495      }
496
497      if (includeParent) jobs.Add(GetJob(parentJobId.Value));
498
499      return jobs;
500    }
501
502    #endregion
503
504    #region Appointment Methods
505
506    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
507    public Guid AddAppointment(Appointment appointment) {
508      return trans.UseTransaction(() => dao.AddAppointment(appointment));
509    }
510
511    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
512    public void DeleteAppointment(Guid appointmentId) {
513      trans.UseTransaction(() => {
514        dao.DeleteAppointment(appointmentId);
515      });
516    }
517
518    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
519    public void UpdateAppointment(Appointment appointment) {
520      trans.UseTransaction(() => {
521        dao.UpdateAppointment(appointment);
522      });
523    }
524
525    // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
526    public IEnumerable<Appointment> GetScheduleForResource(Guid resourceId) {
527      return trans.UseTransaction(() => dao.GetAppointments(x => x.ResourceId == resourceId));
528    }
529
530    public IEnumerable<Job> GetJobsByResourceId(Guid resourceId) {
531      return trans.UseTransaction(() => dao.GetJobsByResourceId(resourceId));
532    }
533    #endregion
534  }
535}
Note: See TracBrowser for help on using the repository browser.