aggiunta stampa di un json alla creazione del report
This commit is contained in:
parent
62a6f238f0
commit
6effeecf35
@ -56,6 +56,9 @@
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
||||
<HintPath>..\GestoreTrimestrale\packages\NLog.4.2.3\lib\net45\NLog.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
|
@ -1,23 +1,24 @@
|
||||
using Amib.Threading;
|
||||
using DataAccessLayer;
|
||||
using PDFGenerator;
|
||||
using PDFGenerator.BusinessLayer;
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Configuration;
|
||||
using System.Data;
|
||||
using System.Diagnostics;
|
||||
using System.Collections.Specialized;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using Amib.Threading;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using PDFGenerator.BusinessLayer;
|
||||
using PDFGenerator;
|
||||
|
||||
|
||||
using DataAccessLayer;
|
||||
|
||||
namespace GestorePDF.Logic
|
||||
{
|
||||
using Newtonsoft.Json;
|
||||
using NLog;
|
||||
using System.Xml;
|
||||
|
||||
public class GestoreThread
|
||||
{
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net48" />
|
||||
<package id="NLog" version="4.2.3" targetFramework="net45" />
|
||||
</packages>
|
@ -0,0 +1,55 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PDFGenerator.BusinessLayer.Json
|
||||
{
|
||||
public class JsonExporter
|
||||
{
|
||||
private static string ExecutionTimestamp = DateTime.Now.ToString("yyyyMMdd_HHmmss");
|
||||
public static void ExportForJasperReport(DataThread dataThread, string codice)
|
||||
{
|
||||
string fileName = $"{codice}.json";
|
||||
string directory = Path.Combine(CACHE.SavePDFtoDISK_Folder, ExecutionTimestamp);
|
||||
|
||||
// Crea la directory se non esiste
|
||||
Directory.CreateDirectory(directory);
|
||||
|
||||
string fullPath = Path.Combine(directory, fileName);
|
||||
ExportToJson(dataThread, fullPath);
|
||||
|
||||
Console.WriteLine($"Data source per Jasper creato: {fileName}");
|
||||
}
|
||||
|
||||
private static void ExportToJson(DataThread dataThread, string filePath)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Serializza l'oggetto in JSON con formattazione
|
||||
string json = JsonConvert.SerializeObject(dataThread, Newtonsoft.Json.Formatting.Indented, new JsonSerializerSettings
|
||||
{
|
||||
// Gestisce le referenze circolari se presenti
|
||||
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
|
||||
// Include proprietà null
|
||||
NullValueHandling = NullValueHandling.Include,
|
||||
// Formato data personalizzato
|
||||
DateFormatString = "yyyy-MM-dd HH:mm:ss"
|
||||
});
|
||||
|
||||
// Scrive il JSON nel file
|
||||
File.WriteAllText(filePath, json);
|
||||
|
||||
Console.WriteLine($"DataThread esportato con successo in: {filePath}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Errore durante l'esportazione: {ex.Message}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@ using PDFGenerator.Presentation.Section;
|
||||
using PDFGenerator.BusinessLayer.DataSection;
|
||||
|
||||
using PDFGenerator.Presentation.TemplateGenerator;
|
||||
using PDFGenerator.BusinessLayer.Json;
|
||||
|
||||
|
||||
namespace PDFGenerator.BusinessLayer
|
||||
@ -449,6 +450,8 @@ namespace PDFGenerator.BusinessLayer
|
||||
if (notsez.Equals(_codice)) data.Esito = 0;
|
||||
}
|
||||
|
||||
//QUI
|
||||
JsonExporter.ExportForJasperReport(_dataThread, this.Codice);
|
||||
|
||||
if (data!=null && data.Esito > 0)
|
||||
{
|
||||
|
@ -796,7 +796,7 @@ namespace PDFGenerator
|
||||
if (string.IsNullOrWhiteSpace(_dataThread.NomeFilePdf))
|
||||
{
|
||||
logger.Info("_dataThread.NomeFilePdf è vuoto");
|
||||
_dataThread.NomeFilePdf = "Test";
|
||||
_dataThread.NomeFilePdf = DateTime.Now.ToString("yyyyMMdd_HHmmss");
|
||||
}
|
||||
|
||||
// Percorso completo della cartella
|
||||
|
@ -96,6 +96,9 @@
|
||||
<Reference Include="Microsoft.Practices.ObjectBuilder">
|
||||
<HintPath>..\DLLesterne\Microsoft.Practices.ObjectBuilder.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
||||
<HintPath>..\GestoreTrimestrale\packages\NLog.4.2.3\lib\net40\NLog.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
@ -857,6 +860,7 @@
|
||||
<Compile Include="BusinessLayer\DataSection\StructColor.cs" />
|
||||
<Compile Include="BusinessLayer\DataThread.cs" />
|
||||
<Compile Include="BusinessLayer\DataThreadModel.cs" />
|
||||
<Compile Include="BusinessLayer\Json\JsonExporter.cs" />
|
||||
<Compile Include="BusinessLayer\LibFunction.cs" />
|
||||
<Compile Include="BusinessLayer\ParagrafoReport.cs" />
|
||||
<Compile Include="BusinessLayer\ParametriReport.cs" />
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net48" />
|
||||
<package id="NLog" version="4.2.3" targetFramework="net40" />
|
||||
</packages>
|
Loading…
x
Reference in New Issue
Block a user