Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/16/10 06:42:00 (14 years ago)
Author:
swagner
Message:

Worked on OKB data model and services (#1174)

File:
1 edited

Legend:

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

    r4390 r4407  
    3131  [ServiceBehavior(IncludeExceptionDetailInFaults = true)]
    3232  public class AdminService : IAdminService {
     33    public void AddAlgorithmClass(AlgorithmClass algorithmClass) {
     34      using (OKBDataContext okb = new OKBDataContext()) {
     35        okb.AlgorithmClasses.InsertOnSubmit(new AlgorithmClass() {
     36          Name = algorithmClass.Name,
     37          Description = algorithmClass.Description
     38        });
     39        okb.SubmitChanges();
     40      }
     41    }
     42    public AlgorithmClass[] GetAlgorithmClasses() {
     43      using (OKBDataContext okb = new OKBDataContext()) {
     44        return okb.AlgorithmClasses.ToArray();
     45      }
     46    }
     47    public void UpdateAlgorithmClass(AlgorithmClass algorithmClass) {
     48      using (OKBDataContext okb = new OKBDataContext()) {
     49        AlgorithmClass original = okb.AlgorithmClasses.First(a => a.Id == algorithmClass.Id);
     50        original.Name = algorithmClass.Name;
     51        original.Description = algorithmClass.Description;
     52        okb.SubmitChanges();
     53      }
     54    }
     55    public void DeleteAlgorithmClass(long algorithmClassId) {
     56      using (OKBDataContext okb = new OKBDataContext()) {
     57        okb.AlgorithmClasses.DeleteOnSubmit(okb.AlgorithmClasses.First(a => a.Id == algorithmClassId));
     58        okb.SubmitChanges();
     59      }
     60    }
     61
     62    public void AddAlgorithm(Algorithm algorithm) {
     63      using (OKBDataContext okb = new OKBDataContext()) {
     64        okb.Algorithms.InsertOnSubmit(new Algorithm() {
     65          AlgorithmClassId = algorithm.AlgorithmClassId,
     66          PlatformId = algorithm.PlatformId,
     67          Name = algorithm.Name,
     68          Description = algorithm.Description
     69        });
     70        okb.SubmitChanges();
     71      }
     72    }
     73    public Algorithm[] GetAlgorithms() {
     74      using (OKBDataContext okb = new OKBDataContext()) {
     75        return okb.Algorithms.ToArray();
     76      }
     77    }
     78    public void UpdateAlgorithm(Algorithm algorithm) {
     79      using (OKBDataContext okb = new OKBDataContext()) {
     80        Algorithm original = okb.Algorithms.First(a => a.Id == algorithm.Id);
     81        original.AlgorithmClassId = algorithm.AlgorithmClassId;
     82        original.PlatformId = algorithm.PlatformId;
     83        original.Name = algorithm.Name;
     84        original.Description = algorithm.Description;
     85        okb.SubmitChanges();
     86      }
     87    }
     88    public void DeleteAlgorithm(long algorithmId) {
     89      using (OKBDataContext okb = new OKBDataContext()) {
     90        okb.Algorithms.DeleteOnSubmit(okb.Algorithms.First(a => a.Id == algorithmId));
     91        okb.SubmitChanges();
     92      }
     93    }
     94
    3395    /// <summary>
    3496    /// Gets all available platforms.
     
    80142        var dlo = new DataLoadOptions();
    81143        dlo.LoadWith<Problem>(p => p.ProblemClass);
    82         dlo.LoadWith<Problem>(p => p.SolutionRepresentation);
    83144        dlo.LoadWith<Problem>(p => p.Platform);
    84145        dlo.LoadWith<Problem>(p => p.ProblemUsers);
    85146        dlo.LoadWith<ProblemUser>(u => u.User);
    86         dlo.LoadWith<Problem>(p => p.ProblemCharacteristicIntValues);
    87         dlo.LoadWith<Problem>(p => p.ProblemCharacteristicFloatValues);
    88         dlo.LoadWith<Problem>(p => p.ProblemCharacteristicStringValues);
    89         dlo.LoadWith<ProblemCharacteristicIntValue>(ipcv => ipcv.ProblemCharacteristic);
    90         dlo.LoadWith<ProblemCharacteristicFloatValue>(fpcv => fpcv.ProblemCharacteristic);
    91         dlo.LoadWith<ProblemCharacteristicStringValue>(cpcv => cpcv.ProblemCharacteristic);
    92         dlo.LoadWith<ProblemCharacteristic>(pc => pc.DataType);
    93147        okb.LoadOptions = dlo;
    94148        return okb.Problems.Single(p => p.Id == id);
     
    143197        Problem originalProblem = okb.Problems.Single(p => p.Id == problem.Id);
    144198        UpdateProblemData(problem, originalProblem, okb);
    145         UpdateProblemCharacteristics(problem, originalProblem, okb);
    146199        okb.SubmitChanges();
    147200      }
     
    178231      }
    179232    }
    180     private static void UpdateProblemCharacteristics(Problem problem, Problem original, OKBDataContext okb) {
    181       okb.ProblemCharacteristicIntValues.DeleteAllOnSubmit(original.ProblemCharacteristicIntValues);
    182       okb.ProblemCharacteristicFloatValues.DeleteAllOnSubmit(original.ProblemCharacteristicFloatValues);
    183       okb.ProblemCharacteristicStringValues.DeleteAllOnSubmit(original.ProblemCharacteristicStringValues);
    184       original.ProblemCharacteristicIntValues.Clear();
    185       original.ProblemCharacteristicFloatValues.Clear();
    186       original.ProblemCharacteristicStringValues.Clear();
    187       foreach (var ipc in problem.ProblemCharacteristicIntValues) {
    188         original.ProblemCharacteristicIntValues.Add(new ProblemCharacteristicIntValue() {
    189           ProblemId = original.Id,
    190           ProblemCharacteristicId = ipc.ProblemCharacteristicId,
    191           Value = ipc.Value,
    192         });
    193       }
    194       foreach (var fpc in problem.ProblemCharacteristicFloatValues) {
    195         original.ProblemCharacteristicFloatValues.Add(new ProblemCharacteristicFloatValue() {
    196           ProblemId = original.Id,
    197           ProblemCharacteristicId = fpc.ProblemCharacteristicId,
    198           Value = fpc.Value,
    199         });
    200       }
    201       foreach (var cpc in problem.ProblemCharacteristicStringValues) {
    202         original.ProblemCharacteristicStringValues.Add(new ProblemCharacteristicStringValue() {
    203           ProblemId = original.Id,
    204           ProblemCharacteristicId = cpc.ProblemCharacteristicId,
    205           Value = cpc.Value,
    206         });
    207       }
    208     }
    209 
    210 
    211     public void AddAlgorithmClass(AlgorithmClass algorithmClass) {
    212       using (OKBDataContext okb = new OKBDataContext()) {
    213         okb.AlgorithmClasses.InsertOnSubmit(new AlgorithmClass() { Name = algorithmClass.Name, Description = algorithmClass.Description });
    214         okb.SubmitChanges();
    215       }
    216     }
    217 
    218     public AlgorithmClass[] GetAlgorithmClasses() {
    219       using (OKBDataContext okb = new OKBDataContext()) {
    220         return okb.AlgorithmClasses.ToArray();
    221       }
    222     }
    223 
    224     public void UpdateAlgorithmClass(AlgorithmClass algorithmClass) {
    225       using (OKBDataContext okb = new OKBDataContext()) {
    226         AlgorithmClass original = okb.AlgorithmClasses.First(a => a.Id == algorithmClass.Id);
    227         original.Name = algorithmClass.Name;
    228         original.Description = algorithmClass.Description;
    229         okb.SubmitChanges();
    230       }
    231     }
    232 
    233     public void DeleteAlgorithmClass(long algorithmClassId) {
    234       using (OKBDataContext okb = new OKBDataContext()) {
    235         okb.AlgorithmClasses.DeleteOnSubmit(okb.AlgorithmClasses.First(a => a.Id == algorithmClassId));
    236         okb.SubmitChanges();
    237       }
    238     }
    239 
    240233  }
    241234}
Note: See TracChangeset for help on using the changeset viewer.