Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3.3-Hive/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.LINQDataAccess/3.3/PluginInfoDao.cs @ 4539

Last change on this file since 4539 was 4424, checked in by cneumuel, 14 years ago
  • Added and updated License Information in every file
  • Sort and remove usings in every file
  • Deleted obsolete DataAccess.ADOHelper
  • Deleted some obsolete files
File size: 4.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using HeuristicLab.Hive.Contracts.BusinessObjects;
26using HeuristicLab.Hive.Server.DataAccess;
27
28namespace HeuristicLab.Hive.Server.LINQDataAccess {
29  public class PluginInfoDao: BaseDao<HivePluginInfoDto, PluginInfo>, IPluginInfoDao {
30    #region IGenericDao<HivePluginInfoDto,PluginInfo> Members
31
32    public HivePluginInfoDto FindById(Guid id) {
33      return (from pi in Context.PluginInfos
34              where pi.PluginId.Equals(id)
35              select EntityToDto(pi, null)
36             ).SingleOrDefault(); 
37    }
38
39    public IEnumerable<HivePluginInfoDto> FindAll() {
40      return (from pi in Context.PluginInfos             
41              select EntityToDto(pi, null)
42       ).ToList(); 
43    }
44
45    public HivePluginInfoDto Insert(HivePluginInfoDto bObj) {
46      PluginInfo pi = DtoToEntity(bObj, null);
47      Context.PluginInfos.InsertOnSubmit(pi);
48      CommitChanges();
49      bObj.Id = pi.PluginId;
50      return bObj;
51    }
52
53    public void Delete(Guid id) {
54      PluginInfo pi = Context.PluginInfos.SingleOrDefault(p => p.PluginId.Equals(id));
55      Context.PluginInfos.DeleteOnSubmit(pi);     
56    }
57
58    public void Update(HivePluginInfoDto bObj) {
59      PluginInfo pi = Context.PluginInfos.SingleOrDefault(p => p.PluginId.Equals(bObj.Id));
60      DtoToEntity(bObj, pi);
61      CommitChanges();
62    }
63
64    public void InsertPluginDependenciesForJob(JobDto jobDto) {
65      foreach (HivePluginInfoDto info in jobDto.PluginsNeeded) {               
66        PluginInfo dbpi =
67          Context.PluginInfos.Where(pi => pi.Name.Equals(info.Name) && pi.Version == info.Version.ToString()).SingleOrDefault();
68        if (dbpi == null) {
69          dbpi = new PluginInfo {
70                                  Name = info.Name,
71                                  Version = info.Version.ToString()
72                                };
73          Context.PluginInfos.InsertOnSubmit(dbpi);
74          CommitChanges();
75        }
76
77        RequiredPlugin rq = new RequiredPlugin();
78        rq.JobId = jobDto.Id;
79        rq.PluginInfo = dbpi;
80        Context.RequiredPlugins.InsertOnSubmit(rq);
81        CommitChanges();
82      }
83    }
84
85    public List<HivePluginInfoDto> GetPluginDependenciesForJob(JobDto jobDto) {
86      return (from rp in Context.RequiredPlugins
87              where rp.JobId.Equals(jobDto.Id)
88              select EntityToDto(rp.PluginInfo, null)).ToList();
89     
90    }
91
92    #endregion
93
94    // Build Date not mapped - won't matter anyway, it's a obsolete field.
95    public override PluginInfo DtoToEntity(HivePluginInfoDto source, PluginInfo target) {
96      if (source == null)
97        return null;
98      if (target == null)
99        target = new PluginInfo();
100
101      target.Name = source.Name;
102      target.PluginId = source.Id;
103      target.Version = source.Version.ToString();     
104
105      return target;
106
107    }
108
109    public override HivePluginInfoDto EntityToDto(PluginInfo source, HivePluginInfoDto target) {
110      if (source == null)
111        return null;
112      if (target == null)
113        target = new HivePluginInfoDto();
114
115      target.Name = source.Name;
116      target.Id = source.PluginId;
117      target.Version = new Version(source.Version);
118
119      return target;
120    }
121  }
122}
Note: See TracBrowser for help on using the repository browser.