Merge branch 'vnext' of https://github.com/pazof/yavsc.git
commit
7dcfe1227c
@ -1,27 +0,0 @@
|
|||||||
|
|
||||||
.gitignore
|
|
||||||
appsettings.*.json
|
|
||||||
.idea/
|
|
||||||
.vscode/
|
|
||||||
.vs/
|
|
||||||
YavscWeb.userprefs
|
|
||||||
bin/
|
|
||||||
obj/
|
|
||||||
bower_components/
|
|
||||||
node_modules/
|
|
||||||
docfx_project/
|
|
||||||
debugcmd
|
|
||||||
undefined/
|
|
||||||
debugcode/
|
|
||||||
kestrel*.pid
|
|
||||||
kestrel*.log
|
|
||||||
scaffold.cmds
|
|
||||||
DataProtection-Keys
|
|
||||||
RSA-Params.json
|
|
||||||
Components/
|
|
||||||
packages/
|
|
||||||
build/
|
|
||||||
*.user
|
|
||||||
*.bak
|
|
||||||
*~
|
|
||||||
|
|
@ -0,0 +1,58 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNet.Mvc;
|
||||||
|
using Microsoft.Data.Entity;
|
||||||
|
using Yavsc.Models;
|
||||||
|
using Yavsc.Models.Billing;
|
||||||
|
using Yavsc.ViewModels.Gen;
|
||||||
|
|
||||||
|
namespace Yavsc.ViewComponents
|
||||||
|
{
|
||||||
|
public class EstimateViewComponent : ViewComponent
|
||||||
|
{
|
||||||
|
ApplicationDbContext dbContext;
|
||||||
|
public EstimateViewComponent(ApplicationDbContext dbContext)
|
||||||
|
{
|
||||||
|
this.dbContext = dbContext;
|
||||||
|
}
|
||||||
|
public async Task<IViewComponentResult> InvokeAsync(long id, bool toPdf = false)
|
||||||
|
{
|
||||||
|
Estimate estimate =
|
||||||
|
dbContext.Estimates.Include(x => x.Query)
|
||||||
|
.Include(x => x.Query.Client)
|
||||||
|
.Include(x => x.Query.PerformerProfile)
|
||||||
|
.Include(x => x.Query.PerformerProfile.OrganizationAddress)
|
||||||
|
.Include(x => x.Query.PerformerProfile.Performer)
|
||||||
|
.Include(e => e.Bill).FirstOrDefault(x => x.Id == id);
|
||||||
|
if (estimate == null)
|
||||||
|
throw new Exception("No data");
|
||||||
|
if (toPdf)
|
||||||
|
{
|
||||||
|
string tex = null;
|
||||||
|
var oldWriter = ViewComponentContext.ViewContext.Writer;
|
||||||
|
|
||||||
|
using (var writer = new StringWriter())
|
||||||
|
{
|
||||||
|
this.ViewComponentContext.ViewContext.Writer = writer;
|
||||||
|
|
||||||
|
var resultTex = View("Estimate_tex", estimate);
|
||||||
|
resultTex.Execute(this.ViewComponentContext);
|
||||||
|
tex = writer.ToString();
|
||||||
|
|
||||||
|
}
|
||||||
|
ViewComponentContext.ViewContext.Writer = oldWriter;
|
||||||
|
|
||||||
|
return this.View("Estimate_pdf",
|
||||||
|
new PdfGenerationViewModel{
|
||||||
|
TeXSource = tex,
|
||||||
|
DestDir = Startup.UserBillsDirName,
|
||||||
|
BaseFileName = $"estimate-{id}"
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
return this.View("Estimate_tex", estimate);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -1,55 +0,0 @@
|
|||||||
|
|
||||||
@using System.Reflection
|
|
||||||
@using System.IO
|
|
||||||
@using Microsoft.Extensions.WebEncoders
|
|
||||||
@using System.Diagnostics
|
|
||||||
@using System.Text
|
|
||||||
@using Yavsc.Formatters
|
|
||||||
|
|
||||||
@model Estimate
|
|
||||||
@{
|
|
||||||
Layout = null;
|
|
||||||
ViewBag.Pdf = "";
|
|
||||||
ViewBag.TeX = "";
|
|
||||||
var writer = new System.IO.StringWriter();
|
|
||||||
var content = await Html.PartialAsync("Estimate.tex", Model );
|
|
||||||
content.WriteTo(writer, new TexEncoder());
|
|
||||||
var contentStr = writer.ToString();
|
|
||||||
string name = $"tmpestimtex-{Model.Id}";
|
|
||||||
string fullname = new FileInfo(
|
|
||||||
System.IO.Path.Combine(ViewBag.TempDir,name)).FullName;
|
|
||||||
|
|
||||||
FileInfo fi = new FileInfo(fullname + ".tex");
|
|
||||||
FileInfo fo = new FileInfo(fullname + ".pdf");
|
|
||||||
using (StreamWriter sw = new StreamWriter (fi.FullName))
|
|
||||||
{
|
|
||||||
sw.Write (contentStr);
|
|
||||||
}
|
|
||||||
if (!fi.Exists)
|
|
||||||
{
|
|
||||||
throw new Exception ("Source write failed");
|
|
||||||
}
|
|
||||||
using (Process p = new Process ()) {
|
|
||||||
p.StartInfo.WorkingDirectory = ViewBag.TempDir;
|
|
||||||
p.StartInfo = new ProcessStartInfo ();
|
|
||||||
p.StartInfo.UseShellExecute = false;
|
|
||||||
p.StartInfo.FileName = "/usr/bin/texi2pdf";
|
|
||||||
p.StartInfo.Arguments = $"--batch --build-dir=. -o {fo.FullName} {fi.FullName}";
|
|
||||||
p.Start ();
|
|
||||||
p.WaitForExit ();
|
|
||||||
if (p.ExitCode != 0) {
|
|
||||||
throw new Exception ("Pdf generation failed with exit code:" + p.ExitCode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (fo.Exists) {
|
|
||||||
UTF8Encoding utf8 = new UTF8Encoding();
|
|
||||||
|
|
||||||
using (StreamReader sr = new StreamReader (fo.FullName)) {
|
|
||||||
byte[] buffer = File.ReadAllBytes (fo.FullName);
|
|
||||||
ViewBag.Pdf = utf8.GetString(buffer,0,buffer.Length);
|
|
||||||
}
|
|
||||||
fo.Delete();
|
|
||||||
}
|
|
||||||
fi.Delete();
|
|
||||||
}
|
|
||||||
@ViewBag.Pdf
|
|
@ -0,0 +1,50 @@
|
|||||||
|
@using System.Reflection
|
||||||
|
@using System.IO
|
||||||
|
@using Microsoft.Extensions.WebEncoders
|
||||||
|
@using System.Diagnostics
|
||||||
|
@using System.Text
|
||||||
|
@using Yavsc.Formatters
|
||||||
|
@model Yavsc.ViewModels.Gen.PdfGenerationViewModel
|
||||||
|
@{
|
||||||
|
string errorMsg = null;
|
||||||
|
var billdir = Model.DestDir;
|
||||||
|
var tempdir = Startup.SiteSetup.TempDir;
|
||||||
|
string name = Model.BaseFileName;
|
||||||
|
string fullname = new FileInfo(
|
||||||
|
System.IO.Path.Combine(tempdir,name)).FullName;
|
||||||
|
string ofullname = new FileInfo(
|
||||||
|
System.IO.Path.Combine(billdir,name)).FullName;
|
||||||
|
|
||||||
|
FileInfo fi = new FileInfo(fullname + ".tex");
|
||||||
|
FileInfo fo = new FileInfo(ofullname + ".pdf");
|
||||||
|
using (StreamWriter sw = new StreamWriter (fi.FullName))
|
||||||
|
{
|
||||||
|
sw.Write (Model.TeXSource);
|
||||||
|
}
|
||||||
|
if (!fi.Exists)
|
||||||
|
{
|
||||||
|
errorMsg = "Source write failed";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
using (Process p = new Process ()) {
|
||||||
|
p.StartInfo.WorkingDirectory = tempdir;
|
||||||
|
p.StartInfo = new ProcessStartInfo ();
|
||||||
|
p.StartInfo.UseShellExecute = false;
|
||||||
|
p.StartInfo.FileName = "/usr/bin/texi2pdf";
|
||||||
|
p.StartInfo.Arguments = $"--batch --build-dir=. -o {fo.FullName} {fi.FullName}";
|
||||||
|
p.Start ();
|
||||||
|
p.WaitForExit ();
|
||||||
|
if (p.ExitCode != 0) {
|
||||||
|
errorMsg = $"Pdf generation failed with exit code: {p.ExitCode}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fi.Delete();
|
||||||
|
}
|
||||||
|
ViewBag.GenSuccess = fo.Exists;
|
||||||
|
}
|
||||||
|
@if (ViewBag.GenSuccess) {
|
||||||
|
@($"{name}.pdf")
|
||||||
|
} else {
|
||||||
|
@errorMsg
|
||||||
|
<text>Something went wrong ...</text>
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
\relax
|
||||||
|
\catcode `:\active
|
||||||
|
\catcode `;\active
|
||||||
|
\catcode `!\active
|
||||||
|
\catcode `?\active
|
||||||
|
\select@language{french}
|
||||||
|
\@writefile{toc}{\select@language{french}}
|
||||||
|
\@writefile{lof}{\select@language{french}}
|
||||||
|
\@writefile{lot}{\select@language{french}}
|
@ -0,0 +1,9 @@
|
|||||||
|
\relax
|
||||||
|
\catcode `:\active
|
||||||
|
\catcode `;\active
|
||||||
|
\catcode `!\active
|
||||||
|
\catcode `?\active
|
||||||
|
\select@language{french}
|
||||||
|
\@writefile{toc}{\select@language{french}}
|
||||||
|
\@writefile{lof}{\select@language{french}}
|
||||||
|
\@writefile{lot}{\select@language{french}}
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue