Submit all LeafInputFiles together

This commit is contained in:
2016-03-28 10:20:50 -04:00
parent 4b2757b19a
commit 9e86b92f08
29 changed files with 353 additions and 268 deletions
+32 -22
View File
@@ -39,25 +39,35 @@ namespace LeafWeb.Core.Remote
return new ScpClient(_connectionInfo);
}
public void RunLeafInputFile(PiscalLeafInputFile file)
private void CopyLeafInput(PiscalLeafInput leafInput, string directory)
{
var inputPath = $"{BaseDirectory}/{file.DirectoryName}/{file.Filename}";
// copy file
// copy files
using (var scp = GetScpClient())
using (var stream = new MemoryStream(file.Contents))
foreach (var file in leafInput.InputFiles)
{
Console.WriteLine(inputPath);
scp.Connect();
scp.Upload(stream, inputPath);
scp.Disconnect();
var inputPath = $"{directory}/{file.Filename}";
using (var stream = new MemoryStream(file.Contents))
{
Console.WriteLine(inputPath);
scp.Connect();
scp.Upload(stream, inputPath);
scp.Disconnect();
}
}
}
public void RunLeafInput(PiscalLeafInput leafInput)
{
var inputDirectory = $"{BaseDirectory}/{leafInput.DirectoryName}";
CopyLeafInput(leafInput, inputDirectory);
// begin processing
using (var ssh = GetSshClient())
{
ssh.Connect();
var commandText = $"{RemoteScriptPath} -d {file.DirectoryName} -f {file.Filename} -p {file.PhotosyntheticType}";
var commandText = $"{RemoteScriptPath} -d {leafInput.DirectoryName} -p {leafInput.PhotosyntheticType}";
Console.Write(commandText);
var command = ssh.CreateCommand(commandText);
command.Execute();
ssh.Disconnect();
@@ -69,9 +79,9 @@ namespace LeafWeb.Core.Remote
}
}
public PiscalStatus GetLeafInputFileStatus(PiscalLeafInputFile file)
public PiscalStatus GetLeafInputStatus(PiscalLeafInput leafInput)
{
var statusRaw = GetLeafInputStatusRaw(file);
var statusRaw = GetLeafInputStatusRaw(leafInput);
switch (statusRaw[0])
{
@@ -86,12 +96,12 @@ namespace LeafWeb.Core.Remote
}
}
private string[] GetLeafInputStatusRaw(PiscalLeafInputFile file)
private string[] GetLeafInputStatusRaw(PiscalLeafInput leafInput)
{
using (var ssh = GetSshClient())
{
ssh.Connect();
var commandText = $"{RemoteScriptPath} -d {file.DirectoryName} -s";
var commandText = $"{RemoteScriptPath} -d {leafInput.DirectoryName} -s";
var command = ssh.CreateCommand(commandText);
command.Execute();
ssh.Disconnect();
@@ -109,10 +119,10 @@ namespace LeafWeb.Core.Remote
/// <summary>
/// Gets the leaf output from piscal, only run on if result status is success
/// </summary>
public IEnumerable<PiscalLeafOutputFile> RetrieveLeafOutput(PiscalLeafInputFile file)
public IEnumerable<PiscalLeafOutputFile> RetrieveLeafOutput(PiscalLeafInput leafInput)
{
// get output files
var status = GetLeafInputStatusRaw(file);
var status = GetLeafInputStatusRaw(leafInput);
if (status[0] != StatusSuccess)
throw new PiscalClientException("output not available, status is " + status[0]);
@@ -131,7 +141,7 @@ namespace LeafWeb.Core.Remote
{
Contents = stream.ToArray(),
Filename = filePath.FilenameFromPath(),
DirectoryName = file.DirectoryName
DirectoryName = leafInput.DirectoryName
};
}
}
@@ -140,9 +150,9 @@ namespace LeafWeb.Core.Remote
}
}
public string GetErrorMessage(PiscalLeafInputFile file)
public string GetErrorMessage(PiscalLeafInput leafInput)
{
var status = GetLeafInputStatusRaw(file);
var status = GetLeafInputStatusRaw(leafInput);
if (status[0] != StatusError)
return string.Empty;
@@ -150,16 +160,16 @@ namespace LeafWeb.Core.Remote
return errorLines.Join(Environment.NewLine);
}
public void CleanupLeafProcess(PiscalLeafInputFile file)
public void CleanupLeafProcess(PiscalLeafInput leafInput)
{
var status = GetLeafInputStatusRaw(file);
var status = GetLeafInputStatusRaw(leafInput);
if (status[0] == StatusRunning)
throw new PiscalClientException("Trying to cleanup a running process");
using (var ssh = GetSshClient())
{
ssh.Connect();
var commandText = $"{RemoteScriptPath} -d {file.DirectoryName} -c";
var commandText = $"{RemoteScriptPath} -d {leafInput.DirectoryName} -c";
var command = ssh.CreateCommand(commandText);
command.Execute();
ssh.Disconnect();