Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Async/HeuristicLab.Services.WebApp.Maintenance/3.3/WebApi/PluginController.cs @ 13401

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

#2388 fixed plugin queries for maintenance page

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 usedPluginIds = requiredPluginDao.GetAll()       
42          .Select(x => x.PluginId)
43          .Distinct().ToArray();
44        var tmpQuery = pluginDao.GetAll().Select(x=>x.PluginId).ToArray().Where(x => !usedPluginIds.Any(y => y == x)).ToArray();
45        var query = pluginDao.GetAll().Where(x => tmpQuery.Contains(x.PluginId)).ToArray();
46        return new DT.PluginPage {
47          TotalPlugins = query.Count(),
48          Plugins = query.OrderBy(x => x.DateCreated).ThenBy(x => x.Name)
49            .Skip((page - 1) * size)
50            .Take(size).Select(x => new DT.Plugin {
51              Id = x.PluginId,
52              Name = x.Name,
53              Version = x.Version,
54              DateCreated = x.DateCreated
55            })
56            .ToList()
57        };
58      });
59    }
60
61    [HttpPost]
62    public void DeletePlugin(Guid id) {
63      var pm = PersistenceManager;
64      var pluginDao = pm.PluginDao;
65      pm.UseTransaction(() => {
66        pluginDao.Delete(id);
67        pm.SubmitChanges();
68      });
69    }
70
71    [HttpPost]
72    public void DeleteUnusedPlugins() {
73      var pm = PersistenceManager;
74      var pluginDao = pm.PluginDao;
75      pm.UseTransaction(() => {
76        pluginDao.DeleteUnusedPlugins();
77        pm.SubmitChanges();
78      });
79    }
80  }
81}
Note: See TracBrowser for help on using the repository browser.