Free cookie consent management tool by TermsFeed Policy Generator

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

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

#2429:

  • Unused plugins are now sorted by date and name
  • Fixed a small bug in the FactClientInfo aggregation
File size: 2.9 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      using (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
63    [HttpPost]
64    public void DeletePlugin(Guid id) {
65      using (var pm = PersistenceManager) {
66        var pluginDao = pm.PluginDao;
67        pm.UseTransaction(() => {
68          pluginDao.Delete(id);
69          pm.SubmitChanges();
70        });
71      }
72    }
73
74    [HttpPost]
75    public void DeleteUnusedPlugins() {
76      using (var pm = PersistenceManager) {
77        var pluginDao = pm.PluginDao;
78        pm.UseTransaction(() => {
79          pluginDao.DeleteUnusedPlugins();
80          pm.SubmitChanges();
81        });
82      }
83    }
84  }
85}
Note: See TracBrowser for help on using the repository browser.