Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/24/10 02:37:56 (14 years ago)
Author:
swagner
Message:

Worked on OKB user authentication (#1167)

File:
1 edited

Legend:

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

    r4279 r4298  
    7272    private byte[] GetData(EntityType type, int id) {
    7373      Log("loading data", type, id);
    74       OKBDataContext okb = new OKBDataContext();
    75       switch (type) {
    76         case EntityType.Algorithm:
    77           Algorithm algorithm = okb.Algorithms.Single(a => a.Id == id);
    78           if (algorithm.AlgorithmData == null) {
    79             algorithm.AlgorithmData = new AlgorithmData() {
    80               AlgorithmId = algorithm.Id,
    81               Data = new Binary(new byte[0])
    82             };
    83             okb.SubmitChanges();
    84           }
    85           return algorithm.AlgorithmData.Data.ToArray();
    86           break;
    87         case EntityType.Problem:
    88           Problem problem = okb.Problems.Single(p => p.Id == id);
    89           if (problem.ProblemData == null) {
    90             problem.ProblemData = new ProblemData() {
    91               ProblemId = problem.Id,
    92               Data = new Binary(new byte[0])
    93             };
    94             okb.SubmitChanges();
    95           }
    96           return problem.ProblemData.Data.ToArray();
    97           break;
    98         default:
    99           throw new FaultException("Unsupported EntityType");
     74      using (OKBDataContext okb = new OKBDataContext()) {
     75        switch (type) {
     76          case EntityType.Algorithm:
     77            Algorithm algorithm = okb.Algorithms.Single(a => a.Id == id);
     78            if (algorithm.AlgorithmData == null) {
     79              algorithm.AlgorithmData = new AlgorithmData() {
     80                AlgorithmId = algorithm.Id,
     81                Data = new Binary(new byte[0])
     82              };
     83              okb.SubmitChanges();
     84            }
     85            return algorithm.AlgorithmData.Data.ToArray();
     86            break;
     87          case EntityType.Problem:
     88            Problem problem = okb.Problems.Single(p => p.Id == id);
     89            if (problem.ProblemData == null) {
     90              problem.ProblemData = new ProblemData() {
     91                ProblemId = problem.Id,
     92                Data = new Binary(new byte[0])
     93              };
     94              okb.SubmitChanges();
     95            }
     96            return problem.ProblemData.Data.ToArray();
     97            break;
     98          default:
     99            throw new FaultException("Unsupported EntityType");
     100        }
    100101      }
    101       okb.Dispose();
    102102    }
    103103
Note: See TracChangeset for help on using the changeset viewer.