1 | using HeuristicLab.Clients.Hive.WebJobManager.ViewModels;
|
---|
2 | using Microsoft.AspNet.Hosting;
|
---|
3 | using System;
|
---|
4 | using System.Collections.Generic;
|
---|
5 | using System.Linq;
|
---|
6 | using System.Threading;
|
---|
7 | using System.Threading.Tasks;
|
---|
8 |
|
---|
9 | namespace HeuristicLab.Clients.Hive.WebJobManager.Services
|
---|
10 | {
|
---|
11 | /// <summary>
|
---|
12 | /// Used for opening a file and uploading this to Hive.
|
---|
13 | /// Saves all relevant Job information needed for uploading.
|
---|
14 | /// Outsourced to selectedJob keep the current job loaded
|
---|
15 | /// </summary>
|
---|
16 | public class FileOpeningService
|
---|
17 | {
|
---|
18 | public Guid UserId { get; set; }
|
---|
19 |
|
---|
20 | private WebLoginService weblog;
|
---|
21 | public RefreshableJob Job { get; set; }
|
---|
22 | public FileOpeningViewModel vm { get; set; }
|
---|
23 | public IHostingEnvironment env { get; set; }
|
---|
24 | public List<Guid> previousids {
|
---|
25 | get; set; }
|
---|
26 | public List<int> previousLogs { get; set; }
|
---|
27 |
|
---|
28 |
|
---|
29 | public FileOpeningService(Guid u)
|
---|
30 | {
|
---|
31 | weblog = WebLoginService.Instance;
|
---|
32 | UserId = u;
|
---|
33 | }
|
---|
34 |
|
---|
35 |
|
---|
36 | /// <summary>
|
---|
37 | /// Clears loaded jobs and start new one
|
---|
38 | /// </summary>
|
---|
39 | public void NewModel()
|
---|
40 | {
|
---|
41 | vm = new FileOpeningViewModel();
|
---|
42 | Job = new RefreshableJob();
|
---|
43 | Job.Job.Name = "init";
|
---|
44 |
|
---|
45 | }
|
---|
46 | /// <summary>
|
---|
47 | /// Attaches tasks from viewmodel to job
|
---|
48 | /// </summary>
|
---|
49 | public void setTasks()
|
---|
50 | {
|
---|
51 |
|
---|
52 | Job.HiveTasks.Add(vm.SelectedTask);
|
---|
53 | }
|
---|
54 | /// <summary>
|
---|
55 | /// Refresh all info from a job from the server
|
---|
56 | /// </summary>
|
---|
57 | public void refreshJob()
|
---|
58 | {
|
---|
59 | weblog.getClientWeb(UserId).LoadJob(Job);
|
---|
60 | }
|
---|
61 | /// <summary>
|
---|
62 | /// Adds loaded job from vm onto server
|
---|
63 | /// </summary>
|
---|
64 | /// <returns>Job being uploaded</returns>
|
---|
65 | public RefreshableJob AddCurrentModelToHive()
|
---|
66 | {
|
---|
67 | if (vm != null)
|
---|
68 | {
|
---|
69 | var clientWeb = weblog.getClientWeb(UserId);
|
---|
70 | clientWeb.CurrentEnv = env;
|
---|
71 | clientWeb.Refresh();
|
---|
72 | clientWeb.StartJob((ex) => { throw ex; }, Job, CancellationToken.None);
|
---|
73 | return Job;
|
---|
74 | }
|
---|
75 | return null;
|
---|
76 | }
|
---|
77 | }
|
---|
78 | }
|
---|