- Timestamp:
- 03/29/16 17:02:16 (9 years ago)
- Location:
- branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Controllers
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Controllers/HomeController.cs
r13733 r13739 5 5 using Microsoft.AspNet.Mvc; 6 6 using System.ServiceModel.Security; 7 using Microsoft.AspNet.Http; 8 using System; 9 using HeuristicLab.Clients.Hive.WebJobManager.ViewModels; 7 10 8 11 namespace HeuristicLab.Clients.Hive.WebJobManager.Controllers … … 13 16 public class HomeController : Controller 14 17 { 15 private LoginViewModelService loginViewModelService;18 private WebLoginService weblog; 16 19 private HiveServiceClient client; 17 public HomeController( ILoginViewModelService loginViewModelService)20 public HomeController() 18 21 { 19 this. loginViewModelService = (LoginViewModelService)loginViewModelService;22 this.weblog = WebLoginService.Instance; 20 23 } 21 24 #region Login … … 27 30 { 28 31 ViewBag.Title = "Login"; 29 loginViewModelService.clear(); 30 return View(loginViewModelService.GetLoginViewModel()); 32 var user = HttpContext.Session.GetString("UserId"); 33 if(user != null && user != "") 34 { 35 Guid t = Guid.Parse(user); 36 weblog.logout(t); 37 HttpContext.Session.Clear(); 38 } 39 return View(new LoginViewModel()); 40 31 41 } 32 42 /// <summary> … … 40 50 if (!string.IsNullOrEmpty(loginName) && !string.IsNullOrEmpty(password)) 41 51 { 42 var model = loginViewModelService.GetLoginViewModel(); 43 HiveServiceLocatorWeb hiveServiceLocator = (HiveServiceLocatorWeb)HiveServiceLocatorWeb.Instance; 44 HeuristicLab.Clients.Common.Properties.Settings.Default.UserName = loginName; 45 HeuristicLab.Clients.Common.Properties.Settings.Default.Password = Common.CryptoService.EncryptString(password); 46 HeuristicLab.Clients.Common.Properties.Settings.Default.Save(); 52 var passE = Common.CryptoService.EncryptString(password); 53 var model = new LoginViewModel(loginName, passE); 54 HiveServiceLocatorWeb hiveServiceLocator = new HiveServiceLocatorWeb(); 55 Common.Properties.Settings.Default.UserName = loginName; 56 Common.Properties.Settings.Default.Password = passE; 57 Common.Properties.Settings.Default.Save(); 47 58 hiveServiceLocator.Username = loginName; 48 59 hiveServiceLocator.Password = password; 60 hiveServiceLocator.UserId = model.userId; 49 61 50 62 client = hiveServiceLocator.getHiveServiceClient(); … … 52 64 var test = client.GetJobs();//Throws messageSecurityException if login failss 53 65 ViewBag.Title = "Login succesful"; 54 66 weblog.newLogin(model, hiveServiceLocator); 67 HttpContext.Session.SetString("UserId", model.userId.ToString()); 55 68 return RedirectToAction("Index","Job"); 56 69 } … … 58 71 { 59 72 ViewBag.Title = "Login"; 73 model = new LoginViewModel(); 60 74 model.errorMessage = "Wrong login, try again"; 61 75 return View("Index", model); … … 66 80 { 67 81 ViewBag.Title = "Login"; 68 var model = loginViewModelService.GetLoginViewModel();82 var model = new LoginViewModel(); 69 83 model.errorMessage = "You should fill in both fields"; 70 84 return View("Index", model); -
branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Controllers/JobController.cs
r13735 r13739 23 23 public class JobController : Controller 24 24 { 25 private HiveServiceClient client; 25 private WebLoginService weblog; 26 27 private HiveServiceLocatorWeb serviceLocator; 28 private HiveServiceClient serviceClient; 29 private HiveClientWeb clientWeb; 30 private Guid userId; 31 26 32 private JobViewModel vm; 27 33 private IHostingEnvironment _environment; 28 34 35 36 29 37 public JobController(IHostingEnvironment env) 30 38 { 31 HiveServiceLocatorWeb hiveServiceLocator = (HiveServiceLocatorWeb)HiveServiceLocatorWeb.Instance; 32 client = hiveServiceLocator.getHiveServiceClient(); 39 weblog = WebLoginService.Instance; 33 40 vm = new JobViewModel(); 34 35 36 41 _environment = env; 37 42 } 43 44 /// <summary> 45 /// initializes the connection for the right user. Not constructor because httpcontext is needed. 46 /// </summary> 47 private void init() 48 { 49 var u = HttpContext.Session.GetString("UserId"); 50 if (u == null || u == "" || Guid.Parse(u) == Guid.Empty) 51 { 52 userId = Guid.Empty; 53 serviceLocator = new HiveServiceLocatorWeb(); 54 serviceClient = serviceLocator.getHiveServiceClient(); 55 clientWeb = new HiveClientWeb(serviceLocator, userId); 56 } 57 else 58 { 59 userId = Guid.Parse(u); 60 serviceLocator = weblog.getServiceLocator(userId); 61 serviceClient = serviceLocator.getHiveServiceClient(); 62 clientWeb = weblog.getClientWeb(userId); 63 } 64 } 65 38 66 #region Jobs 39 67 /// <summary> … … 45 73 try 46 74 { 47 HiveClientWeb.Instance.Refresh();48 49 vm.userJobs = HiveClientWeb.Instance.Jobs.ToList();75 init(); 76 clientWeb.Refresh(); 77 vm.userJobs = clientWeb.Jobs.ToList(); 50 78 } 51 79 catch (Exception e) … … 53 81 if (e is MessageSecurityException || e is InvalidOperationException) 54 82 { 55 HiveServiceLocatorWeb.SetLoginErrorMessage();56 83 return RedirectToAction("Index", "Home"); 57 84 } 58 85 throw; 59 86 } 87 ViewBag.SessionId = HttpContext.Session.GetString("UserId"); 60 88 ViewBag.Title = "Jobs"; 61 89 return View(vm); … … 68 96 public IActionResult Selected(Guid id) 69 97 { 70 if (((HiveServiceLocatorWeb)(HiveServiceLocatorWeb.Instance)).CheckLogin()) 71 { 72 HiveClientWeb.Instance.Refresh(); 73 74 vm.userJobs = HiveClientWeb.Instance.Jobs.ToList(); 75 foreach(var j in vm.userJobs) 76 { 77 if(j.Id == id) 98 init(); 99 if (serviceLocator.CheckLogin()) 100 { 101 clientWeb.Refresh(); 102 103 vm.userJobs = clientWeb.Jobs.ToList(); 104 foreach (var j in vm.userJobs) 105 { 106 if (j.Id == id) 78 107 { 79 108 vm.selectedJob = j; 80 109 } 81 110 } 82 vm.selectedJob.RefreshAutomatically = true;83 HiveClientWeb.LoadJob(vm.selectedJob);84 FileOpeningService.Instance.NewModel();85 FileOpeningService.Instance.Job = vm.selectedJob;111 //vm.selectedJob.RefreshAutomatically = true; 112 clientWeb.LoadJob(vm.selectedJob); 113 weblog.getFileOpener(userId).NewModel(); 114 weblog.getFileOpener(userId).Job = vm.selectedJob; 86 115 ViewBag.Title = vm.selectedJob.Job.Name + " - Jobs"; 116 ViewBag.SessionId = HttpContext.Session.GetString("UserId"); 87 117 return View("Index", vm); 88 118 } 89 119 else 90 120 { 91 HiveServiceLocatorWeb.SetLoginErrorMessage();92 121 return RedirectToAction("Index", "Home"); 93 122 } … … 100 129 public IActionResult Delete(Guid id) 101 130 { 102 if (((HiveServiceLocatorWeb)(HiveServiceLocatorWeb.Instance)).CheckLogin()) 103 { 104 105 vm.message = client.GetJob(id).Name + " deleted"; 106 client.DeleteJob(id); 107 HiveClientWeb.Instance.Refresh(); 108 109 vm.userJobs = HiveClientWeb.Instance.Jobs.ToList(); 131 init(); 132 if (serviceLocator.CheckLogin()) 133 { 134 135 vm.message = serviceClient.GetJob(id).Name + " deleted"; 136 serviceClient.DeleteJob(id); 137 clientWeb.Refresh(); 138 139 vm.userJobs = clientWeb.Jobs.ToList(); 110 140 ViewBag.Title = "Jobs"; 111 141 return View("Index", vm); … … 113 143 else 114 144 { 115 HiveServiceLocatorWeb.SetLoginErrorMessage();116 145 return RedirectToAction("Index", "Home"); 117 146 } … … 126 155 public IActionResult Uploads() 127 156 { 128 if (((HiveServiceLocatorWeb)(HiveServiceLocatorWeb.Instance)).CheckLogin()) 157 init(); 158 if (serviceLocator.CheckLogin()) 129 159 { 130 160 UploadedJobViewModel upper = new UploadedJobViewModel(); 131 161 fillUploadsPaths(upper, -1); 132 ViewBag.Name = client.ClientCredentials.UserName.UserName;162 ViewBag.Name = serviceClient.ClientCredentials.UserName.UserName; 133 163 ViewBag.Title = "Uploaded files"; 134 164 return View("Uploads", upper); … … 136 166 else 137 167 { 138 HiveServiceLocatorWeb.SetLoginErrorMessage();139 168 return RedirectToAction("Index", "Home"); 140 169 } … … 147 176 public IActionResult UploadDir(int index) 148 177 { 149 if (((HiveServiceLocatorWeb)(HiveServiceLocatorWeb.Instance)).CheckLogin()) 178 init(); 179 if (serviceLocator.CheckLogin()) 150 180 { 151 181 UploadedJobViewModel upper = new UploadedJobViewModel(); … … 157 187 else 158 188 { 159 HiveServiceLocatorWeb.SetLoginErrorMessage();160 189 return RedirectToAction("Index", "Home"); 161 190 } … … 167 196 /// <param name="index">Index selected directory</param> 168 197 private void fillUploadsPaths(UploadedJobViewModel vm, int index) 169 170 198 { 171 199 var tempdex = index; //Fix when maps gets deleted 172 var start = Path.Combine(_environment.WebRootPath, "uploads", client.ClientCredentials.UserName.UserName);200 var start = Path.Combine(_environment.WebRootPath, "uploads", serviceClient.ClientCredentials.UserName.UserName); 173 201 var dirs = Directory.GetDirectories(start); 174 202 foreach (string dir in dirs) … … 205 233 public IActionResult DeleteFile(int index, int filedex) 206 234 { 207 if (((HiveServiceLocatorWeb)(HiveServiceLocatorWeb.Instance)).CheckLogin()) 235 init(); 236 if (serviceLocator.CheckLogin()) 208 237 { 209 238 UploadedJobViewModel upper = new UploadedJobViewModel(); … … 221 250 else 222 251 { 223 HiveServiceLocatorWeb.SetLoginErrorMessage();224 252 return RedirectToAction("Index", "Home"); 225 253 } … … 233 261 public IActionResult OpenFile(int index, int filedex) 234 262 { 235 if (((HiveServiceLocatorWeb)(HiveServiceLocatorWeb.Instance)).CheckLogin()) 263 init(); 264 if (serviceLocator.CheckLogin()) 236 265 { 237 266 UploadedJobViewModel upper = new UploadedJobViewModel(); 238 267 fillUploadsPaths(upper, index); 239 268 240 FileOpeningService serve = FileOpeningService.Instance;269 var serve = weblog.getFileOpener(userId); 241 270 serve.NewModel(); 242 271 serve.env = _environment; … … 260 289 ViewBag.JobsCount = serve.Job.Job.JobCount; 261 290 ViewBag.Title = serve.vm.SelectedTask.ItemTask.Name + " - Open file"; 262 291 ViewBag.SessionId = HttpContext.Session.GetString("UserId"); 263 292 return View("OpenFile", serve.vm); 264 293 } 265 294 else 266 295 { 267 HiveServiceLocatorWeb.SetLoginErrorMessage();268 296 return RedirectToAction("Index", "Home"); 269 297 } … … 275 303 public IActionResult AddToHive() 276 304 { 277 i f (((HiveServiceLocatorWeb)(HiveServiceLocatorWeb.Instance)).CheckLogin())278 {279 var job = FileOpeningService.Instance.AddCurrentModelToHive();280 while (job.Progress.ProgressValue != 1)281 { }282 283 Thread.Sleep(1000); 284 job.Progress.Status = "Upload finished";285 Thread.Sleep(2000);286 return RedirectToAction("Index", "Job");287 }288 else289 {290 HiveServiceLocatorWeb.SetLoginErrorMessage();305 init(); 306 if (serviceLocator.CheckLogin()) 307 { 308 var job = weblog.getFileOpener(userId).AddCurrentModelToHive(); 309 while (job.Progress.ProgressValue != 1) 310 { } 311 312 Thread.Sleep(1000); 313 job.Progress.Status = "Upload finished"; 314 Thread.Sleep(2000); 315 return RedirectToAction("Index", "Job"); 316 } 317 else 318 { 291 319 return RedirectToAction("Index", "Home"); 292 320 } … … 334 362 public async Task<IActionResult> Uploader(ICollection<IFormFile> files, string directory) 335 363 { 336 364 init(); 337 365 UploadedJobViewModel upper = new UploadedJobViewModel(); 338 var uploads = Path.Combine(_environment.WebRootPath, "uploads", client.ClientCredentials.UserName.UserName,366 var uploads = Path.Combine(_environment.WebRootPath, "uploads", serviceClient.ClientCredentials.UserName.UserName, 339 367 directory); 340 368 Directory.CreateDirectory(uploads); -
branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Controllers/ResourceController.cs
r13733 r13739 1 1 using HeuristicLab.Clients.Hive.WebJobManager.Services; 2 2 using Microsoft.AspNet.Hosting; 3 using Microsoft.AspNet.Http; 3 4 using Microsoft.AspNet.Mvc; 4 5 using System; … … 12 13 public class ResourceController : Controller 13 14 { 14 private HiveServiceClient client; 15 private WebLoginService weblog; 16 private HiveServiceLocatorWeb serviceLocator; 17 private HiveServiceClient serviceClient; 18 private HiveClientWeb clientWeb; 19 private Guid userId; 20 15 21 private IHostingEnvironment _environment; 16 22 17 23 public ResourceController(IHostingEnvironment env) 18 24 { 19 HiveServiceLocatorWeb hiveServiceLocator = (HiveServiceLocatorWeb)HiveServiceLocatorWeb.Instance; 20 client = hiveServiceLocator.getHiveServiceClient(); 25 weblog = WebLoginService.Instance; 26 var u = HttpContext.Session.GetString("UserId"); 27 if (u == null || u == "" || Guid.Parse(u) == Guid.Empty) 28 { 29 userId = Guid.Empty; 30 serviceLocator = new HiveServiceLocatorWeb(); 31 serviceClient = serviceLocator.getHiveServiceClient(); 32 clientWeb = new HiveClientWeb(serviceLocator, userId); 33 } 34 else { 35 userId = Guid.Parse(u); 36 37 serviceLocator = weblog.getServiceLocator(userId); 38 serviceClient = serviceLocator.getHiveServiceClient(); 39 clientWeb = weblog.getClientWeb(userId); 40 } 21 41 22 42 _environment = env; … … 24 44 public IActionResult Index() 25 45 { 26 if ( ((HiveServiceLocatorWeb)(HiveServiceLocatorWeb.Instance)).CheckLogin())46 if (serviceLocator.CheckLogin()) 27 47 { 28 48 … … 32 52 else 33 53 { 34 HiveServiceLocatorWeb.SetLoginErrorMessage();35 54 return RedirectToAction("Index", "Home"); 36 55 } -
branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Controllers/UserController.cs
r13733 r13739 1 1 using HeuristicLab.Clients.Hive.WebJobManager.Services; 2 2 using Microsoft.AspNet.Hosting; 3 using Microsoft.AspNet.Http; 3 4 using Microsoft.AspNet.Mvc; 4 5 using System; … … 12 13 public class UserController: Controller 13 14 { 14 private HiveServiceClient client; 15 private WebLoginService weblog; 16 private HiveServiceLocatorWeb serviceLocator; 17 private HiveServiceClient serviceClient; 18 private HiveClientWeb clientWeb; 19 private Guid userId; 20 15 21 private IHostingEnvironment _environment; 16 22 17 23 public UserController(IHostingEnvironment env) 18 24 { 19 HiveServiceLocatorWeb hiveServiceLocator = (HiveServiceLocatorWeb)HiveServiceLocatorWeb.Instance; 20 client = hiveServiceLocator.getHiveServiceClient(); 25 weblog = WebLoginService.Instance; 26 var u = HttpContext.Session.GetString("UserId"); 27 if (u == null || u == "" || Guid.Parse(u) == Guid.Empty) 28 { 29 userId = Guid.Empty; 30 serviceLocator = new HiveServiceLocatorWeb(); 31 serviceClient = serviceLocator.getHiveServiceClient(); 32 clientWeb = new HiveClientWeb(serviceLocator, userId); 33 } 34 else { 35 userId = Guid.Parse(u); 36 37 serviceLocator = weblog.getServiceLocator(userId); 38 serviceClient = serviceLocator.getHiveServiceClient(); 39 clientWeb = weblog.getClientWeb(userId); 40 } 21 41 22 42 _environment = env; … … 24 44 public IActionResult Index() 25 45 { 26 if ( ((HiveServiceLocatorWeb)(HiveServiceLocatorWeb.Instance)).CheckLogin())46 if (serviceLocator.CheckLogin()) 27 47 { 28 48 … … 32 52 else 33 53 { 34 HiveServiceLocatorWeb.SetLoginErrorMessage();35 54 return RedirectToAction("Index", "Home"); 36 55 }
Note: See TracChangeset
for help on using the changeset viewer.