- Timestamp:
- 03/29/16 17:02:16 (9 years ago)
- Location:
- branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager
- Files:
-
- 2 added
- 12 deleted
- 21 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 } -
branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Hubs/JobUpdaterHub.cs
r13735 r13739 1 1 using HeuristicLab.Clients.Hive.WebJobManager.Services; 2 2 using HeuristicLab.Common; 3 using Microsoft.AspNet.Http; 3 4 using Microsoft.AspNet.SignalR; 4 5 using Newtonsoft.Json; 5 6 using System; 6 7 using System.Collections.Generic; 8 using System.Threading.Tasks; 7 9 8 10 namespace HeuristicLab.Clients.Hive.WebJobManager … … 15 17 16 18 private RefreshableJob Job;//Current job (only used as reference, instance gets lost) 17 19 20 private WebLoginService weblog; 21 private FileOpeningService fileopener; 22 private Guid userId; 23 24 private void loader() 25 { 26 weblog = WebLoginService.Instance; 27 string uid = Context.QueryString["userid"]; 28 if (uid == null || uid == "" || Guid.Parse(uid) == Guid.Empty) 29 { 30 userId = Guid.Empty; 31 } 32 else { 33 userId = Guid.Parse(uid); 34 fileopener = weblog.getFileOpener(userId); 35 } 36 } 18 37 /// <summary> 19 38 /// Initial connection call from client … … 21 40 public void initConnection() 22 41 { 23 FileOpeningService.Instance.previousids = new List<Guid>(); 24 FileOpeningService.Instance.previousLogs = new List<int>(); 25 Job = FileOpeningService.Instance.Job; 42 loader(); 43 fileopener.previousids = new List<Guid>(); 44 fileopener.previousLogs = new List<int>(); 45 Job = fileopener.Job; 26 46 updateAll();//start initial update 27 47 … … 32 52 public void updateAll() 33 53 { 34 FileOpeningService.Instance.refreshJob();//refresh all data from job 35 Job = FileOpeningService.Instance.Job; 54 loader(); 55 fileopener.refreshJob();//refresh all data from job 56 Job = fileopener.Job; 36 57 updateJob(); 37 58 foreach (var t in Job.HiveTasks) … … 45 66 46 67 } 47 p ublicvoid updateJob()68 private void updateJob() 48 69 { 49 70 Clients.Caller.processJobData(Job.Job.CalculatingCount, Job.Job.FinishedCount); … … 59 80 int index; 60 81 bool test = false; 61 if ( FileOpeningService.Instance.previousids.Contains(task.Task.Id))82 if (fileopener.previousids.Contains(task.Task.Id)) 62 83 { 63 index = FileOpeningService.Instance.previousids.IndexOf(task.Task.Id);84 index = fileopener.previousids.IndexOf(task.Task.Id); 64 85 } 65 86 else 66 87 {//initial add to previous list, used to check if updates happened 67 FileOpeningService.Instance.previousids.Add(task.Task.Id);68 index = FileOpeningService.Instance.previousids.IndexOf(task.Task.Id);69 FileOpeningService.Instance.previousLogs.Add(task.Task.StateLog.Count);88 fileopener.previousids.Add(task.Task.Id); 89 index = fileopener.previousids.IndexOf(task.Task.Id); 90 fileopener.previousLogs.Add(task.Task.StateLog.Count); 70 91 test = true;//initial added task, data must be sent 71 92 } 72 var previous = FileOpeningService.Instance.previousLogs[index];93 var previous = fileopener.previousLogs[index]; 73 94 if (test || previous < task.Task.StateLog.Count) 74 95 {//Checks if change happened so data is not sent unnecessary 75 FileOpeningService.Instance.previousLogs[index] = task.Task.StateLog.Count;96 fileopener.previousLogs[index] = task.Task.StateLog.Count; 76 97 JsonSerializerSettings settings = new JsonSerializerSettings(); 77 98 settings.ContractResolver = new JsonTaskResolver(); … … 94 115 public void restartTask(Guid id) 95 116 { 96 ((HiveServiceLocatorWeb)(HiveServiceLocatorWeb.Instance)).getHiveServiceClient().RestartTask(id); 117 loader(); 118 weblog.getServiceLocator(userId).getHiveServiceClient().RestartTask(id); 97 119 } 98 120 } -
branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Hubs/ProgressHub.cs
r13735 r13739 15 15 public class ProgressHub : Hub 16 16 { 17 private RefreshableJob Job; 17 private WebLoginService weblog; 18 private Guid userId; 19 private FileOpeningService fileopener; 20 private void loader() 21 { 22 weblog = WebLoginService.Instance; 23 string uid = Context.QueryString["userid"]; 24 if (uid == null || uid == "" || Guid.Parse(uid) == Guid.Empty) 25 { 26 userId = Guid.Empty; 27 } 28 else { 29 userId = Guid.Parse(uid); 30 fileopener = weblog.getFileOpener(userId); 31 } 32 } 33 18 34 /// <summary> 19 35 /// First message from client … … 22 38 public void HandleMessage(string receivedString) 23 39 { 24 40 loader(); 25 41 Clients.Caller.processMessage("Connection Established"); 26 Job = FileOpeningService.Instance.Job; 27 Job.Progress.StatusChanged += runHub; 42 fileopener.Job.Progress.StatusChanged += runHub; 28 43 } 29 44 /// <summary> … … 33 48 public void ChangeNameResource(string name, string resource) 34 49 { 50 loader(); 35 51 if (name != null) 36 FileOpeningService.Instance.Job.Job.Name = name;52 fileopener.Job.Job.Name = name; 37 53 if(resource != null && resource != "") 38 54 { 39 FileOpeningService.Instance.Job.Job.ResourceNames += "/" + resource;55 fileopener.Job.Job.ResourceNames += "/" + resource; 40 56 } 41 57 } … … 49 65 public void ToggleChild(int[][] arr) 50 66 { 51 Job = FileOpeningService.Instance.Job;52 HiveTask current = Job.HiveTasks.ToList()[0];67 loader(); 68 HiveTask current = fileopener.Job.HiveTasks.ToList()[0]; 53 69 if (arr.Length == 0) 54 70 {//check if upper job … … 92 108 public void ChangePriority(int[][] arr, int prior) 93 109 { 94 Job = FileOpeningService.Instance.Job;95 HiveTask current = Job.HiveTasks.ToList()[0];110 loader(); 111 HiveTask current = fileopener.Job.HiveTasks.ToList()[0]; 96 112 if (arr.Length == 0) 97 113 {//check if upper job … … 132 148 public void runHub(object sender, EventArgs e) 133 149 { 150 loader(); 134 151 int value = 0; 135 152 136 switch ( Job.Progress.Status)153 switch (fileopener.Job.Progress.Status) 137 154 { 138 155 case "Connecting to server...": … … 152 169 break; 153 170 default://Tasks are uploading individually 154 value = (int)(50 + (40 * Job.Progress.ProgressValue));171 value = (int)(50 + (40 * fileopener.Job.Progress.ProgressValue)); 155 172 break; 156 173 157 174 } 158 175 //send info to client 159 Clients.Caller.processMessage( Job.Progress.Status, value);176 Clients.Caller.processMessage(fileopener.Job.Progress.Status, value); 160 177 161 178 } -
branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Services/Imports/ConcurrentTaskDownloaderWeb.cs
r13733 r13739 30 30 31 31 // 32 /// <summary> 33 /// Rewritten to use HiveServiceLocatorWeb and HiveClientWeb 34 /// </summary> 35 public class ConcurrentTaskDownloaderWeb<T> : IDisposable where T : class, ITask { 36 private bool abort = false; 37 // use semaphore to ensure only few concurrenct connections and few SerializedJob objects in memory 38 private Semaphore downloadSemaphore; 39 private Semaphore deserializeSemaphore; 32 /// <summary> 33 /// Rewritten to use HiveServiceLocatorWeb and HiveClientWeb 34 /// </summary> 35 public class ConcurrentTaskDownloaderWeb<T> : IDisposable where T : class, ITask 36 { 37 private bool abort = false; 38 // use semaphore to ensure only few concurrenct connections and few SerializedJob objects in memory 39 private Semaphore downloadSemaphore; 40 private Semaphore deserializeSemaphore; 41 private HiveServiceLocatorWeb serviceLocator; 42 public ConcurrentTaskDownloaderWeb(int concurrentDownloads, int concurrentDeserializations, HiveServiceLocatorWeb hiv) 43 { 44 downloadSemaphore = new Semaphore(concurrentDownloads, concurrentDownloads); 45 deserializeSemaphore = new Semaphore(concurrentDeserializations, concurrentDeserializations); 46 serviceLocator = hiv; 47 } 40 48 41 public ConcurrentTaskDownloaderWeb(int concurrentDownloads, int concurrentDeserializations) { 42 downloadSemaphore = new Semaphore(concurrentDownloads, concurrentDownloads); 43 deserializeSemaphore = new Semaphore(concurrentDeserializations, concurrentDeserializations); 49 public void DownloadTaskData(Task t, Action<Task, T> onFinishedAction) 50 { 51 Task<Tuple<Task, T>> task = Task<Tuple<Task, TaskData>>.Factory.StartNew(DownloadTaskData, t) 52 .ContinueWith((y) => DeserializeTask(y.Result)); 53 54 task.ContinueWith((x) => OnTaskFinished(x, onFinishedAction), TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.OnlyOnRanToCompletion); 55 task.ContinueWith((x) => OnTaskFailed(x), TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.OnlyOnFaulted); 56 } 57 58 public void DownloadTaskDataAndTask(Guid taskId, Action<Task, T> onFinishedAction) 59 { 60 Task<Tuple<Task, T>> task = Task<Task>.Factory.StartNew(DownloadTask, taskId) 61 .ContinueWith((x) => DownloadTaskData(x.Result)) 62 .ContinueWith((y) => DeserializeTask(y.Result)); 63 64 task.ContinueWith((x) => OnTaskFinished(x, onFinishedAction), TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.OnlyOnRanToCompletion); 65 task.ContinueWith((x) => OnTaskFailed(x), TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.OnlyOnFaulted); 66 } 67 68 private void OnTaskFinished(Task<Tuple<Task, T>> task, Action<Task, T> onFinishedAction) 69 { 70 onFinishedAction(task.Result.Item1, task.Result.Item2); 71 } 72 private void OnTaskFailed(Task<Tuple<Task, T>> task) 73 { 74 task.Exception.Flatten().Handle((e) => { return true; }); 75 OnExceptionOccured(task.Exception.Flatten()); 76 } 77 78 private Task DownloadTask(object taskId) 79 { 80 Task t = null; 81 HiveClientWeb.TryAndRepeat(() => 82 { 83 t = serviceLocator.CallHiveService(s => s.GetTask((Guid)taskId)); 84 }, Settings.Default.MaxRepeatServiceCalls, "Failed to download task."); 85 return t; 86 } 87 88 protected Tuple<Task, TaskData> DownloadTaskData(object taskId) 89 { 90 return DownloadTaskData((Task)taskId); 91 } 92 93 protected Tuple<Task, TaskData> DownloadTaskData(Task task) 94 { 95 downloadSemaphore.WaitOne(); 96 TaskData result = null; 97 try 98 { 99 if (abort) return null; 100 HiveClientWeb.TryAndRepeat(() => 101 { 102 result = serviceLocator.CallHiveService(s => s.GetTaskData(task.Id)); 103 }, Settings.Default.MaxRepeatServiceCalls, "Failed to download task data."); 104 } 105 finally 106 { 107 downloadSemaphore.Release(); 108 } 109 return new Tuple<Task, TaskData>(task, result); 110 } 111 112 protected Tuple<Task, T> DeserializeTask(Tuple<Task, TaskData> taskData) 113 { 114 deserializeSemaphore.WaitOne(); 115 try 116 { 117 if (abort || taskData.Item2 == null || taskData.Item1 == null) return null; 118 var deserializedJob = PersistenceUtil.Deserialize<T>(taskData.Item2.Data); 119 taskData.Item2.Data = null; // reduce memory consumption. 120 return new Tuple<Task, T>(taskData.Item1, deserializedJob); 121 } 122 finally 123 { 124 deserializeSemaphore.Release(); 125 } 126 } 127 128 public event EventHandler<EventArgs<Exception>> ExceptionOccured; 129 private void OnExceptionOccured(Exception exception) 130 { 131 var handler = ExceptionOccured; 132 if (handler != null) handler(this, new EventArgs<Exception>(exception)); 133 } 134 135 #region IDisposable Members 136 public void Dispose() 137 { 138 deserializeSemaphore.Dispose(); 139 downloadSemaphore.Dispose(); 140 } 141 #endregion 44 142 } 45 46 public void DownloadTaskData(Task t, Action<Task, T> onFinishedAction) {47 Task<Tuple<Task, T>> task = Task<Tuple<Task, TaskData>>.Factory.StartNew(DownloadTaskData, t)48 .ContinueWith((y) => DeserializeTask(y.Result));49 50 task.ContinueWith((x) => OnTaskFinished(x, onFinishedAction), TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.OnlyOnRanToCompletion);51 task.ContinueWith((x) => OnTaskFailed(x), TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.OnlyOnFaulted);52 }53 54 public void DownloadTaskDataAndTask(Guid taskId, Action<Task, T> onFinishedAction) {55 Task<Tuple<Task, T>> task = Task<Task>.Factory.StartNew(DownloadTask, taskId)56 .ContinueWith((x) => DownloadTaskData(x.Result))57 .ContinueWith((y) => DeserializeTask(y.Result));58 59 task.ContinueWith((x) => OnTaskFinished(x, onFinishedAction), TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.OnlyOnRanToCompletion);60 task.ContinueWith((x) => OnTaskFailed(x), TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.OnlyOnFaulted);61 }62 63 private void OnTaskFinished(Task<Tuple<Task, T>> task, Action<Task, T> onFinishedAction) {64 onFinishedAction(task.Result.Item1, task.Result.Item2);65 }66 private void OnTaskFailed(Task<Tuple<Task, T>> task) {67 task.Exception.Flatten().Handle((e) => { return true; });68 OnExceptionOccured(task.Exception.Flatten());69 }70 71 private Task DownloadTask(object taskId) {72 Task t = null;73 HiveClientWeb.TryAndRepeat(() => {74 t = HiveServiceLocatorWeb.Instance.CallHiveService(s => s.GetTask((Guid)taskId));75 }, Settings.Default.MaxRepeatServiceCalls, "Failed to download task.");76 return t;77 }78 79 protected Tuple<Task, TaskData> DownloadTaskData(object taskId) {80 return DownloadTaskData((Task)taskId);81 }82 83 protected Tuple<Task, TaskData> DownloadTaskData(Task task) {84 downloadSemaphore.WaitOne();85 TaskData result = null;86 try {87 if (abort) return null;88 HiveClientWeb.TryAndRepeat(() => {89 result = HiveServiceLocatorWeb.Instance.CallHiveService(s => s.GetTaskData(task.Id));90 }, Settings.Default.MaxRepeatServiceCalls, "Failed to download task data.");91 }92 finally {93 downloadSemaphore.Release();94 }95 return new Tuple<Task, TaskData>(task, result);96 }97 98 protected Tuple<Task, T> DeserializeTask(Tuple<Task, TaskData> taskData) {99 deserializeSemaphore.WaitOne();100 try {101 if (abort || taskData.Item2 == null || taskData.Item1 == null) return null;102 var deserializedJob = PersistenceUtil.Deserialize<T>(taskData.Item2.Data);103 taskData.Item2.Data = null; // reduce memory consumption.104 return new Tuple<Task, T>(taskData.Item1, deserializedJob);105 }106 finally {107 deserializeSemaphore.Release();108 }109 }110 111 public event EventHandler<EventArgs<Exception>> ExceptionOccured;112 private void OnExceptionOccured(Exception exception) {113 var handler = ExceptionOccured;114 if (handler != null) handler(this, new EventArgs<Exception>(exception));115 }116 117 #region IDisposable Members118 public void Dispose() {119 deserializeSemaphore.Dispose();120 downloadSemaphore.Dispose();121 }122 #endregion123 }124 143 } -
branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Services/Imports/HiveClientWeb.cs
r13733 r13739 46 46 public sealed class HiveClientWeb : IContent 47 47 { 48 private static HiveClientWeb instance; 49 public static HiveClientWeb Instance 50 { 51 get 52 { 53 if (instance == null) instance = new HiveClientWeb(); 54 return instance; 55 } 56 } 57 public static IHostingEnvironment CurrentEnv { get; set; } //Current building area 48 49 public IHostingEnvironment CurrentEnv { get; set; } //Current building area 58 50 #region Properties 59 51 private HiveItemCollection<RefreshableJob> jobs; … … 86 78 #endregion 87 79 88 private HiveClientWeb() 89 { 90 } 80 private HiveServiceLocatorWeb serviceLocator; 81 public Guid UserId { get; set; } 82 public HiveClientWeb(HiveServiceLocatorWeb serv, Guid u) 83 { 84 serviceLocator = serv; 85 UserId = u; 86 } 87 /// <summary> 88 /// Reaches to the webloginservice to get the current instance of the servicelocator. 89 /// </summary> 90 public void updateServiceLocator() 91 {// No idea if needed 92 serviceLocator = WebLoginService.Instance.getServiceLocator(UserId); 93 } 94 91 95 92 96 public void ClearHiveClientWeb() … … 117 121 { 118 122 jobs = new HiveItemCollection<RefreshableJob>(); 119 var jobsLoaded = HiveServiceLocatorWeb.Instance.CallHiveService<IEnumerable<Job>>(s => s.GetJobs());123 var jobsLoaded = serviceLocator.CallHiveService<IEnumerable<Job>>(s => s.GetJobs()); 120 124 121 125 foreach (var j in jobsLoaded) … … 158 162 159 163 #region Store 160 public staticvoid Store(IHiveItem item, CancellationToken cancellationToken)164 public void Store(IHiveItem item, CancellationToken cancellationToken) 161 165 { 162 166 if (item.Id == Guid.Empty) … … 164 168 if (item is RefreshableJob) 165 169 { 166 HiveClientWeb.Instance.UploadJob((RefreshableJob)item, cancellationToken);170 this.UploadJob((RefreshableJob)item, cancellationToken); 167 171 } 168 172 if (item is JobPermission) 169 173 { 170 174 var hep = (JobPermission)item; 171 hep.GrantedUserId = HiveServiceLocatorWeb.Instance.CallHiveService((s) => s.GetUserIdByUsername(hep.GrantedUserName));175 hep.GrantedUserId = serviceLocator.CallHiveService((s) => s.GetUserIdByUsername(hep.GrantedUserName)); 172 176 if (hep.GrantedUserId == Guid.Empty) 173 177 { 174 178 throw new ArgumentException(string.Format("The user {0} was not found.", hep.GrantedUserName)); 175 179 } 176 HiveServiceLocatorWeb.Instance.CallHiveService((s) => s.GrantPermission(hep.JobId, hep.GrantedUserId, hep.Permission));180 serviceLocator.CallHiveService((s) => s.GrantPermission(hep.JobId, hep.GrantedUserId, hep.Permission)); 177 181 } 178 182 } 179 183 else { 180 184 if (item is Job) 181 HiveServiceLocatorWeb.Instance.CallHiveService(s => s.UpdateJob((Job)item));182 } 183 } 184 public staticvoid StoreAsync(Action<Exception> exceptionCallback, IHiveItem item, CancellationToken cancellationToken)185 serviceLocator.CallHiveService(s => s.UpdateJob((Job)item)); 186 } 187 } 188 public void StoreAsync(Action<Exception> exceptionCallback, IHiveItem item, CancellationToken cancellationToken) 185 189 { 186 190 var call = new Func<Exception>(delegate () … … 205 209 206 210 #region Delete 207 public staticvoid Delete(IHiveItem item)211 public void Delete(IHiveItem item) 208 212 { 209 213 if (item.Id == Guid.Empty && item.GetType() != typeof(JobPermission)) … … 211 215 212 216 if (item is Job) 213 HiveServiceLocatorWeb.Instance.CallHiveService(s => s.DeleteJob(item.Id));217 serviceLocator.CallHiveService(s => s.DeleteJob(item.Id)); 214 218 if (item is RefreshableJob) 215 219 { … … 219 223 job.StopResultPolling(); 220 224 } 221 HiveServiceLocatorWeb.Instance.CallHiveService(s => s.DeleteJob(item.Id));225 serviceLocator.CallHiveService(s => s.DeleteJob(item.Id)); 222 226 } 223 227 if (item is JobPermission) 224 228 { 225 229 var hep = (JobPermission)item; 226 HiveServiceLocatorWeb.Instance.CallHiveService(s => s.RevokePermission(hep.JobId, hep.GrantedUserId));230 serviceLocator.CallHiveService(s => s.RevokePermission(hep.JobId, hep.GrantedUserId)); 227 231 } 228 232 item.Id = Guid.Empty; … … 251 255 #endregion 252 256 253 public staticvoid StartJob(Action<Exception> exceptionCallback, RefreshableJob refreshableJob, CancellationToken cancellationToken)254 { 255 HiveClientWeb.StoreAsync(257 public void StartJob(Action<Exception> exceptionCallback, RefreshableJob refreshableJob, CancellationToken cancellationToken) 258 { 259 this.StoreAsync( 256 260 new Action<Exception>((Exception ex) => 257 261 { … … 262 266 } 263 267 264 public staticvoid PauseJob(RefreshableJob refreshableJob)265 { 266 HiveServiceLocatorWeb.Instance.CallHiveService(service =>268 public void PauseJob(RefreshableJob refreshableJob) 269 { 270 serviceLocator.CallHiveService(service => 267 271 { 268 272 foreach (HiveTask task in refreshableJob.GetAllHiveTasks()) … … 274 278 } 275 279 276 public staticvoid StopJob(RefreshableJob refreshableJob)277 { 278 HiveServiceLocatorWeb.Instance.CallHiveService(service =>280 public void StopJob(RefreshableJob refreshableJob) 281 { 282 serviceLocator.CallHiveService(service => 279 283 { 280 284 foreach (HiveTask task in refreshableJob.GetAllHiveTasks()) … … 286 290 } 287 291 288 public staticvoid ResumeJob(RefreshableJob refreshableJob)289 { 290 HiveServiceLocatorWeb.Instance.CallHiveService(service =>292 public void ResumeJob(RefreshableJob refreshableJob) 293 { 294 serviceLocator.CallHiveService(service => 291 295 { 292 296 foreach (HiveTask task in refreshableJob.GetAllHiveTasks()) … … 315 319 foreach (var resourceName in resourceNames) 316 320 { 317 Guid resourceId = HiveServiceLocatorWeb.Instance.CallHiveService((s) => s.GetResourceId(resourceName));321 Guid resourceId = serviceLocator.CallHiveService((s) => s.GetResourceId(resourceName)); 318 322 if (resourceId == Guid.Empty) 319 323 { … … 330 334 // upload Job 331 335 refreshableJob.Progress.Status = "Uploading Job..."; 332 refreshableJob.Job.Id = HiveServiceLocatorWeb.Instance.CallHiveService((s) => s.AddJob(refreshableJob.Job));333 refreshableJob.Job = HiveServiceLocatorWeb.Instance.CallHiveService((s) => s.GetJob(refreshableJob.Job.Id)); // update owner and permissions336 refreshableJob.Job.Id = serviceLocator.CallHiveService((s) => s.AddJob(refreshableJob.Job)); 337 refreshableJob.Job = serviceLocator.CallHiveService((s) => s.GetJob(refreshableJob.Job.Id)); // update owner and permissions 334 338 cancellationToken.ThrowIfCancellationRequested(); 335 339 … … 340 344 // upload plugins 341 345 refreshableJob.Progress.Status = "Uploading plugins..."; 342 this.OnlinePlugins = HiveServiceLocatorWeb.Instance.CallHiveService((s) => s.GetPlugins());346 this.OnlinePlugins = serviceLocator.CallHiveService((s) => s.GetPlugins()); 343 347 this.AlreadyUploadedPlugins = new List<Plugin>(); 344 Plugin configFilePlugin = HiveServiceLocatorWeb.Instance.CallHiveService((s) => UploadConfigurationFile(s, onlinePlugins));348 Plugin configFilePlugin = serviceLocator.CallHiveService((s) => UploadConfigurationFile(s, onlinePlugins)); 345 349 this.alreadyUploadedPlugins.Add(configFilePlugin); 346 350 cancellationToken.ThrowIfCancellationRequested(); … … 371 375 /// Uploads the local configuration file as plugin 372 376 /// </summary> 373 private staticPlugin UploadConfigurationFile(IHiveService service, List<Plugin> onlinePlugins)377 private Plugin UploadConfigurationFile(IHiveService service, List<Plugin> onlinePlugins) 374 378 { 375 379 string exeFilePath = Path.Combine( CurrentEnv.WebRootPath, "bin" , HeuristicLab.Clients.Hive.Settings.Default.HLBinaryName); … … 436 440 lock (pluginLocker) 437 441 { 438 HiveServiceLocatorWeb.Instance.CallHiveService((s) => hiveTask.Task.PluginsNeededIds = PluginUtil.GetPluginDependencies(s, this.onlinePlugins, this.alreadyUploadedPlugins, plugins));442 serviceLocator.CallHiveService((s) => hiveTask.Task.PluginsNeededIds = PluginUtil.GetPluginDependencies(s, this.onlinePlugins, this.alreadyUploadedPlugins, plugins)); 439 443 } 440 444 } … … 451 455 if (parentHiveTask != null) 452 456 { 453 hiveTask.Task.Id = HiveServiceLocatorWeb.Instance.CallHiveService((s) => s.AddChildTask(parentHiveTask.Task.Id, hiveTask.Task, taskData));457 hiveTask.Task.Id = serviceLocator.CallHiveService((s) => s.AddChildTask(parentHiveTask.Task.Id, hiveTask.Task, taskData)); 454 458 } 455 459 else { 456 hiveTask.Task.Id = HiveServiceLocatorWeb.Instance.CallHiveService((s) => s.AddTask(hiveTask.Task, taskData, groups.ToList()));460 hiveTask.Task.Id = serviceLocator.CallHiveService((s) => s.AddTask(hiveTask.Task, taskData, groups.ToList())); 457 461 } 458 462 } … … 488 492 489 493 #region Download Experiment 490 public staticvoid LoadJob(RefreshableJob refreshableJob)494 public void LoadJob(RefreshableJob refreshableJob) 491 495 { 492 496 var hiveExperiment = refreshableJob.Job; … … 501 505 // fetch all task objects to create the full tree of tree of HiveTask objects 502 506 refreshableJob.Progress.Start("Downloading list of tasks..."); 503 allTasks = HiveServiceLocatorWeb.Instance.CallHiveService(s => s.GetLightweightJobTasksWithoutStateLog(hiveExperiment.Id));507 allTasks = serviceLocator.CallHiveService(s => s.GetLightweightJobTasksWithoutStateLog(hiveExperiment.Id)); 504 508 totalJobCount = allTasks.Count(); 505 509 506 510 refreshableJob.Progress.Status = "Downloading tasks..."; 507 downloader = new TaskDownloaderWeb(allTasks.Select(x => x.Id) );511 downloader = new TaskDownloaderWeb(allTasks.Select(x => x.Id), serviceLocator); 508 512 downloader.StartAsync(); 509 513 … … 572 576 } 573 577 574 public staticItemTask LoadItemJob(Guid jobId)575 { 576 TaskData taskData = HiveServiceLocatorWeb.Instance.CallHiveService(s => s.GetTaskData(jobId));578 public ItemTask LoadItemJob(Guid jobId) 579 { 580 TaskData taskData = serviceLocator.CallHiveService(s => s.GetTaskData(jobId)); 577 581 try 578 582 { … … 603 607 } 604 608 605 public staticHiveItemCollection<JobPermission> GetJobPermissions(Guid jobId)606 { 607 return HiveServiceLocatorWeb.Instance.CallHiveService((service) =>609 public HiveItemCollection<JobPermission> GetJobPermissions(Guid jobId) 610 { 611 return serviceLocator.CallHiveService((service) => 608 612 { 609 613 IEnumerable<JobPermission> jps = service.GetJobPermissions(jobId); -
branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Services/Imports/HiveServiceLocatorWeb.cs
r13733 r13739 2 2 using HeuristicLab.Clients.Common.Properties; 3 3 using HeuristicLab.Clients.Hive.WebJobManager.ViewModels; 4 using Microsoft.AspNet.Http; 4 5 using Microsoft.AspNet.Mvc; 5 6 using System; … … 17 18 public class HiveServiceLocatorWeb : IHiveServiceLocator 18 19 { 19 private static IHiveServiceLocator instance = null;20 20 private HiveServiceClient clientinst; 21 public static IHiveServiceLocator Instance 22 { 23 get 24 { 25 if (instance == null) 26 { 27 instance = new HiveServiceLocatorWeb(); 28 } 29 return instance; 30 } 31 } 21 public Guid UserId {get; set; } 32 22 private string username; 33 23 public string Username … … 47 37 public string WorkingEndpoint { get; private set; } 48 38 49 public static void clear()50 {51 instance = null;52 }53 39 54 40 #region #unknownCalls … … 132 118 return false; 133 119 } 134 public static void SetLoginErrorMessage()135 {136 LoginViewModelService.Instance.GetLoginViewModel().errorMessage = "Login timed out";137 }138 120 139 121 public string GetEndpointInformation() … … 195 177 } 196 178 197 public void destroy ()179 public void destroyClient() 198 180 { 199 181 clientinst = null; 200 instance = null;201 182 } 202 183 } -
branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Services/Imports/TaskDownloaderWeb.cs
r13733 r13739 26 26 using HeuristicLab.Common; 27 27 28 namespace HeuristicLab.Clients.Hive.WebJobManager.Services.Imports { 28 namespace HeuristicLab.Clients.Hive.WebJobManager.Services.Imports 29 { 29 30 30 31 /// <summary> 31 32 /// Rewritten to use HiveClientWeb and HiveServiceLocatorWeb 32 33 /// </summary> 33 public class TaskDownloaderWeb : IDisposable { 34 private IEnumerable<Guid> taskIds; 35 private ConcurrentTaskDownloaderWeb<ItemTask> taskDownloader; 36 private IDictionary<Guid, HiveTask> results; 37 private bool exceptionOccured = false; 38 private Exception currentException; 39 private ReaderWriterLockSlim resultsLock = new ReaderWriterLockSlim(); 34 public class TaskDownloaderWeb : IDisposable 35 { 36 private HiveServiceLocatorWeb serviceLocator; 37 private IEnumerable<Guid> taskIds; 38 private ConcurrentTaskDownloaderWeb<ItemTask> taskDownloader; 39 private IDictionary<Guid, HiveTask> results; 40 private bool exceptionOccured = false; 41 private Exception currentException; 42 private ReaderWriterLockSlim resultsLock = new ReaderWriterLockSlim(); 40 43 41 public bool IsFinished { 42 get { 43 try { 44 resultsLock.EnterReadLock(); 45 return results.Count == taskIds.Count(); 44 public bool IsFinished 45 { 46 get 47 { 48 try 49 { 50 resultsLock.EnterReadLock(); 51 return results.Count == taskIds.Count(); 52 } 53 finally { resultsLock.ExitReadLock(); } 54 } 46 55 } 47 finally { resultsLock.ExitReadLock(); } 48 } 56 57 public bool IsFaulted 58 { 59 get 60 { 61 return exceptionOccured; 62 } 63 } 64 65 public Exception Exception 66 { 67 get 68 { 69 return currentException; 70 } 71 } 72 73 public int FinishedCount 74 { 75 get 76 { 77 try 78 { 79 resultsLock.EnterReadLock(); 80 return results.Count; 81 } 82 finally { resultsLock.ExitReadLock(); } 83 } 84 } 85 86 public IDictionary<Guid, HiveTask> Results 87 { 88 get 89 { 90 try 91 { 92 resultsLock.EnterReadLock(); 93 return results; 94 } 95 finally { resultsLock.ExitReadLock(); } 96 } 97 } 98 99 public TaskDownloaderWeb(IEnumerable<Guid> jobIds, HiveServiceLocatorWeb hiv) 100 { 101 taskIds = jobIds; 102 serviceLocator = hiv; 103 taskDownloader = new ConcurrentTaskDownloaderWeb<ItemTask>( 104 Settings.Default.MaxParallelDownloads, 105 Settings.Default.MaxParallelDownloads, 106 serviceLocator); 107 taskDownloader.ExceptionOccured += new EventHandler<EventArgs<Exception>>(taskDownloader_ExceptionOccured); 108 results = new Dictionary<Guid, HiveTask>(); 109 110 } 111 112 public void StartAsync() 113 { 114 foreach (Guid taskId in taskIds) 115 { 116 taskDownloader.DownloadTaskDataAndTask(taskId, 117 (localTask, itemTask) => 118 { 119 if (localTask != null && itemTask != null) 120 { 121 HiveTask hiveTask = itemTask.CreateHiveTask(); 122 hiveTask.Task = localTask; 123 try 124 { 125 resultsLock.EnterWriteLock(); 126 results.Add(localTask.Id, hiveTask); 127 } 128 finally { resultsLock.ExitWriteLock(); } 129 } 130 }); 131 } 132 } 133 134 private void taskDownloader_ExceptionOccured(object sender, EventArgs<Exception> e) 135 { 136 OnExceptionOccured(e.Value); 137 } 138 139 public event EventHandler<EventArgs<Exception>> ExceptionOccured; 140 private void OnExceptionOccured(Exception exception) 141 { 142 exceptionOccured = true; 143 currentException = exception; 144 var handler = ExceptionOccured; 145 if (handler != null) handler(this, new EventArgs<Exception>(exception)); 146 } 147 148 #region IDisposable Members 149 public void Dispose() 150 { 151 taskDownloader.ExceptionOccured -= new EventHandler<EventArgs<Exception>>(taskDownloader_ExceptionOccured); 152 resultsLock.Dispose(); 153 taskDownloader.Dispose(); 154 } 155 #endregion 49 156 } 50 51 public bool IsFaulted {52 get {53 return exceptionOccured;54 }55 }56 57 public Exception Exception {58 get {59 return currentException;60 }61 }62 63 public int FinishedCount {64 get {65 try {66 resultsLock.EnterReadLock();67 return results.Count;68 }69 finally { resultsLock.ExitReadLock(); }70 }71 }72 73 public IDictionary<Guid, HiveTask> Results {74 get {75 try {76 resultsLock.EnterReadLock();77 return results;78 }79 finally { resultsLock.ExitReadLock(); }80 }81 }82 83 public TaskDownloaderWeb(IEnumerable<Guid> jobIds) {84 taskIds = jobIds;85 taskDownloader = new ConcurrentTaskDownloaderWeb<ItemTask>(Settings.Default.MaxParallelDownloads, Settings.Default.MaxParallelDownloads);86 taskDownloader.ExceptionOccured += new EventHandler<EventArgs<Exception>>(taskDownloader_ExceptionOccured);87 results = new Dictionary<Guid, HiveTask>();88 }89 90 public void StartAsync() {91 foreach (Guid taskId in taskIds) {92 taskDownloader.DownloadTaskDataAndTask(taskId,93 (localTask, itemTask) => {94 if (localTask != null && itemTask != null) {95 HiveTask hiveTask = itemTask.CreateHiveTask();96 hiveTask.Task = localTask;97 try {98 resultsLock.EnterWriteLock();99 results.Add(localTask.Id, hiveTask);100 }101 finally { resultsLock.ExitWriteLock(); }102 }103 });104 }105 }106 107 private void taskDownloader_ExceptionOccured(object sender, EventArgs<Exception> e) {108 OnExceptionOccured(e.Value);109 }110 111 public event EventHandler<EventArgs<Exception>> ExceptionOccured;112 private void OnExceptionOccured(Exception exception) {113 exceptionOccured = true;114 currentException = exception;115 var handler = ExceptionOccured;116 if (handler != null) handler(this, new EventArgs<Exception>(exception));117 }118 119 #region IDisposable Members120 public void Dispose() {121 taskDownloader.ExceptionOccured -= new EventHandler<EventArgs<Exception>>(taskDownloader_ExceptionOccured);122 resultsLock.Dispose();123 taskDownloader.Dispose();124 }125 #endregion126 }127 157 } -
branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Services/Jobs/FileOpeningService.cs
r13733 r13739 16 16 public class FileOpeningService 17 17 { 18 public Guid UserId { get; set; } 19 20 private WebLoginService weblog; 18 21 public RefreshableJob Job { get; set; } 19 22 public FileOpeningViewModel vm { get; set; } … … 22 25 get; set; } 23 26 public List<int> previousLogs { get; set; } 24 private static FileOpeningService instance; 25 public static FileOpeningService Instance 27 28 29 public FileOpeningService(Guid u) 26 30 { 27 get 28 { 29 if (instance == null) 30 { 31 instance = new FileOpeningService(); 32 } 33 return instance; 34 } 31 weblog = WebLoginService.Instance; 32 UserId = u; 35 33 } 34 35 36 36 /// <summary> 37 37 /// Clears loaded jobs and start new one … … 58 58 { 59 59 // HiveClientWeb.Instance.Refresh(); 60 HiveClientWeb.LoadJob(Job);60 weblog.getClientWeb(UserId).LoadJob(Job); 61 61 } 62 62 /// <summary> … … 68 68 if (vm != null) 69 69 { 70 71 72 73 HiveServiceLocatorWeb serv = (HiveServiceLocatorWeb)HiveServiceLocatorWeb.Instance; 74 //job.Job.Id = serv.getHiveServiceClient().AddJob(job.Job); 75 // job.Job = serv.getHiveServiceClient().GetJob(job.Job.Id); 76 77 HiveClientWeb.CurrentEnv = env; 78 HiveClientWeb.Instance.Refresh(); 79 HiveClientWeb.StartJob((ex) => { throw ex; }, Job, CancellationToken.None); 70 var clientWeb = weblog.getClientWeb(UserId); 71 clientWeb.CurrentEnv = env; 72 clientWeb.Refresh(); 73 clientWeb.StartJob((ex) => { throw ex; }, Job, CancellationToken.None); 80 74 return Job; 81 75 } -
branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Startup.cs
r13733 r13739 7 7 using HeuristicLab.Core; 8 8 using HeuristicLab.PluginInfrastructure; 9 9 using System; 10 10 11 11 namespace HeuristicLab.Clients.Hive.WebJobManager … … 33 33 34 34 services.AddMvc(); 35 services.AddSingleton<ILoginViewModelService, LoginViewModelService>(); 35 36 services.AddCaching(); 37 services.AddSession(options => { 38 options.IdleTimeout = TimeSpan.FromMinutes(30); 39 options.CookieName = ".HiveWJM"; 40 }); 36 41 services.AddSingleton<IHiveServiceLocator, HiveServiceLocatorWeb>(); 37 42 services.AddSignalR(); … … 45 50 46 51 app.UseIISPlatformHandler(); 47 52 app.UseSession(); 48 53 app.UseStaticFiles(); 49 54 app.UseSignalR(); -
branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/ViewModels/LoginViewModel.cs
r13733 r13739 12 12 public class LoginViewModel 13 13 { 14 /// <summary> 15 /// Used only for the WebHive. Identifies logged in users. 16 /// </summary> 17 public Guid userId { get; set; } 18 /// <summary> 19 /// Login name from the user 20 /// </summary> 14 21 [Display(Name = "Username")] 15 22 public string loginName { get; set; } 23 /// <summary> 24 /// Encrypted password 25 /// </summary> 16 26 [Display(Name = "Password")] 17 27 public string password { get; set; } 18 28 19 29 public string errorMessage { get; set; } 30 /// <summary> 31 /// Initialize the loginViewModel. Creates a unique Guid for the WebHive 32 /// </summary> 33 /// <param name="n">Login name</param> 34 /// <param name="p">Encrypted password</param> 35 public LoginViewModel(string n, string p) 36 { 37 loginName = n; 38 password = p; 39 userId = Guid.NewGuid(); 40 } 41 public LoginViewModel() 42 { 43 userId = Guid.Empty; 44 loginName = ""; 45 password = ""; 46 } 20 47 } 21 48 } -
branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Views/Job/Index.cshtml
r13735 r13739 1 1 @using HeuristicLab.Clients.Hive.WebJobManager.ViewModels 2 2 @model JobViewModel 3 3 <div id="userId" style="display:none">@ViewBag.SessionId</div> 4 4 <div> 5 5 @Html.Partial("Navbar", new NavbarViewModel("Job")) … … 165 165 } 166 166 </div> 167 167 168 168 169 } -
branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Views/Job/OpenFile.cshtml
r13735 r13739 1 @model HeuristicLab.Clients.Hive.WebJobManager.ViewModels.FileOpeningViewModel 1 @using Microsoft.AspNet.Http; 2 3 @model HeuristicLab.Clients.Hive.WebJobManager.ViewModels.FileOpeningViewModel 2 4 3 5 … … 9 11 onscroll="showScrolly()" 10 12 style="margin-bottom:500px;margin-left:1px;margin-right:1px;"> 11 13 <div id="userId" style="display:none">@ViewBag.SessionId</div> 12 14 @Html.Partial("Navbar", new HeuristicLab.Clients.Hive.WebJobManager.ViewModels.NavbarViewModel("Job")) 13 15 … … 181 183 </ul> 182 184 </nav> 185 183 186 <script src="~/js/scripts/hubber.js"></script> 184 187 <script> -
branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Views/Job/UploaderPartial/_UploaderPartial.cshtml
r13733 r13739 25 25 <div class="row" style="margin:10px"> 26 26 27 <div id="selectedfiles"></div> 27 <div id="selectedfiles"> 28 <h3>Files</h3> 29 <p>No files selected: press the above button to choose files</p> 30 </div> 28 31 29 < div style="display:none;margin-bottom:10px; box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);32 <button style="margin-bottom:10px; box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19); 30 33 text-shadow:2px 2px black;" 34 type="button" 35 disabled 31 36 id="del" 32 37 class='btn btn-danger' … … 34 39 <span class='glyphicon glyphicon-trash' aria-hidden='true'></span> 35 40 Remove files 36 </ div>41 </button> 37 42 38 <div id="dir"39 style=" display:none;margin-top:20px;margin-bottom:20px">43 <div 44 style="margin-top:20px;margin-bottom:20px"> 40 45 41 46 <label for="basic-url">Directory name</label> … … 45 50 .../uploads/@ViewBag.Name 46 51 </span> 47 <input type="text" 52 <input 53 type="text" 54 disabled 48 55 class="form-control" 49 56 id="directory" … … 53 60 </div> 54 61 </div> 55 <button style=" display:none;box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);62 <button style=" box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19); 56 63 text-shadow:2px 2px black;" 57 id="upl" 64 disabled 65 id="upl" 58 66 class="btn btn-lg btn-block btn-success" 59 67 type="submit" … … 70 78 var div = document.getElementById("selectedfiles"); 71 79 var files = document.getElementById("files").files; 72 div.innerHTML = " ";80 div.innerHTML = "<h3>Files</h3>"; 73 81 if (files.length > 0) { 74 document.getElementById("upl"). style.display = "";75 document.getElementById("del"). style.display = "";76 document.getElementById("dir ").style.display = "";82 document.getElementById("upl").disabled = false; 83 document.getElementById("del").disabled = false; 84 document.getElementById("directory").disabled = false; 77 85 78 div.innerHTML += "<h3>Files</h3>";86 79 87 for (var i = 0; i < files.length; i++) { 80 88 div.innerHTML += "<p>File " + (i + 1) + ":" + files[i].name + … … 84 92 } 85 93 else { 86 document.getElementById("upl").style.display = "none"; 87 document.getElementById("del").style.display = "none"; 88 document.getElementById("dir").style.display = "none"; 94 div.innerHTML += "<p>No files selected</p>"; 95 document.getElementById("upl").disabled = true; 96 document.getElementById("del").disabled = true; 97 document.getElementById("directory").disabled = true; 89 98 } 90 99 -
branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Views/Job/Uploads.cshtml
r13733 r13739 45 45 <div class="col-sm-4"> 46 46 <div class="btn-group-vertical btn-block"> 47 <a class="btn btn-success btn-lg btn-block 47 <a class="btn btn-info btn-lg btn-block disabled" 48 style="box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19); 49 text-shadow:2px 2px black;"> 50 <i class="fa fa-cloud"></i> Uploads 51 </a> 52 <a class="btn btn-success btn-block 48 53 @(Model.SelectedIndex == -1 ? "active" : "") 49 54 " -
branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Views/Shared/_Layout.cshtml
r13733 r13739 12 12 </environment> 13 13 <link href="https://gitcdn.github.io/bootstrap-toggle/2.2.0/css/bootstrap-toggle.min.css" rel="stylesheet"> 14 <link rel="shortcut icon" type="image/x-icon" href="~/favicon.ico" /> 14 15 <link rel="stylesheet" href="//rawgithub.com/Caged/d3-tip/master/examples/example-styles.css"> 15 16 </head> … … 28 29 <script src="~/js/jquery.signalr-2.1.2.js"></script> 29 30 <script src='~/signalr/js'></script> 30 <script src="~/js/morris.js"></script>31 <script src="~/js/npm.js"></script>32 <script src="~/js/raphael.js"></script>33 31 <script src="~/js/plotly.js"></script> 34 <script src="~/js/moment.js"></script>35 <script src="~/js/moment-timezone-with-data.js"></script>36 32 <script src="~/js/d3.js"></script> 37 33 <script src="~/js/d3.v3.min.js"></script> -
branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/project.json
r13689 r13739 22 22 "Microsoft.AspNet.SignalR.Server": "3.0.0-rc1-final", 23 23 "Microsoft.AspNet.Tooling.Razor": "1.0.0-rc1-final", 24 "Microsoft.Extensions.Configuration.Json": "1.0.0-rc1-final" 24 "Microsoft.Extensions.Configuration.Json": "1.0.0-rc1-final", 25 "Microsoft.AspNet.Session": "1.0.0-rc1-final", 26 "Microsoft.Extensions.Caching.Memory": "1.0.0-rc1-final" 25 27 }, 26 28 -
branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/wwwroot/js/Scripts/Graphs/GraphHubber.js
r13733 r13739 2 2 3 3 $(function () { 4 //$.connection.hub.logging = true; 4 // $.connection.hub.logging = true; 5 var v = document.getElementById("userId").innerHTML; 6 console.log(v); 7 $.connection.hub.qs = { 'userid': v }; 5 8 $.connection.hub.start().done(function () { 6 9 hubber.server.initConnection(); -
branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/wwwroot/js/Scripts/hubber.js
r13735 r13739 2 2 3 3 $(function () { 4 $.connection.hub.logging = true; 4 // $.connection.hub.logging = true; 5 var v = document.getElementById("userId").innerHTML; 6 console.log(v); 7 $.connection.hub.qs = { 'userid': v }; 5 8 $.connection.hub.start().done(function () { 6 9 $("#progress").css("width", 0 + '%');
Note: See TracChangeset
for help on using the changeset viewer.