Piscal Client improvements
This commit is contained in:
@@ -1,52 +1,58 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using LeafWeb.Core.Entities;
|
||||
using LeafWeb.Core.Utility;
|
||||
using Renci.SshNet;
|
||||
|
||||
namespace LeafWeb.Core
|
||||
namespace LeafWeb.Core.Remote
|
||||
{
|
||||
public interface IPiscalClient
|
||||
{
|
||||
void SubmitLeafInputFile(LeafInputFile file);
|
||||
void RetrieveLeafInputResult();
|
||||
void SubmitLeafInputFile(PiscalLeafInputFile file);
|
||||
void RetrieveLeafInputResult(PiscalLeafInputFile file);
|
||||
}
|
||||
|
||||
public class PiscalSshClient : IPiscalClient
|
||||
{
|
||||
private readonly Dictionary<string, string> _conn;
|
||||
private const string BaseDirectory = "LeafInput";
|
||||
private readonly PasswordConnectionInfo _connectionInfo;
|
||||
|
||||
public PiscalSshClient(string connectionString)
|
||||
{
|
||||
_conn = connectionString.Split(';')
|
||||
.Select(t => t.Split(new [] { '=' }, 2))
|
||||
.ToDictionary(t => t[0].Trim(), t => t[1].Trim(), StringComparer.InvariantCultureIgnoreCase);
|
||||
var conn = connectionString.SplitConnectionString();
|
||||
|
||||
var host = conn["host"];
|
||||
var username = conn["username"];
|
||||
var password = conn["password"];
|
||||
_connectionInfo = new PasswordConnectionInfo(host, username, password);
|
||||
}
|
||||
|
||||
private SshClient GetSshClient()
|
||||
{
|
||||
return new SshClient(_conn["host"], _conn["username"], _conn["password"]);
|
||||
}
|
||||
private ScpClient GetScpClient()
|
||||
{
|
||||
return new ScpClient(_conn["host"], _conn["username"], _conn["password"]);
|
||||
return new SshClient(_connectionInfo);
|
||||
}
|
||||
|
||||
public void SubmitLeafInputFile(LeafInputFile file)
|
||||
private ScpClient GetScpClient()
|
||||
{
|
||||
return new ScpClient(_connectionInfo);
|
||||
}
|
||||
|
||||
public void SubmitLeafInputFile(PiscalLeafInputFile file)
|
||||
{
|
||||
var inputPath = BaseDirectory + "/" + file.DirectoryName + "/" + file.Filename;
|
||||
var outputPath = BaseDirectory + "/" + file.DirectoryName + "/" + file.Filename;
|
||||
|
||||
using (var scp = GetScpClient())
|
||||
using (var stream = new MemoryStream(file.Contents))
|
||||
{
|
||||
scp.Connect();
|
||||
scp.Upload(stream, file.Filename);
|
||||
scp.Upload(stream, inputPath);
|
||||
}
|
||||
|
||||
using (var ssh = GetSshClient())
|
||||
{
|
||||
ssh.Connect();
|
||||
var lsCommend = ssh.CreateCommand("ls");
|
||||
var lsCommend = ssh.CreateCommand("ls -r");
|
||||
lsCommend.Execute();
|
||||
//var extendedData = Encoding.ASCII.GetString(cmd.ExtendedOutputStream.ToArray());
|
||||
var extendedData = new StreamReader(lsCommend.ExtendedOutputStream, Encoding.ASCII).ReadToEnd();
|
||||
@@ -62,9 +68,15 @@ namespace LeafWeb.Core
|
||||
// begin processing
|
||||
}
|
||||
|
||||
public void RetrieveLeafInputResult()
|
||||
public void RetrieveLeafInputResult(PiscalLeafInputFile file)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
using (var scp = GetScpClient())
|
||||
using (var stream = new MemoryStream(file.Contents))
|
||||
{
|
||||
scp.Connect();
|
||||
scp.Upload(stream, BaseDirectory + "/" + file.DirectoryName + "/" + file.Filename);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user