Retrieve LeafOutput operational
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
using System;
|
||||
using System.Configuration;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Hangfire;
|
||||
using LeafWeb.Core.Entities;
|
||||
using LeafWeb.Core.Remote;
|
||||
using LeafWeb.Web.Attributes;
|
||||
using LeafWeb.Web.ViewModels;
|
||||
using LeafWeb.Web.ViewModels.LeafInput;
|
||||
@@ -69,7 +72,7 @@ namespace LeafWeb.Web.Controllers
|
||||
// convert viewModel into Model
|
||||
var leafInput = viewModel.GetFileInput(DataService);
|
||||
// load files into LeafInputFile
|
||||
leafInput.LeafInputFiles =
|
||||
leafInput.Files =
|
||||
(from f in files
|
||||
let bytes = System.IO.File.ReadAllBytes(f.FullName)
|
||||
select new LeafInputFile {Filename = f.Name, Contents = bytes}).ToList();
|
||||
@@ -78,7 +81,13 @@ namespace LeafWeb.Web.Controllers
|
||||
DataService.AddLeafInput(leafInput);
|
||||
|
||||
DeleteBackloadDirectory(Session.SessionID);
|
||||
|
||||
|
||||
foreach (var file in leafInput.Files.Select(f => new PiscalLeafInputFile(f)))
|
||||
{
|
||||
BackgroundJob.Enqueue(() => ProcessLeafInput(file));
|
||||
}
|
||||
|
||||
|
||||
SetStatusMessage(
|
||||
HttpUtility.HtmlEncode(
|
||||
$"A data set has submitted for '{viewModel.Identifier}' from '{viewModel.SiteId}'. " + Environment.NewLine
|
||||
@@ -91,6 +100,12 @@ namespace LeafWeb.Web.Controllers
|
||||
return View("Index", viewModel);
|
||||
}
|
||||
|
||||
public void ProcessLeafInput(PiscalLeafInputFile leafInputFile)
|
||||
{
|
||||
var piscalSshClient = new PiscalSshClient(ConfigurationManager.ConnectionStrings["PiscalServer"].ConnectionString);
|
||||
piscalSshClient.SubmitLeafInputFile(leafInputFile);
|
||||
}
|
||||
|
||||
private FileInfo[] GetBackloadDirectoryFiles(string directoryName)
|
||||
{
|
||||
var path = Path.Combine(Server.MapPath("~/Files/"), directoryName + "\\");
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Configuration;
|
||||
using System.Linq;
|
||||
using LeafWeb.Core.DAL;
|
||||
using LeafWeb.Core.Entities;
|
||||
using LeafWeb.Core.Remote;
|
||||
|
||||
namespace LeafWeb.Web.Services
|
||||
{
|
||||
public class JobService : IDisposable
|
||||
{
|
||||
protected readonly DataService DataService = new DataService();
|
||||
|
||||
protected IPiscalClient GetPiscalClient()
|
||||
{
|
||||
return new PiscalSshClient(ConfigurationManager.ConnectionStrings["PiscalServer"].ConnectionString);
|
||||
}
|
||||
|
||||
public void ProcessNextLeafInput()
|
||||
{
|
||||
var leafInputFile = DataService.GetNextUnprocessedLeafInputFile();
|
||||
if (leafInputFile == null) // no inputs, quit
|
||||
return;
|
||||
|
||||
var inputFile = new PiscalLeafInputFile(leafInputFile);
|
||||
|
||||
var piscalSshClient = GetPiscalClient();
|
||||
piscalSshClient.SubmitLeafInputFile(inputFile);
|
||||
|
||||
DataService.SetLeafInputFileStatus(leafInputFile, LeafInputStatusType.ProcessStarted);
|
||||
}
|
||||
|
||||
public void UpdateLeafInputStatus()
|
||||
{
|
||||
var leafInputFiles =
|
||||
DataService
|
||||
.GetLeafInputFiles(LeafInputStatusType.ProcessStarted)
|
||||
.Select(f => new PiscalLeafInputFile(f));
|
||||
|
||||
var piscalClient = GetPiscalClient();
|
||||
foreach (var file in leafInputFiles)
|
||||
{
|
||||
var status = piscalClient.GetLeafInputStatus(file);
|
||||
switch (status)
|
||||
{
|
||||
case PiscalStatus.Success:
|
||||
// retrieve LeafOutput
|
||||
var outputFile = piscalClient.RetrieveLeafOutput(file);
|
||||
break;
|
||||
case PiscalStatus.Error:
|
||||
// record error
|
||||
break;
|
||||
case PiscalStatus.Running:
|
||||
// do nothing
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
DataService.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -921,6 +921,7 @@
|
||||
</Compile>
|
||||
<Compile Include="Attributes\HttpParamActionAttribute.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Services\JobService.cs" />
|
||||
<Compile Include="Startup.cs" />
|
||||
<Compile Include="Utility\MarkdownHelper.cs" />
|
||||
<Compile Include="Utility\Validation.cs" />
|
||||
|
||||
Reference in New Issue
Block a user