Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Hive.Server.LINQDataAccess/3.2/PluginInfoDao.cs @ 3578

Last change on this file since 3578 was 3578, checked in by kgrading, 14 years ago

Removed References to HiveLogging and updated the default logging mechanism (#991)

File size: 3.3 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.Hive.Contracts.BusinessObjects;
6using HeuristicLab.Hive.Server.DataAccess;
7
8namespace HeuristicLab.Hive.Server.LINQDataAccess {
9  public class PluginInfoDao: BaseDao<HivePluginInfoDto, PluginInfo>, IPluginInfoDao {
10    #region IGenericDao<HivePluginInfoDto,PluginInfo> Members
11
12    public HivePluginInfoDto FindById(Guid id) {
13      return (from pi in Context.PluginInfos
14              where pi.PluginId.Equals(id)
15              select EntityToDto(pi, null)
16             ).SingleOrDefault(); 
17    }
18
19    public IEnumerable<HivePluginInfoDto> FindAll() {
20      return (from pi in Context.PluginInfos             
21              select EntityToDto(pi, null)
22       ).ToList(); 
23    }
24
25    public HivePluginInfoDto Insert(HivePluginInfoDto bObj) {
26      PluginInfo pi = DtoToEntity(bObj, null);
27      Context.PluginInfos.InsertOnSubmit(pi);
28      CommitChanges();
29      bObj.Id = pi.PluginId;
30      return bObj;
31    }
32
33    public void Delete(HivePluginInfoDto bObj) {
34      PluginInfo pi = Context.PluginInfos.SingleOrDefault(p => p.PluginId.Equals(bObj.Id));
35      Context.PluginInfos.DeleteOnSubmit(pi);     
36    }
37
38    public void Update(HivePluginInfoDto bObj) {
39      PluginInfo pi = Context.PluginInfos.SingleOrDefault(p => p.PluginId.Equals(bObj.Id));
40      DtoToEntity(bObj, pi);
41      CommitChanges();
42    }
43
44    public void InsertPluginDependenciesForJob(JobDto jobDto) {
45      foreach (HivePluginInfoDto info in jobDto.PluginsNeeded) {       
46        PluginInfo dbpi =
47          Context.PluginInfos.Where(pi => pi.Name.Equals(info.Name) && pi.Version == info.Version).SingleOrDefault();
48        if (dbpi == null) {
49          dbpi = new PluginInfo {
50                                  BuildDate = info.BuildDate.ToString(),
51                                  Name = info.Name,
52                                  Version = info.Version
53                                };
54          Context.PluginInfos.InsertOnSubmit(dbpi);
55          CommitChanges();
56        }
57
58        RequiredPlugin rq = new RequiredPlugin();
59        rq.JobId = jobDto.Id;
60        rq.PluginInfo = dbpi;
61        Context.RequiredPlugins.InsertOnSubmit(rq);
62        CommitChanges();
63      }
64    }
65
66    public List<HivePluginInfoDto> GetPluginDependenciesForJob(JobDto jobDto) {
67      return (from rp in Context.RequiredPlugins
68              where rp.JobId.Equals(jobDto.Id)
69              select EntityToDto(rp.PluginInfo, null)).ToList();
70     
71    }
72
73    #endregion
74
75    // Build Date not mapped - won't matter anyway, it's a obsolete field.
76    public override PluginInfo DtoToEntity(HivePluginInfoDto source, PluginInfo target) {
77      if (source == null)
78        return null;
79      if (target == null)
80        target = new PluginInfo();
81
82      target.Name = source.Name;
83      target.PluginId = source.Id;
84      target.Version = source.Version;     
85
86      return target;
87
88    }
89
90    public override HivePluginInfoDto EntityToDto(PluginInfo source, HivePluginInfoDto target) {
91      if (source == null)
92        return null;
93      if (target == null)
94        target = new HivePluginInfoDto();
95
96      target.Name = source.Name;
97      target.Id = source.PluginId;
98      target.Version = source.Version;
99
100      return target;
101    }
102  }
103}
Note: See TracBrowser for help on using the repository browser.