Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HiveStatistics/sources/HeuristicLab.Services.WebApp.Maintenance/3.3/WebApi/PluginController.cs @ 12858

Last change on this file since 12858 was 12858, checked in by ascheibe, 9 years ago

#2388

  • prevent disposing of hive data context
  • more cleanups
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.Linq;
24using System.Web.Http;
25using HeuristicLab.Services.Hive;
26using HeuristicLab.Services.Hive.DataAccess.Interfaces;
27using DT = HeuristicLab.Services.WebApp.Maintenance.WebApi.DataTransfer;
28
29namespace HeuristicLab.Services.WebApp.Maintenance.WebApi {
30  public class PluginController : ApiController {
31    private IPersistenceManager PersistenceManager {
32      get { return ServiceLocator.Instance.PersistenceManager; }
33    }
34
35    public DT.PluginPage GetUnusedPlugins(int page, int size) {
36      var pm = PersistenceManager;
37      var pluginDao = pm.PluginDao;
38      var requiredPluginDao = pm.RequiredPluginDao;
39      var taskDao = pm.TaskDao;
40      return pm.UseTransaction(() => {
41        var taskIds = taskDao.GetAll().Select(x => x.TaskId);
42        var usedPluginIds = requiredPluginDao.GetAll()
43          .Where(x => taskIds.Contains(x.TaskId))
44          .Select(x => x.PluginId)
45          .Distinct();
46        var query = pluginDao.GetAll().Where(x => !usedPluginIds.Any(y => y == x.PluginId));
47        return new DT.PluginPage {
48          TotalPlugins = query.Count(),
49          Plugins = query.OrderBy(x => x.DateCreated).ThenBy(x => x.Name)
50            .Skip((page - 1) * size)
51            .Take(size).Select(x => new DT.Plugin {
52              Id = x.PluginId,
53              Name = x.Name,
54              Version = x.Version,
55              DateCreated = x.DateCreated
56            })
57            .ToList()
58        };
59      });
60    }
61
62    [HttpPost]
63    public void DeletePlugin(Guid id) {
64      var pm = PersistenceManager;
65      var pluginDao = pm.PluginDao;
66      pm.UseTransaction(() => {
67        pluginDao.Delete(id);
68        pm.SubmitChanges();
69      });
70    }
71
72    [HttpPost]
73    public void DeleteUnusedPlugins() {
74      var pm = PersistenceManager;
75      var pluginDao = pm.PluginDao;
76      pm.UseTransaction(() => {
77        pluginDao.DeleteUnusedPlugins();
78        pm.SubmitChanges();
79      });
80    }
81  }
82}
Note: See TracBrowser for help on using the repository browser.