[12761] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[17181] | 3 | * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[12761] | 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 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Linq;
|
---|
| 24 | using System.Web.Http;
|
---|
| 25 | using HeuristicLab.Services.Hive;
|
---|
| 26 | using HeuristicLab.Services.Hive.DataAccess.Interfaces;
|
---|
| 27 | using DT = HeuristicLab.Services.WebApp.Maintenance.WebApi.DataTransfer;
|
---|
| 28 |
|
---|
| 29 | namespace 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) {
|
---|
[12858] | 36 | var pm = PersistenceManager;
|
---|
| 37 | var pluginDao = pm.PluginDao;
|
---|
| 38 | var requiredPluginDao = pm.RequiredPluginDao;
|
---|
| 39 | var taskDao = pm.TaskDao;
|
---|
| 40 | return pm.UseTransaction(() => {
|
---|
[12962] | 41 | var usedPluginIds = requiredPluginDao.GetAll()
|
---|
[12858] | 42 | .Select(x => x.PluginId)
|
---|
[12962] | 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();
|
---|
[12858] | 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 | });
|
---|
[12761] | 59 | }
|
---|
| 60 |
|
---|
| 61 | [HttpPost]
|
---|
| 62 | public void DeletePlugin(Guid id) {
|
---|
[12858] | 63 | var pm = PersistenceManager;
|
---|
| 64 | var pluginDao = pm.PluginDao;
|
---|
| 65 | pm.UseTransaction(() => {
|
---|
| 66 | pluginDao.Delete(id);
|
---|
| 67 | pm.SubmitChanges();
|
---|
| 68 | });
|
---|
[12761] | 69 | }
|
---|
| 70 |
|
---|
| 71 | [HttpPost]
|
---|
| 72 | public void DeleteUnusedPlugins() {
|
---|
[12858] | 73 | var pm = PersistenceManager;
|
---|
| 74 | var pluginDao = pm.PluginDao;
|
---|
| 75 | pm.UseTransaction(() => {
|
---|
| 76 | pluginDao.DeleteUnusedPlugins();
|
---|
| 77 | pm.SubmitChanges();
|
---|
| 78 | });
|
---|
[12761] | 79 | }
|
---|
| 80 | }
|
---|
| 81 | }
|
---|