[13862] | 1 | using HeuristicLab.Clients.Hive.WebJobManager.Services;
|
---|
| 2 | using HeuristicLab.Clients.Hive.WebJobManager.Services.Imports;
|
---|
[13871] | 3 | using HeuristicLab.Clients.OKB.Administration;
|
---|
[13862] | 4 | using Microsoft.AspNetCore.SignalR;
|
---|
[13871] | 5 | using Newtonsoft.Json;
|
---|
| 6 | using Newtonsoft.Json.Linq;
|
---|
[13862] | 7 | using System;
|
---|
| 8 | using System.Collections.Generic;
|
---|
| 9 | using System.Linq;
|
---|
| 10 | using System.Threading.Tasks;
|
---|
| 11 |
|
---|
| 12 | namespace HeuristicLab.Clients.Hive.WebJobManager.Hubs
|
---|
| 13 | {
|
---|
| 14 | public class OkbManagerHub : Hub
|
---|
| 15 | {
|
---|
| 16 | private WebLoginService weblog;
|
---|
| 17 | private Guid userId;
|
---|
| 18 | private OkbAdministrationWebClient adminclient;
|
---|
| 19 | /// <summary>
|
---|
| 20 | /// Loads up the services for the client (Instance is only created upon a call from a client)
|
---|
| 21 | /// </summary>
|
---|
| 22 | private void loader()
|
---|
| 23 | {
|
---|
| 24 | weblog = WebLoginService.Instance;
|
---|
| 25 | string uid = Context.QueryString["userid"];
|
---|
| 26 | if (uid == null || uid == "" || Guid.Parse(uid) == Guid.Empty)
|
---|
| 27 | {
|
---|
| 28 | userId = Guid.Empty;
|
---|
| 29 | }
|
---|
| 30 | else
|
---|
| 31 | {
|
---|
| 32 | userId = Guid.Parse(uid);
|
---|
| 33 | adminclient = weblog.getOkbAdminClient(userId);
|
---|
| 34 | }
|
---|
| 35 | }
|
---|
[13871] | 36 | public void Save(string json, string name)
|
---|
| 37 | {
|
---|
| 38 | loader();
|
---|
| 39 | JObject obj = JObject.Parse(json);
|
---|
| 40 | NamedOKBItem tostore = null;
|
---|
| 41 | Type objtype = null;
|
---|
| 42 | int id = ((int)obj.GetValue("Id"));
|
---|
| 43 | switch (name)
|
---|
| 44 | {
|
---|
| 45 | case "Algorithms":
|
---|
| 46 | objtype = typeof(Algorithm);
|
---|
| 47 | if (id != -1)
|
---|
| 48 | tostore = adminclient.Algorithms.Find(x => x.Id == id);
|
---|
| 49 | else
|
---|
| 50 | tostore = new Algorithm();
|
---|
| 51 | break;
|
---|
| 52 | case "Platforms":
|
---|
| 53 | objtype = typeof(Platform);
|
---|
| 54 | if (id != -1)
|
---|
| 55 | tostore = adminclient.Platforms.Find(x => x.Id == id);
|
---|
| 56 | else
|
---|
| 57 | tostore = new Platform();
|
---|
| 58 | break;
|
---|
| 59 | case "Algorithm classes":
|
---|
| 60 | objtype = typeof(AlgorithmClass);
|
---|
| 61 | if (id != -1)
|
---|
| 62 | tostore = adminclient.AlgorithmClasses.Find(x => x.Id == id);
|
---|
| 63 | else
|
---|
| 64 | tostore = new AlgorithmClass();
|
---|
| 65 | break;
|
---|
| 66 | case "Problem classes":
|
---|
| 67 | objtype = typeof(ProblemClass);
|
---|
| 68 | if (id != -1)
|
---|
| 69 | tostore = adminclient.ProblemClasses.Find(x => x.Id == id);
|
---|
| 70 | else
|
---|
| 71 | tostore = new ProblemClass();
|
---|
| 72 | break;
|
---|
| 73 | case "Problems":
|
---|
| 74 | objtype = typeof(Problem);
|
---|
| 75 | if (id != -1)
|
---|
| 76 | tostore = adminclient.Problems.Find(x => x.Id == id);
|
---|
| 77 | else
|
---|
| 78 | tostore = new Problem();
|
---|
| 79 | break;
|
---|
| 80 | }
|
---|
| 81 | tostore.Name = obj.GetValue("Name").ToString();
|
---|
| 82 | tostore.Description = obj.GetValue("Description").ToString();
|
---|
| 83 | if (objtype == typeof(Algorithm))
|
---|
| 84 | {
|
---|
| 85 | ((Algorithm)tostore).PlatformId = ((int)obj.GetValue("PlatformId"));
|
---|
| 86 | ((Algorithm)tostore).AlgorithmClassId = ((int)obj.GetValue("AlgorithmClassId"));
|
---|
| 87 |
|
---|
| 88 | }
|
---|
| 89 | else if (objtype == typeof(Problem))
|
---|
| 90 | {
|
---|
| 91 | ((Problem)tostore).PlatformId = ((int)obj.GetValue("PlatformId"));
|
---|
| 92 | ((Problem)tostore).ProblemClassId = ((int)obj.GetValue("ProblemClassId"));
|
---|
| 93 | }
|
---|
| 94 | adminclient.Store(tostore);
|
---|
| 95 | Clients.Caller.saveComplete("Succesfully saved");
|
---|
| 96 | refresh(name);
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | public void Delete(string id, string name)
|
---|
| 100 | {
|
---|
| 101 | loader();
|
---|
| 102 | IOKBItem todel = null;
|
---|
| 103 | int todelid = int.Parse(id);
|
---|
| 104 | switch (name)
|
---|
| 105 | {
|
---|
| 106 | case "Algorithms":
|
---|
| 107 | todel = adminclient.Algorithms.Find(x => x.Id == todelid);
|
---|
| 108 | break;
|
---|
| 109 | case "Platforms":
|
---|
| 110 | todel = adminclient.Platforms.Find(x => x.Id == todelid);
|
---|
| 111 | break;
|
---|
| 112 | case "Algorithm classes":
|
---|
| 113 | todel = adminclient.AlgorithmClasses.Find(x => x.Id == todelid);
|
---|
| 114 | break;
|
---|
| 115 | case "Problem classes":
|
---|
| 116 | todel = adminclient.ProblemClasses.Find(x => x.Id == todelid);
|
---|
| 117 | break;
|
---|
| 118 | case "Problems":
|
---|
| 119 | todel = adminclient.Problems.Find(x => x.Id == todelid);
|
---|
| 120 | break;
|
---|
| 121 | }
|
---|
| 122 | adminclient.Delete(todel);
|
---|
| 123 | Clients.Caller.deleteComplete("Succesfully deleted");
|
---|
| 124 | refresh(name);
|
---|
| 125 | }
|
---|
| 126 | private void refresh(string name)
|
---|
| 127 | {
|
---|
| 128 | adminclient.Refresh();
|
---|
| 129 | switch (name)
|
---|
| 130 | {
|
---|
| 131 | case "Algorithms":
|
---|
| 132 | Clients.Caller.refreshData("algos", JsonConvert.SerializeObject(adminclient.Algorithms));
|
---|
| 133 | break;
|
---|
| 134 | case "Platforms":
|
---|
| 135 | Clients.Caller.refreshData("platforms", JsonConvert.SerializeObject(adminclient.Platforms));
|
---|
| 136 | break;
|
---|
| 137 | case "Algorithm classes":
|
---|
| 138 | Clients.Caller.refreshData("algoclass", JsonConvert.SerializeObject(adminclient.AlgorithmClasses));
|
---|
| 139 | break;
|
---|
| 140 | case "Problem classes":
|
---|
| 141 | Clients.Caller.refreshData("probclass", JsonConvert.SerializeObject(adminclient.ProblemClasses));
|
---|
| 142 | break;
|
---|
| 143 | case "Problems":
|
---|
| 144 | Clients.Caller.refreshData("problems", JsonConvert.SerializeObject(adminclient.Problems));
|
---|
| 145 | break;
|
---|
| 146 | }
|
---|
| 147 | }
|
---|
[13862] | 148 | }
|
---|
[13871] | 149 | } |
---|