#region License Information
/* HeuristicLab
* Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using HeuristicLab.Hive.Contracts.BusinessObjects;
using HeuristicLab.Hive.Server.DataAccess;
namespace HeuristicLab.Hive.Server.LINQDataAccess {
public class PluginInfoDao: BaseDao, IPluginInfoDao {
#region IGenericDao Members
public HivePluginInfoDto FindById(Guid id) {
return (from pi in Context.PluginInfos
where pi.PluginId.Equals(id)
select EntityToDto(pi, null)
).SingleOrDefault();
}
public IEnumerable FindAll() {
return (from pi in Context.PluginInfos
select EntityToDto(pi, null)
).ToList();
}
public HivePluginInfoDto Insert(HivePluginInfoDto bObj) {
PluginInfo pi = DtoToEntity(bObj, null);
Context.PluginInfos.InsertOnSubmit(pi);
CommitChanges();
bObj.Id = pi.PluginId;
return bObj;
}
public void Delete(Guid id) {
PluginInfo pi = Context.PluginInfos.SingleOrDefault(p => p.PluginId.Equals(id));
Context.PluginInfos.DeleteOnSubmit(pi);
}
public void Update(HivePluginInfoDto bObj) {
PluginInfo pi = Context.PluginInfos.SingleOrDefault(p => p.PluginId.Equals(bObj.Id));
DtoToEntity(bObj, pi);
CommitChanges();
}
public void InsertPluginDependenciesForJob(JobDto jobDto) {
foreach (HivePluginInfoDto info in jobDto.PluginsNeeded) {
PluginInfo dbpi =
Context.PluginInfos.Where(pi => pi.Name.Equals(info.Name) && pi.Version == info.Version.ToString()).SingleOrDefault();
if (dbpi == null) {
dbpi = new PluginInfo {
Name = info.Name,
Version = info.Version.ToString()
};
Context.PluginInfos.InsertOnSubmit(dbpi);
CommitChanges();
}
RequiredPlugin rq = new RequiredPlugin();
rq.JobId = jobDto.Id;
rq.PluginInfo = dbpi;
Context.RequiredPlugins.InsertOnSubmit(rq);
CommitChanges();
}
}
public List GetPluginDependenciesForJob(JobDto jobDto) {
return (from rp in Context.RequiredPlugins
where rp.JobId.Equals(jobDto.Id)
select EntityToDto(rp.PluginInfo, null)).ToList();
}
#endregion
// Build Date not mapped - won't matter anyway, it's a obsolete field.
public override PluginInfo DtoToEntity(HivePluginInfoDto source, PluginInfo target) {
if (source == null)
return null;
if (target == null)
target = new PluginInfo();
target.Name = source.Name;
target.PluginId = source.Id;
target.Version = source.Version.ToString();
return target;
}
public override HivePluginInfoDto EntityToDto(PluginInfo source, HivePluginInfoDto target) {
if (source == null)
return null;
if (target == null)
target = new HivePluginInfoDto();
target.Name = source.Name;
target.Id = source.PluginId;
target.Version = new Version(source.Version);
return target;
}
}
}