diff --git a/Core.Tests/Core.Tests.csproj b/Core.Tests/Core.Tests.csproj index 142d6bd..05dbcc5 100644 --- a/Core.Tests/Core.Tests.csproj +++ b/Core.Tests/Core.Tests.csproj @@ -35,6 +35,7 @@ True + diff --git a/Core.Tests/Remote/PiscalSshClientTests.cs b/Core.Tests/Remote/PiscalSshClientTests.cs index 674e79c..6c746b7 100644 --- a/Core.Tests/Remote/PiscalSshClientTests.cs +++ b/Core.Tests/Remote/PiscalSshClientTests.cs @@ -1,4 +1,6 @@ -using LeafWeb.Core.Entities; +using System.Configuration; +using LeafWeb.Core.Entities; +using LeafWeb.Core.Utility; using NUnit.Framework; namespace LeafWeb.Core.Tests.Remote @@ -9,8 +11,9 @@ namespace LeafWeb.Core.Tests.Remote [Test] public void Client() { - var leafInputFile = new LeafInputFile {Filename = "blah", Id = 1}; - var client = new PiscalSshClient(); + var leafInputFile = new LeafInputFile {Filename = "blah", Id = 1, Contents = "test".GetBytes()}; + var piscalConnectionString = ConfigurationManager.ConnectionStrings["PiscalServer"]; + var client = new PiscalSshClient(piscalConnectionString.ConnectionString); client.SubmitLeafInputFile(leafInputFile); } } diff --git a/Core/Remote/IPiscalClient.cs b/Core/Remote/IPiscalClient.cs index c6a185e..a4b3027 100644 --- a/Core/Remote/IPiscalClient.cs +++ b/Core/Remote/IPiscalClient.cs @@ -1,5 +1,7 @@ using System; +using System.Collections.Generic; using System.IO; +using System.Linq; using System.Text; using LeafWeb.Core.Entities; using Renci.SshNet; @@ -14,13 +16,22 @@ namespace LeafWeb.Core public class PiscalSshClient : IPiscalClient { + private readonly Dictionary _conn; + + public PiscalSshClient(string connectionString) + { + _conn = connectionString.Split(';') + .Select(t => t.Split(new [] { '=' }, 2)) + .ToDictionary(t => t[0].Trim(), t => t[1].Trim(), StringComparer.InvariantCultureIgnoreCase); + } + private SshClient GetSshClient() { - return new SshClient("40.76.47.173", "piscaladmin", "password"); + return new SshClient(_conn["host"], _conn["username"], _conn["password"]); } private ScpClient GetScpClient() { - return new ScpClient("40.76.47.173", "piscaladmin", "password"); + return new ScpClient(_conn["host"], _conn["username"], _conn["password"]); } public void SubmitLeafInputFile(LeafInputFile file) @@ -35,13 +46,13 @@ namespace LeafWeb.Core using (var ssh = GetSshClient()) { ssh.Connect(); - var cmd = ssh.CreateCommand("ps"); - cmd.Execute(); + var lsCommend = ssh.CreateCommand("ls"); + lsCommend.Execute(); //var extendedData = Encoding.ASCII.GetString(cmd.ExtendedOutputStream.ToArray()); - var extendedData = new StreamReader(cmd.ExtendedOutputStream, Encoding.ASCII).ReadToEnd(); + var extendedData = new StreamReader(lsCommend.ExtendedOutputStream, Encoding.ASCII).ReadToEnd(); ssh.Disconnect(); - Console.Write(cmd.Result); + Console.Write(lsCommend.Result); Console.Write(extendedData); //Assert.AreEqual("12345\n", cmd.Result); //Assert.AreEqual("654321\n", extendedData); diff --git a/Core/Utility/StringExtensions.cs b/Core/Utility/StringExtensions.cs index fe892eb..e3615dd 100644 --- a/Core/Utility/StringExtensions.cs +++ b/Core/Utility/StringExtensions.cs @@ -24,5 +24,19 @@ namespace LeafWeb.Core.Utility // Return char and concat substring. return char.ToLowerInvariant(s[0]) + s.Substring(1); } + + public static byte[] GetBytes(this string str) + { + var bytes = new byte[str.Length * sizeof(char)]; + Buffer.BlockCopy(str.ToCharArray(), 0, bytes, 0, bytes.Length); + return bytes; + } + + public static string GetString(this byte[] bytes) + { + var chars = new char[bytes.Length / sizeof(char)]; + Buffer.BlockCopy(bytes, 0, chars, 0, bytes.Length); + return new string(chars); + } } } diff --git a/Web/ViewModels/LeafInput/CreateViewModel.cs b/Web/ViewModels/LeafInput/CreateViewModel.cs index eaedd42..4c327f5 100644 --- a/Web/ViewModels/LeafInput/CreateViewModel.cs +++ b/Web/ViewModels/LeafInput/CreateViewModel.cs @@ -33,7 +33,7 @@ namespace LeafWeb.Web.ViewModels.LeafInput public string SiteId { get; set; } [Display(Name = "Photosynthetic Pathways")] - [Required(ErrorMessage = "A photosynthesis pathway must be chosen")] + [Required(ErrorMessage = "A Photosynthetic pathway must be chosen")] public SelectListViewModel PhotosynthesisType { get; set; } static CreateViewModel()