- Timestamp:
- 06/02/16 12:35:30 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Controllers/OkbManagementController.cs
r13862 r13871 2 2 using HeuristicLab.Clients.Hive.WebJobManager.Services.Imports; 3 3 using HeuristicLab.Clients.Hive.WebJobManager.ViewModels; 4 using HeuristicLab.Common; 5 using HeuristicLab.Optimization; 4 6 using Microsoft.AspNetCore.Http; 5 7 using Microsoft.AspNetCore.Mvc; 6 8 using System; 9 using System.Collections.Generic; 10 using System.IO; 11 using System.Threading.Tasks; 7 12 8 13 namespace HeuristicLab.Clients.Hive.WebJobManager.Controllers 9 14 { 10 public class OkbManagementController : Controller15 public class OkbManagementController : Controller 11 16 { 12 17 private OkbManagementVM vm; 13 18 private WebLoginService weblog; 14 19 private Guid userId; 15 20 16 21 private bool init() 17 22 { … … 26 31 userId = Guid.Parse(u); 27 32 vm = new OkbManagementVM(weblog.getCurrentUser(userId), weblog.getOkbAdminClient(userId)); 28 if(vm.client != null) 33 if (vm.client != null) 34 { 35 vm.client.Refresh(); 29 36 return true; 37 } 30 38 } 31 39 return false; … … 46 54 } 47 55 } 56 57 [HttpPost] 58 public async Task<IActionResult> Uploader(ICollection<IFormFile> fileupl, string name, int id) 59 { 60 if (init()) 61 { 62 try 63 { 64 byte[] data = null; 65 foreach (var file in fileupl) 66 { 67 if (file.Length > 0) 68 { 69 using (var fileStream = file.OpenReadStream()) 70 using (var ms = new MemoryStream()) 71 { 72 fileStream.CopyTo(ms); 73 data = ms.ToArray(); 74 // act on the Base64 data 75 } 76 } 77 } 78 var deser = PersistenceUtil.Deserialize<IOptimizer>(data); 79 OKB.Administration.IOKBItem obj = null; 80 if (name == "Algorithms" && deser is IAlgorithm) 81 { 82 vm.client.UpdateAlgorithmData((long)id, PersistenceUtil.Serialize(deser)); 83 vm.message = "Upload has been completed, the file is now set as the new algorithm for " + vm.client.Algorithms.Find(x => x.Id == id).Name; 84 obj = vm.client.Algorithms.Find(x => x.Id == id); 85 ((OKB.Administration.Algorithm)obj).DataTypeName = deser.GetType().Name; 86 ((OKB.Administration.Algorithm)obj).DataTypeTypeName = deser.GetType().AssemblyQualifiedName; 87 } 88 else if (name == "Problems" && deser is IProblem) 89 { 90 vm.client.UpdateProblemData((long)id, PersistenceUtil.Serialize(deser)); 91 vm.message = "Upload has been completed, the file is now set as the new problem for " + vm.client.Problems.Find(x => x.Id == id).Name; 92 obj = vm.client.Problems.Find(x => x.Id == id); 93 ((OKB.Administration.Problem)obj).DataTypeName = deser.GetType().Name; 94 ((OKB.Administration.Problem)obj).DataTypeTypeName = deser.GetType().AssemblyQualifiedName; 95 } 96 else 97 { 98 throw new Exception(); 99 } 100 101 vm.client.Store(obj); 102 ViewBag.Title = "Upload complete - OKB Management"; 103 ViewBag.Success = true; 104 105 } 106 catch (Exception e) 107 { 108 109 vm.message = "Upload failed, please try again."; 110 ViewBag.Success = false; 111 ViewBag.Title = "Upload failed - OKB Management"; 112 113 } 114 ViewBag.SessionId = HttpContext.Session.GetString("UserId"); 115 vm.client.Refresh(); 116 return View("Index", vm); 117 } 118 else 119 { 120 return RedirectToAction("Index", "Query"); 121 } 122 } 48 123 } 49 124 }
Note: See TracChangeset
for help on using the changeset viewer.