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
+7 -7
View File
@@ -14,23 +14,23 @@ namespace LeafWeb.Web.Controllers
{
public class LeafCharterController : ControllerBase
{
public ActionResult Index(int leafInputFileId)
public ActionResult Index(int leafInputId)
{
var hasLeafOutputFile =
DataService
.GetLeafInputFile(leafInputFileId)?
.LeafOutputFiles?
.GetLeafInput(leafInputId)?
.OutputFiles?
.FirstOrDefault(f => f.IsLeafChartFile) != null;
return View(leafInputFileId);
return View(leafInputId);
}
public ActionResult LeafCharts(int leafInputFileId, int number)
public ActionResult LeafCharts(int leafInputId, int number)
{
var leafOutputFile =
DataService
.GetLeafInputFile(leafInputFileId)?
.LeafOutputFiles?
.GetLeafInput(leafInputId)?
.OutputFiles?
.FirstOrDefault(f => f.IsLeafChartFile);
if (leafOutputFile == null)
+2 -2
View File
@@ -72,7 +72,7 @@ namespace LeafWeb.Web.Controllers
// convert viewModel into Model
var leafInput = viewModel.GetFileInput(DataService);
// load files into LeafInputFile
leafInput.Files =
leafInput.InputFiles =
(from f in files
let bytes = System.IO.File.ReadAllBytes(f.FullName)
select new LeafInputFile {Filename = f.Name, Contents = bytes}).ToList();
@@ -89,7 +89,7 @@ namespace LeafWeb.Web.Controllers
var logger = LogManager.GetCurrentClassLogger();
logger.Info("LeafInput: {0} Added, {1}, {2}, {3}", leafInput.Id, leafInput.Identifier, leafInput.SiteId, leafInput.Email);
logger.Info("LeafInputFiles: {0}, Queued", leafInput.Files.Select(f => f.Id.ToString()).Join(", "));
logger.Info("LeafInputFiles: {0}, Queued", leafInput.InputFiles.Select(f => f.Id.ToString()).Join(", "));
HangfireStartup.TriggerPiscalProcessQueue();
@@ -1,18 +1,18 @@
using System.Linq;
using System.Web.Mvc;
using LeafWeb.Web.ViewModels.LeafOutput;
using LeafWeb.Web.ViewModels.ResultStatus;
namespace LeafWeb.Web.Controllers
{
public class LeafOutputController : ControllerBase
public class ResultStatusController : ControllerBase
{
public ActionResult Index()
{
var viewModel =
DataService.GetLeafInputFiles()
DataService.GetLeafInputs()
.OrderByDescending(f => f.Id)
.ToList()
.Select(f => new LeafOutputViewModel(f));
.Select(leafInput => new ResultStatusViewModel(leafInput));
return View(viewModel);
}
}
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
This file is used by the publish/package process of your Web project. You can customize the behavior of this process
by editing this MSBuild file. In order to learn more about this please visit http://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>MSDeploy</WebPublishMethod>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish>http://leafweb.azurewebsites.net</SiteUrlToLaunchAfterPublish>
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>False</ExcludeApp_Data>
<MSDeployServiceURL>leafweb.scm.azurewebsites.net:443</MSDeployServiceURL>
<DeployIisAppPath>LeafWeb</DeployIisAppPath>
<RemoteSitePhysicalPath />
<SkipExtraFilesOnServer>True</SkipExtraFilesOnServer>
<MSDeployPublishMethod>WMSVC</MSDeployPublishMethod>
<EnableMSDeployBackup>True</EnableMSDeployBackup>
<UserName>$LeafWeb</UserName>
<_SavePWD>True</_SavePWD>
<_DestinationType>AzureWebSite</_DestinationType>
<PublishDatabaseSettings>
<Objects xmlns="">
<ObjectGroup Name="LeafWebContext" Order="1" Enabled="False">
<Destination Path="Data Source=tcp:leafweb.database.windows.net;Initial Catalog=leafweb;Integrated Security=False;User ID=lwadmin@leafweb;Password=j4f1a2e!;Encrypt=True" Name="Server=tcp:leafweb.database.windows.net;Database=leafweb;User ID=lwadmin@leafweb;Password=j4f1a2e!;Trusted_Connection=False;Encrypt=True" />
<Object Type="DbCodeFirst">
<Source Path="DBContext" DbContext="LeafWeb.Core.DAL.LeafWebContext, Core" Origin="Configuration" />
</Object>
</ObjectGroup>
</Objects>
</PublishDatabaseSettings>
</PropertyGroup>
<ItemGroup>
<MSDeployParameterValue Include="$(DeployParameterPrefix)LeafWebContext-Web.config Connection String">
<ParameterValue>Server=tcp:leafweb.database.windows.net;Database=leafweb;User ID=lwadmin@leafweb;Password=j4f1a2e!;Trusted_Connection=False;Encrypt=True</ParameterValue>
</MSDeployParameterValue>
</ItemGroup>
</Project>
+9 -9
View File
@@ -31,25 +31,25 @@ namespace LeafWeb.Web.Services
public EmailNotificationService() : this(new DataService())
{ }
public void SendLeafWebError(int leafWebFileId, string errorMessage)
public void SendLeafWebError(int leafInputId, string errorMessage)
{
var file = _dataService.GetLeafInputFile(leafWebFileId);
var body = $"Your LeafWeb analysis job, {file.LeafInput.Identifier} (with filename {file.Filename}), encountered the following errors." + Environment.NewLine
var leafInput = _dataService.GetLeafInput(leafInputId);
var body = $"Your LeafWeb analysis job, {leafInput.Identifier}, encountered the following errors." + Environment.NewLine
+ "You will need to correct your input and resubmit." + Environment.NewLine + Environment.NewLine
+ errorMessage;
var message = new MailMessage(_emaialFromAddress, file.LeafInput.Email, "LeafWeb processing error", body);
var message = new MailMessage(_emaialFromAddress, leafInput.Email, "LeafWeb processing error", body);
SendMessage(message);
}
public void SendLeafWebSuccess(int leafWebFileId)
public void SendLeafWebSuccess(int leafInputId)
{
var file = _dataService.GetLeafInputFile(leafWebFileId);
var body = $"Your LeafWeb analysis job, {file.LeafInput.Identifier} (with filename {file.Filename}), has completed." + Environment.NewLine;
var message = new MailMessage(_emaialFromAddress, file.LeafInput.Email, "LeafWeb results", body);
var leafInput = _dataService.GetLeafInput(leafInputId);
var body = $"Your LeafWeb analysis job, {leafInput.Identifier}, has completed." + Environment.NewLine;
var message = new MailMessage(_emaialFromAddress, leafInput.Email, "LeafWeb results", body);
var fileStreams =
(from outputFile in
file.LeafOutputFiles
leafInput.OutputFiles
select Tuple.Create(outputFile, new MemoryStream(outputFile.Contents))).ToList();
try
+16 -16
View File
@@ -55,39 +55,39 @@ namespace LeafWeb.Web.Services
private void ProcessQueue(ILogger logger)
{
var runningLeafInputFiles = _dataService.GetLeafInputFiles(LeafInputStatusType.Running).ToList();
if (runningLeafInputFiles.Any())
var runningLeafInputs = _dataService.GetLeafInputs(LeafInputStatusType.Running).ToList();
if (runningLeafInputs.Any())
return;
var queuedFile =
var pending =
_dataService
.GetLeafInputFiles(LeafInputStatusType.Queued)
.GetLeafInputs(LeafInputStatusType.Pending)
.OrderBy(l => l.StatusHistory.Min(sh => sh.DateTime))
.FirstOrDefault();
if (queuedFile == null)
if (pending == null)
return;
logger.Info("LeafInputFile: {0}, Start", queuedFile.Id);
logger.Info("LeafInputFile: {0}, Start", pending.Id);
try
{
_piscalService.Run(queuedFile);
_piscalService.Run(pending);
}
catch (PiscalClientException ex)
{
logger.Error("LeafInputFile: {0}, ProcessQueue Exception: {1}", queuedFile.Id, ex.Message);
_dataService.SetLeafInputFileStatus(queuedFile, LeafInputStatusType.Error, "Error occurred submitting LeafInput");
logger.Error("LeafInputFile: {0}, ProcessQueue Exception: {1}", pending.Id, ex.Message);
_dataService.SetLeafInputStatus(pending, LeafInputStatusType.Error, "Error occurred submitting LeafInput");
// TODO: re-queue
//_dataService.SetLeafInputFileStatus(queuedFile, LeafInputStatusType.Queued, "Re-queuing LeafInput");
}
_dataService.SetLeafInputFileStatus(queuedFile, LeafInputStatusType.Running);
_dataService.SetLeafInputStatus(pending, LeafInputStatusType.Running);
}
private void ProcessRunning(ILogger logger)
{
var runningLeafInputFiles = _dataService.GetLeafInputFiles(LeafInputStatusType.Running).ToList();
foreach (var file in runningLeafInputFiles)
var running = _dataService.GetLeafInputs(LeafInputStatusType.Running).ToList();
foreach (var file in running)
{
var status = _piscalService.GetStatus(file);
try
@@ -110,7 +110,7 @@ namespace LeafWeb.Web.Services
string.Join(", ", leafOutputFiles.Select(o => o.Filename)));
// update db
_dataService.SetLeafInputFileStatus(file, LeafInputStatusType.Complete);
_dataService.SetLeafInputStatus(file, LeafInputStatusType.Complete);
BackgroundJob.Enqueue(() => _emailService.SendLeafWebSuccess(file.Id));
@@ -122,7 +122,7 @@ namespace LeafWeb.Web.Services
case PiscalStatus.NotStarted:
logger.Warn("LeafInputFile: {0}, Not Started, re-queueing", file.Id);
// if it's not started, try to requeue the process - unusual state
_dataService.SetLeafInputFileStatus(file, LeafInputStatusType.Queued);
_dataService.SetLeafInputStatus(file, LeafInputStatusType.Pending);
break;
case PiscalStatus.Error:
@@ -131,7 +131,7 @@ namespace LeafWeb.Web.Services
var errorMessage = _piscalService.GetErrorMessage(file);
logger.Info("LeafInputFile: {0}, Error Message: {1}", file.Id, errorMessage);
_dataService.SetLeafInputFileStatus(file, LeafInputStatusType.Error, errorMessage);
_dataService.SetLeafInputStatus(file, LeafInputStatusType.Error, errorMessage);
BackgroundJob.Enqueue(() => _emailService.SendLeafWebError(file.Id, errorMessage));
@@ -144,7 +144,7 @@ namespace LeafWeb.Web.Services
catch (PiscalClientException ex)
{
logger.Error("LeafInputFile: {0}, ProcessRunning Exception: {1}", file.Id, ex.Message);
_dataService.SetLeafInputFileStatus(file, LeafInputStatusType.Error, "Error occurred processing LeafInput");
_dataService.SetLeafInputStatus(file, LeafInputStatusType.Error, "Error occurred processing LeafInput");
// TODO: re-queue
}
+15 -15
View File
@@ -18,40 +18,40 @@ namespace LeafWeb.Web.Services
{
}
public void Run(LeafInputFile leafInputFile)
public void Run(LeafInput leafInput)
{
var inputFile = new PiscalLeafInputFile(leafInputFile);
_piscalClient.RunLeafInputFile(inputFile);
var inputFile = new PiscalLeafInput(leafInput);
_piscalClient.RunLeafInput(inputFile);
}
public PiscalStatus GetStatus(LeafInputFile leafInputFile)
public PiscalStatus GetStatus(LeafInput leafInput)
{
var inputFile = new PiscalLeafInputFile(leafInputFile);
return _piscalClient.GetLeafInputFileStatus(inputFile);
var inputFile = new PiscalLeafInput(leafInput);
return _piscalClient.GetLeafInputStatus(inputFile);
}
public IEnumerable<LeafOutputFile> RetrieveOutputFiles(LeafInputFile leafInputFile)
public IEnumerable<LeafOutputFile> RetrieveOutputFiles(LeafInput leafInput)
{
var inputFile = new PiscalLeafInputFile(leafInputFile);
var piscalLeafOutputFiles = _piscalClient.RetrieveLeafOutput(inputFile);
var input = new PiscalLeafInput(leafInput);
var piscalLeafOutputFiles = _piscalClient.RetrieveLeafOutput(input);
foreach (var file in piscalLeafOutputFiles)
{
var leafOutputFile = file.GetLeafOutputFile();
leafOutputFile.LeafInputFile = leafInputFile;
leafOutputFile.LeafInput = leafInput;
yield return leafOutputFile;
}
}
public string GetErrorMessage(LeafInputFile leafInputFile)
public string GetErrorMessage(LeafInput leafInput)
{
var inputFile = new PiscalLeafInputFile(leafInputFile);
var inputFile = new PiscalLeafInput(leafInput);
return _piscalClient.GetErrorMessage(inputFile);
}
public void Cleanup(LeafInputFile leafInputFile)
public void Cleanup(LeafInput leafInput)
{
var inputFile = new PiscalLeafInputFile(leafInputFile);
_piscalClient.CleanupLeafProcess(inputFile);
var input = new PiscalLeafInput(leafInput);
_piscalClient.CleanupLeafProcess(input);
}
}
}
@@ -2,45 +2,43 @@
using AutoMapper;
using LeafWeb.Core.Entities;
namespace LeafWeb.Web.ViewModels.LeafOutput
namespace LeafWeb.Web.ViewModels.ResultStatus
{
public class LeafOutputViewModel
public class ResultStatusViewModel
{
private static readonly IMapper Mapper;
public int LeafInputFileId { get; set; }
public string LeafInputFilename { get; set; }
public string CurrentStatus { get; set; }
public string[] ErrorMessages { get; set; }
public string[] LeafOutputFilenames { get; set; }
public bool HasLeafChartOutputFile { get; set; }
public int LeafInputId { get; set; }
public string LeafInputName { get; set; }
public string LeafInputIdentifier { get; set; }
public string LeafInputSiteId { get; set; }
public string LeafInputPhotosynthesisType { get; set; }
public string CurrentStatus { get; set; }
public string[] ErrorMessages { get; set; }
public string[] LeafOutputFilenames { get; set; }
public bool HasLeafChartOutputFile { get; set; }
static LeafOutputViewModel()
static ResultStatusViewModel()
{
var config =
new MapperConfiguration(cfg =>
{
cfg.CreateMap<LeafInputFile, LeafOutputViewModel>()
.ForMember(dest => dest.LeafInputFileId, opt => opt.MapFrom(src => src.Id))
.ForMember(dest => dest.LeafInputFilename, opt => opt.MapFrom(src => src.Filename))
cfg.CreateMap<Core.Entities.LeafInput, ResultStatusViewModel>()
.ForMember(dest => dest.LeafInputId, opt => opt.MapFrom(src => src.Id))
.ForMember(dest => dest.LeafOutputFilenames,
opt => opt.ResolveUsing(
file =>
file.LeafOutputFiles?
src =>
src.OutputFiles?
.Select(o => o.Filename)
.ToArray()
?? new string[] {}))
.ForMember(dest => dest.HasLeafChartOutputFile,
opt => opt.ResolveUsing(
file => file.LeafOutputFiles?.Any(o => o.IsLeafChartFile)))
.ForMember(dest => dest.LeafInputName, opt => opt.MapFrom(src => src.LeafInput.Name))
.ForMember(dest => dest.LeafInputIdentifier, opt => opt.MapFrom(src => src.LeafInput.Identifier))
.ForMember(dest => dest.LeafInputSiteId, opt => opt.MapFrom(src => src.LeafInput.SiteId))
.ForMember(dest => dest.LeafInputPhotosynthesisType, opt => opt.MapFrom(src => src.LeafInput.PhotosynthesisType.Name))
file => file.OutputFiles?.Any(o => o.IsLeafChartFile)))
.ForMember(dest => dest.LeafInputName, opt => opt.MapFrom(src => src.Name))
.ForMember(dest => dest.LeafInputIdentifier, opt => opt.MapFrom(src => src.Identifier))
.ForMember(dest => dest.LeafInputSiteId, opt => opt.MapFrom(src => src.SiteId))
.ForMember(dest => dest.LeafInputPhotosynthesisType, opt => opt.MapFrom(src => src.PhotosynthesisType.Name))
.ForMember(dest => dest.ErrorMessages,
opt => opt.ResolveUsing(
src =>
@@ -53,7 +51,7 @@ namespace LeafWeb.Web.ViewModels.LeafOutput
Mapper = config.CreateMapper();
}
public LeafOutputViewModel(LeafInputFile leafInput)
public ResultStatusViewModel(Core.Entities.LeafInput leafInput)
{
Mapper.Map(leafInput, this);
}
+5 -3
View File
@@ -4,13 +4,15 @@
@Styles.Render("~/backload/blueimp/bootstrap/BasicPlusUI/css")
}
@Html.Partial("_StatusMessage")
<h1>Submitting Data and Retrieving EDO Results</h1>
<p>
There is no limit on the number of files you may submit for analysis. Keep selecting files and hitting the Add button until all of the files you need to upload are shown in the list. Then enter an identifier for this set of data and click the Upload button.
There is no limit on the number of files you may submit for analysis.
Keep selecting files and hitting the Add button until all of the files you need to upload are shown in the list.
Then enter an identifier for this set of data and click the Upload button.
</p>
@Html.Partial("_StatusMessage")
<div class="row">
<div class="col-md-7 well">
@Html.Partial("_ValidationSummary")
@@ -1,4 +1,4 @@
@model IEnumerable<LeafWeb.Web.ViewModels.LeafOutput.LeafOutputViewModel>
@model IEnumerable<LeafWeb.Web.ViewModels.ResultStatus.ResultStatusViewModel>
@{
ViewBag.Title = "Results";
@@ -11,10 +11,8 @@
grid.Columns(
grid.Column("LeafInputIdentifier", "Identifier"),
grid.Column("LeafInputSiteId", "Site Id"),
grid.Column("LeafInputFilename", "Filename"),
grid.Column("LeafInputName", "Submitted By"),
grid.Column("CurrentStatus", "Status"),
grid.Column("Chart", "Chart", item => @Html.ActionLink("Chart", "Index", "LeafCharter", new { leafInputFileId = item.LeafInputFileId}, new {}))
grid.Column("CurrentStatus", "Status")
),
htmlAttributes: new { @class = "table table-striped table-bordered table-hover table-condensed" }
)
+1 -1
View File
@@ -31,7 +31,7 @@
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Leaf Data <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="/LeafInput">Submit Data</a></li>
<li><a href="/LeafOutput">Result Status</a></li>
<li><a href="/ResultStatus">Result Status</a></li>
</ul>
</li>
<li>
+4 -3
View File
@@ -524,6 +524,7 @@
<SubType>Designer</SubType>
</None>
<None Include="Properties\PublishProfiles\LeafWeb - Web Deploy.pubxml" />
<None Include="Properties\PublishProfiles\LeafWeb.pubxml" />
<None Include="Scripts\jquery-1.9.1.intellisense.js" />
<Content Include="Scripts\angular-mocks.js" />
<Content Include="Scripts\bootstrap-datepicker.js" />
@@ -926,7 +927,7 @@
<Compile Include="Controllers\FluxnetSiteController.cs" />
<Compile Include="Controllers\LeafCharterController.cs" />
<Compile Include="Controllers\LeafInputController.cs" />
<Compile Include="Controllers\LeafOutputController.cs" />
<Compile Include="Controllers\ResultStatusController.cs" />
<Compile Include="Controllers\PagesController.cs" />
<Compile Include="Global.asax.cs">
<DependentUpon>Global.asax</DependentUpon>
@@ -941,7 +942,7 @@
<Compile Include="Utility\Validation.cs" />
<Compile Include="ViewModels\LeafInput\ConfirmViewModel.cs" />
<Compile Include="ViewModels\LeafInput\CreateViewModel.cs" />
<Compile Include="ViewModels\LeafOutput\LeafOutputViewModel.cs" />
<Compile Include="ViewModels\ResultStatus\ResultStatusViewModel.cs" />
<Compile Include="ViewModels\SelectListViewModel.cs" />
</ItemGroup>
<ItemGroup>
@@ -974,7 +975,7 @@
<Content Include="Views\Shared\_StatusMessage.cshtml" />
<Content Include="Views\Shared\_ValidationField.cshtml" />
<Content Include="Views\Shared\EditorTemplates\SelectListViewModel.cshtml" />
<Content Include="Views\LeafOutput\Index.cshtml" />
<Content Include="Views\ResultStatus\Index.cshtml" />
<Content Include="Views\Pages\Information.cshtml" />
<None Include="Web.Debug.config">
<DependentUpon>Web.config</DependentUpon>