using HeuristicLab.Clients.Hive.WebJobManager.ViewModels;
using Microsoft.AspNet.Hosting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace HeuristicLab.Clients.Hive.WebJobManager.Services
{
///
/// Used for opening a file and uploading this to Hive.
/// Saves all relevant Job information needed for uploading.
/// Outsourced to selectedJob keep the current job loaded
///
public class FileOpeningService
{
public Guid UserId { get; set; }
private WebLoginService weblog;
public RefreshableJob Job { get; set; }
public FileOpeningViewModel vm { get; set; }
public IHostingEnvironment env { get; set; }
public List previousids {
get; set; }
public List previousLogs { get; set; }
public FileOpeningService(Guid u)
{
weblog = WebLoginService.Instance;
UserId = u;
}
///
/// Clears loaded jobs and start new one
///
public void NewModel()
{
vm = new FileOpeningViewModel();
Job = new RefreshableJob();
Job.Job.Name = "init";
}
///
/// Attaches tasks from viewmodel to job
///
public void setTasks()
{
Job.HiveTasks.Add(vm.SelectedTask);
}
///
/// Refresh all info from a job from the server
///
public void refreshJob()
{
weblog.getClientWeb(UserId).LoadJob(Job);
}
///
/// Adds loaded job from vm onto server
///
/// Job being uploaded
public RefreshableJob AddCurrentModelToHive()
{
if (vm != null)
{
var clientWeb = weblog.getClientWeb(UserId);
clientWeb.CurrentEnv = env;
clientWeb.Refresh();
clientWeb.StartJob((ex) => { throw ex; }, Job, CancellationToken.None);
return Job;
}
return null;
}
}
}