Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/16/11 04:59:43 (14 years ago)
Author:
swagner
Message:

Worked on OKB (#1174)

Location:
branches/OKB (trunk integration)/HeuristicLab.Services.OKB/3.3/Administration
Files:
9 added
2 edited

Legend:

Unmodified
Added
Removed
  • branches/OKB (trunk integration)/HeuristicLab.Services.OKB/3.3/Administration/AdministrationService.cs

    r5479 r5482  
    2222using System;
    2323using System.Collections.Generic;
    24 using System.Data.Linq;
    2524using System.Linq;
    26 using System.Security.Cryptography;
    2725using System.ServiceModel;
    2826using HeuristicLab.Services.OKB.DataAccess;
     
    3533  public class AdministrationService : IAdministrationService {
    3634    #region Platform Methods
    37     public DataTransfer.Platform GetPlatform(long id) {
    38       using (OKBDataContext okb = new OKBDataContext()) {
    39         return Convert.ToDto(okb.Platforms.FirstOrDefault(x => x.Id == id));
    40       }
    41     }
    4235    public IEnumerable<DataTransfer.Platform> GetPlatforms() {
    4336      using (OKBDataContext okb = new OKBDataContext()) {
     
    6962    #endregion
    7063
    71     #region DataType Methods
    72     public DataTransfer.DataType GetDataType(long id) {
    73       using (OKBDataContext okb = new OKBDataContext()) {
    74         return Convert.ToDto(okb.DataTypes.FirstOrDefault(x => x.Id == id));
    75       }
    76     }
    77     public long AddDataType(DataTransfer.DataType dto) {
    78       using (OKBDataContext okb = new OKBDataContext()) {
    79         var entity = okb.DataTypes.Where(x => (x.PlatformId == dto.PlatformId) && (x.Name == dto.Name) && (x.TypeName == dto.TypeName)).FirstOrDefault();
    80         if (entity == null) {
    81           entity = Convert.ToEntity(dto); entity.Id = 0;
    82           okb.DataTypes.InsertOnSubmit(entity);
    83           okb.SubmitChanges();
    84         }
    85         return entity.Id;
    86       }
    87     }
    88     #endregion
    89 
    90     #region BinaryData Methods
    91     public long GetBinaryDataId(byte[] hash) {
    92       using (OKBDataContext okb = new OKBDataContext()) {
    93         var id = okb.BinaryDatas.Where(x => x.Hash.Equals(hash)).Select(x => x.Id).FirstOrDefault();
    94         if (id == 0) return -1;
    95         else return id;
    96       }
    97     }
    98     public long AddBinaryData(DataTransfer.BinaryData dto) {
    99       byte[] hash;
    100       using (SHA1 sha1 = SHA1.Create()) {
    101         hash = sha1.ComputeHash(dto.Data);
    102       }
    103 
    104       using (OKBDataContext okb = new OKBDataContext()) {
    105         var id = okb.BinaryDatas.Where(x => x.Hash.Equals(hash)).Select(x => x.Id).FirstOrDefault();
    106         if (id != 0) {
    107           return id;
    108         } else {
    109           DataAccess.BinaryData entity = Convert.ToEntity(dto); entity.Id = 0;
    110           okb.BinaryDatas.InsertOnSubmit(entity);
    111           okb.SubmitChanges();
    112           return entity.Id;
    113         }
    114       }
    115     }
    116     #endregion
    117 
    11864    #region AlgorithmClass Methods
    119     public DataTransfer.AlgorithmClass GetAlgorithmClass(long id) {
    120       using (OKBDataContext okb = new OKBDataContext()) {
    121         return Convert.ToDto(okb.AlgorithmClasses.FirstOrDefault(x => x.Id == id));
    122       }
    123     }
    12465    public IEnumerable<DataTransfer.AlgorithmClass> GetAlgorithmClasses() {
    12566      using (OKBDataContext okb = new OKBDataContext()) {
     
    15293
    15394    #region Algorithm Methods
    154     public DataTransfer.Algorithm GetAlgorithm(long id) {
    155       using (OKBDataContext okb = new OKBDataContext()) {
    156         return Convert.ToDto(okb.Algorithms.FirstOrDefault(x => x.Id == id));
    157       }
    158     }
    15995    public IEnumerable<DataTransfer.Algorithm> GetAlgorithms() {
    16096      using (OKBDataContext okb = new OKBDataContext()) {
     
    164100    public long AddAlgorithm(DataTransfer.Algorithm dto) {
    165101      using (OKBDataContext okb = new OKBDataContext()) {
    166         DataAccess.Algorithm entity = Convert.ToEntity(dto); entity.Id = 0;
     102        DataAccess.Algorithm entity = Convert.ToEntity(dto, okb); entity.Id = 0;
    167103        okb.Algorithms.InsertOnSubmit(entity);
    168104        okb.SubmitChanges();
     
    173109      using (OKBDataContext okb = new OKBDataContext()) {
    174110        DataAccess.Algorithm entity = okb.Algorithms.FirstOrDefault(x => x.Id == dto.Id);
    175         Convert.ToEntity(dto, entity);
     111        Convert.ToEntity(dto, entity, okb);
    176112        okb.SubmitChanges();
    177113      }
     
    196132      }
    197133    }
    198     public DataTransfer.BinaryData GetAlgorithmData(long algorithmId) {
    199       using (OKBDataContext okb = new OKBDataContext()) {
    200         DataLoadOptions dlo = new DataLoadOptions();
    201         dlo.LoadWith<Algorithm>(x => x.BinaryData);
    202         okb.LoadOptions = dlo;
    203         return Convert.ToDto(okb.Algorithms.Where(x => x.Id == algorithmId).Select(x => x.BinaryData).FirstOrDefault());
     134    public byte[] GetAlgorithmData(long algorithmId) {
     135      using (OKBDataContext okb = new OKBDataContext()) {
     136        return okb.Algorithms.Where(x => x.Id == algorithmId).Select(x => x.BinaryData.Data.ToArray()).FirstOrDefault();
     137      }
     138    }
     139    public void UpdateAlgorithmData(long algorithmId, byte[] data) {
     140      using (OKBDataContext okb = new OKBDataContext()) {
     141        var entity = okb.Algorithms.Where(x => x.Id == algorithmId).FirstOrDefault();
     142        if (entity != null)
     143          entity.BinaryData = Convert.ToEntity(data, okb);
     144        okb.SubmitChanges();
    204145      }
    205146    }
     
    207148
    208149    #region ProblemClass Methods
    209     public DataTransfer.ProblemClass GetProblemClass(long id) {
    210       using (OKBDataContext okb = new OKBDataContext()) {
    211         return Convert.ToDto(okb.ProblemClasses.FirstOrDefault(x => x.Id == id));
    212       }
    213     }
    214150    public IEnumerable<DataTransfer.ProblemClass> GetProblemClasses() {
    215151      using (OKBDataContext okb = new OKBDataContext()) {
     
    242178
    243179    #region Problem Methods
    244     public DataTransfer.Problem GetProblem(long id) {
    245       using (OKBDataContext okb = new OKBDataContext()) {
    246         return Convert.ToDto(okb.Problems.FirstOrDefault(x => x.Id == id));
    247       }
    248     }
    249180    public IEnumerable<DataTransfer.Problem> GetProblems() {
    250181      using (OKBDataContext okb = new OKBDataContext()) {
     
    254185    public long AddProblem(DataTransfer.Problem dto) {
    255186      using (OKBDataContext okb = new OKBDataContext()) {
    256         DataAccess.Problem entity = Convert.ToEntity(dto); entity.Id = 0;
     187        DataAccess.Problem entity = Convert.ToEntity(dto, okb); entity.Id = 0;
    257188        okb.Problems.InsertOnSubmit(entity);
    258189        okb.SubmitChanges();
     
    263194      using (OKBDataContext okb = new OKBDataContext()) {
    264195        DataAccess.Problem entity = okb.Problems.FirstOrDefault(x => x.Id == dto.Id);
    265         Convert.ToEntity(dto, entity);
     196        Convert.ToEntity(dto, entity, okb);
    266197        okb.SubmitChanges();
    267198      }
     
    286217      }
    287218    }
    288     public DataTransfer.BinaryData GetProblemData(long problemId) {
    289       using (OKBDataContext okb = new OKBDataContext()) {
    290         DataLoadOptions dlo = new DataLoadOptions();
    291         dlo.LoadWith<Problem>(x => x.BinaryData);
    292         okb.LoadOptions = dlo;
    293         return Convert.ToDto(okb.Problems.Where(x => x.Id == problemId).Select(x => x.BinaryData).FirstOrDefault());
    294       }
    295     }
    296     #endregion
    297 
    298     #region Run Methods
    299     public DataTransfer.Run GetRun(long id) {
    300       using (OKBDataContext okb = new OKBDataContext()) {
    301         DataLoadOptions dlo = new DataLoadOptions();
    302         dlo.LoadWith<Run>(x => x.Values);
    303         dlo.LoadWith<Value>(x => x.ValueName);
    304         okb.LoadOptions = dlo;
    305         return Convert.ToDto(okb.Runs.FirstOrDefault(x => x.Id == id));
    306       }
    307     }
    308     public IEnumerable<DataTransfer.Run> GetRuns(long algorithmId, long problemId) {
    309       using (OKBDataContext okb = new OKBDataContext()) {
    310         DataLoadOptions dlo = new DataLoadOptions();
    311         dlo.LoadWith<Run>(x => x.Values);
    312         dlo.LoadWith<Value>(x => x.ValueName);
    313         okb.LoadOptions = dlo;
    314         if ((algorithmId != 0) && (problemId != 0))
    315           return okb.Runs.Where(x => (x.AlgorithmId == algorithmId) && (x.ProblemId == problemId)).Select(x => Convert.ToDto(x)).ToArray();
    316         else if (algorithmId != 0)
    317           return okb.Runs.Where(x => x.AlgorithmId == algorithmId).Select(x => Convert.ToDto(x)).ToArray();
    318         else if (problemId != 0)
    319           return okb.Runs.Where(x => x.ProblemId == problemId).Select(x => Convert.ToDto(x)).ToArray();
    320         else
    321           return okb.Runs.Select(x => Convert.ToDto(x)).ToArray();
    322       }
    323     }
    324     public long AddRun(DataTransfer.Run dto) {
    325       using (OKBDataContext okb = new OKBDataContext()) {
    326         DataAccess.Run entity = Convert.ToEntity(dto); entity.Id = 0;
    327         okb.Runs.InsertOnSubmit(entity);
    328         okb.SubmitChanges();
    329         return entity.Id;
    330       }
    331     }
    332     public void DeleteRun(long id) {
    333       using (OKBDataContext okb = new OKBDataContext()) {
    334         IEnumerable<DataAccess.ResultBlobValue> resultBlobValues = okb.ResultBlobValues.Where(x => x.RunId == id);
    335         okb.ResultBlobValues.DeleteAllOnSubmit(resultBlobValues);
    336         IEnumerable<DataAccess.ResultBoolValue> resultBoolValues = okb.ResultBoolValues.Where(x => x.RunId == id);
    337         okb.ResultBoolValues.DeleteAllOnSubmit(resultBoolValues);
    338         IEnumerable<DataAccess.ResultFloatValue> resultFloatValues = okb.ResultFloatValues.Where(x => x.RunId == id);
    339         okb.ResultFloatValues.DeleteAllOnSubmit(resultFloatValues);
    340         IEnumerable<DataAccess.ResultIntValue> resultIntValues = okb.ResultIntValues.Where(x => x.RunId == id);
    341         okb.ResultIntValues.DeleteAllOnSubmit(resultIntValues);
    342         IEnumerable<DataAccess.ResultStringValue> resultStringValues = okb.ResultStringValues.Where(x => x.RunId == id);
    343         okb.ResultStringValues.DeleteAllOnSubmit(resultStringValues);
    344 
    345         DataAccess.Run entity = okb.Runs.FirstOrDefault(x => x.Id == id);
    346         if (entity != null) okb.Runs.DeleteOnSubmit(entity);
     219    public byte[] GetProblemData(long problemId) {
     220      using (OKBDataContext okb = new OKBDataContext()) {
     221        return okb.Problems.Where(x => x.Id == problemId).Select(x => x.BinaryData.Data.ToArray()).FirstOrDefault();
     222      }
     223    }
     224    public void UpdateProblemData(long problemId, byte[] data) {
     225      using (OKBDataContext okb = new OKBDataContext()) {
     226        var entity = okb.Problems.Where(x => x.Id == problemId).FirstOrDefault();
     227        if (entity != null)
     228          entity.BinaryData = Convert.ToEntity(data, okb);
    347229        okb.SubmitChanges();
    348230      }
  • branches/OKB (trunk integration)/HeuristicLab.Services.OKB/3.3/Administration/IAdministrationService.cs

    r5479 r5482  
    2424using System.Net.Security;
    2525using System.ServiceModel;
    26 using HeuristicLab.Services.OKB.DataTransfer;
     26using HeuristicLab.Services.OKB.Administration.DataTransfer;
    2727
    2828namespace HeuristicLab.Services.OKB.Administration {
     
    3333  public interface IAdministrationService {
    3434    #region Platform Methods
    35     [OperationContract]
    36     Platform GetPlatform(long id);
    3735    [OperationContract]
    3836    IEnumerable<Platform> GetPlatforms();
     
    4543    #endregion
    4644
    47     #region DataType Methods
    48     [OperationContract]
    49     DataType GetDataType(long id);
    50     [OperationContract]
    51     long AddDataType(DataType dto);
    52     #endregion
    53 
    54     #region BinaryData Methods
    55     [OperationContract]
    56     long GetBinaryDataId(byte[] hash);
    57     [OperationContract]
    58     long AddBinaryData(BinaryData dto);
    59     #endregion
    60 
    6145    #region AlgorithmClass Methods
    62     [OperationContract]
    63     AlgorithmClass GetAlgorithmClass(long id);
    6446    [OperationContract]
    6547    IEnumerable<AlgorithmClass> GetAlgorithmClasses();
     
    7355
    7456    #region Algorithm Methods
    75     [OperationContract]
    76     Algorithm GetAlgorithm(long id);
    7757    [OperationContract]
    7858    IEnumerable<Algorithm> GetAlgorithms();
     
    8868    void UpdateAlgorithmUsers(long algorithmId, IEnumerable<Guid> users);
    8969    [OperationContract]
    90     BinaryData GetAlgorithmData(long algorithmId);
     70    byte[] GetAlgorithmData(long algorithmId);
     71    [OperationContract]
     72    void UpdateAlgorithmData(long algorithmId, byte[] data);
    9173    #endregion
    9274
    9375    #region ProblemClass Methods
    94     [OperationContract]
    95     ProblemClass GetProblemClass(long id);
    9676    [OperationContract]
    9777    IEnumerable<ProblemClass> GetProblemClasses();
     
    10585
    10686    #region Problem Methods
    107     [OperationContract]
    108     Problem GetProblem(long id);
    10987    [OperationContract]
    11088    IEnumerable<Problem> GetProblems();
     
    12098    void UpdateProblemUsers(long problemId, IEnumerable<Guid> users);
    12199    [OperationContract]
    122     BinaryData GetProblemData(long problemId);
    123     #endregion
    124 
    125     #region Run Methods
     100    byte[] GetProblemData(long problemId);
    126101    [OperationContract]
    127     Run GetRun(long id);
    128     [OperationContract]
    129     IEnumerable<Run> GetRuns(long algorithmId, long problemId);
    130     [OperationContract]
    131     long AddRun(Run dto);
    132     [OperationContract]
    133     void DeleteRun(long id);
     102    void UpdateProblemData(long problemId, byte[] data);
    134103    #endregion
    135104  }
Note: See TracChangeset for help on using the changeset viewer.