Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/24/10 06:53:43 (14 years ago)
Author:
swagner
Message:

Worked on OKB (#1174)

Location:
branches/OKB/HeuristicLab.Services.OKB/3.3
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/OKB/HeuristicLab.Services.OKB/3.3/AdminService.cs

    r4467 r4481  
    4343      }
    4444    }
    45     public void StorePlatform(DataTransfer.Platform dto) {
     45    public long AddPlatform(DataTransfer.Platform dto) {
     46      using (OKBDataContext okb = new OKBDataContext()) {
     47        DataAccess.Platform entity = Convert.ToEntity(dto); entity.Id = 0;
     48        okb.Platforms.InsertOnSubmit(entity);
     49        okb.SubmitChanges();
     50        return entity.Id;
     51      }
     52    }
     53    public void UpdatePlatform(DataTransfer.Platform dto) {
    4654      using (OKBDataContext okb = new OKBDataContext()) {
    4755        DataAccess.Platform entity = okb.Platforms.FirstOrDefault(x => x.Id == dto.Id);
    48         if (entity == null) okb.Platforms.InsertOnSubmit(Convert.ToEntity(dto));
    49         else Convert.ToEntity(dto, entity);
     56        Convert.ToEntity(dto, entity);
    5057        okb.SubmitChanges();
    5158      }
     
    6067    #endregion
    6168
     69    #region DataType Methods
     70    public DataTransfer.DataType GetDataType(long id) {
     71      using (OKBDataContext okb = new OKBDataContext()) {
     72        return Convert.ToDto(okb.DataTypes.FirstOrDefault(x => x.Id == id));
     73      }
     74    }
     75    public IEnumerable<DataTransfer.DataType> GetDataTypes() {
     76      using (OKBDataContext okb = new OKBDataContext()) {
     77        return okb.DataTypes.Select(x => Convert.ToDto(x)).ToArray();
     78      }
     79    }
     80    public long AddDataType(DataTransfer.DataType dto) {
     81      using (OKBDataContext okb = new OKBDataContext()) {
     82        DataAccess.DataType entity = Convert.ToEntity(dto); entity.Id = 0;
     83        okb.DataTypes.InsertOnSubmit(entity);
     84        okb.SubmitChanges();
     85        return entity.Id;
     86      }
     87    }
     88    public void UpdateDataType(DataTransfer.DataType dto) {
     89      using (OKBDataContext okb = new OKBDataContext()) {
     90        DataAccess.DataType entity = okb.DataTypes.FirstOrDefault(x => x.Id == dto.Id);
     91        Convert.ToEntity(dto, entity);
     92        okb.SubmitChanges();
     93      }
     94    }
     95    public void DeleteDataType(long id) {
     96      using (OKBDataContext okb = new OKBDataContext()) {
     97        DataAccess.DataType entity = okb.DataTypes.FirstOrDefault(x => x.Id == id);
     98        if (entity != null) okb.DataTypes.DeleteOnSubmit(entity);
     99        okb.SubmitChanges();
     100      }
     101    }
     102    #endregion
     103
    62104    #region AlgorithmClass Methods
    63105    public DataTransfer.AlgorithmClass GetAlgorithmClass(long id) {
     
    71113      }
    72114    }
    73     public void StoreAlgorithmClass(DataTransfer.AlgorithmClass dto) {
     115    public long AddAlgorithmClass(DataTransfer.AlgorithmClass dto) {
     116      using (OKBDataContext okb = new OKBDataContext()) {
     117        DataAccess.AlgorithmClass entity = Convert.ToEntity(dto); entity.Id = 0;
     118        okb.AlgorithmClasses.InsertOnSubmit(entity);
     119        okb.SubmitChanges();
     120        return entity.Id;
     121      }
     122    }
     123    public void UpdateAlgorithmClass(DataTransfer.AlgorithmClass dto) {
    74124      using (OKBDataContext okb = new OKBDataContext()) {
    75125        DataAccess.AlgorithmClass entity = okb.AlgorithmClasses.FirstOrDefault(x => x.Id == dto.Id);
    76         if (entity == null) okb.AlgorithmClasses.InsertOnSubmit(Convert.ToEntity(dto));
    77         else Convert.ToEntity(dto, entity);
     126        Convert.ToEntity(dto, entity);
    78127        okb.SubmitChanges();
    79128      }
     
    99148      }
    100149    }
    101     public void StoreAlgorithm(DataTransfer.Algorithm dto) {
     150    public long AddAlgorithm(DataTransfer.Algorithm dto) {
     151      using (OKBDataContext okb = new OKBDataContext()) {
     152        DataAccess.Algorithm entity = Convert.ToEntity(dto); entity.Id = 0;
     153        okb.Algorithms.InsertOnSubmit(entity);
     154        okb.SubmitChanges();
     155        return entity.Id;
     156      }
     157    }
     158    public void UpdateAlgorithm(DataTransfer.Algorithm dto) {
    102159      using (OKBDataContext okb = new OKBDataContext()) {
    103160        DataAccess.Algorithm entity = okb.Algorithms.FirstOrDefault(x => x.Id == dto.Id);
    104         if (entity == null) okb.Algorithms.InsertOnSubmit(Convert.ToEntity(dto));
    105         else Convert.ToEntity(dto, entity);
     161        Convert.ToEntity(dto, entity);
    106162        okb.SubmitChanges();
    107163      }
     
    119175      }
    120176    }
    121     public void StoreAlgorithmUsers(long algorithmId, IEnumerable<Guid> users) {
     177    public void UpdateAlgorithmUsers(long algorithmId, IEnumerable<Guid> users) {
    122178      using (OKBDataContext okb = new OKBDataContext()) {
    123179        okb.AlgorithmUsers.DeleteAllOnSubmit(okb.AlgorithmUsers.Where(x => x.AlgorithmId == algorithmId));
     
    134190      }
    135191    }
    136     public void StoreAlgorithmData(DataTransfer.AlgorithmData dto) {
     192    public void UpdateAlgorithmData(DataTransfer.AlgorithmData dto) {
    137193      using (OKBDataContext okb = new OKBDataContext()) {
    138194        DataAccess.AlgorithmData entity = okb.AlgorithmDatas.FirstOrDefault(x => x.AlgorithmId == dto.AlgorithmId);
     
    144200    #endregion
    145201
    146     #region DataType Methods
    147     public DataTransfer.DataType GetDataType(long id) {
    148       using (OKBDataContext okb = new OKBDataContext()) {
    149         return Convert.ToDto(okb.DataTypes.FirstOrDefault(x => x.Id == id));
    150       }
    151     }
    152     public IEnumerable<DataTransfer.DataType> GetDataTypes() {
    153       using (OKBDataContext okb = new OKBDataContext()) {
    154         return okb.DataTypes.Select(x => Convert.ToDto(x)).ToArray();
    155       }
    156     }
    157     public void StoreDataType(DataTransfer.DataType dto) {
    158       using (OKBDataContext okb = new OKBDataContext()) {
    159         DataAccess.DataType entity = okb.DataTypes.FirstOrDefault(x => x.Id == dto.Id);
    160         if (entity == null) okb.DataTypes.InsertOnSubmit(Convert.ToEntity(dto));
     202    #region ProblemClass Methods
     203    public DataTransfer.ProblemClass GetProblemClass(long id) {
     204      using (OKBDataContext okb = new OKBDataContext()) {
     205        return Convert.ToDto(okb.ProblemClasses.FirstOrDefault(x => x.Id == id));
     206      }
     207    }
     208    public IEnumerable<DataTransfer.ProblemClass> GetProblemClasses() {
     209      using (OKBDataContext okb = new OKBDataContext()) {
     210        return okb.ProblemClasses.Select(x => Convert.ToDto(x)).ToArray();
     211      }
     212    }
     213    public long AddProblemClass(DataTransfer.ProblemClass dto) {
     214      using (OKBDataContext okb = new OKBDataContext()) {
     215        DataAccess.ProblemClass entity = Convert.ToEntity(dto); entity.Id = 0;
     216        okb.ProblemClasses.InsertOnSubmit(entity);
     217        okb.SubmitChanges();
     218        return entity.Id;
     219      }
     220    }
     221    public void UpdateProblemClass(DataTransfer.ProblemClass dto) {
     222      using (OKBDataContext okb = new OKBDataContext()) {
     223        DataAccess.ProblemClass entity = okb.ProblemClasses.FirstOrDefault(x => x.Id == dto.Id);
     224        Convert.ToEntity(dto, entity);
     225        okb.SubmitChanges();
     226      }
     227    }
     228    public void DeleteProblemClass(long id) {
     229      using (OKBDataContext okb = new OKBDataContext()) {
     230        DataAccess.ProblemClass entity = okb.ProblemClasses.FirstOrDefault(x => x.Id == id);
     231        if (entity != null) okb.ProblemClasses.DeleteOnSubmit(entity);
     232        okb.SubmitChanges();
     233      }
     234    }
     235    #endregion
     236
     237    #region Problem Methods
     238    public DataTransfer.Problem GetProblem(long id) {
     239      using (OKBDataContext okb = new OKBDataContext()) {
     240        return Convert.ToDto(okb.Problems.FirstOrDefault(x => x.Id == id));
     241      }
     242    }
     243    public IEnumerable<DataTransfer.Problem> GetProblems() {
     244      using (OKBDataContext okb = new OKBDataContext()) {
     245        return okb.Problems.Select(x => Convert.ToDto(x)).ToArray();
     246      }
     247    }
     248    public long AddProblem(DataTransfer.Problem dto) {
     249      using (OKBDataContext okb = new OKBDataContext()) {
     250        DataAccess.Problem entity = Convert.ToEntity(dto); entity.Id = 0;
     251        okb.Problems.InsertOnSubmit(entity);
     252        okb.SubmitChanges();
     253        return entity.Id;
     254      }
     255    }
     256    public void UpdateProblem(DataTransfer.Problem dto) {
     257      using (OKBDataContext okb = new OKBDataContext()) {
     258        DataAccess.Problem entity = okb.Problems.FirstOrDefault(x => x.Id == dto.Id);
     259        Convert.ToEntity(dto, entity);
     260        okb.SubmitChanges();
     261      }
     262    }
     263    public void DeleteProblem(long id) {
     264      using (OKBDataContext okb = new OKBDataContext()) {
     265        DataAccess.Problem entity = okb.Problems.FirstOrDefault(x => x.Id == id);
     266        if (entity != null) okb.Problems.DeleteOnSubmit(entity);
     267        okb.SubmitChanges();
     268      }
     269    }
     270    public IEnumerable<Guid> GetProblemUsers(long problemId) {
     271      using (OKBDataContext okb = new OKBDataContext()) {
     272        return okb.ProblemUsers.Where(x => x.ProblemId == problemId).Select(x => x.UserId).ToArray();
     273      }
     274    }
     275    public void UpdateProblemUsers(long problemId, IEnumerable<Guid> users) {
     276      using (OKBDataContext okb = new OKBDataContext()) {
     277        okb.ProblemUsers.DeleteAllOnSubmit(okb.ProblemUsers.Where(x => x.ProblemId == problemId));
     278        okb.ProblemUsers.InsertAllOnSubmit(users.Select(x => new DataAccess.ProblemUser { ProblemId = problemId, UserId = x }));
     279        okb.SubmitChanges();
     280      }
     281    }
     282    #endregion
     283
     284    #region ProblemData Methods
     285    public DataTransfer.ProblemData GetProblemData(long problemId) {
     286      using (OKBDataContext okb = new OKBDataContext()) {
     287        return Convert.ToDto(okb.ProblemDatas.FirstOrDefault(x => x.ProblemId == problemId));
     288      }
     289    }
     290    public void UpdateProblemData(DataTransfer.ProblemData dto) {
     291      using (OKBDataContext okb = new OKBDataContext()) {
     292        DataAccess.ProblemData entity = okb.ProblemDatas.FirstOrDefault(x => x.ProblemId == dto.ProblemId);
     293        if (entity == null) okb.ProblemDatas.InsertOnSubmit(Convert.ToEntity(dto));
    161294        else Convert.ToEntity(dto, entity);
    162         okb.SubmitChanges();
    163       }
    164     }
    165     public void DeleteDataType(long id) {
    166       using (OKBDataContext okb = new OKBDataContext()) {
    167         DataAccess.DataType entity = okb.DataTypes.FirstOrDefault(x => x.Id == id);
    168         if (entity != null) okb.DataTypes.DeleteOnSubmit(entity);
    169295        okb.SubmitChanges();
    170296      }
  • branches/OKB/HeuristicLab.Services.OKB/3.3/Convert.cs

    r4467 r4481  
    2828    #region Platform
    2929    public static DT.Platform ToDto(DA.Platform source) {
     30      if (source == null) return null;
    3031      return new DT.Platform { Id = source.Id, Name = source.Name, Description = source.Description };
    3132    }
    3233    public static DA.Platform ToEntity(DT.Platform source) {
     34      if (source == null) return null;
    3335      return new DA.Platform { Id = source.Id, Name = source.Name, Description = source.Description };
    3436    }
    3537    public static void ToEntity(DT.Platform source, DA.Platform target) {
    36       target.Id = source.Id; target.Name = source.Name; target.Description = source.Description;
     38      if ((source != null) && (target != null))
     39        target.Id = source.Id; target.Name = source.Name; target.Description = source.Description;
     40    }
     41    #endregion
     42
     43    #region DataType
     44    public static DT.DataType ToDto(DA.DataType source) {
     45      if (source == null) return null;
     46      return new DT.DataType { Id = source.Id, Name = source.Name, SqlName = source.SqlName, PlatformId = source.PlatformId };
     47    }
     48    public static DA.DataType ToEntity(DT.DataType source) {
     49      if (source == null) return null;
     50      return new DA.DataType { Id = source.Id, Name = source.Name, SqlName = source.SqlName, PlatformId = source.PlatformId };
     51    }
     52    public static void ToEntity(DT.DataType source, DA.DataType target) {
     53      if ((source != null) && (target != null))
     54        target.Id = source.Id; target.Name = source.Name; target.SqlName = source.SqlName; target.PlatformId = source.PlatformId;
    3755    }
    3856    #endregion
     
    4058    #region AlgorithmClass
    4159    public static DT.AlgorithmClass ToDto(DA.AlgorithmClass source) {
     60      if (source == null) return null;
    4261      return new DT.AlgorithmClass { Id = source.Id, Name = source.Name, Description = source.Description };
    4362    }
    4463    public static DA.AlgorithmClass ToEntity(DT.AlgorithmClass source) {
     64      if (source == null) return null;
    4565      return new DA.AlgorithmClass { Id = source.Id, Name = source.Name, Description = source.Description };
    4666    }
    4767    public static void ToEntity(DT.AlgorithmClass source, DA.AlgorithmClass target) {
    48       target.Id = source.Id; target.Name = source.Name; target.Description = source.Description;
     68      if ((source != null) && (target != null))
     69        target.Id = source.Id; target.Name = source.Name; target.Description = source.Description;
    4970    }
    5071    #endregion
     
    5273    #region Algorithm
    5374    public static DT.Algorithm ToDto(DA.Algorithm source) {
     75      if (source == null) return null;
    5476      return new DT.Algorithm { Id = source.Id, Name = source.Name, Description = source.Description, PlatformId = source.PlatformId, AlgorithmClassId = source.AlgorithmClassId };
    5577    }
    5678    public static DA.Algorithm ToEntity(DT.Algorithm source) {
     79      if (source == null) return null;
    5780      return new DA.Algorithm { Id = source.Id, Name = source.Name, Description = source.Description, PlatformId = source.PlatformId, AlgorithmClassId = source.AlgorithmClassId };
    5881    }
    5982    public static void ToEntity(DT.Algorithm source, DA.Algorithm target) {
    60       target.Id = source.Id; target.Name = source.Name; target.Description = source.Description; target.PlatformId = source.PlatformId; target.AlgorithmClassId = source.AlgorithmClassId;
     83      if ((source != null) && (target != null))
     84        target.Id = source.Id; target.Name = source.Name; target.Description = source.Description; target.PlatformId = source.PlatformId; target.AlgorithmClassId = source.AlgorithmClassId;
    6185    }
    6286    #endregion
     
    6488    #region AlgorithmData
    6589    public static DT.AlgorithmData ToDto(DA.AlgorithmData source) {
     90      if (source == null) return null;
    6691      return new DT.AlgorithmData { AlgorithmId = source.AlgorithmId, DataTypeId = source.DataTypeId, Data = source.Data.ToArray() };
    6792    }
    6893    public static DA.AlgorithmData ToEntity(DT.AlgorithmData source) {
     94      if (source == null) return null;
    6995      return new DA.AlgorithmData { AlgorithmId = source.AlgorithmId, DataTypeId = source.DataTypeId, Data = new Binary(source.Data) };
    7096    }
    7197    public static void ToEntity(DT.AlgorithmData source, DA.AlgorithmData target) {
    72       target.AlgorithmId = source.AlgorithmId; target.DataTypeId = source.DataTypeId; target.Data = new Binary(source.Data);
     98      if ((source != null) && (target != null))
     99        target.AlgorithmId = source.AlgorithmId; target.DataTypeId = source.DataTypeId; target.Data = new Binary(source.Data);
    73100    }
    74101    #endregion
    75102
    76     #region DataType
    77     public static DT.DataType ToDto(DA.DataType source) {
    78       return new DT.DataType { Id = source.Id, Name = source.Name, SqlName = source.SqlName, PlatformId = source.PlatformId };
     103    #region ProblemClass
     104    public static DT.ProblemClass ToDto(DA.ProblemClass source) {
     105      if (source == null) return null;
     106      return new DT.ProblemClass { Id = source.Id, Name = source.Name, Description = source.Description };
    79107    }
    80     public static DA.DataType ToEntity(DT.DataType source) {
    81       return new DA.DataType { Id = source.Id, Name = source.Name, SqlName = source.SqlName, PlatformId = source.PlatformId };
     108    public static DA.ProblemClass ToEntity(DT.ProblemClass source) {
     109      if (source == null) return null;
     110      return new DA.ProblemClass { Id = source.Id, Name = source.Name, Description = source.Description };
    82111    }
    83     public static void ToEntity(DT.DataType source, DA.DataType target) {
    84       target.Id = source.Id; target.Name = source.Name; target.SqlName = source.SqlName; target.PlatformId = source.PlatformId;
     112    public static void ToEntity(DT.ProblemClass source, DA.ProblemClass target) {
     113      if ((source != null) && (target != null))
     114        target.Id = source.Id; target.Name = source.Name; target.Description = source.Description;
     115    }
     116    #endregion
     117
     118    #region Algorithm
     119    public static DT.Problem ToDto(DA.Problem source) {
     120      if (source == null) return null;
     121      return new DT.Problem { Id = source.Id, Name = source.Name, Description = source.Description, PlatformId = source.PlatformId, ProblemClassId = source.ProblemClassId };
     122    }
     123    public static DA.Problem ToEntity(DT.Problem source) {
     124      if (source == null) return null;
     125      return new DA.Problem { Id = source.Id, Name = source.Name, Description = source.Description, PlatformId = source.PlatformId, ProblemClassId = source.ProblemClassId };
     126    }
     127    public static void ToEntity(DT.Problem source, DA.Problem target) {
     128      if ((source != null) && (target != null))
     129        target.Id = source.Id; target.Name = source.Name; target.Description = source.Description; target.PlatformId = source.PlatformId; target.ProblemClassId = source.ProblemClassId;
     130    }
     131    #endregion
     132
     133    #region ProblemData
     134    public static DT.ProblemData ToDto(DA.ProblemData source) {
     135      if (source == null) return null;
     136      return new DT.ProblemData { ProblemId = source.ProblemId, DataTypeId = source.DataTypeId, Data = source.Data.ToArray() };
     137    }
     138    public static DA.ProblemData ToEntity(DT.ProblemData source) {
     139      if (source == null) return null;
     140      return new DA.ProblemData { ProblemId = source.ProblemId, DataTypeId = source.DataTypeId, Data = new Binary(source.Data) };
     141    }
     142    public static void ToEntity(DT.ProblemData source, DA.ProblemData target) {
     143      if ((source != null) && (target != null))
     144        target.ProblemId = source.ProblemId; target.DataTypeId = source.DataTypeId; target.Data = new Binary(source.Data);
    85145    }
    86146    #endregion
  • branches/OKB/HeuristicLab.Services.OKB/3.3/HeuristicLab.Services.OKB-3.3.csproj

    r4480 r4481  
    149149      <FlavorProperties GUID="{3D9AD99F-2412-4246-B90B-4EAA41C64699}">
    150150        <WcfProjectProperties>
    151           <AutoStart>True</AutoStart>
     151          <AutoStart>False</AutoStart>
    152152        </WcfProjectProperties>
    153153      </FlavorProperties>
  • branches/OKB/HeuristicLab.Services.OKB/3.3/Interfaces/IAdminService.cs

    r4467 r4481  
    3838    IEnumerable<Platform> GetPlatforms();
    3939    [OperationContract]
    40     void StorePlatform(Platform dto);
     40    long AddPlatform(Platform dto);
     41    [OperationContract]
     42    void UpdatePlatform(Platform dto);
    4143    [OperationContract]
    4244    void DeletePlatform(long id);
     45    #endregion
     46
     47    #region DataType Methods
     48    [OperationContract]
     49    DataType GetDataType(long id);
     50    [OperationContract]
     51    IEnumerable<DataType> GetDataTypes();
     52    [OperationContract]
     53    long AddDataType(DataType dto);
     54    [OperationContract]
     55    void UpdateDataType(DataType dto);
     56    [OperationContract]
     57    void DeleteDataType(long id);
    4358    #endregion
    4459
     
    4964    IEnumerable<AlgorithmClass> GetAlgorithmClasses();
    5065    [OperationContract]
    51     void StoreAlgorithmClass(AlgorithmClass dto);
     66    long AddAlgorithmClass(AlgorithmClass dto);
     67    [OperationContract]
     68    void UpdateAlgorithmClass(AlgorithmClass dto);
    5269    [OperationContract]
    5370    void DeleteAlgorithmClass(long id);
     
    6077    IEnumerable<Algorithm> GetAlgorithms();
    6178    [OperationContract]
    62     void StoreAlgorithm(Algorithm dto);
     79    long AddAlgorithm(Algorithm dto);
     80    [OperationContract]
     81    void UpdateAlgorithm(Algorithm dto);
    6382    [OperationContract]
    6483    void DeleteAlgorithm(long id);
     
    6685    IEnumerable<Guid> GetAlgorithmUsers(long algorithmId);
    6786    [OperationContract]
    68     void StoreAlgorithmUsers(long algorithmId, IEnumerable<Guid> users);
     87    void UpdateAlgorithmUsers(long algorithmId, IEnumerable<Guid> users);
    6988    #endregion
    7089
     
    7392    AlgorithmData GetAlgorithmData(long algorithmId);
    7493    [OperationContract]
    75     void StoreAlgorithmData(AlgorithmData dto);
     94    void UpdateAlgorithmData(AlgorithmData dto);
    7695    #endregion
    7796
    78     #region DataType Methods
     97    #region ProblemClass Methods
    7998    [OperationContract]
    80     DataType GetDataType(long id);
     99    ProblemClass GetProblemClass(long id);
    81100    [OperationContract]
    82     IEnumerable<DataType> GetDataTypes();
     101    IEnumerable<ProblemClass> GetProblemClasses();
    83102    [OperationContract]
    84     void StoreDataType(DataType dto);
     103    long AddProblemClass(ProblemClass dto);
    85104    [OperationContract]
    86     void DeleteDataType(long id);
     105    void UpdateProblemClass(ProblemClass dto);
     106    [OperationContract]
     107    void DeleteProblemClass(long id);
     108    #endregion
     109
     110    #region Problem Methods
     111    [OperationContract]
     112    Problem GetProblem(long id);
     113    [OperationContract]
     114    IEnumerable<Problem> GetProblems();
     115    [OperationContract]
     116    long AddProblem(Problem dto);
     117    [OperationContract]
     118    void UpdateProblem(Problem dto);
     119    [OperationContract]
     120    void DeleteProblem(long id);
     121    [OperationContract]
     122    IEnumerable<Guid> GetProblemUsers(long problemId);
     123    [OperationContract]
     124    void UpdateProblemUsers(long problemId, IEnumerable<Guid> users);
     125    #endregion
     126
     127    #region ProblemData Methods
     128    [OperationContract]
     129    ProblemData GetProblemData(long problemId);
     130    [OperationContract]
     131    void UpdateProblemData(ProblemData dto);
    87132    #endregion
    88133  }
Note: See TracChangeset for help on using the changeset viewer.