- Timestamp:
- 06/02/16 12:35:30 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Hubs/OkbManagerHub.cs
r13862 r13871 1 1 using HeuristicLab.Clients.Hive.WebJobManager.Services; 2 2 using HeuristicLab.Clients.Hive.WebJobManager.Services.Imports; 3 using HeuristicLab.Clients.OKB.Administration; 3 4 using Microsoft.AspNetCore.SignalR; 5 using Newtonsoft.Json; 6 using Newtonsoft.Json.Linq; 4 7 using System; 5 8 using System.Collections.Generic; … … 31 34 } 32 35 } 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 } 33 148 } 34 149 }
Note: See TracChangeset
for help on using the changeset viewer.