#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.Collections.Generic;
using System.Data.Linq;
using System.Linq;
using System.ServiceModel;
using HeuristicLab.Services.OKB.DataAccess;
namespace HeuristicLab.Services.OKB.RunCreation {
///
/// Implementation of the OKB run creation service (interface ).
///
[ServiceBehavior(IncludeExceptionDetailInFaults = true)]
public class RunCreationService : IRunCreationService {
public IEnumerable GetAlgorithms(string platformName) {
using (OKBDataContext okb = new OKBDataContext()) {
DataLoadOptions dlo = new DataLoadOptions();
dlo.LoadWith(x => x.AlgorithmClass);
dlo.LoadWith(x => x.DataType);
okb.LoadOptions = dlo;
return okb.Algorithms.Where(x => x.Platform.Name == platformName).Select(x => Convert.ToDto(x)).ToArray();
}
}
public byte[] GetAlgorithmData(long algorithmId) {
using (OKBDataContext okb = new OKBDataContext()) {
return okb.Algorithms.Where(x => x.Id == algorithmId).Select(x => x.BinaryData.Data.ToArray()).FirstOrDefault();
}
}
public IEnumerable GetProblems(string platformName) {
using (OKBDataContext okb = new OKBDataContext()) {
DataLoadOptions dlo = new DataLoadOptions();
dlo.LoadWith(x => x.ProblemClass);
dlo.LoadWith(x => x.DataType);
okb.LoadOptions = dlo;
return okb.Problems.Where(x => x.Platform.Name == platformName).Select(x => Convert.ToDto(x)).ToArray();
}
}
public byte[] GetProblemData(long problemId) {
using (OKBDataContext okb = new OKBDataContext()) {
return okb.Problems.Where(x => x.Id == problemId).Select(x => x.BinaryData.Data.ToArray()).FirstOrDefault();
}
}
public long AddRun(DataTransfer.Run run) {
using (OKBDataContext okb = new OKBDataContext()) {
DataAccess.Run entity = Convert.ToEntity(run, okb);
okb.Runs.InsertOnSubmit(entity);
okb.SubmitChanges();
return entity.Id;
}
}
}
}