Add PhotosynthesisType and start SSH work

modified:   Core.Tests/Core.Tests.csproj
	modified:   Core.Tests/Parsers/FluxnetSiteCsvParserTests.cs
	new file:   Core.Tests/Remote/PiscalSshClientTests.cs
	modified:   Core/Core.csproj
	modified:   Core/DAL/LeafWebContext.cs
	modified:   Core/DAL/LeafWebInitializer.cs
	modified:   Core/Models/LeafInput.cs
	new file:   Core/Models/PhotosynthesisType.cs

	new file:   Core/Remote/IPiscalClient.cs

Get Piscal
This commit is contained in:
2016-02-08 15:14:28 -05:00
parent d185adc844
commit 15d911c86b
9 changed files with 119 additions and 0 deletions
+1
View File
@@ -48,6 +48,7 @@
<Compile Include="Parsers\FluxnetSiteCsvParserTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Parsers\LeafInputCsvParserTests.cs" />
<Compile Include="Remote\PiscalSshClientTests.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="Parsers\LeafInputData\LeafInput-valid.csv">
@@ -1,4 +1,5 @@
using System;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using LeafWeb.Core.Parsers;
@@ -34,6 +35,17 @@ namespace LeafWeb.Core.Tests.Parsers
}
}
[Test]
public void Parse_Find_Misencoded_Characters_test()
{
var fileInfo = new FileInfo(@"C:\Users\poprhythm\Documents\code\LeafWeb\Core\DAL\InitialData\fluxnet_site_list_all_October2015_with_joins_corrected.csv");
var parser = new FluxnetSiteCsvParser(fileInfo);
foreach (var fns in parser.Parse().Where(f => Regex.IsMatch(f.SiteName, @"[^\x00-\x7F]") || f.SiteName.Contains("?")))
{
Console.WriteLine($"{fns.FluxnetId} / {fns.SiteName}");
}
}
[Test]
public void Parse_Find_Duplicate_Ids()
{
+17
View File
@@ -0,0 +1,17 @@
using LeafWeb.Core.Models;
using NUnit.Framework;
namespace LeafWeb.Core.Tests.Remote
{
[TestFixture]
public class PiscalSshClientTests
{
[Test]
public void Client()
{
var leafInputFile = new LeafInputFile {Filename = "blah", Id = 1};
var client = new PiscalSshClient();
client.SubmitLeafInputFile(leafInputFile);
}
}
}
+2
View File
@@ -67,6 +67,8 @@
<Compile Include="DAL\DataService.cs" />
<Compile Include="DAL\LeafWebContext.cs" />
<Compile Include="DAL\LeafWebInitializer.cs" />
<Compile Include="Models\PhotosynthesisType.cs" />
<Compile Include="Remote\IPiscalClient.cs" />
<Compile Include="Models\CntrlComparison.cs" />
<Compile Include="Models\CntrlComparisonFittingInfo.cs" />
<Compile Include="Models\CntrlComparisonPhotosyntheticInfo.cs" />
+1
View File
@@ -10,6 +10,7 @@ namespace LeafWeb.Core.DAL
public DbSet<LeafInputFile> LeafInputFiles { get; set; }
public DbSet<LeafInputStatus> LeafInputStatus { get; set; }
public DbSet<FluxnetSite> FluxnetSites { get; set; }
public DbSet<PhotosynthesisType> PhotosynthesisTypes { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
+11
View File
@@ -1,5 +1,6 @@
using System.Data.Entity;
using System.Linq;
using LeafWeb.Core.Models;
using LeafWeb.Core.Parsers;
using LeafWeb.Core.Utility;
@@ -18,6 +19,16 @@ namespace LeafWeb.Core.DAL
// add to context
fluxnetSites.ForEach(s => context.FluxnetSites.Add(s));
var photosynthesisTypes = new []
{
new PhotosynthesisType {Id = "C3_photosynthesis_leafweb", Name = "C3 Photosynthesis"},
new PhotosynthesisType {Id = "C4_photosynthesis_leafweb", Name = "C4 Photosynthesis"},
new PhotosynthesisType {Id = "CAM_photosynthesis_leafweb", Name = "CAM Photosynthesis"}
};
context.PhotosynthesisTypes.AddRange(photosynthesisTypes);
context.SaveChanges();
base.Seed(context);
+2
View File
@@ -23,6 +23,8 @@ namespace LeafWeb.Core.Models
[Required(ErrorMessage = "")]
public string SiteId { get; set; }
public virtual PhotosynthesisType Photosynthesis { get; set; }
[DataType(DataType.Date)]
[Required]
public DateTime Created { get; set; }
+14
View File
@@ -0,0 +1,14 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace LeafWeb.Core.Models
{
public class PhotosynthesisType
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public string Id { get; set; }
public string Name { get; set; }
}
}
+59
View File
@@ -0,0 +1,59 @@
using System;
using System.IO;
using System.Text;
using LeafWeb.Core.Models;
using Renci.SshNet;
namespace LeafWeb.Core
{
public interface IPiscalClient
{
void SubmitLeafInputFile(LeafInputFile file);
void RetrieveLeafInputResult();
}
public class PiscalSshClient : IPiscalClient
{
private SshClient GetSshClient()
{
return new SshClient("40.76.47.173", "piscaladmin", "password");
}
private ScpClient GetScpClient()
{
return new ScpClient("40.76.47.173", "piscaladmin", "password");
}
public void SubmitLeafInputFile(LeafInputFile file)
{
using (var scp = GetScpClient())
using (var stream = new MemoryStream(file.Contents))
{
scp.Connect();
scp.Upload(stream, file.Filename);
}
using (var ssh = GetSshClient())
{
ssh.Connect();
var cmd = ssh.CreateCommand("ps");
cmd.Execute();
//var extendedData = Encoding.ASCII.GetString(cmd.ExtendedOutputStream.ToArray());
var extendedData = new StreamReader(cmd.ExtendedOutputStream, Encoding.ASCII).ReadToEnd();
ssh.Disconnect();
Console.Write(cmd.Result);
Console.Write(extendedData);
//Assert.AreEqual("12345\n", cmd.Result);
//Assert.AreEqual("654321\n", extendedData);
}
// copy file
// begin processing
}
public void RetrieveLeafInputResult()
{
throw new System.NotImplementedException();
}
}
}