Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HiveStatistics/sources/HeuristicLab.Services.WebApp.Statistics/3.3/WebApi/DataController.cs @ 12477

Last change on this file since 12477 was 12477, checked in by dglaser, 9 years ago

#2388: Created WebApp.Statistics plugin

File size: 2.8 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 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.Web.Http;
26using HeuristicLab.Services.Access;
27using HeuristicLab.Services.Hive;
28using HeuristicLab.Services.Hive.DataAccess.Interfaces;
29using DTO = HeuristicLab.Services.WebApp.Statistics.WebApi.DataTransfer;
30
31namespace HeuristicLab.Services.WebApp.Statistics.WebApi {
32
33  [Authorize]
34  public class DataController : ApiController {
35
36    private IPersistenceManager PersistenceManager {
37      get { return ServiceLocator.Instance.PersistenceManager; }
38    }
39
40    private IUserManager UserManager {
41      get { return ServiceLocator.Instance.UserManager; }
42    }
43
44    public IEnumerable<DTO.Job> GetJobs() {
45      return GetJobsByUserId(UserManager.CurrentUserId);
46    }
47
48    public IEnumerable<DTO.Job> GetJobsByUserId(Guid id) {
49      using (var pm = PersistenceManager) {
50        return pm.UseTransaction(() => {
51          var dimJobDao = pm.DimJobDao;
52          return dimJobDao.GetByUserId(id).Select(x => new DTO.Job {
53            Id = x.JobId,
54            Name = x.JobName,
55            DateCreated = x.DateCreated
56          }).ToList();
57        });
58      }
59    }
60
61    public IEnumerable<DTO.Task> GetTasksByJobId(Guid id) {
62      using (var pm = PersistenceManager) {
63        return pm.UseTransaction(() => {
64          var factTaskDao = pm.FactTaskDao;
65          return factTaskDao.GetByJobId(id).Select(x => new DTO.Task {
66            TotalRuntime = x.TotalRuntime,
67            TotalWaitingTime = x.TotalWaitingTime,
68            TotalTransferTime = x.TotalTransferTime,
69            NumCalculationRuns = x.NumCalculationRuns,
70            NumRetries = x.NumRetries,
71            CoresRequired = x.CoresRequired,
72            MemoryRequired = x.MemoryRequired,
73            Priority = x.Priority,
74            LastClientId = x.LastClientId,
75            StartTime = x.StartTime,
76            EndTime = x.EndTime
77          }).ToList();
78        });
79      }
80    }
81
82  }
83}
Note: See TracBrowser for help on using the repository browser.