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 RefreshableJob Job { get; set; }
|
---|
19 | public FileOpeningViewModel vm { get; set; }
|
---|
20 | public IHostingEnvironment env { get; set; }
|
---|
21 | public List<Guid> previousids {
|
---|
22 | get; set; }
|
---|
23 | public List<int> previousLogs { get; set; }
|
---|
24 | private static FileOpeningService instance;
|
---|
25 | public static FileOpeningService Instance
|
---|
26 | {
|
---|
27 | get
|
---|
28 | {
|
---|
29 | if (instance == null)
|
---|
30 | {
|
---|
31 | instance = new FileOpeningService();
|
---|
32 | }
|
---|
33 | return instance;
|
---|
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 | // HiveClientWeb.Instance.Refresh();
|
---|
60 | HiveClientWeb.LoadJob(Job);
|
---|
61 | }
|
---|
62 | /// <summary>
|
---|
63 | /// Adds loaded job from vm onto server
|
---|
64 | /// </summary>
|
---|
65 | /// <returns>Job being uploaded</returns>
|
---|
66 | public RefreshableJob AddCurrentModelToHive()
|
---|
67 | {
|
---|
68 | if (vm != null)
|
---|
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);
|
---|
80 | return Job;
|
---|
81 | }
|
---|
82 | return null;
|
---|
83 | }
|
---|
84 | }
|
---|
85 | }
|
---|