ZUGFeRD Service/WebService: Lesen/Auswertung neue Config-Schalter. GDPicture-Lizenz-Abfrage

This commit is contained in:
2025-01-10 10:50:35 +01:00
parent 64c9f14ec9
commit c6756e13aa
11 changed files with 103 additions and 52 deletions

View File

@@ -3,19 +3,30 @@
public class Config
{
public string Name { get; set; }
public string LogPath { get; set; }
public string MSSQLConnectionString { get; set; }
public string MaxFileSizeInMegabytes { get; set; }
public string GDPictureVersion { get; set; }
public ZugferdConfig Zugferd { get; set; }
}
public class ZugferdConfig
{
public bool AllowFacturX { get; set; } = false;
public bool AllowXRechnung { get; set; } = false;
public bool AllowZugferd10 { get; set; } = true;
public bool AllowZugferd2x { get; set; } = true;
public bool AllowPeppolBISBill3x { get; set; } = false;
}
}

View File

@@ -40,6 +40,9 @@ namespace ZUGFeRDRESTService.Controllers
private bool _AllowXRechnung;
private bool _AllowZugferd2x;
private bool _AllowZugferd10;
private bool _AllowPeppolBISBill3x;
private string _GDPictureVersion;
public ValidationController(ILogging logging, IDatabase database, IConfiguration Config)
{
@@ -49,21 +52,22 @@ namespace ZUGFeRDRESTService.Controllers
_logger.Debug("Validation Controller initializing");
_database = database;
var oGDPictureKey = database.GetGDPictureKey();
var oPropertyMap = database.GetPropertyMap();
// Read config file and assign all option flags related to
// - Zugferd files
// - Filesizes
ParseConfig(Config);
_database = database;
var oGDPictureKey = database.GetGDPictureKey();
var oPropertyMap = database.GetPropertyMap();
_zugferd = new ZUGFeRDInterface(_logConfig, oGDPictureKey, new ZugferdOptions()
{
AllowFacturX_Filename = _AllowFacturX,
AllowXRechnung_Filename = _AllowXRechnung,
AllowZugferd_1_0_Schema = _AllowZugferd10,
AllowZugferd_2_x_Schema = _AllowZugferd2x
AllowZugferd_2_x_Schema = _AllowZugferd2x,
AllowPeppol_3017_Schema = _AllowPeppolBISBill3x
});
_props = new PropertyValues(_logConfig);
@@ -115,6 +119,19 @@ namespace ZUGFeRDRESTService.Controllers
_AllowZugferd10 = true;
}
if (!bool.TryParse(oZugferdConfig["AllowPeppolBISBill3x"], out _AllowPeppolBISBill3x))
{
_logger.Info("Configuration AllowPeppolBISBill3x was not set. Using default value [{0}]", false);
_AllowPeppolBISBill3x = false;
}
_GDPictureVersion = oAppConfig["GDPictureVersion"];
if (string.IsNullOrEmpty(_GDPictureVersion))
{
_logger.Info("Configuration GDPictureVersion was not set. Using default value [string.Empty]");
_GDPictureVersion = string.Empty;
}
if (!int.TryParse(oAppConfig["MaxFileSizeInMegabytes"], out _MaxFileSizeInMegabytes))
{
_logger.Info("Configuration MaxFileSizeInMegabytes was not set. Using default value [{0}]", MAX_FILE_SIZE_DEFAULT);
@@ -238,12 +255,17 @@ namespace ZUGFeRDRESTService.Controllers
};
// Determine if any errors should be sent in the response
List<string> oErrors = ex.ErrorType switch
var oErrors = new List<string>();
switch (ex.ErrorType)
{
// Errors contains the list of missing fields
ErrorType.MissingProperties => oPropertyResult.MissingProperties,
_ => new List<string>()
};
case ErrorType.MissingProperties:
oErrors.AddRange(from item in oPropertyResult.MissingProperties
select item.Description);
break;
default:
break;
}
_logger.Info($"Responding with message: [{oMessage}]");
return new ValidationResponse()

View File

@@ -1,14 +1,10 @@
using System;
using DigitalData.Modules.Database;
using DigitalData.Modules.Interfaces;
using DigitalData.Modules.Config;
using Microsoft.Extensions.Configuration;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Threading.Tasks;
using DigitalData.Modules.Database;
using DigitalData.Modules.Interfaces;
using Microsoft.AspNetCore.Mvc.Formatters;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;
using DigitalData.Modules.Logging;
namespace ZUGFeRDRESTService
{
@@ -18,6 +14,11 @@ namespace ZUGFeRDRESTService
private string _gdPictureKey = null;
private Dictionary<string, XmlItemProperty> _propertyMap = null;
private LogConfig _logConfig = null;
private string _connString;
private string _GDPictureVersion;
private const string QUERY_GET_GDPICTURE_KEY = "SELECT LICENSE FROM TBDD_3RD_PARTY_MODULES WHERE NAME = 'GDPICTURE'";
private const string QUERY_GET_PROPERTY_MAP = "SELECT * FROM TBDD_ZUGFERD_XML_ITEMS WHERE ACTIVE = 1 ORDER BY XML_PATH";
@@ -25,12 +26,14 @@ namespace ZUGFeRDRESTService
public Database(ILogging Logging, IConfiguration Config)
{
var oLogConfig = Logging.LogConfig;
_logConfig = Logging.LogConfig;
var oLogger = Logging.LogConfig.GetLogger();
var oAppConfig = Config.GetSection("Config");
_connString = oAppConfig["MSSQLConnectionString"];
_GDPictureVersion = oAppConfig["GDPictureVersion"];
oLogger.Debug("Establishing MSSQL Database connection..");
MSSQL = new MSSQLServer(oLogConfig, oAppConfig["MSSQLConnectionString"]);
MSSQL = new MSSQLServer(_logConfig, _connString);
oLogger.Debug("MSSQL Connection: [{0}]", MSSQL.CurrentConnectionString);
@@ -39,8 +42,7 @@ namespace ZUGFeRDRESTService
public string GetGDPictureKey()
{
if (_gdPictureKey == null)
_gdPictureKey = MSSQL.GetScalarValue(QUERY_GET_GDPICTURE_KEY).ToString();
_gdPictureKey = ConfigDbFunct.GetProductLicense("GDPICTURE", _GDPictureVersion, _logConfig, _connString);
return _gdPictureKey;
}

View File

@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace ZUGFeRDRESTService
{

View File

@@ -1,14 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using NLog.Web;
using DigitalData.Modules.Logging;
using System.Reflection;
namespace ZUGFeRDRESTService
{

View File

@@ -1,15 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
namespace ZUGFeRDRESTService
{

View File

@@ -22,8 +22,10 @@
"AllowZugferd10": true,
"AllowZugferd2x": false,
"AllowFacturX": false,
"AllowXRechnung": false
"AllowXRechnung": false,
"AllowPeppolBISBill3x": false
},
"MaxFileSizeInMegabytes": 25
"GDPictureVersion": "",
"MaxFileSizeInMegabytes": 25
}
}