- Timestamp:
- 03/11/16 12:56:12 (9 years ago)
- Location:
- branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager
-
Property
svn:ignore
set to
project.lock.json
-
Property
svn:ignore
set to
-
branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Controllers/HomeController.cs
r13656 r13689 27 27 var model = loginViewModelService.GetLoginViewModel(); 28 28 HiveServiceLocatorWebManagerService hiveServiceLocator = (HiveServiceLocatorWebManagerService)HiveServiceLocatorWebManagerService.Instance; 29 Settings.Default.UserName = loginName;30 Settings.Default.Password = Common.CryptoService.EncryptString(password);31 Settings.Default.Save();29 HeuristicLab.Clients.Common.Properties.Settings.Default.UserName = loginName; 30 HeuristicLab.Clients.Common.Properties.Settings.Default.Password = Common.CryptoService.EncryptString(password); 31 HeuristicLab.Clients.Common.Properties.Settings.Default.Save(); 32 32 hiveServiceLocator.Username = loginName; 33 33 hiveServiceLocator.Password = password; -
branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Controllers/JobController.cs
r13656 r13689 14 14 using HeuristicLab.Core; 15 15 using HeuristicLab.Optimization; 16 using System.Threading; 16 17 17 18 namespace HeuristicLab.Clients.Hive.WebJobManager.Controllers … … 32 33 _environment = env; 33 34 } 35 #region Jobs 34 36 public IActionResult Index() 35 37 { 36 38 try 37 39 { 40 38 41 vm.userJobs = client.GetJobs(); 39 42 } … … 56 59 vm.userJobs = client.GetJobs(); 57 60 vm.selectedJob = client.GetJob(id); 58 vm.jobTasks = client.GetLightweightJobTasks(id); 61 62 vm.lightJobTasks = client.GetLightweightJobTasks(id); 63 foreach (var light in vm.lightJobTasks) 64 { 65 vm.filledJobTasks.Add(client.GetTask(light.Id)); 66 } 59 67 ViewBag.Title = vm.selectedJob.Name + " - Jobs"; 60 68 return View("Index", vm); … … 66 74 } 67 75 } 68 public IActionResult Delete(Guid id) 76 public IActionResult Delete(Guid id)// delete a job 69 77 { 70 78 if (((HiveServiceLocatorWebManagerService)(HiveServiceLocatorWebManagerService.Instance)).CheckLogin()) … … 83 91 } 84 92 } 85 86 public IActionResult Upload() 93 #endregion 94 95 #region Uploads 96 public IActionResult Uploads() 97 { 98 if (((HiveServiceLocatorWebManagerService)(HiveServiceLocatorWebManagerService.Instance)).CheckLogin()) 99 { 100 UploadedJobViewModel upper = new UploadedJobViewModel(); 101 fillUploadsPaths(upper, -1); 102 103 ViewBag.Title = "Uploaded files"; 104 return View("Uploads", upper); 105 } 106 else 107 { 108 HiveServiceLocatorWebManagerService.SetLoginErrorMessage(); 109 return RedirectToAction("Index", "Home"); 110 } 111 } 112 public IActionResult UploadDir(int index) 113 { 114 if (((HiveServiceLocatorWebManagerService)(HiveServiceLocatorWebManagerService.Instance)).CheckLogin()) 115 { 116 UploadedJobViewModel upper = new UploadedJobViewModel(); 117 fillUploadsPaths(upper, index); 118 119 ViewBag.Title = "Uploaded files"; 120 return View("Uploads", upper); 121 } 122 else 123 { 124 HiveServiceLocatorWebManagerService.SetLoginErrorMessage(); 125 return RedirectToAction("Index", "Home"); 126 } 127 } 128 private void fillUploadsPaths(UploadedJobViewModel vm, int index) 129 { 130 var tempdex = index; //Fix when maps gets deleted 131 var start = Path.Combine(_environment.WebRootPath, "uploads", client.ClientCredentials.UserName.UserName); 132 var dirs = Directory.GetDirectories(start); 133 foreach (string dir in dirs) 134 { 135 if (Directory.GetFiles(dir).Length == 0 && Directory.GetDirectories(dir).Length == 0) 136 { 137 Directory.Delete(dir, false); 138 tempdex = -1; 139 } 140 else { 141 vm.FullDatePaths.Add(dir); 142 var temp = dir.Split('\\'); 143 vm.DisplayDatePaths.Add(temp[temp.Length - 1]); 144 } 145 } 146 if (tempdex != -1) 147 { 148 vm.SelectedIndex = tempdex; 149 dirs = Directory.GetFiles(vm.FullDatePaths[tempdex]); 150 foreach (string dir in dirs) 151 { 152 vm.FullFilesPaths.Add(dir); 153 var temp = dir.Split('\\'); 154 vm.DisplayFilesPaths.Add(temp[temp.Length - 1]); 155 } 156 } 157 } 158 public IActionResult DeleteFile(int index, int filedex) 159 { 160 if (((HiveServiceLocatorWebManagerService)(HiveServiceLocatorWebManagerService.Instance)).CheckLogin()) 161 { 162 UploadedJobViewModel upper = new UploadedJobViewModel(); 163 fillUploadsPaths(upper, index); 164 System.IO.File.Delete(upper.FullFilesPaths[filedex]); 165 var message = upper.DisplayFilesPaths[filedex] + " has been deleted"; 166 167 upper = new UploadedJobViewModel(); 168 fillUploadsPaths(upper, index); 169 upper.message = message; 170 ViewBag.Title = "Uploaded files"; 171 172 return View("Uploads", upper); 173 } 174 else 175 { 176 HiveServiceLocatorWebManagerService.SetLoginErrorMessage(); 177 return RedirectToAction("Index", "Home"); 178 } 179 } 180 181 public IActionResult OpenFile(int index, int filedex) 182 { 183 if (((HiveServiceLocatorWebManagerService)(HiveServiceLocatorWebManagerService.Instance)).CheckLogin()) 184 { 185 UploadedJobViewModel upper = new UploadedJobViewModel(); 186 fillUploadsPaths(upper, index); 187 188 FileOpeningService serve = FileOpeningService.Instance; 189 serve.NewModel(); 190 serve.env = _environment; 191 192 var ioptimizer = ContentManager.Load(upper.FullFilesPaths[filedex]); 193 194 serve.vm.SelectedTask = new OptimizerHiveTask((IOptimizer)ioptimizer); 195 if (serve.vm.SelectedTask.ItemTask.Item is IAlgorithm) 196 { 197 serve.vm.SelectedAlgorithm = (IAlgorithm)serve.vm.SelectedTask.ItemTask.Item; 198 } 199 else if (serve.vm.SelectedTask.ItemTask.Item is BatchRun) 200 { 201 serve.vm.SelectedBatchRun = (BatchRun)serve.vm.SelectedTask.ItemTask.Item; 202 } 203 else if (serve.vm.SelectedTask.ItemTask.Item is Experiment) 204 { 205 serve.vm.SelectedExperiment = (Experiment)serve.vm.SelectedTask.ItemTask.Item; 206 } 207 208 ViewBag.Title = serve.vm.SelectedTask.ItemTask.Name + " - Open file"; 209 210 return View("OpenFile", serve.vm); 211 } 212 else 213 { 214 HiveServiceLocatorWebManagerService.SetLoginErrorMessage(); 215 return RedirectToAction("Index", "Home"); 216 } 217 } 218 219 public IActionResult AddToHive() 220 { 221 if (((HiveServiceLocatorWebManagerService)(HiveServiceLocatorWebManagerService.Instance)).CheckLogin()) 222 { 223 var job = FileOpeningService.Instance.AddCurrentModelToHive(); 224 while (job.Progress.ProgressValue != 1) 225 { } 226 227 Thread.Sleep(1000); 228 job.Progress.Status = "Upload finished"; 229 Thread.Sleep(2000); 230 return RedirectToAction("Index", "Job"); 231 } 232 else 233 { 234 HiveServiceLocatorWebManagerService.SetLoginErrorMessage(); 235 return RedirectToAction("Index", "Home"); 236 } 237 } 238 //TODO Work in progress 239 /* public async Task<IActionResult> DownloadFile(int index, int filedex) 240 { 241 if (((HiveServiceLocatorWebManagerService)(HiveServiceLocatorWebManagerService.Instance)).CheckLogin()) 242 { 243 UploadedJobViewModel upper = new UploadedJobViewModel(); 244 fillUploadsPaths(upper, index); 245 246 HttpContext.Response.ContentType = "APPLICATION/OCTET-STREAM"; 247 String Header = "Attachment; Filename=" + upper.DisplayFilesPaths[filedex]; 248 HttpContext.Response.Headers.Add("Content-Disposition", Header); 249 System.IO.FileInfo Dfile = new System.IO.FileInfo(upper.FullFilesPaths[filedex]); 250 await HttpContext.Response.WriteAsync(Dfile.FullName); 251 //HttpContext.Response.End(); 252 253 var message = upper.DisplayFilesPaths[filedex] + " has been downloaded"; 254 255 upper.message = message; 256 ViewBag.Title = "Downloaded file"; 257 258 return View("Uploads", upper); 259 } 260 else 261 { 262 HiveServiceLocatorWebManagerService.SetLoginErrorMessage(); 263 return RedirectToAction("Index", "Home"); 264 } 265 }*/ 266 267 #endregion 268 269 #region Uploader 270 public IActionResult Uploader() 87 271 { 88 272 if (((HiveServiceLocatorWebManagerService)(HiveServiceLocatorWebManagerService.Instance)).CheckLogin()) 89 273 { 90 274 ViewBag.Title = "Upload Jobs"; 91 return View("Upload"); 275 ViewBag.Name = client.ClientCredentials.UserName.UserName; 276 return View("Uploader"); 92 277 } 93 278 else … … 98 283 } 99 284 [HttpPost] 100 public async Task<IActionResult> Upload (ICollection<IFormFile> files)285 public async Task<IActionResult> Uploader(ICollection<IFormFile> files, string directory) 101 286 { 102 287 103 288 UploadedJobViewModel upper = new UploadedJobViewModel(); 104 var uploads = Path.Combine(_environment.WebRootPath, "uploads"); 289 var uploads = Path.Combine(_environment.WebRootPath, "uploads", client.ClientCredentials.UserName.UserName, 290 directory); 291 Directory.CreateDirectory(uploads); 105 292 foreach (var file in files) 106 293 { … … 109 296 var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"'); 110 297 await file.SaveAsAsync(Path.Combine(uploads, fileName)); 111 var ioptimizer = ContentManager.Load(Path.Combine(uploads, fileName));112 OptimizerHiveTask task = new OptimizerHiveTask((IOptimizer)ioptimizer);113 upper.Tasks.Add(task);298 // var ioptimizer = ContentManager.Load(Path.Combine(uploads, fileName)); 299 //OptimizerHiveTask task = new OptimizerHiveTask((IOptimizer)ioptimizer); 300 //upper.Tasks.Add(task); 114 301 } 115 302 } 116 303 ViewBag.Title = "Upload complete"; 117 return View(); 118 119 } 304 return RedirectToAction("Uploads", "Job"); 305 306 } 307 #endregion 120 308 } 121 309 }
Note: See TracChangeset
for help on using the changeset viewer.