Retrieve LeafOutput operational
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user