Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Hive.Server.Core/JobManager.cs @ 1121

Last change on this file since 1121 was 1121, checked in by msteinbi, 15 years ago

Add licencse information where missing, added method description comments (#466)

File size: 3.6 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using System.Text;
26using HeuristicLab.Hive.Contracts.Interfaces;
27using HeuristicLab.Hive.Contracts.BusinessObjects;
28using HeuristicLab.Hive.Contracts;
29using HeuristicLab.Hive.Server.Core.InternalInterfaces.DataAccess;
30
31namespace HeuristicLab.Hive.Server.Core {
32  class JobManager: IJobManager {
33
34    IJobAdapter jobAdapter;
35
36    #region IJobManager Members
37
38    public JobManager() {
39      jobAdapter = ServiceLocator.GetJobAdapter();
40    }
41
42    /// <summary>
43    /// returns all jobs stored in the database
44    /// </summary>
45    /// <returns></returns>
46    public ResponseList<Job> GetAllJobs() {
47      ResponseList<Job> response = new ResponseList<Job>();
48
49      response.List = new List<Job>(jobAdapter.GetAll());
50      response.Success = true;
51      response.StatusMessage = ApplicationConstants.RESPONSE_JOB_ALL_JOBS;
52     
53      return response;
54    }
55
56    /// <summary>
57    /// Adds a new job into the database
58    /// </summary>
59    /// <param name="job"></param>
60    /// <returns></returns>
61    public ResponseObject<Job> AddNewJob(Job job) {
62      ResponseObject<Job> response = new ResponseObject<Job>();
63
64      if (job != null) {
65        if (job.State != State.offline) {
66          response.Success = false;
67          response.StatusMessage = ApplicationConstants.RESPONSE_JOB_JOBSTATE_MUST_BE_OFFLINE;
68          return response;
69        }
70        if (job.Id != 0) {
71          response.Success = false;
72          response.StatusMessage = ApplicationConstants.RESPONSE_JOB_ID_MUST_NOT_BE_SET;
73          return response;
74        }
75        if (job.SerializedJob == null) {
76          response.StatusMessage = ApplicationConstants.RESPONSE_JOB_JOB_NULL;
77          response.Success = false;
78          return response;
79        }
80
81        jobAdapter.Update(job);
82        response.Success = true;
83        response.Obj = job;
84        response.StatusMessage = ApplicationConstants.RESPONSE_JOB_JOB_ADDED;
85      } else {
86        response.Success = false;
87        response.StatusMessage = ApplicationConstants.RESPONSE_JOB_JOB_NULL;
88      }
89
90      return response;
91    }
92
93    /// <summary>
94    /// Removes a job from the database
95    /// </summary>
96    /// <param name="jobId"></param>
97    /// <returns></returns>
98    public Response RemoveJob(long jobId) {
99      Response response = new Response();
100
101      Job job = jobAdapter.GetById(jobId);
102      if (job == null) {
103        response.Success = false;
104        response.StatusMessage = ApplicationConstants.RESPONSE_JOB_JOB_DOESNT_EXIST;
105        return response;
106      }
107      jobAdapter.Delete(job);
108      response.Success = false;
109      response.StatusMessage = ApplicationConstants.RESPONSE_JOB_JOB_REMOVED;
110
111      return response;
112    }
113
114    #endregion
115  }
116}
Note: See TracBrowser for help on using the repository browser.